Skip to content

Commit fd5b63c

Browse files
committed
Use classpathFile in the Maven plugin
1 parent 7113a84 commit fd5b63c

File tree

1 file changed

+47
-21
lines changed

1 file changed

+47
-21
lines changed

retrolambda-maven-plugin/src/main/java/net/orfjackal/retrolambda/maven/ProcessClassesMojo.java

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
package net.orfjackal.retrolambda.maven;
66

7-
import com.google.common.base.Joiner;
7+
import com.google.common.base.*;
88
import com.google.common.collect.ImmutableMap;
9+
import com.google.common.io.Files;
910
import net.orfjackal.retrolambda.*;
1011
import org.apache.maven.artifact.DependencyResolutionRequiredException;
1112
import org.apache.maven.execution.MavenSession;
@@ -143,26 +144,33 @@ private void processClassesInForkedProcess() throws MojoExecutionException {
143144

144145
getLog().info("Processing classes with Retrolambda");
145146
String retrolambdaJar = getRetrolambdaJarPath();
146-
executeMojo(
147-
plugin(groupId("org.apache.maven.plugins"),
148-
artifactId("maven-antrun-plugin"),
149-
version("1.7")),
150-
goal("run"),
151-
configuration(element(
152-
"target",
153-
element("exec",
154-
attributes(
155-
attribute("executable", getJavaCommand()),
156-
attribute("failonerror", "true")),
157-
element("arg", attribute("value", "-Dretrolambda.bytecodeVersion=" + targetBytecodeVersions.get(target))),
158-
element("arg", attribute("value", "-Dretrolambda.defaultMethods=" + defaultMethods)),
159-
element("arg", attribute("value", "-Dretrolambda.inputDir=" + getInputDir().getAbsolutePath())),
160-
element("arg", attribute("value", "-Dretrolambda.outputDir=" + getOutputDir().getAbsolutePath())),
161-
element("arg", attribute("value", "-Dretrolambda.classpath=" + getClasspath())),
162-
element("arg", attribute("value", "-javaagent:" + retrolambdaJar)),
163-
element("arg", attribute("value", "-jar")),
164-
element("arg", attribute("value", retrolambdaJar))))),
165-
executionEnvironment(project, session, pluginManager));
147+
File classpathFile = getClasspathFile();
148+
try {
149+
executeMojo(
150+
plugin(groupId("org.apache.maven.plugins"),
151+
artifactId("maven-antrun-plugin"),
152+
version("1.7")),
153+
goal("run"),
154+
configuration(element(
155+
"target",
156+
element("exec",
157+
attributes(
158+
attribute("executable", getJavaCommand()),
159+
attribute("failonerror", "true")),
160+
element("arg", attribute("value", "-Dretrolambda.bytecodeVersion=" + targetBytecodeVersions.get(target))),
161+
element("arg", attribute("value", "-Dretrolambda.defaultMethods=" + defaultMethods)),
162+
element("arg", attribute("value", "-Dretrolambda.inputDir=" + getInputDir().getAbsolutePath())),
163+
element("arg", attribute("value", "-Dretrolambda.outputDir=" + getOutputDir().getAbsolutePath())),
164+
element("arg", attribute("value", "-Dretrolambda.classpathFile=" + classpathFile)),
165+
element("arg", attribute("value", "-javaagent:" + retrolambdaJar)),
166+
element("arg", attribute("value", "-jar")),
167+
element("arg", attribute("value", retrolambdaJar))))),
168+
executionEnvironment(project, session, pluginManager));
169+
} finally {
170+
if (!classpathFile.delete()) {
171+
getLog().warn("Unable to delete " + classpathFile);
172+
}
173+
}
166174
}
167175

168176
private void retrieveRetrolambdaJar(String version) throws MojoExecutionException {
@@ -220,6 +228,24 @@ private String getClasspath() {
220228
}
221229
}
222230

231+
private File getClasspathFile() {
232+
try {
233+
StringBuilder sb = new StringBuilder();
234+
for (String classpathElement : getClasspathElements()) {
235+
sb.append(classpathElement);
236+
sb.append("\n");
237+
}
238+
File file = File.createTempFile("retrolambda", "classpath");
239+
file.deleteOnExit();
240+
Files.write(sb.toString(), file, Charsets.UTF_8);
241+
return file;
242+
} catch (DependencyResolutionRequiredException e) {
243+
throw new RuntimeException(e);
244+
} catch (IOException e) {
245+
throw new RuntimeException(e);
246+
}
247+
}
248+
223249
private String getRetrolambdaJarPath() {
224250
return getRetrolambdaJarDir() + "/" + getRetrolambdaJarName();
225251
}

0 commit comments

Comments
 (0)