Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,21 @@ protected InProcessCompiler inProcessCompiler() {
return inProcessCompiler;
}

/**
* Maps the {@code 1.x} spelling that {@code -source} and {@code -target} accept onto the plain feature
* number, the only form {@code --release} takes: {@code 1.8} becomes {@code 8}. Any other value is
* passed through unchanged, so javac still reports releases it does not support.
*
* @param release the configured release version, never empty
* @return the value to pass to {@code --release}
*/
static String toReleaseArgument(String release) {
if (release.length() == 3 && release.startsWith("1.") && release.charAt(2) >= '1' && release.charAt(2) <= '9') {
return release.substring(2);
}
return release;
}

/**
*
* @return {@code true} if the current context class loader has access to {@code javax.tools.ToolProvider}
Expand Down Expand Up @@ -492,7 +507,7 @@ public static String[] buildCompilerArguments(

if (JavaVersion.JAVA_9.isOlderOrEqualTo(javacVersion) && !StringUtils.isEmpty(config.getReleaseVersion())) {
args.add("--release");
args.add(config.getReleaseVersion());
args.add(toReleaseArgument(config.getReleaseVersion()));
} else {
// TODO: this could be much improved
if (StringUtils.isEmpty(config.getTargetVersion())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,28 @@ public void testReleaseVersion() {
internalTest(compilerConfiguration, expectedArguments, "11.0.1");
}

@Test
public void testReleaseVersionInLegacySpelling() {
List<String> expectedArguments = new ArrayList<>();

CompilerConfiguration compilerConfiguration = new CompilerConfiguration();

// outputLocation
compilerConfiguration.setOutputLocation("/output");
expectedArguments.add("-d");
expectedArguments.add(new File("/output").getAbsolutePath());

// releaseVersion in the -source/-target spelling, which --release rejects
compilerConfiguration.setReleaseVersion("1.8");
expectedArguments.add("--release");
expectedArguments.add("8");

// unshared table
expectedArguments.add("-XDuseUnsharedTable=true");

internalTest(compilerConfiguration, expectedArguments, "11.0.1");
}

@Test
public void testFailOnWarning() {
List<String> expectedArguments = new ArrayList<>();
Expand Down
Loading