Skip to content

Commit

Permalink
Added primitive support for --processor-module-path (#67)
Browse files Browse the repository at this point in the history
* Added primitive support for --processor-module-path

* Tweeks to isPreJava16 and test for Module-Path annotations

close #53
  • Loading branch information
scholzi100 authored Dec 30, 2020
1 parent 8218f10 commit c393637
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,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" );
Expand Down Expand Up @@ -439,29 +448,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 )
{
Expand All @@ -473,7 +512,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" );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,13 @@ protected Collection<String> expectedOutputFiles()
"org/codehaus/foo/Person.class", "org/codehaus/foo/ReservedWord.class" } );
}

public void internalTest( CompilerConfiguration compilerConfiguration, List<String> expectedArguments )
public void internalTest(CompilerConfiguration compilerConfiguration, List<String> expectedArguments) {
internalTest(compilerConfiguration, expectedArguments, new String[0]);
}

public void internalTest(CompilerConfiguration compilerConfiguration, List<String> 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 );
Expand Down Expand Up @@ -277,6 +281,40 @@ public void testJRuntimeArguments()
internalTest( compilerConfiguration, expectedArguments );
}

public void testModulePathAnnotations() throws Exception
{
List<String> 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<String> expectedArguments = new ArrayList<>();
Expand Down

0 comments on commit c393637

Please sign in to comment.