diff --git a/plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/JavacCompiler.java b/plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/JavacCompiler.java index 8f92a64c..3038c0e7 100644 --- a/plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/JavacCompiler.java +++ b/plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/JavacCompiler.java @@ -283,12 +283,21 @@ public static String[] buildCompilerArguments( CompilerConfiguration config, Str args.add( buffer.toString() ); } if ( config.getProcessorPathEntries() != null && !config.getProcessorPathEntries().isEmpty() ) { - args.add( "-processorpath" ); + if(!isPreJava9(config) && Arrays.asList(sourceFiles).contains("module-info.java")){ + args.add( "--processor-module-path" ); + + } else { + args.add( "-processorpath" ); + + } args.add( getPathString( config.getProcessorPathEntries() ) ); } + } + + if ( config.isOptimize() ) { args.add( "-O" ); @@ -432,29 +441,59 @@ private static boolean isPreJava14( CompilerConfiguration config ) */ private static boolean isPreJava16( CompilerConfiguration config ) { - String v = config.getCompilerVersion(); + String v = config.getReleaseVersion(); if ( v == null ) { - //mkleint: i haven't completely understood the reason for the - //compiler version parameter, checking source as well, as most projects will have this one set, not the compiler - String s = config.getSourceVersion(); - if ( s == null ) - { - //now return true, as the 1.6 version is not the default - 1.4 is. - return true; - } - return s.startsWith( "1.5" ) || s.startsWith( "1.4" ) || s.startsWith( "1.3" ) || s.startsWith( "1.2" ) - || s.startsWith( "1.1" ) || s.startsWith( "1.0" ); + v = config.getCompilerVersion(); } - return v.startsWith( "1.5" ) || v.startsWith( "1.4" ) || v.startsWith( "1.3" ) || v.startsWith( "1.2" ) + if ( v == null ) + { + v = config.getSourceVersion(); + } + + if ( v == null ) + { + return true; + } + + return v.startsWith( "5" ) || v.startsWith( "1.5" ) || v.startsWith( "1.4" ) || v.startsWith( "1.3" ) || v.startsWith( "1.2" ) || v.startsWith( "1.1" ) || v.startsWith( "1.0" ); } private static boolean isPreJava18( CompilerConfiguration config ) { - String v = config.getCompilerVersion(); + String v = config.getReleaseVersion(); + + if ( v == null ) + { + v = config.getCompilerVersion(); + } + + if ( v == null ) + { + v = config.getSourceVersion(); + } + + if ( v == null ) + { + return true; + } + + return v.startsWith( "7" ) || v.startsWith( "1.7" ) || v.startsWith( "6" ) ||v.startsWith( "1.6" ) || v.startsWith( "1.5" ) || v.startsWith( "1.4" ) + || v.startsWith( "1.3" ) || v.startsWith( "1.2" ) || v.startsWith( "1.1" ) || v.startsWith( "1.0" ); + } + + private static boolean isPreJava9( CompilerConfiguration config ) + { + + String v = config.getReleaseVersion(); + + if ( v == null ) + { + v = config.getCompilerVersion(); + } if ( v == null ) { @@ -466,7 +505,7 @@ private static boolean isPreJava18( CompilerConfiguration config ) return true; } - return v.startsWith( "1.7" ) || v.startsWith( "1.6" ) || v.startsWith( "1.5" ) || v.startsWith( "1.4" ) + 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" ) || v.startsWith( "1.3" ) || v.startsWith( "1.2" ) || v.startsWith( "1.1" ) || v.startsWith( "1.0" ); } diff --git a/plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/AbstractJavacCompilerTest.java b/plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/AbstractJavacCompilerTest.java index fdee0363..3b22dc1e 100644 --- a/plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/AbstractJavacCompilerTest.java +++ b/plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/AbstractJavacCompilerTest.java @@ -139,9 +139,13 @@ protected Collection expectedOutputFiles() "org/codehaus/foo/Person.class", "org/codehaus/foo/ReservedWord.class" } ); } - public void internalTest( CompilerConfiguration compilerConfiguration, List expectedArguments ) + public void internalTest(CompilerConfiguration compilerConfiguration, List expectedArguments) { + internalTest(compilerConfiguration, expectedArguments, new String[0]); + } + + public void internalTest(CompilerConfiguration compilerConfiguration, List expectedArguments, String[] sources) { - String[] actualArguments = JavacCompiler.buildCompilerArguments( compilerConfiguration, new String[0] ); + String[] actualArguments = JavacCompiler.buildCompilerArguments( compilerConfiguration, sources ); assertEquals( "The expected and actual argument list sizes differ.", expectedArguments.size(), actualArguments.length ); @@ -261,6 +265,40 @@ public void testJRuntimeArguments() internalTest( compilerConfiguration, expectedArguments ); } + public void testModulePathAnnotations() throws Exception + { + List expectedArguments = new ArrayList<>(); + + CompilerConfiguration compilerConfiguration = new CompilerConfiguration(); + + final String[] source = {"module-info.java"}; + + // outputLocation + compilerConfiguration.setOutputLocation( "/output" ); + expectedArguments.add( "-d" ); + expectedArguments.add( new File( "/output" ).getAbsolutePath() ); + + // failOnWarning + compilerConfiguration.setModulepathEntries( Arrays.asList( "/repo/a/b/1.0/b-1.0.jar", + "/repo/c/d/1.0/d-1.0.jar" ) ); + expectedArguments.add( "--module-path" ); + expectedArguments.add( "/repo/a/b/1.0/b-1.0.jar" + File.pathSeparator + + "/repo/c/d/1.0/d-1.0.jar" + File.pathSeparator ); + + compilerConfiguration.setProcessorPathEntries(Arrays.asList("/repo/a/b/1.0/annotations-1.0.jar", + "/repo/f/a/1.0/annotations-4.0.jar")); + expectedArguments.add( "--processor-module-path" ); + expectedArguments.add("/repo/a/b/1.0/annotations-1.0.jar" + File.pathSeparator + + "/repo/f/a/1.0/annotations-4.0.jar" + File.pathSeparator ); + + // releaseVersion + compilerConfiguration.setReleaseVersion( "9" ); + expectedArguments.add( "--release" ); + expectedArguments.add( "9" ); + + internalTest( compilerConfiguration, expectedArguments, source); + } + public void testModulePath() throws Exception { List expectedArguments = new ArrayList<>();