diff --git a/plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/EclipseJavaCompiler.java b/plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/EclipseJavaCompiler.java index b4674197..38ac0d85 100644 --- a/plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/EclipseJavaCompiler.java +++ b/plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/EclipseJavaCompiler.java @@ -24,24 +24,12 @@ * SOFTWARE. */ -import org.codehaus.plexus.compiler.AbstractCompiler; -import org.codehaus.plexus.compiler.Compiler; -import org.codehaus.plexus.compiler.CompilerConfiguration; -import org.codehaus.plexus.compiler.CompilerException; -import org.codehaus.plexus.compiler.CompilerMessage; -import org.codehaus.plexus.compiler.CompilerOutputStyle; -import org.codehaus.plexus.compiler.CompilerResult; -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.util.DirectoryScanner; -import org.codehaus.plexus.util.StringUtils; -import org.eclipse.jdt.core.compiler.CompilationProgress; -import org.eclipse.jdt.core.compiler.batch.BatchCompiler; - import javax.tools.Diagnostic; import javax.tools.DiagnosticListener; import javax.tools.JavaCompiler; import javax.tools.JavaFileObject; import javax.tools.StandardJavaFileManager; + import java.io.File; import java.io.PrintWriter; import java.io.StringWriter; @@ -56,6 +44,19 @@ import java.util.ServiceLoader; import java.util.Set; +import org.codehaus.plexus.compiler.AbstractCompiler; +import org.codehaus.plexus.compiler.Compiler; +import org.codehaus.plexus.compiler.CompilerConfiguration; +import org.codehaus.plexus.compiler.CompilerException; +import org.codehaus.plexus.compiler.CompilerMessage; +import org.codehaus.plexus.compiler.CompilerOutputStyle; +import org.codehaus.plexus.compiler.CompilerResult; +import org.codehaus.plexus.component.annotations.Component; +import org.codehaus.plexus.util.DirectoryScanner; +import org.codehaus.plexus.util.StringUtils; +import org.eclipse.jdt.core.compiler.CompilationProgress; +import org.eclipse.jdt.core.compiler.batch.BatchCompiler; + /** * */ @@ -206,7 +207,14 @@ public CompilerResult performCompile( CompilerConfiguration config ) if ( processorPathEntries != null && processorPathEntries.size() > 0 ) { - args.add( "-processorpath" ); + if ( isReplaceProcessorPath( config ) ) + { + args.add( "--processor-module-path" ); + } + else + { + args.add( "-processorpath" ); + } args.add( getPathString( processorPathEntries ) ); } @@ -478,6 +486,22 @@ public void worked( int i, int i1 ) } } + private static final String OPT_REPLACE_PROCESSOR_PATH = "replaceProcessorPathWithProcessorModulePath"; + private static final String OPT_REPLACE_PROCESSOR_PATH_ = "-" + OPT_REPLACE_PROCESSOR_PATH; + + static boolean isReplaceProcessorPath( CompilerConfiguration config ) + { + for ( Entry entry : config.getCustomCompilerArgumentsEntries() ) + { + String opt = entry.getKey(); + if ( opt.equals( OPT_REPLACE_PROCESSOR_PATH ) || opt.equals( OPT_REPLACE_PROCESSOR_PATH_ ) ) + { + return true; + } + } + return false; + } + static List resortSourcesToPutModuleInfoFirst( List allSources ) { ArrayList resorted = new ArrayList<>(); @@ -538,46 +562,49 @@ static boolean processCustomArguments( CompilerConfiguration config, List uses the tag names - * of its contents to denote option names, and so the compiler mojo happily adds a '-' to - * all of the names there and adds them to the "custom compiler arguments" map as a - * name, value pair where the name always contains a single '-'. The Eclipse compiler (and - * javac too, btw) has options with two dashes (like --add-modules for java 9). These cannot - * be passed using a tag. - * - * The other method is to use , where each SINGLE argument needs to be passed - * using an xxxx tag. In there the xxx is not manipulated by the compiler mojo, so - * if it starts with a dash or more dashes these are perfectly preserved. But of course these - * single entries are not a pair. So the compiler mojo adds them as pairs of (xxxx, null). - * - * We use that knowledge here: if a pair has a null value then do not mess up the key but - * render it as a single value. This should ensure that something like: - * - * --add-modules - * java.se.ee - * - * - * is actually added to the command like as such. - * - * (btw: the above example will still give an error when using ecj <= 4.8M6: - * invalid module name: java.se.ee - * but that seems to be a bug in ecj). - */ - if ( null == optionValue ) - { - //-- We have an option from compilerArgs: use the key as-is as a single option value - args.add( opt ); - } - else + if ( !opt.equals( OPT_REPLACE_PROCESSOR_PATH ) && !opt.equals( OPT_REPLACE_PROCESSOR_PATH_ ) ) { - if ( !opt.startsWith( "-" ) ) + /* + * The compiler mojo makes quite a mess of passing arguments, depending on exactly WHICH + * way is used to pass them. The method method using uses the tag names + * of its contents to denote option names, and so the compiler mojo happily adds a '-' to + * all of the names there and adds them to the "custom compiler arguments" map as a + * name, value pair where the name always contains a single '-'. The Eclipse compiler (and + * javac too, btw) has options with two dashes (like --add-modules for java 9). These cannot + * be passed using a tag. + * + * The other method is to use , where each SINGLE argument needs to be passed + * using an xxxx tag. In there the xxx is not manipulated by the compiler mojo, so + * if it starts with a dash or more dashes these are perfectly preserved. But of course these + * single entries are not a pair. So the compiler mojo adds them as pairs of (xxxx, null). + * + * We use that knowledge here: if a pair has a null value then do not mess up the key but + * render it as a single value. This should ensure that something like: + * + * --add-modules + * java.se.ee + * + * + * is actually added to the command like as such. + * + * (btw: the above example will still give an error when using ecj <= 4.8M6: + * invalid module name: java.se.ee + * but that seems to be a bug in ecj). + */ + if ( null == optionValue ) + { + //-- We have an option from compilerArgs: use the key as-is as a single option value + args.add( opt ); + } + else { - opt = "-" + opt; + if ( !opt.startsWith( "-" ) ) + { + opt = "-" + opt; + } + args.add( opt ); + args.add( optionValue ); } - args.add( opt ); - args.add( optionValue ); } } return result;