Skip to content

Add "fixJava8Classpath" option to support multirelease projects #171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ Configurable system properties:
Alternative to retrolambda.classpath for avoiding the command line
length limit. The file must list one file per line with UTF-8 encoding.

retrolambda.fixJava8Classpath
Whether to replace occurrences of classpath entries ending in /classes
with entries ending in /classes-java8 if such directory is available.
Disabled by default. Enable by setting to "true"

retrolambda.includedFiles
List of files to process, instead of processing all files.
This is useful for a build tool to support incremental compilation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ public class RetrolambdaApi {
public static final String DEFAULT_METHODS = PREFIX + "defaultMethods";
public static final String BYTECODE_VERSION = PREFIX + "bytecodeVersion";
public static final String JAVAC_HACKS = PREFIX + "javacHacks";
public static final String FIX_JAVA8_CLASSPATH = PREFIX + "fixJava8Classpath";
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ abstract class ProcessClassesMojo extends AbstractMojo {
@Parameter(defaultValue = "false")
public boolean fork;

/**
* Whether to replace occurrences of classpath entries ending in {@code /classes}
* with entries ending in {@code /classes-java8} if such directory is available.
* @since 2.5.8
*/
@Parameter(defaultValue = "false", property = "fixJava8Classpath", required = false)
public boolean fixJava8Classpath;

protected abstract File getInputDir();

protected abstract File getOutputDir();
Expand All @@ -126,6 +134,7 @@ public void execute() throws MojoExecutionException {
config.setProperty(RetrolambdaApi.OUTPUT_DIR, getOutputDir().getAbsolutePath());
config.setProperty(RetrolambdaApi.CLASSPATH, getClasspath());
config.setProperty(RetrolambdaApi.JAVAC_HACKS, "" + javacHacks);
config.setProperty(RetrolambdaApi.FIX_JAVA8_CLASSPATH, "" + fixJava8Classpath);

if (fork) {
processClassesInForkedProcess(config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ public interface Config {
boolean isJavacHacksEnabled();

boolean isQuiet();

boolean isFixJava8Classpath();
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,21 @@ public static void run(Config config) throws Throwable {
} else {
Log.INFO();
}

if (config.isFixJava8Classpath()) {
List<Path> classpathNew = new ArrayList<>();
for(Path p : classpath) {
if (p.toString().endsWith("/classes") && Files.isDirectory(p)) {
Path p2 = p.getParent().resolve("classes-java8");
if (Files.isDirectory(p2)) {
p = p2;
}
}
classpathNew.add(p);
}
classpath = classpathNew;
}

Log.info("Bytecode version: " + bytecodeVersion + " (" + Bytecode.getJavaVersion(bytecodeVersion) + ")");
Log.info("Default methods: " + defaultMethodsEnabled);
Log.info("Input directory: " + inputDir);
Expand All @@ -47,6 +62,7 @@ public static void run(Config config) throws Throwable {
Log.info("JVM version: " + System.getProperty("java.version"));
Log.info("Agent enabled: " + Agent.isEnabled());
Log.info("javac hacks: " + isJavacHacksEnabled);
Log.info("Fix classpath: " + config.isFixJava8Classpath());

if (!Files.isDirectory(inputDir)) {
Log.info("Nothing to do; not a directory: " + inputDir);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,20 @@ public Path getOutputDir() {
"length limit. The file must list one file per line with UTF-8 encoding.");
}


// fix Java 8 classpath

static {
optionalParameterHelp(FIX_JAVA8_CLASSPATH,
"Whether to replace occurrences of classpath entries ending in /classes",
"with entries ending in /classes-java8 if such directory is available.",
"Disabled by default. Enable by setting to \"true\"");
}

@Override
public boolean isFixJava8Classpath() {
return Boolean.parseBoolean(p.getProperty(FIX_JAVA8_CLASSPATH, "false"));
}
@Override
public List<Path> getClasspath() {
String classpath = p.getProperty(CLASSPATH);
Expand Down