Skip to content
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ bin
.idea
*.iml
.java-version
*.bak
Original file line number Diff line number Diff line change
Expand Up @@ -259,16 +259,17 @@ private String getOutOfProcessJavacVersion(String executable) throws CompilerExc
*/
cli.addArguments(new String[] {"-version"}); //
CommandLineUtils.StringStreamConsumer out = new CommandLineUtils.StringStreamConsumer();
CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
try {
int exitCode = CommandLineUtils.executeCommandLine(cli, out, out);
int exitCode = CommandLineUtils.executeCommandLine(cli, out, err);
if (exitCode != 0) {
throw new CompilerException("Could not retrieve version from " + executable + ". Exit code "
+ exitCode + ", Output: " + out.getOutput());
+ exitCode + ", Output: " + out.getOutput() + ", Error: " + err.getOutput());
}
} catch (CommandLineException e) {
throw new CompilerException("Error while executing the external compiler " + executable, e);
}
version = extractMajorAndMinorVersion(out.getOutput());
version = tryParseVersion(out.getOutput().trim());
VERSION_PER_EXECUTABLE.put(executable, version);
}
return version;
Expand All @@ -282,6 +283,19 @@ static String extractMajorAndMinorVersion(String text) {
return matcher.group();
}

private String tryParseVersion(String version) {
if (version.startsWith("javac ")) {
version = version.substring(6);
if (version.startsWith("1.")) {
version = version.substring(0, 3);
} else {
version = version.substring(0, 2);
}
return version;
}
return null;
}

@Override
public CompilerResult performCompile(CompilerConfiguration config) throws CompilerException {
File destinationDir = new File(config.getOutputLocation());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,6 @@ void testExtractMajorAndMinorVersion() {
assertEquals("11.0", JavacCompiler.extractMajorAndMinorVersion("javac 11.0.22"));
assertEquals("11.0", JavacCompiler.extractMajorAndMinorVersion("11.0.22"));
assertEquals("21", JavacCompiler.extractMajorAndMinorVersion("javac 21"));
assertEquals("1.8", JavacCompiler.extractMajorAndMinorVersion("javac 1.8.0_432"));
}
}