Skip to content

Commit 74a3a16

Browse files
authored
Eclipse Compiler Support release specifier instead of source/target (#78)
1 parent 66d7c32 commit 74a3a16

File tree

1 file changed

+39
-21
lines changed

1 file changed

+39
-21
lines changed

plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/EclipseJavaCompiler.java

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -88,20 +88,30 @@ public CompilerResult performCompile(CompilerConfiguration config )
8888
args.add("-g:lines,source");
8989
}
9090

91-
String sourceVersion = decodeVersion( config.getSourceVersion() );
92-
93-
if ( sourceVersion != null )
91+
String releaseVersion = decodeVersion( config.getReleaseVersion() );
92+
// EcjFailureException: Failed to run the ecj compiler: option -source is not supported when --release is used
93+
if ( releaseVersion != null )
9494
{
95-
args.add("-source");
96-
args.add(sourceVersion);
95+
args.add("--release");
96+
args.add(releaseVersion);
9797
}
98+
else
99+
{
100+
String sourceVersion = decodeVersion( config.getSourceVersion() );
101+
102+
if ( sourceVersion != null )
103+
{
104+
args.add("-source");
105+
args.add(sourceVersion);
106+
}
98107

99-
String targetVersion = decodeVersion( config.getTargetVersion() );
108+
String targetVersion = decodeVersion( config.getTargetVersion() );
100109

101-
if ( targetVersion != null )
102-
{
103-
args.add("-target");
104-
args.add(targetVersion);
110+
if ( targetVersion != null )
111+
{
112+
args.add("-target");
113+
args.add(targetVersion);
114+
}
105115
}
106116

107117
if ( StringUtils.isNotEmpty( config.getSourceEncoding() ) )
@@ -286,26 +296,23 @@ else if(extras.containsKey("-errorsAsWarnings"))
286296
// ECJ JSR-199 compiles against the latest Java version it supports if no source
287297
// version is given explicitly. BatchCompiler uses 1.3 as default. So check
288298
// whether a source version is specified, and if not supply 1.3 explicitly.
289-
//
299+
if (!haveSourceOrReleaseArgument(args)) {
300+
getLogger().debug("ecj: no source level nor release specified, defaulting to Java 1.3");
301+
args.add("-source");
302+
args.add("1.3");
303+
}
304+
290305
// Also check for the encoding. Could have been set via the CompilerConfig
291306
// above, or also via the arguments explicitly. We need the charset for the
292307
// StandardJavaFileManager below.
293-
String srcVersion = null;
294308
String encoding = null;
295309
Iterator<String> allArgs = args.iterator();
296-
while ((srcVersion == null || encoding == null) && allArgs.hasNext()) {
310+
while (encoding == null && allArgs.hasNext()) {
297311
String option = allArgs.next();
298-
if ("-source".equals(option) && allArgs.hasNext()) {
299-
srcVersion = allArgs.next();
300-
} else if ("-encoding".equals(option) && allArgs.hasNext()) {
312+
if ("-encoding".equals(option) && allArgs.hasNext()) {
301313
encoding = allArgs.next();
302314
}
303315
}
304-
if (srcVersion == null) {
305-
getLogger().debug("ecj: no source level specified, defaulting to Java 1.3");
306-
args.add("-source");
307-
args.add("1.3");
308-
}
309316
final Locale defaultLocale = Locale.getDefault();
310317
final List<CompilerMessage> messages = messageList;
311318
DiagnosticListener<? super JavaFileObject> messageCollector = new DiagnosticListener<JavaFileObject>() {
@@ -446,6 +453,17 @@ public void worked(int i, int i1) {
446453
}
447454
}
448455

456+
private static boolean haveSourceOrReleaseArgument(List<String> args) {
457+
Iterator<String> allArgs = args.iterator();
458+
while (allArgs.hasNext()) {
459+
String option = allArgs.next();
460+
if (("-source".equals(option) || "--release".equals(option)) && allArgs.hasNext()) {
461+
return true;
462+
}
463+
}
464+
return false;
465+
}
466+
449467
private JavaCompiler getEcj() {
450468
ServiceLoader<JavaCompiler> javaCompilerLoader = ServiceLoader.load(JavaCompiler.class,
451469
BatchCompiler.class.getClassLoader());

0 commit comments

Comments
 (0)