Skip to content

Eclipse Compiler Support release specifier instead of source/target #78

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

Merged
merged 2 commits into from Jun 21, 2020
Merged
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 @@ -88,20 +88,30 @@ public CompilerResult performCompile(CompilerConfiguration config )
args.add("-g:lines,source");
}

String sourceVersion = decodeVersion( config.getSourceVersion() );

if ( sourceVersion != null )
String releaseVersion = decodeVersion( config.getReleaseVersion() );
// EcjFailureException: Failed to run the ecj compiler: option -source is not supported when --release is used
if ( releaseVersion != null )
{
args.add("-source");
args.add(sourceVersion);
args.add("--release");
args.add(releaseVersion);
}
else
{
String sourceVersion = decodeVersion( config.getSourceVersion() );

if ( sourceVersion != null )
{
args.add("-source");
args.add(sourceVersion);
}

String targetVersion = decodeVersion( config.getTargetVersion() );
String targetVersion = decodeVersion( config.getTargetVersion() );

if ( targetVersion != null )
{
args.add("-target");
args.add(targetVersion);
if ( targetVersion != null )
{
args.add("-target");
args.add(targetVersion);
}
}

if ( StringUtils.isNotEmpty( config.getSourceEncoding() ) )
Expand Down Expand Up @@ -286,26 +296,23 @@ else if(extras.containsKey("-errorsAsWarnings"))
// ECJ JSR-199 compiles against the latest Java version it supports if no source
// version is given explicitly. BatchCompiler uses 1.3 as default. So check
// whether a source version is specified, and if not supply 1.3 explicitly.
//
if (!haveSourceOrReleaseArgument(args)) {
getLogger().debug("ecj: no source level nor release specified, defaulting to Java 1.3");
args.add("-source");
args.add("1.3");
}

// Also check for the encoding. Could have been set via the CompilerConfig
// above, or also via the arguments explicitly. We need the charset for the
// StandardJavaFileManager below.
String srcVersion = null;
String encoding = null;
Iterator<String> allArgs = args.iterator();
while ((srcVersion == null || encoding == null) && allArgs.hasNext()) {
while (encoding == null && allArgs.hasNext()) {
String option = allArgs.next();
if ("-source".equals(option) && allArgs.hasNext()) {
srcVersion = allArgs.next();
} else if ("-encoding".equals(option) && allArgs.hasNext()) {
if ("-encoding".equals(option) && allArgs.hasNext()) {
encoding = allArgs.next();
}
}
if (srcVersion == null) {
getLogger().debug("ecj: no source level specified, defaulting to Java 1.3");
args.add("-source");
args.add("1.3");
}
final Locale defaultLocale = Locale.getDefault();
final List<CompilerMessage> messages = messageList;
DiagnosticListener<? super JavaFileObject> messageCollector = new DiagnosticListener<JavaFileObject>() {
Expand Down Expand Up @@ -446,6 +453,17 @@ public void worked(int i, int i1) {
}
}

private static boolean haveSourceOrReleaseArgument(List<String> args) {
Iterator<String> allArgs = args.iterator();
while (allArgs.hasNext()) {
String option = allArgs.next();
if (("-source".equals(option) || "--release".equals(option)) && allArgs.hasNext()) {
return true;
}
}
return false;
}

private JavaCompiler getEcj() {
ServiceLoader<JavaCompiler> javaCompilerLoader = ServiceLoader.load(JavaCompiler.class,
BatchCompiler.class.getClassLoader());
Expand Down