1
1
package io .quarkus .maven ;
2
2
3
3
import java .nio .file .Path ;
4
+ import java .util .Arrays ;
4
5
import java .util .Collections ;
5
6
import java .util .HashSet ;
6
7
import java .util .List ;
@@ -31,6 +32,27 @@ public class RunMojo extends QuarkusBootstrapMojo {
31
32
@ Parameter
32
33
Map <String , String > systemProperties = Collections .emptyMap ();
33
34
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
+
34
56
@ Override
35
57
protected boolean beforeExecute () throws MojoExecutionException , MojoFailureException {
36
58
return true ;
@@ -88,6 +110,22 @@ public void accept(Map<String, List> cmds) {
88
110
throw new RuntimeException ("Should never reach this!" );
89
111
}
90
112
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
+ }
91
129
if (getLog ().isInfoEnabled ()) {
92
130
getLog ().info ("Executing \" " + String .join (" " , args ) + "\" " );
93
131
}
@@ -99,6 +137,17 @@ public void accept(Map<String, List> cmds) {
99
137
if (workingDirectory != null ) {
100
138
builder .directory (workingDirectory .toFile ());
101
139
}
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
+ }
102
151
Process process = builder .start ();
103
152
int exit = process .waitFor ();
104
153
} catch (Exception e ) {
0 commit comments