Skip to content

Commit c393637

Browse files
authored
Added primitive support for --processor-module-path (#67)
* Added primitive support for --processor-module-path * Tweeks to isPreJava16 and test for Module-Path annotations close #53
1 parent 8218f10 commit c393637

File tree

2 files changed

+94
-17
lines changed

2 files changed

+94
-17
lines changed

plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/JavacCompiler.java

+54-15
Original file line numberDiff line numberDiff line change
@@ -290,12 +290,21 @@ public static String[] buildCompilerArguments( CompilerConfiguration config, Str
290290
args.add( buffer.toString() );
291291
}
292292
if ( config.getProcessorPathEntries() != null && !config.getProcessorPathEntries().isEmpty() ) {
293-
args.add( "-processorpath" );
294293

294+
if(!isPreJava9(config) && Arrays.asList(sourceFiles).contains("module-info.java")){
295+
args.add( "--processor-module-path" );
296+
297+
} else {
298+
args.add( "-processorpath" );
299+
300+
}
295301
args.add( getPathString( config.getProcessorPathEntries() ) );
296302
}
303+
297304
}
298305

306+
307+
299308
if ( config.isOptimize() )
300309
{
301310
args.add( "-O" );
@@ -439,29 +448,59 @@ private static boolean isPreJava14( CompilerConfiguration config )
439448
*/
440449
private static boolean isPreJava16( CompilerConfiguration config )
441450
{
442-
String v = config.getCompilerVersion();
451+
String v = config.getReleaseVersion();
443452

444453
if ( v == null )
445454
{
446-
//mkleint: i haven't completely understood the reason for the
447-
//compiler version parameter, checking source as well, as most projects will have this one set, not the compiler
448-
String s = config.getSourceVersion();
449-
if ( s == null )
450-
{
451-
//now return true, as the 1.6 version is not the default - 1.4 is.
452-
return true;
453-
}
454-
return s.startsWith( "1.5" ) || s.startsWith( "1.4" ) || s.startsWith( "1.3" ) || s.startsWith( "1.2" )
455-
|| s.startsWith( "1.1" ) || s.startsWith( "1.0" );
455+
v = config.getCompilerVersion();
456456
}
457457

458-
return v.startsWith( "1.5" ) || v.startsWith( "1.4" ) || v.startsWith( "1.3" ) || v.startsWith( "1.2" )
458+
if ( v == null )
459+
{
460+
v = config.getSourceVersion();
461+
}
462+
463+
if ( v == null )
464+
{
465+
return true;
466+
}
467+
468+
return v.startsWith( "5" ) || v.startsWith( "1.5" ) || v.startsWith( "1.4" ) || v.startsWith( "1.3" ) || v.startsWith( "1.2" )
459469
|| v.startsWith( "1.1" ) || v.startsWith( "1.0" );
460470
}
461471

462472
private static boolean isPreJava18( CompilerConfiguration config )
463473
{
464-
String v = config.getCompilerVersion();
474+
String v = config.getReleaseVersion();
475+
476+
if ( v == null )
477+
{
478+
v = config.getCompilerVersion();
479+
}
480+
481+
if ( v == null )
482+
{
483+
v = config.getSourceVersion();
484+
}
485+
486+
if ( v == null )
487+
{
488+
return true;
489+
}
490+
491+
return v.startsWith( "7" ) || v.startsWith( "1.7" ) || v.startsWith( "6" ) ||v.startsWith( "1.6" ) || v.startsWith( "1.5" ) || v.startsWith( "1.4" )
492+
|| v.startsWith( "1.3" ) || v.startsWith( "1.2" ) || v.startsWith( "1.1" ) || v.startsWith( "1.0" );
493+
}
494+
495+
private static boolean isPreJava9( CompilerConfiguration config )
496+
{
497+
498+
String v = config.getReleaseVersion();
499+
500+
if ( v == null )
501+
{
502+
v = config.getCompilerVersion();
503+
}
465504

466505
if ( v == null )
467506
{
@@ -473,7 +512,7 @@ private static boolean isPreJava18( CompilerConfiguration config )
473512
return true;
474513
}
475514

476-
return v.startsWith( "1.7" ) || v.startsWith( "1.6" ) || v.startsWith( "1.5" ) || v.startsWith( "1.4" )
515+
return v.startsWith( "8" ) || v.startsWith( "1.8" ) || v.startsWith( "7" ) || v.startsWith( "1.7" ) || v.startsWith( "1.6" ) || v.startsWith( "1.5" ) || v.startsWith( "1.4" )
477516
|| v.startsWith( "1.3" ) || v.startsWith( "1.2" ) || v.startsWith( "1.1" ) || v.startsWith( "1.0" );
478517
}
479518

plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/AbstractJavacCompilerTest.java

+40-2
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,13 @@ protected Collection<String> expectedOutputFiles()
155155
"org/codehaus/foo/Person.class", "org/codehaus/foo/ReservedWord.class" } );
156156
}
157157

158-
public void internalTest( CompilerConfiguration compilerConfiguration, List<String> expectedArguments )
158+
public void internalTest(CompilerConfiguration compilerConfiguration, List<String> expectedArguments) {
159+
internalTest(compilerConfiguration, expectedArguments, new String[0]);
160+
}
161+
162+
public void internalTest(CompilerConfiguration compilerConfiguration, List<String> expectedArguments, String[] sources)
159163
{
160-
String[] actualArguments = JavacCompiler.buildCompilerArguments( compilerConfiguration, new String[0] );
164+
String[] actualArguments = JavacCompiler.buildCompilerArguments( compilerConfiguration, sources );
161165

162166
assertEquals( "The expected and actual argument list sizes differ.", expectedArguments.size(),
163167
actualArguments.length );
@@ -277,6 +281,40 @@ public void testJRuntimeArguments()
277281
internalTest( compilerConfiguration, expectedArguments );
278282
}
279283

284+
public void testModulePathAnnotations() throws Exception
285+
{
286+
List<String> expectedArguments = new ArrayList<>();
287+
288+
CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
289+
290+
final String[] source = {"module-info.java"};
291+
292+
// outputLocation
293+
compilerConfiguration.setOutputLocation( "/output" );
294+
expectedArguments.add( "-d" );
295+
expectedArguments.add( new File( "/output" ).getAbsolutePath() );
296+
297+
// failOnWarning
298+
compilerConfiguration.setModulepathEntries( Arrays.asList( "/repo/a/b/1.0/b-1.0.jar",
299+
"/repo/c/d/1.0/d-1.0.jar" ) );
300+
expectedArguments.add( "--module-path" );
301+
expectedArguments.add( "/repo/a/b/1.0/b-1.0.jar" + File.pathSeparator +
302+
"/repo/c/d/1.0/d-1.0.jar" + File.pathSeparator );
303+
304+
compilerConfiguration.setProcessorPathEntries(Arrays.asList("/repo/a/b/1.0/annotations-1.0.jar",
305+
"/repo/f/a/1.0/annotations-4.0.jar"));
306+
expectedArguments.add( "--processor-module-path" );
307+
expectedArguments.add("/repo/a/b/1.0/annotations-1.0.jar" + File.pathSeparator +
308+
"/repo/f/a/1.0/annotations-4.0.jar" + File.pathSeparator );
309+
310+
// releaseVersion
311+
compilerConfiguration.setReleaseVersion( "9" );
312+
expectedArguments.add( "--release" );
313+
expectedArguments.add( "9" );
314+
315+
internalTest( compilerConfiguration, expectedArguments, source);
316+
}
317+
280318
public void testModulePath() throws Exception
281319
{
282320
List<String> expectedArguments = new ArrayList<>();

0 commit comments

Comments
 (0)