@@ -109,10 +109,19 @@ abstract class ProcessClassesMojo extends AbstractMojo {
109
109
public void execute () throws MojoExecutionException {
110
110
validateTarget ();
111
111
validateFork ();
112
+
113
+ Properties config = new Properties ();
114
+ config .setProperty (RetrolambdaApi .BYTECODE_VERSION , "" + targetBytecodeVersions .get (target ));
115
+ config .setProperty (RetrolambdaApi .DEFAULT_METHODS , "" + defaultMethods );
116
+ config .setProperty (RetrolambdaApi .QUIET , "" + quiet );
117
+ config .setProperty (RetrolambdaApi .INPUT_DIR , getInputDir ().getAbsolutePath ());
118
+ config .setProperty (RetrolambdaApi .OUTPUT_DIR , getOutputDir ().getAbsolutePath ());
119
+ config .setProperty (RetrolambdaApi .CLASSPATH , getClasspath ());
120
+
112
121
if (fork ) {
113
- processClassesInForkedProcess ();
122
+ processClassesInForkedProcess (config );
114
123
} else {
115
- processClassesInCurrentProcess ();
124
+ processClassesInCurrentProcess (config );
116
125
}
117
126
}
118
127
@@ -131,27 +140,20 @@ private void validateFork() {
131
140
}
132
141
}
133
142
134
- private void processClassesInCurrentProcess () throws MojoExecutionException {
143
+ private void processClassesInCurrentProcess (Properties config ) throws MojoExecutionException {
135
144
getLog ().info ("Processing classes with Retrolambda" );
136
145
try {
137
- Properties p = new Properties ();
138
- p .setProperty (RetrolambdaApi .BYTECODE_VERSION , "" + targetBytecodeVersions .get (target ));
139
- p .setProperty (RetrolambdaApi .DEFAULT_METHODS , "" + defaultMethods );
140
- p .setProperty (RetrolambdaApi .QUIET , "" + quiet );
141
- p .setProperty (RetrolambdaApi .INPUT_DIR , getInputDir ().getAbsolutePath ());
142
- p .setProperty (RetrolambdaApi .OUTPUT_DIR , getOutputDir ().getAbsolutePath ());
143
- p .setProperty (RetrolambdaApi .CLASSPATH , getClasspath ());
144
146
// XXX: Retrolambda is compiled for Java 8, but this Maven plugin is compiled for Java 6,
145
147
// so we need to break the compile-time dependency using reflection
146
148
Class .forName ("net.orfjackal.retrolambda.Retrolambda" )
147
149
.getMethod ("run" , Properties .class )
148
- .invoke (null , p );
150
+ .invoke (null , config );
149
151
} catch (Throwable t ) {
150
152
throw new MojoExecutionException ("Failed to run Retrolambda" , t );
151
153
}
152
154
}
153
155
154
- private void processClassesInForkedProcess () throws MojoExecutionException {
156
+ private void processClassesInForkedProcess (Properties config ) throws MojoExecutionException {
155
157
String version = getRetrolambdaVersion ();
156
158
getLog ().info ("Retrieving Retrolambda " + version );
157
159
retrieveRetrolambdaJar (version );
@@ -160,6 +162,14 @@ private void processClassesInForkedProcess() throws MojoExecutionException {
160
162
String retrolambdaJar = getRetrolambdaJarPath ();
161
163
File classpathFile = getClasspathFile ();
162
164
try {
165
+ List <Element > args = new ArrayList <Element >();
166
+ for (Object key : config .keySet ()) {
167
+ Object value = config .get (key );
168
+ args .add (element ("arg" , attribute ("value" , "-D" + key + "=" + value )));
169
+ }
170
+ args .add (element ("arg" , attribute ("value" , "-javaagent:" + retrolambdaJar )));
171
+ args .add (element ("arg" , attribute ("value" , "-jar" )));
172
+ args .add (element ("arg" , attribute ("value" , retrolambdaJar )));
163
173
executeMojo (
164
174
plugin (groupId ("org.apache.maven.plugins" ),
165
175
artifactId ("maven-antrun-plugin" ),
@@ -171,15 +181,7 @@ private void processClassesInForkedProcess() throws MojoExecutionException {
171
181
attributes (
172
182
attribute ("executable" , getJavaCommand ()),
173
183
attribute ("failonerror" , "true" )),
174
- element ("arg" , attribute ("value" , "-Dretrolambda.bytecodeVersion=" + targetBytecodeVersions .get (target ))),
175
- element ("arg" , attribute ("value" , "-Dretrolambda.defaultMethods=" + defaultMethods )),
176
- element ("arg" , attribute ("value" , "-Dretrolambda.quiet=" + quiet )),
177
- element ("arg" , attribute ("value" , "-Dretrolambda.inputDir=" + getInputDir ().getAbsolutePath ())),
178
- element ("arg" , attribute ("value" , "-Dretrolambda.outputDir=" + getOutputDir ().getAbsolutePath ())),
179
- element ("arg" , attribute ("value" , "-Dretrolambda.classpathFile=" + classpathFile )),
180
- element ("arg" , attribute ("value" , "-javaagent:" + retrolambdaJar )),
181
- element ("arg" , attribute ("value" , "-jar" )),
182
- element ("arg" , attribute ("value" , retrolambdaJar ))))),
184
+ args .toArray (new Element [0 ])))),
183
185
executionEnvironment (project , session , pluginManager ));
184
186
} finally {
185
187
if (!classpathFile .delete ()) {
0 commit comments