Skip to content

Commit

Permalink
Remove duplicate parameter mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
luontola committed Dec 27, 2017
1 parent 7943690 commit c534b94
Showing 1 changed file with 23 additions and 21 deletions.
Expand Up @@ -109,10 +109,19 @@ abstract class ProcessClassesMojo extends AbstractMojo {
public void execute() throws MojoExecutionException { public void execute() throws MojoExecutionException {
validateTarget(); validateTarget();
validateFork(); validateFork();

Properties config = new Properties();
config.setProperty(RetrolambdaApi.BYTECODE_VERSION, "" + targetBytecodeVersions.get(target));
config.setProperty(RetrolambdaApi.DEFAULT_METHODS, "" + defaultMethods);
config.setProperty(RetrolambdaApi.QUIET, "" + quiet);
config.setProperty(RetrolambdaApi.INPUT_DIR, getInputDir().getAbsolutePath());
config.setProperty(RetrolambdaApi.OUTPUT_DIR, getOutputDir().getAbsolutePath());
config.setProperty(RetrolambdaApi.CLASSPATH, getClasspath());

if (fork) { if (fork) {
processClassesInForkedProcess(); processClassesInForkedProcess(config);
} else { } else {
processClassesInCurrentProcess(); processClassesInCurrentProcess(config);
} }
} }


Expand All @@ -131,27 +140,20 @@ private void validateFork() {
} }
} }


private void processClassesInCurrentProcess() throws MojoExecutionException { private void processClassesInCurrentProcess(Properties config) throws MojoExecutionException {
getLog().info("Processing classes with Retrolambda"); getLog().info("Processing classes with Retrolambda");
try { try {
Properties p = new Properties();
p.setProperty(RetrolambdaApi.BYTECODE_VERSION, "" + targetBytecodeVersions.get(target));
p.setProperty(RetrolambdaApi.DEFAULT_METHODS, "" + defaultMethods);
p.setProperty(RetrolambdaApi.QUIET, "" + quiet);
p.setProperty(RetrolambdaApi.INPUT_DIR, getInputDir().getAbsolutePath());
p.setProperty(RetrolambdaApi.OUTPUT_DIR, getOutputDir().getAbsolutePath());
p.setProperty(RetrolambdaApi.CLASSPATH, getClasspath());
// XXX: Retrolambda is compiled for Java 8, but this Maven plugin is compiled for Java 6, // XXX: Retrolambda is compiled for Java 8, but this Maven plugin is compiled for Java 6,
// so we need to break the compile-time dependency using reflection // so we need to break the compile-time dependency using reflection
Class.forName("net.orfjackal.retrolambda.Retrolambda") Class.forName("net.orfjackal.retrolambda.Retrolambda")
.getMethod("run", Properties.class) .getMethod("run", Properties.class)
.invoke(null, p); .invoke(null, config);
} catch (Throwable t) { } catch (Throwable t) {
throw new MojoExecutionException("Failed to run Retrolambda", t); throw new MojoExecutionException("Failed to run Retrolambda", t);
} }
} }


private void processClassesInForkedProcess() throws MojoExecutionException { private void processClassesInForkedProcess(Properties config) throws MojoExecutionException {
String version = getRetrolambdaVersion(); String version = getRetrolambdaVersion();
getLog().info("Retrieving Retrolambda " + version); getLog().info("Retrieving Retrolambda " + version);
retrieveRetrolambdaJar(version); retrieveRetrolambdaJar(version);
Expand All @@ -160,6 +162,14 @@ private void processClassesInForkedProcess() throws MojoExecutionException {
String retrolambdaJar = getRetrolambdaJarPath(); String retrolambdaJar = getRetrolambdaJarPath();
File classpathFile = getClasspathFile(); File classpathFile = getClasspathFile();
try { try {
List<Element> args = new ArrayList<Element>();
for (Object key : config.keySet()) {
Object value = config.get(key);
args.add(element("arg", attribute("value", "-D" + key + "=" + value)));
}
args.add(element("arg", attribute("value", "-javaagent:" + retrolambdaJar)));
args.add(element("arg", attribute("value", "-jar")));
args.add(element("arg", attribute("value", retrolambdaJar)));
executeMojo( executeMojo(
plugin(groupId("org.apache.maven.plugins"), plugin(groupId("org.apache.maven.plugins"),
artifactId("maven-antrun-plugin"), artifactId("maven-antrun-plugin"),
Expand All @@ -171,15 +181,7 @@ private void processClassesInForkedProcess() throws MojoExecutionException {
attributes( attributes(
attribute("executable", getJavaCommand()), attribute("executable", getJavaCommand()),
attribute("failonerror", "true")), attribute("failonerror", "true")),
element("arg", attribute("value", "-Dretrolambda.bytecodeVersion=" + targetBytecodeVersions.get(target))), args.toArray(new Element[0])))),
element("arg", attribute("value", "-Dretrolambda.defaultMethods=" + defaultMethods)),
element("arg", attribute("value", "-Dretrolambda.quiet=" + quiet)),
element("arg", attribute("value", "-Dretrolambda.inputDir=" + getInputDir().getAbsolutePath())),
element("arg", attribute("value", "-Dretrolambda.outputDir=" + getOutputDir().getAbsolutePath())),
element("arg", attribute("value", "-Dretrolambda.classpathFile=" + classpathFile)),
element("arg", attribute("value", "-javaagent:" + retrolambdaJar)),
element("arg", attribute("value", "-jar")),
element("arg", attribute("value", retrolambdaJar))))),
executionEnvironment(project, session, pluginManager)); executionEnvironment(project, session, pluginManager));
} finally { } finally {
if (!classpathFile.delete()) { if (!classpathFile.delete()) {
Expand Down

0 comments on commit c534b94

Please sign in to comment.