From e92995625532e23283caab575531b608ea2d7bcf Mon Sep 17 00:00:00 2001 From: Paul Scholz Date: Mon, 10 May 2021 09:51:50 +0200 Subject: [PATCH] fix: --processor-module-path behaviour with absolut sourcepath Extended module-info.java check inside absolute sourcepath those where ignored previously. Signed-off-by: Paul Scholz --- .../plexus/compiler/javac/JavacCompiler.java | 15 ++++++++++++++- .../compiler/javac/AbstractJavacCompilerTest.java | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) 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 63bc5722..2a345852 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 @@ -291,7 +291,7 @@ public static String[] buildCompilerArguments( CompilerConfiguration config, Str } if ( config.getProcessorPathEntries() != null && !config.getProcessorPathEntries().isEmpty() ) { - if(!isPreJava9(config) && Arrays.asList(sourceFiles).contains("module-info.java")){ + if(!isPreJava9(config) && containsModuleInfo(sourceFiles)){ args.add( "--processor-module-path" ); } else { @@ -531,6 +531,19 @@ private static boolean isPreJava9( CompilerConfiguration config ) || v.startsWith( "1.3" ) || v.startsWith( "1.2" ) || v.startsWith( "1.1" ) || v.startsWith( "1.0" ); } + /** + * Check if a list of paths contains a module-info.java file + * @param sourceFiles list of source files + * @return true if a module-info.java is contained + */ + private static boolean containsModuleInfo(String[] sourceFiles){ + for (String sourceFile : sourceFiles) { + if (sourceFile.endsWith("module-info.java")) { + return true; + } + } + return false; + } private static boolean suppressSource( CompilerConfiguration config ) { 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 0f413940..88f9dcf2 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 @@ -301,7 +301,7 @@ public void testModulePathAnnotations() throws Exception CompilerConfiguration compilerConfiguration = new CompilerConfiguration(); - final String[] source = {"module-info.java"}; + final String[] source = {"/src/main/one/module-info.java"}; // outputLocation compilerConfiguration.setOutputLocation( "/output" );