-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
394 additions
and
13 deletions.
There are no files selected for viewing
118 changes: 118 additions & 0 deletions
118
devtools/maven/src/main/java/io/quarkus/maven/CreateJBangMojo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package io.quarkus.maven; | ||
|
||
import static org.fusesource.jansi.Ansi.ansi; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import org.apache.maven.plugin.AbstractMojo; | ||
import org.apache.maven.plugin.MojoExecutionException; | ||
import org.apache.maven.plugins.annotations.Component; | ||
import org.apache.maven.plugins.annotations.Mojo; | ||
import org.apache.maven.plugins.annotations.Parameter; | ||
import org.eclipse.aether.RepositorySystem; | ||
import org.eclipse.aether.RepositorySystemSession; | ||
import org.eclipse.aether.impl.RemoteRepositoryManager; | ||
import org.eclipse.aether.repository.RemoteRepository; | ||
|
||
import io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver; | ||
import io.quarkus.devtools.commands.CreateJBangProject; | ||
import io.quarkus.devtools.commands.data.QuarkusCommandException; | ||
import io.quarkus.platform.descriptor.QuarkusPlatformDescriptor; | ||
|
||
@Mojo(name = "create-jbang", requiresProject = false) | ||
public class CreateJBangMojo extends AbstractMojo { | ||
|
||
@Parameter(property = "noJBangWrapper", defaultValue = "false") | ||
private boolean noJBangWrapper; | ||
|
||
/** | ||
* Group ID of the target platform BOM | ||
*/ | ||
@Parameter(property = "platformGroupId", required = false) | ||
private String bomGroupId; | ||
|
||
/** | ||
* Artifact ID of the target platform BOM | ||
*/ | ||
@Parameter(property = "platformArtifactId", required = false) | ||
private String bomArtifactId; | ||
|
||
/** | ||
* Version of the target platform BOM | ||
*/ | ||
@Parameter(property = "platformVersion", required = false) | ||
private String bomVersion; | ||
|
||
@Parameter(property = "extensions") | ||
private Set<String> extensions; | ||
|
||
@Parameter(property = "outputDirectory", defaultValue = "${basedir}/jbang-with-quarkus") | ||
private File outputDirectory; | ||
|
||
@Parameter(defaultValue = "${project.remoteProjectRepositories}", readonly = true, required = true) | ||
private List<RemoteRepository> repos; | ||
|
||
@Parameter(defaultValue = "${repositorySystemSession}", readonly = true) | ||
private RepositorySystemSession repoSession; | ||
|
||
@Component | ||
private RepositorySystem repoSystem; | ||
|
||
@Component | ||
RemoteRepositoryManager remoteRepoManager; | ||
|
||
@Override | ||
public void execute() throws MojoExecutionException { | ||
try { | ||
Files.createDirectories(outputDirectory.toPath()); | ||
} catch (IOException e) { | ||
throw new MojoExecutionException("Could not create directory " + outputDirectory, e); | ||
} | ||
|
||
File projectRoot = outputDirectory; | ||
final Path projectDirPath = projectRoot.toPath(); | ||
|
||
final MavenArtifactResolver mvn; | ||
try { | ||
mvn = MavenArtifactResolver.builder() | ||
.setRepositorySystem(repoSystem) | ||
.setRepositorySystemSession(repoSession) | ||
.setRemoteRepositories(repos) | ||
.setRemoteRepositoryManager(remoteRepoManager) | ||
.build(); | ||
} catch (Exception e) { | ||
throw new MojoExecutionException("Failed to initialize Maven artifact resolver", e); | ||
} | ||
|
||
final QuarkusPlatformDescriptor platform = CreateUtils.resolvePlatformDescriptor(bomGroupId, bomArtifactId, bomVersion, | ||
mvn, getLog()); | ||
|
||
final CreateJBangProject createJBangProject = new CreateJBangProject(projectDirPath, platform) | ||
.extensions(extensions) | ||
.setValue("noJBangWrapper", noJBangWrapper); | ||
|
||
boolean success; | ||
|
||
try { | ||
success = createJBangProject.execute().isSuccess(); | ||
} catch (QuarkusCommandException e) { | ||
throw new MojoExecutionException("Failed to generate JBang Quarkus project", e); | ||
} | ||
|
||
if (success) { | ||
getLog().info(""); | ||
getLog().info("========================================================================"); | ||
getLog().warn(ansi().a("Quarkus JBang project is an experimental feature.").toString()); | ||
getLog().info("========================================================================"); | ||
getLog().info(""); | ||
} else { | ||
throw new MojoExecutionException( | ||
"Failed to generate JBang Quarkus project"); | ||
} | ||
} | ||
} |
4 changes: 1 addition & 3 deletions
4
...tarts/quarkus-jbang/code/jbang-resteasy-code/java/src/{resource.class-name}.tpl.qute.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
.../tools/devtools-common/src/main/java/io/quarkus/devtools/commands/CreateJBangProject.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package io.quarkus.devtools.commands; | ||
|
||
import static io.quarkus.devtools.project.codegen.ProjectGenerator.EXTENSIONS; | ||
import static java.util.Objects.requireNonNull; | ||
|
||
import io.quarkus.devtools.commands.data.QuarkusCommandException; | ||
import io.quarkus.devtools.commands.data.QuarkusCommandInvocation; | ||
import io.quarkus.devtools.commands.data.QuarkusCommandOutcome; | ||
import io.quarkus.devtools.commands.handlers.CreateJBangProjectCommandHandler; | ||
import io.quarkus.devtools.project.BuildTool; | ||
import io.quarkus.devtools.project.QuarkusProject; | ||
import io.quarkus.platform.descriptor.QuarkusPlatformDescriptor; | ||
import java.nio.file.Path; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
public class CreateJBangProject { | ||
public static final String NAME = "create-jbang"; | ||
|
||
private final Path projectDirPath; | ||
private final QuarkusPlatformDescriptor platformDescr; | ||
private BuildTool buildTool = BuildTool.MAVEN; | ||
|
||
private Set<String> extensions = new HashSet<>(); | ||
private Map<String, Object> values = new HashMap<>(); | ||
|
||
public CreateJBangProject(Path projectDirPath, QuarkusPlatformDescriptor platformDescr) { | ||
this.projectDirPath = requireNonNull(projectDirPath, "projectDirPath is required"); | ||
this.platformDescr = requireNonNull(platformDescr, "platformDescr is required"); | ||
} | ||
|
||
public CreateJBangProject extensions(Set<String> extensions) { | ||
if (extensions == null) { | ||
return this; | ||
} | ||
this.extensions.addAll(extensions); | ||
return this; | ||
} | ||
|
||
public CreateJBangProject setValue(String name, Object value) { | ||
if (value != null) { | ||
values.put(name, value); | ||
} | ||
return this; | ||
} | ||
|
||
public QuarkusCommandOutcome execute() throws QuarkusCommandException { | ||
setValue(EXTENSIONS, extensions); | ||
final QuarkusProject quarkusProject = QuarkusProject.of(projectDirPath, platformDescr, buildTool); | ||
final QuarkusCommandInvocation invocation = new QuarkusCommandInvocation(quarkusProject, values); | ||
return new CreateJBangProjectCommandHandler().execute(invocation); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...src/main/java/io/quarkus/devtools/commands/handlers/CreateJBangProjectCommandHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package io.quarkus.devtools.commands.handlers; | ||
|
||
import static io.quarkus.devtools.commands.handlers.QuarkusCommandHandlers.computeCoordsFromQuery; | ||
|
||
import io.quarkus.bootstrap.model.AppArtifactCoords; | ||
import io.quarkus.devtools.codestarts.jbang.QuarkusJBangCodestartCatalog; | ||
import io.quarkus.devtools.codestarts.jbang.QuarkusJBangCodestartProjectInput; | ||
import io.quarkus.devtools.commands.data.QuarkusCommandException; | ||
import io.quarkus.devtools.commands.data.QuarkusCommandInvocation; | ||
import io.quarkus.devtools.commands.data.QuarkusCommandOutcome; | ||
import io.quarkus.devtools.messagewriter.MessageIcons; | ||
import io.quarkus.devtools.project.codegen.ProjectGenerator; | ||
import io.quarkus.platform.descriptor.QuarkusPlatformDescriptor; | ||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
public class CreateJBangProjectCommandHandler implements QuarkusCommandHandler { | ||
@Override | ||
public QuarkusCommandOutcome execute(QuarkusCommandInvocation invocation) throws QuarkusCommandException { | ||
final Set<String> extensionsQuery = invocation.getValue(ProjectGenerator.EXTENSIONS, Collections.emptySet()); | ||
final List<AppArtifactCoords> extensionsToAdd = computeCoordsFromQuery(invocation, extensionsQuery); | ||
if (extensionsToAdd == null) { | ||
throw new QuarkusCommandException("Failed to create project because of invalid extensions"); | ||
} | ||
|
||
final QuarkusJBangCodestartProjectInput input = QuarkusJBangCodestartProjectInput.builder() | ||
.addExtensions(extensionsToAdd) | ||
.setNoJBangWrapper(invocation.getBooleanValue("noJBangWrapper")) | ||
.putData("quarkus.version", invocation.getPlatformDescriptor().getBomVersion()) | ||
.build(); | ||
|
||
final Path projectDir = invocation.getQuarkusProject().getProjectDirPath(); | ||
try { | ||
invocation.log().info("-----------"); | ||
if (!extensionsToAdd.isEmpty()) { | ||
invocation.log().info("selected extensions: \n" | ||
+ extensionsToAdd.stream().map(e -> "- " + e.getGroupId() + ":" + e.getArtifactId() + "\n") | ||
.collect(Collectors.joining())); | ||
} | ||
getCatalog(invocation.getPlatformDescriptor()).createProject(input).generate(projectDir); | ||
invocation.log() | ||
.info("\n-----------\n" + MessageIcons.NOOP_ICON | ||
+ " jbang project has been successfully generated in:\n--> " | ||
+ invocation.getQuarkusProject().getProjectDirPath().toString() + "\n-----------"); | ||
} catch (IOException e) { | ||
throw new QuarkusCommandException("Failed to create JBang project", e); | ||
} | ||
return QuarkusCommandOutcome.success(); | ||
} | ||
|
||
private QuarkusJBangCodestartCatalog getCatalog(QuarkusPlatformDescriptor platformDescriptor) throws IOException { | ||
return QuarkusJBangCodestartCatalog.fromQuarkusPlatformDescriptor(platformDescriptor); | ||
} | ||
} |
Oops, something went wrong.