Skip to content

Commit

Permalink
Add the ability to configure launch for quarkus:run
Browse files Browse the repository at this point in the history
  • Loading branch information
geoand committed Jan 31, 2025
1 parent 4be415d commit c81a840
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions devtools/maven/src/main/java/io/quarkus/maven/RunMojo.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -31,6 +32,27 @@ public class RunMojo extends QuarkusBootstrapMojo {
@Parameter
Map<String, String> 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;
Expand Down Expand Up @@ -88,6 +110,22 @@ public void accept(Map<String, List> cmds) {
throw new RuntimeException("Should never reach this!");
}
List<String> args = (List<String>) 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) + "\"");
}
Expand All @@ -99,6 +137,17 @@ public void accept(Map<String, List> 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) {
Expand Down

0 comments on commit c81a840

Please sign in to comment.