Skip to content

Commit c443919

Browse files
committed
Add the ability to configure launch for quarkus:run
Closes: #46001
1 parent 4be415d commit c443919

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

devtools/maven/src/main/java/io/quarkus/maven/RunMojo.java

+49
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.quarkus.maven;
22

33
import java.nio.file.Path;
4+
import java.util.Arrays;
45
import java.util.Collections;
56
import java.util.HashSet;
67
import java.util.List;
@@ -31,6 +32,27 @@ public class RunMojo extends QuarkusBootstrapMojo {
3132
@Parameter
3233
Map<String, String> systemProperties = Collections.emptyMap();
3334

35+
/**
36+
* Additional system properties meant to be passed on the command line in a formal like
37+
* {@code -DsysProps=prop1=val1,prop2=val2}
38+
*/
39+
@Parameter(defaultValue = "${sysProps}")
40+
String additionalSystemProperties;
41+
42+
/**
43+
* The list of environment variables with which the process will be launched. To be specified in a format like
44+
* {@code -DsysProps=prop1=val1,prop2=val2}
45+
*/
46+
@Parameter(defaultValue = "${envVars}")
47+
String environmentVariables;
48+
49+
/**
50+
* The list of program arguments with which the process will be launched. To be specified in a format like
51+
* {@code -Dargs=1,2,k=v}
52+
*/
53+
@Parameter(defaultValue = "${args}")
54+
String programArguments;
55+
3456
@Override
3557
protected boolean beforeExecute() throws MojoExecutionException, MojoFailureException {
3658
return true;
@@ -88,6 +110,22 @@ public void accept(Map<String, List> cmds) {
88110
throw new RuntimeException("Should never reach this!");
89111
}
90112
List<String> args = (List<String>) cmd.get(0);
113+
if (additionalSystemProperties != null) {
114+
String[] props = additionalSystemProperties.split(",");
115+
for (int i = props.length - 1; i >= 0; i--) {
116+
String prop = props[i];
117+
String[] parts = prop.split("=");
118+
if (parts.length == 2) {
119+
// we want to set the system property write after the command
120+
args.add(1, "-D" + prop);
121+
} else {
122+
throw new RuntimeException("Invalid system property: " + prop);
123+
}
124+
}
125+
}
126+
if (programArguments != null) {
127+
args.addAll(Arrays.asList(programArguments.split(",")));
128+
}
91129
if (getLog().isInfoEnabled()) {
92130
getLog().info("Executing \"" + String.join(" ", args) + "\"");
93131
}
@@ -99,6 +137,17 @@ public void accept(Map<String, List> cmds) {
99137
if (workingDirectory != null) {
100138
builder.directory(workingDirectory.toFile());
101139
}
140+
if (environmentVariables != null) {
141+
String[] envVars = environmentVariables.split(",");
142+
for (String envVar : envVars) {
143+
String[] parts = envVar.split("=");
144+
if (parts.length == 2) {
145+
builder.environment().put(parts[0], parts[1]);
146+
} else {
147+
throw new RuntimeException("Invalid environment variable: " + envVar);
148+
}
149+
}
150+
}
102151
Process process = builder.start();
103152
int exit = process.waitFor();
104153
} catch (Exception e) {

0 commit comments

Comments
 (0)