diff --git a/devtools/maven/src/main/java/io/quarkus/maven/RunMojo.java b/devtools/maven/src/main/java/io/quarkus/maven/RunMojo.java index 2bbea14df481d..25207062f8663 100644 --- a/devtools/maven/src/main/java/io/quarkus/maven/RunMojo.java +++ b/devtools/maven/src/main/java/io/quarkus/maven/RunMojo.java @@ -1,6 +1,7 @@ package io.quarkus.maven; import java.nio.file.Path; +import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.List; @@ -31,6 +32,27 @@ public class RunMojo extends QuarkusBootstrapMojo { @Parameter Map systemProperties = Collections.emptyMap(); + /** + * Additional system properties meant to be passed on the command line in a formal like + * {@code -DsysProps=prop1=val1,prop2=val2} + */ + @Parameter(defaultValue = "${sysProps}") + String additionalSystemProperties; + + /** + * The list of environment variables with which the process will be launched. To be specified in a format like + * {@code -DsysProps=prop1=val1,prop2=val2} + */ + @Parameter(defaultValue = "${envVars}") + String environmentVariables; + + /** + * The list of program arguments with which the process will be launched. To be specified in a format like + * {@code -Dargs=1,2,k=v} + */ + @Parameter(defaultValue = "${args}") + String programArguments; + @Override protected boolean beforeExecute() throws MojoExecutionException, MojoFailureException { return true; @@ -88,6 +110,22 @@ public void accept(Map cmds) { throw new RuntimeException("Should never reach this!"); } List args = (List) cmd.get(0); + if (additionalSystemProperties != null) { + String[] props = additionalSystemProperties.split(","); + for (int i = props.length - 1; i >= 0; i--) { + String prop = props[i]; + String[] parts = prop.split("="); + if (parts.length == 2) { + // we want to set the system property write after the command + args.add(1, "-D" + prop); + } else { + throw new RuntimeException("Invalid system property: " + prop); + } + } + } + if (programArguments != null) { + args.addAll(Arrays.asList(programArguments.split(","))); + } if (getLog().isInfoEnabled()) { getLog().info("Executing \"" + String.join(" ", args) + "\""); } @@ -99,6 +137,17 @@ public void accept(Map cmds) { if (workingDirectory != null) { builder.directory(workingDirectory.toFile()); } + if (environmentVariables != null) { + String[] envVars = additionalSystemProperties.split(","); + for (String envVar : envVars) { + String[] parts = envVar.split("="); + if (parts.length == 2) { + builder.environment().put(parts[0], parts[1]); + } else { + throw new RuntimeException("Invalid environment variable: " + envVar); + } + } + } Process process = builder.start(); int exit = process.waitFor(); } catch (Exception e) {