Skip to content

Commit

Permalink
CLI: more -D support; don't set user.dir
Browse files Browse the repository at this point in the history
  • Loading branch information
ebullient committed Jun 21, 2021
1 parent 49641a9 commit 9d105f6
Show file tree
Hide file tree
Showing 21 changed files with 286 additions and 228 deletions.
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
10 changes: 9 additions & 1 deletion devtools/cli/src/main/java/io/quarkus/cli/CreateApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.HashSet;
import java.util.Set;

import io.quarkus.cli.common.PropertiesOptions;
import io.quarkus.cli.create.BaseCreateCommand;
import io.quarkus.cli.create.CodeGenerationGroup;
import io.quarkus.cli.create.CreateProjectMixin;
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
+ '}';
}
}
10 changes: 9 additions & 1 deletion devtools/cli/src/main/java/io/quarkus/cli/CreateCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.HashSet;
import java.util.Set;

import io.quarkus.cli.common.PropertiesOptions;
import io.quarkus.cli.create.BaseCreateCommand;
import io.quarkus.cli.create.CodeGenerationGroup;
import io.quarkus.cli.create.CreateProjectMixin;
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
+ '}';
}
}
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 @@ -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
23 changes: 10 additions & 13 deletions devtools/cli/src/main/java/io/quarkus/cli/common/DevOptions.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package io.quarkus.cli.common;

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

import picocli.CommandLine;

public class DevOptions {
public Map<String, String> properties = new HashMap<>();
@CommandLine.Option(order = 2, names = { "--dry-run" }, description = "Show actions that would be taken.")
boolean dryRun = false;

@CommandLine.Option(order = 2, names = { "--dryrun" }, description = "Show actions that would be taken.")
public boolean dryRun = false;
// Allow the option variant, but don't crowd help
@CommandLine.Option(names = { "--dryrun" }, hidden = true)
boolean dryRun2 = false;

@CommandLine.Option(order = 3, names = {
"--clean" }, description = "Perform clean as part of build. False by default.", negatable = true)
Expand All @@ -19,18 +18,16 @@ public class DevOptions {
"--no-tests" }, description = "Toggle continuous testing mode. Enabled by default.", negatable = true, hidden = true)
public boolean runTests = true; // TODO: does this make sense re: continuous test?

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

public boolean skipTests() {
return !runTests;
}

public boolean isDryRun() {
return dryRun || dryRun2;
}

@Override
public String toString() {
return "DevOptions [clean=" + clean + ", properties=" + properties + ", tests=" + runTests
+ "]";
return "DevOptions [clean=" + clean + ", tests=" + runTests + "]";
}
}
Loading

0 comments on commit 9d105f6

Please sign in to comment.