Skip to content

Commit

Permalink
Made it possible to configure the Maven plugin's input and output dir…
Browse files Browse the repository at this point in the history
…ectories

Closes #20
  • Loading branch information
luontola committed Jun 4, 2014
1 parent b51bbfa commit 3f8210d
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 22 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ package-private.
Version History
---------------

### Upcoming

- Maven plugin: made the input and output directories configurable
([Issue #20](https://github.com/orfjackal/retrolambda/issues/20))

### Retrolambda 1.2.3 (2014-05-19)

- Android: Fixed NoSuchMethodError when calling a private method to which
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ abstract class ProcessClassesMojo extends AbstractMojo {

/**
* The location of the Java 8 JDK (not JRE).
*
* @since 1.2.0
*/
@Parameter(required = false, property = "java8home", defaultValue = "${env.JAVA8_HOME}")
@Parameter(defaultValue = "${env.JAVA8_HOME}", property = "java8home", required = true)
public String java8home;

/**
Expand All @@ -46,32 +48,22 @@ abstract class ProcessClassesMojo extends AbstractMojo {
* with the target JVM provided the known limitations are considered. See
* <a href="https://github.com/orfjackal/retrolambda">project documentation</a>
* for more details.
*
* @since 1.2.0
*/
@Parameter(required = false, property = "retrolambdaTarget", defaultValue = "1.7")
@Parameter(defaultValue = "1.7", property = "retrolambdaTarget", required = true)
public String target;

/**
* The directory containing the main (non-test) compiled classes. These
* classes will be overwritten with bytecode changes to obtain compatibility
* with target Java runtime.
*/
@Parameter(required = false, property = "retrolambdaMainClassesDir", defaultValue = "${project.build.outputDirectory}")
public String mainClassesDir;

/**
* The directory containing the compiled test classes. These classes will be
* overwritten with bytecode changes to obtain compatibility with target
* Java runtime.
*/
@Parameter(required = false, property = "retrolambdaTestClassesDir", defaultValue = "${project.build.testOutputDirectory}")
public String testClassesDir;

private final ClassesType classesType;

ProcessClassesMojo(ClassesType classesType) {
this.classesType = classesType;
}

protected abstract File getInputDir();

protected abstract File getOutputDir();

@Override
public void execute() throws MojoExecutionException {
validateJava8home();
Expand All @@ -97,9 +89,9 @@ public void execute() throws MojoExecutionException {

getLog().info("Processing classes with Retrolambda");
if (classesType == ClassesType.MAIN) {
processClasses(mainClassesDir, "maven.compile.classpath");
processClasses("maven.compile.classpath");
} else {
processClasses(testClassesDir, "maven.test.classpath");
processClasses("maven.test.classpath");
}
}

Expand All @@ -118,7 +110,7 @@ private void validateJava8home() throws MojoExecutionException {
}
}

private void processClasses(String inputDir, String classpathId) throws MojoExecutionException {
private void processClasses(String classpathId) throws MojoExecutionException {
String retrolambdaJar = getRetrolambdaJarPath();
executeMojo(
plugin(groupId("org.apache.maven.plugins"),
Expand All @@ -135,7 +127,8 @@ private void processClasses(String inputDir, String classpathId) throws MojoExec
attribute("executable", java8home + "/bin/java"),
attribute("failonerror", "true")),
element("arg", attribute("value", "-Dretrolambda.bytecodeVersion=" + targetBytecodeVersions.get(target))),
element("arg", attribute("value", "-Dretrolambda.inputDir=" + inputDir)),
element("arg", attribute("value", "-Dretrolambda.inputDir=" + getInputDir().getAbsolutePath())),
element("arg", attribute("value", "-Dretrolambda.outputDir=" + getOutputDir().getAbsolutePath())),
element("arg", attribute("value", "-Dretrolambda.classpath=${the_classpath}")),
element("arg", attribute("value", "-javaagent:" + retrolambdaJar)),
element("arg", attribute("value", "-jar")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import org.apache.maven.plugins.annotations.*;

import java.io.File;

/**
* Processes main (non-test) classes compiled with Java 8 so that they will be
* compatible with Java 5, 6 or 7 runtime.
Expand All @@ -15,7 +17,34 @@
requiresDependencyResolution = ResolutionScope.COMPILE)
public class ProcessMainClassesMojo extends ProcessClassesMojo {

/**
* Directory containing the original classes compiled with Java 8.
*
* @since 1.3.0
*/
@Parameter(defaultValue = "${project.build.outputDirectory}", property = "retrolambdaMainInputDir", required = true)
public File mainInputDir;

/**
* Directory where to write the backported main classes.
* If same as the input directory, will overwrite the original classes.
*
* @since 1.3.0
*/
@Parameter(defaultValue = "${project.build.outputDirectory}", property = "retrolambdaMainOutputDir", required = true)
public File mainOutputDir;

public ProcessMainClassesMojo() {
super(ClassesType.MAIN);
}

@Override
protected File getInputDir() {
return mainInputDir;
}

@Override
protected File getOutputDir() {
return mainOutputDir;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import org.apache.maven.plugins.annotations.*;

import java.io.File;

/**
* Processes test classes compiled with Java 8 so that they will be compatible with
* Java 5, 6 or 7 runtime.
Expand All @@ -18,4 +20,31 @@ public class ProcessTestClassesMojo extends ProcessClassesMojo {
public ProcessTestClassesMojo() {
super(ClassesType.TEST);
}

/**
* Directory containing the original classes compiled with Java 8.
*
* @since 1.3.0
*/
@Parameter(defaultValue = "${project.build.testOutputDirectory}", property = "retrolambdaTestInputDir", required = true)
public File testInputDir;

/**
* Directory where to write the backported main classes.
* If same as the input directory, will overwrite the original classes.
*
* @since 1.3.0
*/
@Parameter(defaultValue = "${project.build.testOutputDirectory}", property = "retrolambdaTestOutputDir", required = true)
public File testOutputDir;

@Override
protected File getInputDir() {
return testInputDir;
}

@Override
protected File getOutputDir() {
return testOutputDir;
}
}

0 comments on commit 3f8210d

Please sign in to comment.