Skip to content

Commit

Permalink
Avoid having to run Retrolambda on itself by extracting a Java 6 comp…
Browse files Browse the repository at this point in the history
…atible retrolambda-api module for the Maven plugin to compile against

Fixes #137
  • Loading branch information
luontola committed Dec 27, 2017
1 parent e896452 commit 7943690
Show file tree
Hide file tree
Showing 19 changed files with 178 additions and 88 deletions.
10 changes: 3 additions & 7 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/libraries/Maven__org_apache_commons_commons_lang3_3_5.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@

<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<version>3.1.0</version>
<configuration>
<!-- Keep the generated POM file out of the base directory -->
<dependencyReducedPomLocation>
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<modules>
<module>parent</module>
<module>retrolambda</module>
<module>retrolambda-api</module>
<module>retrolambda-maven-plugin</module>
<module>end-to-end-tests</module>
</modules>
Expand Down
41 changes: 41 additions & 0 deletions retrolambda-api/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>net.orfjackal.retrolambda</groupId>
<artifactId>parent</artifactId>
<version>2.5.2-SNAPSHOT</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>

<artifactId>retrolambda-api</artifactId>
<packaging>jar</packaging>

<build>
<plugins>

<plugin>
<artifactId>maven-toolchains-plugin</artifactId>
<configuration>
<toolchains>
<jdk>
<version>1.6</version>
</jdk>
</toolchains>
</configuration>
</plugin>

<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>

</plugins>
</build>

</project>
19 changes: 19 additions & 0 deletions retrolambda-api/retrolambda-api.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-library:1.3" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.mockito:mockito-core:1.10.19" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.objenesis:objenesis:2.1" level="project" />
</component>
</module>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright © 2013-2017 Esko Luontola and other Retrolambda contributors
// This software is released under the Apache License 2.0.
// The license text is at http://www.apache.org/licenses/LICENSE-2.0

package net.orfjackal.retrolambda.api;

public class RetrolambdaApi {

private static final String PREFIX = "retrolambda.";
public static final String QUIET = PREFIX + "quiet";
public static final String INCLUDED_FILES = PREFIX + "includedFiles";
public static final String INCLUDED_FILES_FILE = INCLUDED_FILES + "File";
public static final String CLASSPATH = PREFIX + "classpath";
public static final String CLASSPATH_FILE = CLASSPATH + "File";
public static final String OUTPUT_DIR = PREFIX + "outputDir";
public static final String INPUT_DIR = PREFIX + "inputDir";
public static final String DEFAULT_METHODS = PREFIX + "defaultMethods";
public static final String BYTECODE_VERSION = PREFIX + "bytecodeVersion";
}
11 changes: 11 additions & 0 deletions retrolambda-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
<artifactId>retrolambda</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>net.orfjackal.retrolambda</groupId>
<artifactId>retrolambda-api</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.apache.maven</groupId>
Expand Down Expand Up @@ -53,6 +58,12 @@
<artifactId>guava</artifactId>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.5</version>
</dependency>

</dependencies>

<build>
Expand Down
2 changes: 2 additions & 0 deletions retrolambda-maven-plugin/retrolambda-maven-plugin.iml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<orderEntry type="module" module-name="retrolambda" />
<orderEntry type="library" name="Maven: org.ow2.asm:asm-debug-all:5.2" level="project" />
<orderEntry type="library" name="Maven: com.esotericsoftware:minlog:1.3" level="project" />
<orderEntry type="module" module-name="retrolambda-api" />
<orderEntry type="library" name="Maven: org.apache.maven:maven-plugin-api:3.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.maven:maven-model:3.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.maven:maven-artifact:3.0" level="project" />
Expand All @@ -40,6 +41,7 @@
<orderEntry type="library" name="Maven: org.sonatype.plexus:plexus-sec-dispatcher:1.3" level="project" />
<orderEntry type="library" name="Maven: org.sonatype.plexus:plexus-cipher:1.4" level="project" />
<orderEntry type="library" name="Maven: com.google.guava:guava:18.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.5" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-library:1.3" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import com.google.common.base.*;
import com.google.common.collect.ImmutableMap;
import com.google.common.io.Files;
import net.orfjackal.retrolambda.*;
import net.orfjackal.retrolambda.api.RetrolambdaApi;
import org.apache.commons.lang3.*;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.*;
Expand Down Expand Up @@ -124,7 +125,7 @@ private void validateTarget() throws MojoExecutionException {
}

private void validateFork() {
if (!fork && !Main.isRunningJava8()) {
if (!fork && !SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_1_8)) {
getLog().warn("Maven is not running under Java 8 - forced to fork the process");
fork = true;
}
Expand All @@ -134,13 +135,17 @@ private void processClassesInCurrentProcess() throws MojoExecutionException {
getLog().info("Processing classes with Retrolambda");
try {
Properties p = new Properties();
p.setProperty(SystemPropertiesConfig.BYTECODE_VERSION, "" + targetBytecodeVersions.get(target));
p.setProperty(SystemPropertiesConfig.DEFAULT_METHODS, "" + defaultMethods);
p.setProperty(SystemPropertiesConfig.QUIET, "" + quiet);
p.setProperty(SystemPropertiesConfig.INPUT_DIR, getInputDir().getAbsolutePath());
p.setProperty(SystemPropertiesConfig.OUTPUT_DIR, getOutputDir().getAbsolutePath());
p.setProperty(SystemPropertiesConfig.CLASSPATH, getClasspath());
Retrolambda.run(new SystemPropertiesConfig(p));
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,
// so we need to break the compile-time dependency using reflection
Class.forName("net.orfjackal.retrolambda.Retrolambda")
.getMethod("run", Properties.class)
.invoke(null, p);
} catch (Throwable t) {
throw new MojoExecutionException("Failed to run Retrolambda", t);
}
Expand Down
38 changes: 6 additions & 32 deletions retrolambda/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@

<dependencies>

<dependency>
<groupId>net.orfjackal.retrolambda</groupId>
<artifactId>retrolambda-api</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-debug-all</artifactId>
Expand Down Expand Up @@ -50,38 +56,6 @@
</configuration>
</plugin>

<!-- To allow the Maven plugin be directly compiled against Retrolamdba,
we must backport Retrolambda itself to Java 6 -->

<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>retrolambda-inception</id>
<phase>process-classes</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<property name="compile_classpath" refid="maven.compile.classpath"/>
<exec executable="${env.JAVA8_HOME}/bin/java" failonerror="true">
<arg value="-Dretrolambda.bytecodeVersion=50"/>
<arg value="-Dretrolambda.inputDir=${project.build.outputDirectory}"/>
<arg value="-Dretrolambda.classpath=${compile_classpath}"/>
<arg value="-Dretrolambda.includedFiles=${project.build.outputDirectory}/net/orfjackal/retrolambda/Main.class${path.separator}${project.build.outputDirectory}/net/orfjackal/retrolambda/Config.class${path.separator}${project.build.outputDirectory}/net/orfjackal/retrolambda/SystemPropertiesConfig.class${path.separator}${project.build.outputDirectory}/net/orfjackal/retrolambda/Retrolambda.class"/>
<arg value="-cp"/>
<arg value="${project.build.outputDirectory}"/>
<arg value="-cp"/>
<arg value="${compile_classpath}"/>
<arg value="net.orfjackal.retrolambda.Main"/>
</exec>
</target>
</configuration>
</execution>
</executions>
</plugin>

<!-- Create an uber jar containing all dependencies -->

<plugin>
Expand Down
1 change: 1 addition & 0 deletions retrolambda/retrolambda.iml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="retrolambda-api" />
<orderEntry type="library" name="Maven: org.ow2.asm:asm-debug-all:5.2" level="project" />
<orderEntry type="library" name="Maven: com.google.guava:guava:18.0" level="project" />
<orderEntry type="library" name="Maven: com.esotericsoftware:minlog:1.3" level="project" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@

public class Retrolambda {

public static void run(Properties systemProperties) throws Throwable {
SystemPropertiesConfig config = new SystemPropertiesConfig(systemProperties);
if (!config.isFullyConfigured()) {
throw new IllegalArgumentException("not fully configured");
}
run(config);
}

public static void run(Config config) throws Throwable {
int bytecodeVersion = config.getBytecodeVersion();
boolean defaultMethodsEnabled = config.isDefaultMethodsEnabled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,9 @@
import java.util.*;
import java.util.stream.*;

public class SystemPropertiesConfig implements Config {
import static net.orfjackal.retrolambda.api.RetrolambdaApi.*;

private static final String PREFIX = "retrolambda.";
public static final String BYTECODE_VERSION = PREFIX + "bytecodeVersion";
public static final String DEFAULT_METHODS = PREFIX + "defaultMethods";
public static final String INPUT_DIR = PREFIX + "inputDir";
public static final String OUTPUT_DIR = PREFIX + "outputDir";
public static final String CLASSPATH = PREFIX + "classpath";
public static final String CLASSPATH_FILE = CLASSPATH + "File";
public static final String INCLUDED_FILES = PREFIX + "includedFiles";
public static final String INCLUDED_FILES_FILE = INCLUDED_FILES + "File";
public static final String QUIET = PREFIX + "quiet";
public class SystemPropertiesConfig implements Config {

private static final List<String> requiredProperties = new ArrayList<>();
private static final Map<String, String> alternativeProperties = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Copyright © 2013-2015 Esko Luontola <www.orfjackal.net>
// Copyright © 2013-2017 Esko Luontola and other Retrolambda contributors
// This software is released under the Apache License 2.0.
// The license text is at http://www.apache.org/licenses/LICENSE-2.0

package net.orfjackal.retrolambda;

import net.orfjackal.retrolambda.api.RetrolambdaApi;
import org.junit.*;
import org.junit.rules.TemporaryFolder;

Expand Down Expand Up @@ -77,11 +78,11 @@ public void ignores_included_files_that_are_outside_the_input_directory() throws
@Test
public void copies_resources_to_output_directory() throws Throwable {
Properties p = new Properties();
p.setProperty(SystemPropertiesConfig.INPUT_DIR, inputDir.toString());
p.setProperty(SystemPropertiesConfig.OUTPUT_DIR, outputDir.toString());
p.setProperty(SystemPropertiesConfig.CLASSPATH, "");
p.setProperty(RetrolambdaApi.INPUT_DIR, inputDir.toString());
p.setProperty(RetrolambdaApi.OUTPUT_DIR, outputDir.toString());
p.setProperty(RetrolambdaApi.CLASSPATH, "");

Retrolambda.run(new SystemPropertiesConfig(p));
Retrolambda.run(p);

assertIsFile(outputDir.resolve("file1.txt"));
assertIsFile(outputDir.resolve("subdir/file.txt"));
Expand Down
Loading

0 comments on commit 7943690

Please sign in to comment.