Skip to content

Commit 8cc8c9f

Browse files
vipcxjslachiewicz
authored andcommitted
Add a custom compile argument replaceProcessorPathWithProcessorModulePath to force the plugin replace processorPath with processormodulepath
Closes #191 #192
1 parent 18d380e commit 8cc8c9f

File tree

1 file changed

+78
-51
lines changed

1 file changed

+78
-51
lines changed

plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/EclipseJavaCompiler.java

+78-51
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,12 @@
2424
* SOFTWARE.
2525
*/
2626

27-
import org.codehaus.plexus.compiler.AbstractCompiler;
28-
import org.codehaus.plexus.compiler.Compiler;
29-
import org.codehaus.plexus.compiler.CompilerConfiguration;
30-
import org.codehaus.plexus.compiler.CompilerException;
31-
import org.codehaus.plexus.compiler.CompilerMessage;
32-
import org.codehaus.plexus.compiler.CompilerOutputStyle;
33-
import org.codehaus.plexus.compiler.CompilerResult;
34-
import org.codehaus.plexus.component.annotations.Component;
35-
import org.codehaus.plexus.util.DirectoryScanner;
36-
import org.codehaus.plexus.util.StringUtils;
37-
import org.eclipse.jdt.core.compiler.CompilationProgress;
38-
import org.eclipse.jdt.core.compiler.batch.BatchCompiler;
39-
4027
import javax.tools.Diagnostic;
4128
import javax.tools.DiagnosticListener;
4229
import javax.tools.JavaCompiler;
4330
import javax.tools.JavaFileObject;
4431
import javax.tools.StandardJavaFileManager;
32+
4533
import java.io.File;
4634
import java.io.PrintWriter;
4735
import java.io.StringWriter;
@@ -56,6 +44,19 @@
5644
import java.util.ServiceLoader;
5745
import java.util.Set;
5846

47+
import org.codehaus.plexus.compiler.AbstractCompiler;
48+
import org.codehaus.plexus.compiler.Compiler;
49+
import org.codehaus.plexus.compiler.CompilerConfiguration;
50+
import org.codehaus.plexus.compiler.CompilerException;
51+
import org.codehaus.plexus.compiler.CompilerMessage;
52+
import org.codehaus.plexus.compiler.CompilerOutputStyle;
53+
import org.codehaus.plexus.compiler.CompilerResult;
54+
import org.codehaus.plexus.component.annotations.Component;
55+
import org.codehaus.plexus.util.DirectoryScanner;
56+
import org.codehaus.plexus.util.StringUtils;
57+
import org.eclipse.jdt.core.compiler.CompilationProgress;
58+
import org.eclipse.jdt.core.compiler.batch.BatchCompiler;
59+
5960
/**
6061
*
6162
*/
@@ -206,7 +207,14 @@ public CompilerResult performCompile( CompilerConfiguration config )
206207

207208
if ( processorPathEntries != null && processorPathEntries.size() > 0 )
208209
{
209-
args.add( "-processorpath" );
210+
if ( isReplaceProcessorPath( config ) )
211+
{
212+
args.add( "--processor-module-path" );
213+
}
214+
else
215+
{
216+
args.add( "-processorpath" );
217+
}
210218
args.add( getPathString( processorPathEntries ) );
211219
}
212220

@@ -478,6 +486,22 @@ public void worked( int i, int i1 )
478486
}
479487
}
480488

489+
private static final String OPT_REPLACE_PROCESSOR_PATH = "replaceProcessorPathWithProcessorModulePath";
490+
private static final String OPT_REPLACE_PROCESSOR_PATH_ = "-" + OPT_REPLACE_PROCESSOR_PATH;
491+
492+
static boolean isReplaceProcessorPath( CompilerConfiguration config )
493+
{
494+
for ( Entry<String, String> entry : config.getCustomCompilerArgumentsEntries() )
495+
{
496+
String opt = entry.getKey();
497+
if ( opt.equals( OPT_REPLACE_PROCESSOR_PATH ) || opt.equals( OPT_REPLACE_PROCESSOR_PATH_ ) )
498+
{
499+
return true;
500+
}
501+
}
502+
return false;
503+
}
504+
481505
static List<String> resortSourcesToPutModuleInfoFirst( List<String> allSources )
482506
{
483507
ArrayList<String> resorted = new ArrayList<>();
@@ -538,46 +562,49 @@ static boolean processCustomArguments( CompilerConfiguration config, List<String
538562
continue;
539563
}
540564

541-
/*
542-
* The compiler mojo makes quite a mess of passing arguments, depending on exactly WHICH
543-
* way is used to pass them. The method method using <compilerArguments> uses the tag names
544-
* of its contents to denote option names, and so the compiler mojo happily adds a '-' to
545-
* all of the names there and adds them to the "custom compiler arguments" map as a
546-
* name, value pair where the name always contains a single '-'. The Eclipse compiler (and
547-
* javac too, btw) has options with two dashes (like --add-modules for java 9). These cannot
548-
* be passed using a <compilerArguments> tag.
549-
*
550-
* The other method is to use <compilerArgs>, where each SINGLE argument needs to be passed
551-
* using an <arg>xxxx</arg> tag. In there the xxx is not manipulated by the compiler mojo, so
552-
* if it starts with a dash or more dashes these are perfectly preserved. But of course these
553-
* single <arg> entries are not a pair. So the compiler mojo adds them as pairs of (xxxx, null).
554-
*
555-
* We use that knowledge here: if a pair has a null value then do not mess up the key but
556-
* render it as a single value. This should ensure that something like:
557-
* <compilerArgs>
558-
* <arg>--add-modules</arg>
559-
* <arg>java.se.ee</arg>
560-
* </compilerArgs>
561-
*
562-
* is actually added to the command like as such.
563-
*
564-
* (btw: the above example will still give an error when using ecj <= 4.8M6:
565-
* invalid module name: java.se.ee
566-
* but that seems to be a bug in ecj).
567-
*/
568-
if ( null == optionValue )
569-
{
570-
//-- We have an option from compilerArgs: use the key as-is as a single option value
571-
args.add( opt );
572-
}
573-
else
565+
if ( !opt.equals( OPT_REPLACE_PROCESSOR_PATH ) && !opt.equals( OPT_REPLACE_PROCESSOR_PATH_ ) )
574566
{
575-
if ( !opt.startsWith( "-" ) )
567+
/*
568+
* The compiler mojo makes quite a mess of passing arguments, depending on exactly WHICH
569+
* way is used to pass them. The method method using <compilerArguments> uses the tag names
570+
* of its contents to denote option names, and so the compiler mojo happily adds a '-' to
571+
* all of the names there and adds them to the "custom compiler arguments" map as a
572+
* name, value pair where the name always contains a single '-'. The Eclipse compiler (and
573+
* javac too, btw) has options with two dashes (like --add-modules for java 9). These cannot
574+
* be passed using a <compilerArguments> tag.
575+
*
576+
* The other method is to use <compilerArgs>, where each SINGLE argument needs to be passed
577+
* using an <arg>xxxx</arg> tag. In there the xxx is not manipulated by the compiler mojo, so
578+
* if it starts with a dash or more dashes these are perfectly preserved. But of course these
579+
* single <arg> entries are not a pair. So the compiler mojo adds them as pairs of (xxxx, null).
580+
*
581+
* We use that knowledge here: if a pair has a null value then do not mess up the key but
582+
* render it as a single value. This should ensure that something like:
583+
* <compilerArgs>
584+
* <arg>--add-modules</arg>
585+
* <arg>java.se.ee</arg>
586+
* </compilerArgs>
587+
*
588+
* is actually added to the command like as such.
589+
*
590+
* (btw: the above example will still give an error when using ecj <= 4.8M6:
591+
* invalid module name: java.se.ee
592+
* but that seems to be a bug in ecj).
593+
*/
594+
if ( null == optionValue )
595+
{
596+
//-- We have an option from compilerArgs: use the key as-is as a single option value
597+
args.add( opt );
598+
}
599+
else
576600
{
577-
opt = "-" + opt;
601+
if ( !opt.startsWith( "-" ) )
602+
{
603+
opt = "-" + opt;
604+
}
605+
args.add( opt );
606+
args.add( optionValue );
578607
}
579-
args.add( opt );
580-
args.add( optionValue );
581608
}
582609
}
583610
return result;

0 commit comments

Comments
 (0)