Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI: nix CreateProjectMixin; fix base commands #20487

Merged
merged 1 commit into from
Oct 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions devtools/cli/src/main/java/io/quarkus/cli/Create.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package io.quarkus.cli;

import java.util.List;
import java.util.concurrent.Callable;

import io.quarkus.cli.create.BaseCreateCommand;
import io.quarkus.cli.common.OutputOptionMixin;
import picocli.CommandLine;
import picocli.CommandLine.ParseResult;
import picocli.CommandLine.Unmatched;
Expand All @@ -11,12 +12,17 @@
CreateApp.class,
CreateCli.class,
CreateExtension.class }, headerHeading = "%n", commandListHeading = "%nCommands:%n", synopsisHeading = "%nUsage: ", optionListHeading = "%nOptions:%n")
public class Create extends BaseCreateCommand {
public class Create implements Callable<Integer> {

@CommandLine.Mixin
protected OutputOptionMixin output;

@CommandLine.Spec
protected CommandLine.Model.CommandSpec spec;

@Unmatched // avoids throwing errors for unmatched arguments
List<String> unmatchedArgs;

@Override
public Integer call() throws Exception {
output.info("Creating an app (default project type, see --help).");

Expand Down
22 changes: 9 additions & 13 deletions devtools/cli/src/main/java/io/quarkus/cli/CreateApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import io.quarkus.cli.common.TargetQuarkusVersionGroup;
import io.quarkus.cli.create.BaseCreateCommand;
import io.quarkus.cli.create.CodeGenerationGroup;
import io.quarkus.cli.create.CreateProjectMixin;
import io.quarkus.cli.create.TargetBuildToolGroup;
import io.quarkus.cli.create.TargetGAVGroup;
import io.quarkus.cli.create.TargetLanguageGroup;
Expand All @@ -25,9 +24,6 @@
+ "it will use Maven to build an artifact with GROUP-ID='org.acme', ARTIFACT-ID='code-with-quarkus', and VERSION='1.0.0-SNAPSHOT'."
+ "%n" }, headerHeading = "%n", commandListHeading = "%nCommands:%n", synopsisHeading = "%nUsage: ", parameterListHeading = "%n", optionListHeading = "Options:%n")
public class CreateApp extends BaseCreateCommand {
@Mixin
CreateProjectMixin createProject;

@Mixin
TargetGAVGroup gav = new TargetGAVGroup();

Expand Down Expand Up @@ -56,24 +52,24 @@ public Integer call() throws Exception {
output.debug("Creating a new project with initial parameters: %s", this);
output.throwIfUnmatchedArguments(spec.commandLine());

createProject.setSingleProjectGAV(gav);
createProject.setTestOutputDirectory(output.getTestDirectory());
if (createProject.checkProjectRootAlreadyExists(output, runMode.isDryRun())) {
setSingleProjectGAV(gav);
setTestOutputDirectory(output.getTestDirectory());
if (checkProjectRootAlreadyExists(runMode.isDryRun())) {
return CommandLine.ExitCode.USAGE;
}

BuildTool buildTool = targetBuildTool.getBuildTool(BuildTool.MAVEN);
SourceType sourceType = targetLanguage.getSourceType(buildTool, extensions, output);
createProject.setSourceTypeExtensions(extensions, sourceType);
createProject.setCodegenOptions(codeGeneration);
setSourceTypeExtensions(extensions, sourceType);
setCodegenOptions(codeGeneration);

QuarkusCommandInvocation invocation = createProject.build(buildTool, targetQuarkusVersion,
output, propertiesOptions.properties);
QuarkusCommandInvocation invocation = build(buildTool, targetQuarkusVersion,
propertiesOptions.properties);

boolean success = true;

if (runMode.isDryRun()) {
createProject.dryRun(buildTool, invocation, output);
dryRun(buildTool, invocation, output);
} else if (buildTool == BuildTool.JBANG) {
success = new CreateJBangProjectCommandHandler().execute(invocation).isSuccess();
} else { // maven or gradle
Expand Down Expand Up @@ -103,7 +99,7 @@ public String toString() {
+ ", targetLanguage=" + targetLanguage
+ ", codeGeneration=" + codeGeneration
+ ", extensions=" + extensions
+ ", project=" + createProject
+ ", project=" + super.toString()
+ ", properties=" + propertiesOptions.properties
+ '}';
}
Expand Down
22 changes: 9 additions & 13 deletions devtools/cli/src/main/java/io/quarkus/cli/CreateCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import io.quarkus.cli.common.TargetQuarkusVersionGroup;
import io.quarkus.cli.create.BaseCreateCommand;
import io.quarkus.cli.create.CodeGenerationGroup;
import io.quarkus.cli.create.CreateProjectMixin;
import io.quarkus.cli.create.TargetBuildToolGroup;
import io.quarkus.cli.create.TargetGAVGroup;
import io.quarkus.cli.create.TargetLanguageGroup;
Expand All @@ -25,9 +24,6 @@
+ "it will use Maven to build an artifact with GROUP-ID='org.acme', ARTIFACT-ID='code-with-quarkus', and VERSION='1.0.0-SNAPSHOT'."
+ "%n" }, headerHeading = "%n", commandListHeading = "%nCommands:%n", synopsisHeading = "%nUsage: ", parameterListHeading = "%n", optionListHeading = "Options:%n")
public class CreateCli extends BaseCreateCommand {
@Mixin
CreateProjectMixin createProject;

@Mixin
TargetGAVGroup gav = new TargetGAVGroup();

Expand Down Expand Up @@ -58,23 +54,23 @@ public Integer call() throws Exception {

extensions.add("picocli"); // make sure picocli is selected.

createProject.setSingleProjectGAV(gav);
createProject.setTestOutputDirectory(output.getTestDirectory());
if (createProject.checkProjectRootAlreadyExists(output, false)) {
setSingleProjectGAV(gav);
setTestOutputDirectory(output.getTestDirectory());
if (checkProjectRootAlreadyExists(false)) {
return CommandLine.ExitCode.USAGE;
}

BuildTool buildTool = targetBuildTool.getBuildTool(BuildTool.MAVEN);
SourceType sourceType = targetLanguage.getSourceType(buildTool, extensions, output);
createProject.setSourceTypeExtensions(extensions, sourceType);
createProject.setCodegenOptions(codeGeneration);
setSourceTypeExtensions(extensions, sourceType);
setCodegenOptions(codeGeneration);

QuarkusCommandInvocation invocation = createProject.build(buildTool, targetQuarkusVersion,
output, propertiesOptions.properties);
QuarkusCommandInvocation invocation = build(buildTool, targetQuarkusVersion,
propertiesOptions.properties);

boolean success = true;
if (runMode.isDryRun()) {
createProject.dryRun(buildTool, invocation, output);
dryRun(buildTool, invocation, output);
} else if (BuildTool.JBANG.equals(buildTool)) {
success = new CreateJBangProjectCommandHandler().execute(invocation).isSuccess();
} else {
Expand Down Expand Up @@ -104,7 +100,7 @@ public String toString() {
+ ", targetLanguage=" + targetLanguage
+ ", codeGeneration=" + codeGeneration
+ ", extensions=" + extensions
+ ", project=" + createProject
+ ", project=" + super.toString()
+ ", properties=" + propertiesOptions.properties
+ '}';
}
Expand Down
18 changes: 7 additions & 11 deletions devtools/cli/src/main/java/io/quarkus/cli/CreateExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import io.quarkus.cli.common.PropertiesOptions;
import io.quarkus.cli.common.TargetQuarkusVersionGroup;
import io.quarkus.cli.create.BaseCreateCommand;
import io.quarkus.cli.create.CreateProjectMixin;
import io.quarkus.cli.create.ExtensionGAVMixin;
import io.quarkus.cli.create.ExtensionNameGenerationGroup;
import io.quarkus.cli.create.ExtensionTestGenerationGroup;
Expand Down Expand Up @@ -73,9 +72,6 @@ public class CreateExtension extends BaseCreateCommand {
@CommandLine.Spec
protected CommandLine.Model.CommandSpec spec;

@Mixin
CreateProjectMixin createProject;

@Mixin
ExtensionGAVMixin gav = new ExtensionGAVMixin();

Expand All @@ -97,19 +93,19 @@ public Integer call() throws Exception {
output.debug("Creating a new extension project with initial parameters: %s", this);
output.throwIfUnmatchedArguments(spec.commandLine());

createProject.setExtensionId(gav.getExtensionId());
createProject.setTestOutputDirectory(output.getTestDirectory());
if (createProject.checkProjectRootAlreadyExists(output, runMode.isDryRun())) {
setExtensionId(gav.getExtensionId());
setTestOutputDirectory(output.getTestDirectory());
if (checkProjectRootAlreadyExists(runMode.isDryRun())) {
return CommandLine.ExitCode.USAGE;
}

BuildTool buildTool = BuildTool.MAVEN;
QuarkusProject quarkusProject = createProject.getExtensionVersions(buildTool, targetQuarkusVersion, output);
QuarkusProject quarkusProject = getExtensionVersions(buildTool, targetQuarkusVersion);
ExtensionCatalog catalog = quarkusProject.getExtensionsCatalog();
ArtifactCoords quarkusBom = catalog.getBom();

final CreateExtensionCommandHandler createExtension = new io.quarkus.devtools.commands.CreateExtension(
createProject.outputDirectory())
outputDirectory())
.extensionId(gav.getExtensionId())
.groupId(gav.getGroupId())
.version(gav.getVersion())
Expand Down Expand Up @@ -153,12 +149,12 @@ public void dryRun(BuildTool buildTool, CreateExtensionCommandHandler invocation
CommandLine.Help help = spec.commandLine().getHelp();
output.printText(new String[] {
"\nA new extension would have been created in",
"\t" + createProject.outputDirectory().toString(),
"\t" + outputDirectory().toString(),
"\nThe extension would have been created using the following settings:\n"
});
Map<String, String> dryRunOutput = new TreeMap<>();
for (Map.Entry<String, Object> entry : invocation.getData().entrySet()) {
dryRunOutput.put(createProject.prettyName(entry.getKey()), entry.getValue().toString());
dryRunOutput.put(prettyName(entry.getKey()), entry.getValue().toString());
}
dryRunOutput.put("Skip Unit Test", "" + testGeneration.skipUnitTest());
dryRunOutput.put("Skip Dev-mode Test", "" + testGeneration.skipDevModeTest());
Expand Down
10 changes: 8 additions & 2 deletions devtools/cli/src/main/java/io/quarkus/cli/ProjectExtensions.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.util.concurrent.Callable;
import java.util.stream.Collectors;

import io.quarkus.cli.build.BaseBuildCommand;
import io.quarkus.cli.common.OutputOptionMixin;
import picocli.CommandLine;
import picocli.CommandLine.ParseResult;
import picocli.CommandLine.Unmatched;
Expand All @@ -15,7 +15,13 @@
ProjectExtensionsCategories.class,
ProjectExtensionsAdd.class,
ProjectExtensionsRemove.class }, headerHeading = "%n", commandListHeading = "%nCommands:%n", synopsisHeading = "%nUsage: ", optionListHeading = "Options:%n")
public class ProjectExtensions extends BaseBuildCommand implements Callable<Integer> {
public class ProjectExtensions implements Callable<Integer> {

@CommandLine.Mixin
protected OutputOptionMixin output;

@CommandLine.Spec
protected CommandLine.Model.CommandSpec spec;

@Unmatched // avoids throwing errors for unmatched arguments
List<String> unmatchedArgs;
Expand Down
12 changes: 9 additions & 3 deletions devtools/cli/src/main/java/io/quarkus/cli/Registry.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package io.quarkus.cli;

import java.util.List;
import java.util.concurrent.Callable;

import io.quarkus.cli.registry.BaseRegistryCommand;
import io.quarkus.cli.common.OutputOptionMixin;
import picocli.CommandLine;
import picocli.CommandLine.ParseResult;
import picocli.CommandLine.Unmatched;
Expand All @@ -11,12 +12,17 @@
RegistryListCommand.class,
RegistryAddCommand.class,
RegistryRemoveCommand.class }, headerHeading = "%n", commandListHeading = "%nCommands:%n", synopsisHeading = "%nUsage: ", optionListHeading = "%nOptions:%n")
public class Registry extends BaseRegistryCommand {
public class Registry implements Callable<Integer> {

@CommandLine.Mixin
protected OutputOptionMixin output;

@CommandLine.Spec
protected CommandLine.Model.CommandSpec spec;

@Unmatched // avoids throwing errors for unmatched arguments
List<String> unmatchedArgs;

@Override
public Integer call() throws Exception {
final ParseResult result = spec.commandLine().getParseResult();
final CommandLine appCommand = spec.subcommands().get("list");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.util.stream.Collectors;

import io.quarkus.cli.registry.BaseRegistryCommand;
import io.quarkus.cli.registry.RegistryClientMixin;
import io.quarkus.registry.config.RegistriesConfig;
import io.quarkus.registry.config.RegistriesConfigLocator;
import io.quarkus.registry.config.RegistryConfig;
Expand All @@ -20,9 +19,6 @@
+ "This command will add a Quarkus extension registry to the registry client configuration unless it's already present.", headerHeading = "%n", commandListHeading = "%nCommands:%n", synopsisHeading = "%nUsage: ", parameterListHeading = "%n", optionListHeading = "Options:%n")
public class RegistryAddCommand extends BaseRegistryCommand {

@CommandLine.Mixin
protected RegistryClientMixin registryClient;

@CommandLine.Parameters(arity = "0..1", paramLabel = "REGISTRY-ID[,REGISTRY-ID]", description = "Registry ID to add to the registry client configuration%n"
+ " Example:%n"
+ " registry.quarkus.io%n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.nio.file.Path;

import io.quarkus.cli.registry.BaseRegistryCommand;
import io.quarkus.cli.registry.RegistryClientMixin;
import io.quarkus.registry.ExtensionCatalogResolver;
import io.quarkus.registry.catalog.Platform;
import io.quarkus.registry.catalog.PlatformCatalog;
Expand All @@ -17,9 +16,6 @@
+ "This command will list currently enabled Quarkus extension registries.", headerHeading = "%n", commandListHeading = "%nCommands:%n", synopsisHeading = "%nUsage: ", parameterListHeading = "%n", optionListHeading = "Options:%n")
public class RegistryListCommand extends BaseRegistryCommand {

@CommandLine.Mixin
protected RegistryClientMixin registryClient;

@CommandLine.Option(names = {
"--streams" }, description = "List currently recommended platform streams", defaultValue = "false")
boolean streams;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.util.Map;

import io.quarkus.cli.registry.BaseRegistryCommand;
import io.quarkus.cli.registry.RegistryClientMixin;
import io.quarkus.registry.config.RegistriesConfig;
import io.quarkus.registry.config.RegistriesConfigLocator;
import io.quarkus.registry.config.RegistryConfig;
Expand All @@ -19,9 +18,6 @@
+ "This command will remove a Quarkus extension registry from the registry client configuration.", headerHeading = "%n", commandListHeading = "%nCommands:%n", synopsisHeading = "%nUsage: ", parameterListHeading = "%n", optionListHeading = "Options:%n")
public class RegistryRemoveCommand extends BaseRegistryCommand {

@CommandLine.Mixin
protected RegistryClientMixin registryClient;

@CommandLine.Parameters(arity = "0..1", paramLabel = "REGISTRY-ID[,REGISTRY-ID]", description = "Registry ID to remove from the registry client configuration%n"
+ " Example:%n"
+ " registry.quarkus.io%n"
Expand Down
Loading