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 cleanup #18013

Merged
merged 3 commits into from
Jun 21, 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
9 changes: 7 additions & 2 deletions devtools/cli/src/main/java/io/quarkus/cli/Build.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.quarkus.cli.build.BaseBuildCommand;
import io.quarkus.cli.build.BuildSystemRunner;
import io.quarkus.cli.common.BuildOptions;
import io.quarkus.cli.common.PropertiesOptions;
import io.quarkus.cli.common.RunModeOption;
import io.quarkus.devtools.project.BuildTool;
import picocli.CommandLine;
Expand All @@ -23,6 +24,9 @@ public class Build extends BaseBuildCommand implements Callable<Integer> {
@CommandLine.ArgGroup(order = 1, exclusive = false, validate = false, heading = "%nBuild options%n")
BuildOptions buildOptions = new BuildOptions();

@CommandLine.ArgGroup(order = 2, exclusive = false, validate = false)
PropertiesOptions propertiesOptions = new PropertiesOptions();

@Parameters(description = "Additional parameters passed to the build system")
List<String> params = new ArrayList<>();

Expand All @@ -33,7 +37,8 @@ public Integer call() {
output.throwIfUnmatchedArguments(spec.commandLine());

BuildSystemRunner runner = getRunner();
BuildSystemRunner.BuildCommandArgs commandArgs = runner.prepareBuild(buildOptions, runMode, params);
BuildSystemRunner.BuildCommandArgs commandArgs = runner.prepareBuild(buildOptions, propertiesOptions, runMode,
params);

if (runMode.isDryRun()) {
dryRunBuild(spec.commandLine().getHelp(), runner.getBuildTool(), commandArgs);
Expand Down Expand Up @@ -68,7 +73,7 @@ public String toString() {
+ ", buildNative=" + buildOptions.buildNative
+ ", offline=" + buildOptions.offline
+ ", runTests=" + buildOptions.runTests
+ ", properties=" + buildOptions.properties
+ ", properties=" + propertiesOptions.properties
+ ", output=" + output
+ ", params=" + params + "]";
}
Expand Down
12 changes: 10 additions & 2 deletions devtools/cli/src/main/java/io/quarkus/cli/CreateApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
import java.util.HashSet;
import java.util.Set;

import io.quarkus.cli.common.PropertiesOptions;
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;
import io.quarkus.cli.create.TargetQuarkusVersionGroup;
import io.quarkus.devtools.commands.data.QuarkusCommandInvocation;
import io.quarkus.devtools.commands.handlers.CreateJBangProjectCommandHandler;
import io.quarkus.devtools.commands.handlers.CreateProjectCommandHandler;
Expand Down Expand Up @@ -41,6 +42,9 @@ public class CreateApp extends BaseCreateCommand {
@CommandLine.ArgGroup(order = 5, exclusive = false, heading = "%nCode Generation%n")
CodeGenerationGroup codeGeneration = new CodeGenerationGroup();

@CommandLine.ArgGroup(order = 6, exclusive = false, validate = false)
PropertiesOptions propertiesOptions = new PropertiesOptions();

@CommandLine.Parameters(arity = "0..1", paramLabel = "EXTENSION", description = "Extension(s) to add to the project.")
Set<String> extensions = new HashSet<>();

Expand All @@ -51,14 +55,17 @@ public Integer call() throws Exception {
output.throwIfUnmatchedArguments(spec.commandLine());

createProject.setSingleProjectGAV(gav);
createProject.setTestOutputDirectory(output.getTestDirectory());
createProject.projectRoot(); // verify project directories early

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

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

boolean success = true;

if (runMode.isDryRun()) {
Expand All @@ -85,6 +92,7 @@ public String toString() {
+ ", codeGeneration=" + codeGeneration
+ ", extensions=" + extensions
+ ", project=" + createProject
+ ", properties=" + propertiesOptions.properties
+ '}';
}
}
12 changes: 10 additions & 2 deletions devtools/cli/src/main/java/io/quarkus/cli/CreateCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
import java.util.HashSet;
import java.util.Set;

import io.quarkus.cli.common.PropertiesOptions;
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;
import io.quarkus.cli.create.TargetQuarkusVersionGroup;
import io.quarkus.devtools.commands.data.QuarkusCommandInvocation;
import io.quarkus.devtools.commands.handlers.CreateJBangProjectCommandHandler;
import io.quarkus.devtools.commands.handlers.CreateProjectCommandHandler;
Expand Down Expand Up @@ -41,6 +42,9 @@ public class CreateCli extends BaseCreateCommand {
@CommandLine.ArgGroup(order = 5, exclusive = false, heading = "%nCode Generation%n")
CodeGenerationGroup codeGeneration = new CodeGenerationGroup();

@CommandLine.ArgGroup(order = 6, exclusive = false, validate = false)
PropertiesOptions propertiesOptions = new PropertiesOptions();

@CommandLine.Parameters(arity = "0..1", paramLabel = "EXTENSION", description = "Extensions to add to project.")
Set<String> extensions = new HashSet<>();

Expand All @@ -51,14 +55,17 @@ public Integer call() throws Exception {
output.throwIfUnmatchedArguments(spec.commandLine());

createProject.setSingleProjectGAV(gav);
createProject.setTestOutputDirectory(output.getTestDirectory());
createProject.projectRoot(); // verify project directories early

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

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

boolean success = true;

// TODO: default extension (picocli)
Expand Down Expand Up @@ -88,6 +95,7 @@ public String toString() {
+ ", codeGeneration=" + codeGeneration
+ ", extensions=" + extensions
+ ", project=" + createProject
+ ", properties=" + propertiesOptions.properties
+ '}';
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package io.quarkus.cli;

import io.quarkus.cli.common.TargetQuarkusVersionGroup;
import io.quarkus.cli.create.BaseCreateCommand;
import io.quarkus.cli.create.CreateProjectMixin;
import io.quarkus.cli.create.ExtensionNameGenerationGroup;
import io.quarkus.cli.create.ExtensionTargetGVGroup;
import io.quarkus.cli.create.ExtensionTestGenerationGroup;
import io.quarkus.cli.create.TargetQuarkusVersionGroup;
import io.quarkus.devtools.project.BuildTool;
import io.quarkus.devtools.project.codegen.SourceType;
import picocli.CommandLine;
Expand Down
12 changes: 9 additions & 3 deletions devtools/cli/src/main/java/io/quarkus/cli/Dev.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.quarkus.cli.build.BuildSystemRunner;
import io.quarkus.cli.common.DebugOptions;
import io.quarkus.cli.common.DevOptions;
import io.quarkus.cli.common.PropertiesOptions;
import io.quarkus.devtools.project.BuildTool;
import picocli.CommandLine;
import picocli.CommandLine.Parameters;
Expand All @@ -20,7 +21,10 @@ public class Dev extends BaseBuildCommand implements Callable<Integer> {
@CommandLine.ArgGroup(order = 1, exclusive = false, heading = "%nDev Mode options%n")
DevOptions devOptions = new DevOptions();

@CommandLine.ArgGroup(order = 2, exclusive = false, validate = true, heading = "%nDebug options%n")
@CommandLine.ArgGroup(order = 2, exclusive = false, validate = false)
PropertiesOptions propertiesOptions = new PropertiesOptions();

@CommandLine.ArgGroup(order = 3, exclusive = false, validate = true, heading = "%nDebug options%n")
DebugOptions debugOptions = new DebugOptions();

@Parameters(description = "Parameters passed to the application.")
Expand All @@ -33,9 +37,10 @@ public Integer call() {
output.throwIfUnmatchedArguments(spec.commandLine());

BuildSystemRunner runner = getRunner();
BuildSystemRunner.BuildCommandArgs commandArgs = runner.prepareDevMode(devOptions, debugOptions, params);
BuildSystemRunner.BuildCommandArgs commandArgs = runner.prepareDevMode(devOptions, propertiesOptions, debugOptions,
params);

if (devOptions.dryRun) {
if (devOptions.isDryRun()) {
dryRunDev(spec.commandLine().getHelp(), runner.getBuildTool(), commandArgs);
return CommandLine.ExitCode.OK;
}
Expand Down Expand Up @@ -66,6 +71,7 @@ void dryRunDev(CommandLine.Help help, BuildTool buildTool, BuildSystemRunner.Bui
public String toString() {
return "Dev [debugOptions=" + debugOptions
+ ", devOptions=" + devOptions
+ ", properties=" + propertiesOptions.properties
+ ", output=" + output
+ ", params=" + params + "]";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import io.quarkus.cli.build.BuildSystemRunner;
import io.quarkus.cli.common.ListFormatOptions;
import io.quarkus.cli.common.RunModeOption;
import io.quarkus.cli.create.TargetQuarkusVersionGroup;
import io.quarkus.cli.common.TargetQuarkusVersionGroup;
import io.quarkus.devtools.commands.ListExtensions;
import io.quarkus.devtools.commands.data.QuarkusCommandException;
import io.quarkus.devtools.commands.data.QuarkusCommandOutcome;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ public class BaseBuildCommand {

public Path projectRoot() {
if (projectRoot == null) {
projectRoot = Paths.get(System.getProperty("user.dir")).toAbsolutePath();
projectRoot = output.getTestDirectory();
if (projectRoot == null) {
projectRoot = Paths.get(System.getProperty("user.dir")).toAbsolutePath();
}
}
return projectRoot;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.quarkus.cli.common.DevOptions;
import io.quarkus.cli.common.ListFormatOptions;
import io.quarkus.cli.common.OutputOptionMixin;
import io.quarkus.cli.common.PropertiesOptions;
import io.quarkus.cli.common.RegistryClientMixin;
import io.quarkus.cli.common.RunModeOption;
import io.quarkus.devtools.project.BuildTool;
Expand Down Expand Up @@ -88,9 +89,11 @@ Integer listExtensions(RunModeOption runMode, ListFormatOptions format, boolean

Integer removeExtension(RunModeOption runMode, Set<String> extensions) throws Exception;

BuildCommandArgs prepareBuild(BuildOptions buildOptions, RunModeOption runMode, List<String> params);
BuildCommandArgs prepareBuild(BuildOptions buildOptions, PropertiesOptions propertiesOptions, RunModeOption runMode,
List<String> params);

BuildCommandArgs prepareDevMode(DevOptions devOptions, DebugOptions debugOptions, List<String> params);
BuildCommandArgs prepareDevMode(DevOptions devOptions, PropertiesOptions propertiesOptions, DebugOptions debugOptions,
List<String> params);

Path getProjectRoot();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.quarkus.cli.common.DevOptions;
import io.quarkus.cli.common.ListFormatOptions;
import io.quarkus.cli.common.OutputOptionMixin;
import io.quarkus.cli.common.PropertiesOptions;
import io.quarkus.cli.common.RunModeOption;
import io.quarkus.devtools.project.BuildTool;
import io.quarkus.registry.config.RegistriesConfigLocator;
Expand Down Expand Up @@ -97,7 +98,8 @@ public Integer removeExtension(RunModeOption runMode, Set<String> extensions) {
}

@Override
public BuildCommandArgs prepareBuild(BuildOptions buildOptions, RunModeOption runMode, List<String> params) {
public BuildCommandArgs prepareBuild(BuildOptions buildOptions, PropertiesOptions propertiesOptions, RunModeOption runMode,
List<String> params) {
ArrayDeque<String> args = new ArrayDeque<>();
setGradleProperties(args, runMode.isBatchMode());

Expand All @@ -116,15 +118,16 @@ public BuildCommandArgs prepareBuild(BuildOptions buildOptions, RunModeOption ru
}

// add any other discovered properties
args.addAll(flattenMappedProperties(buildOptions.properties));
args.addAll(flattenMappedProperties(propertiesOptions.properties));
// Add any other unmatched arguments
args.addAll(params);

return prependExecutable(args);
}

@Override
public BuildCommandArgs prepareDevMode(DevOptions devOptions, DebugOptions debugOptions, List<String> params) {
public BuildCommandArgs prepareDevMode(DevOptions devOptions, PropertiesOptions propertiesOptions,
DebugOptions debugOptions, List<String> params) {
ArrayDeque<String> args = new ArrayDeque<>();
setGradleProperties(args, false);

Expand All @@ -140,7 +143,7 @@ public BuildCommandArgs prepareDevMode(DevOptions devOptions, DebugOptions debug
//TODO: addDebugArguments(args, debugOptions);

// add any other discovered properties
args.addAll(flattenMappedProperties(devOptions.properties));
args.addAll(flattenMappedProperties(propertiesOptions.properties));
// Add any other unmatched arguments
args.addAll(params);
return prependExecutable(args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.quarkus.cli.common.DevOptions;
import io.quarkus.cli.common.ListFormatOptions;
import io.quarkus.cli.common.OutputOptionMixin;
import io.quarkus.cli.common.PropertiesOptions;
import io.quarkus.cli.common.RegistryClientMixin;
import io.quarkus.cli.common.RunModeOption;
import io.quarkus.devtools.project.BuildTool;
Expand Down Expand Up @@ -58,7 +59,8 @@ public Integer removeExtension(RunModeOption runMode, Set<String> extensions) {
}

@Override
public BuildCommandArgs prepareBuild(BuildOptions buildOptions, RunModeOption runMode, List<String> params) {
public BuildCommandArgs prepareBuild(BuildOptions buildOptions, PropertiesOptions propertiesOptions, RunModeOption runMode,
List<String> params) {
ArrayDeque<String> args = new ArrayDeque<>();

if (buildOptions.offline) {
Expand All @@ -77,7 +79,8 @@ public BuildCommandArgs prepareBuild(BuildOptions buildOptions, RunModeOption ru
}

@Override
public BuildCommandArgs prepareDevMode(DevOptions devOptions, DebugOptions debugOptions, List<String> params) {
public BuildCommandArgs prepareDevMode(DevOptions devOptions, PropertiesOptions propertiesOptions,
DebugOptions debugOptions, List<String> params) {
throw new UnsupportedOperationException("Not there yet. ;)");
}

Expand Down
11 changes: 7 additions & 4 deletions devtools/cli/src/main/java/io/quarkus/cli/build/MavenRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import io.quarkus.cli.common.DevOptions;
import io.quarkus.cli.common.ListFormatOptions;
import io.quarkus.cli.common.OutputOptionMixin;
import io.quarkus.cli.common.PropertiesOptions;
import io.quarkus.cli.common.RunModeOption;
import io.quarkus.devtools.commands.AddExtensions;
import io.quarkus.devtools.commands.ListExtensions;
Expand Down Expand Up @@ -97,7 +98,8 @@ public Integer removeExtension(RunModeOption runMode, Set<String> extensions) th
}

@Override
public BuildCommandArgs prepareBuild(BuildOptions buildOptions, RunModeOption runMode, List<String> params) {
public BuildCommandArgs prepareBuild(BuildOptions buildOptions, PropertiesOptions propertiesOptions, RunModeOption runMode,
List<String> params) {
ArrayDeque<String> args = new ArrayDeque<>();
setMavenProperties(args, runMode.isBatchMode());

Expand All @@ -122,15 +124,16 @@ public BuildCommandArgs prepareBuild(BuildOptions buildOptions, RunModeOption ru
}

// add any other discovered properties
args.addAll(flattenMappedProperties(buildOptions.properties));
args.addAll(flattenMappedProperties(propertiesOptions.properties));
// Add any other unmatched arguments
args.addAll(params);

return prependExecutable(args);
}

@Override
public BuildCommandArgs prepareDevMode(DevOptions devOptions, DebugOptions debugOptions, List<String> params) {
public BuildCommandArgs prepareDevMode(DevOptions devOptions, PropertiesOptions propertiesOptions,
DebugOptions debugOptions, List<String> params) {
ArrayDeque<String> args = new ArrayDeque<>();
setMavenProperties(args, false);

Expand All @@ -145,7 +148,7 @@ public BuildCommandArgs prepareDevMode(DevOptions devOptions, DebugOptions debug

//TODO: addDebugArguments(args, debugOptions);

args.addAll(flattenMappedProperties(devOptions.properties));
args.addAll(flattenMappedProperties(propertiesOptions.properties));
// Add any other unmatched arguments
args.addAll(params);
return prependExecutable(args);
Expand Down
10 changes: 0 additions & 10 deletions devtools/cli/src/main/java/io/quarkus/cli/common/BuildOptions.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
package io.quarkus.cli.common;

import java.util.HashMap;
import java.util.Map;

import picocli.CommandLine;

public class BuildOptions {
public Map<String, String> properties = new HashMap<>();

@CommandLine.Option(order = 3, names = {
"--clean" }, description = "Perform clean as part of build. False by default.", negatable = true)
public boolean clean = false;
Expand All @@ -21,11 +16,6 @@ public class BuildOptions {
@CommandLine.Option(order = 6, names = { "--tests" }, description = "Run tests.", negatable = true)
public boolean runTests = true;

@CommandLine.Option(order = 7, names = "-D", mapFallbackValue = "", description = "Additional Java properties.")
void setProperty(Map<String, String> props) {
this.properties = props;
}

public boolean skipTests() {
return !runTests;
}
Expand Down
Loading