Skip to content

Commit 3f8210d

Browse files
committed
Made it possible to configure the Maven plugin's input and output directories
Closes #20
1 parent b51bbfa commit 3f8210d

File tree

4 files changed

+78
-22
lines changed

4 files changed

+78
-22
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ package-private.
142142
Version History
143143
---------------
144144

145+
### Upcoming
146+
147+
- Maven plugin: made the input and output directories configurable
148+
([Issue #20](https://github.com/orfjackal/retrolambda/issues/20))
149+
145150
### Retrolambda 1.2.3 (2014-05-19)
146151

147152
- Android: Fixed NoSuchMethodError when calling a private method to which

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

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ abstract class ProcessClassesMojo extends AbstractMojo {
3636

3737
/**
3838
* The location of the Java 8 JDK (not JRE).
39+
*
40+
* @since 1.2.0
3941
*/
40-
@Parameter(required = false, property = "java8home", defaultValue = "${env.JAVA8_HOME}")
42+
@Parameter(defaultValue = "${env.JAVA8_HOME}", property = "java8home", required = true)
4143
public String java8home;
4244

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

53-
/**
54-
* The directory containing the main (non-test) compiled classes. These
55-
* classes will be overwritten with bytecode changes to obtain compatibility
56-
* with target Java runtime.
57-
*/
58-
@Parameter(required = false, property = "retrolambdaMainClassesDir", defaultValue = "${project.build.outputDirectory}")
59-
public String mainClassesDir;
60-
61-
/**
62-
* The directory containing the compiled test classes. These classes will be
63-
* overwritten with bytecode changes to obtain compatibility with target
64-
* Java runtime.
65-
*/
66-
@Parameter(required = false, property = "retrolambdaTestClassesDir", defaultValue = "${project.build.testOutputDirectory}")
67-
public String testClassesDir;
68-
6957
private final ClassesType classesType;
7058

7159
ProcessClassesMojo(ClassesType classesType) {
7260
this.classesType = classesType;
7361
}
7462

63+
protected abstract File getInputDir();
64+
65+
protected abstract File getOutputDir();
66+
7567
@Override
7668
public void execute() throws MojoExecutionException {
7769
validateJava8home();
@@ -97,9 +89,9 @@ public void execute() throws MojoExecutionException {
9789

9890
getLog().info("Processing classes with Retrolambda");
9991
if (classesType == ClassesType.MAIN) {
100-
processClasses(mainClassesDir, "maven.compile.classpath");
92+
processClasses("maven.compile.classpath");
10193
} else {
102-
processClasses(testClassesDir, "maven.test.classpath");
94+
processClasses("maven.test.classpath");
10395
}
10496
}
10597

@@ -118,7 +110,7 @@ private void validateJava8home() throws MojoExecutionException {
118110
}
119111
}
120112

121-
private void processClasses(String inputDir, String classpathId) throws MojoExecutionException {
113+
private void processClasses(String classpathId) throws MojoExecutionException {
122114
String retrolambdaJar = getRetrolambdaJarPath();
123115
executeMojo(
124116
plugin(groupId("org.apache.maven.plugins"),
@@ -135,7 +127,8 @@ private void processClasses(String inputDir, String classpathId) throws MojoExec
135127
attribute("executable", java8home + "/bin/java"),
136128
attribute("failonerror", "true")),
137129
element("arg", attribute("value", "-Dretrolambda.bytecodeVersion=" + targetBytecodeVersions.get(target))),
138-
element("arg", attribute("value", "-Dretrolambda.inputDir=" + inputDir)),
130+
element("arg", attribute("value", "-Dretrolambda.inputDir=" + getInputDir().getAbsolutePath())),
131+
element("arg", attribute("value", "-Dretrolambda.outputDir=" + getOutputDir().getAbsolutePath())),
139132
element("arg", attribute("value", "-Dretrolambda.classpath=${the_classpath}")),
140133
element("arg", attribute("value", "-javaagent:" + retrolambdaJar)),
141134
element("arg", attribute("value", "-jar")),

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

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

9+
import java.io.File;
10+
911
/**
1012
* Processes main (non-test) classes compiled with Java 8 so that they will be
1113
* compatible with Java 5, 6 or 7 runtime.
@@ -15,7 +17,34 @@
1517
requiresDependencyResolution = ResolutionScope.COMPILE)
1618
public class ProcessMainClassesMojo extends ProcessClassesMojo {
1719

20+
/**
21+
* Directory containing the original classes compiled with Java 8.
22+
*
23+
* @since 1.3.0
24+
*/
25+
@Parameter(defaultValue = "${project.build.outputDirectory}", property = "retrolambdaMainInputDir", required = true)
26+
public File mainInputDir;
27+
28+
/**
29+
* Directory where to write the backported main classes.
30+
* If same as the input directory, will overwrite the original classes.
31+
*
32+
* @since 1.3.0
33+
*/
34+
@Parameter(defaultValue = "${project.build.outputDirectory}", property = "retrolambdaMainOutputDir", required = true)
35+
public File mainOutputDir;
36+
1837
public ProcessMainClassesMojo() {
1938
super(ClassesType.MAIN);
2039
}
40+
41+
@Override
42+
protected File getInputDir() {
43+
return mainInputDir;
44+
}
45+
46+
@Override
47+
protected File getOutputDir() {
48+
return mainOutputDir;
49+
}
2150
}

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

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

9+
import java.io.File;
10+
911
/**
1012
* Processes test classes compiled with Java 8 so that they will be compatible with
1113
* Java 5, 6 or 7 runtime.
@@ -18,4 +20,31 @@ public class ProcessTestClassesMojo extends ProcessClassesMojo {
1820
public ProcessTestClassesMojo() {
1921
super(ClassesType.TEST);
2022
}
23+
24+
/**
25+
* Directory containing the original classes compiled with Java 8.
26+
*
27+
* @since 1.3.0
28+
*/
29+
@Parameter(defaultValue = "${project.build.testOutputDirectory}", property = "retrolambdaTestInputDir", required = true)
30+
public File testInputDir;
31+
32+
/**
33+
* Directory where to write the backported main classes.
34+
* If same as the input directory, will overwrite the original classes.
35+
*
36+
* @since 1.3.0
37+
*/
38+
@Parameter(defaultValue = "${project.build.testOutputDirectory}", property = "retrolambdaTestOutputDir", required = true)
39+
public File testOutputDir;
40+
41+
@Override
42+
protected File getInputDir() {
43+
return testInputDir;
44+
}
45+
46+
@Override
47+
protected File getOutputDir() {
48+
return testOutputDir;
49+
}
2150
}

0 commit comments

Comments
 (0)