|  | 
| 24 | 24 |  * SOFTWARE. | 
| 25 | 25 |  */ | 
| 26 | 26 | 
 | 
| 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 |  | - | 
| 40 | 27 | import javax.tools.Diagnostic; | 
| 41 | 28 | import javax.tools.DiagnosticListener; | 
| 42 | 29 | import javax.tools.JavaCompiler; | 
| 43 | 30 | import javax.tools.JavaFileObject; | 
| 44 | 31 | import javax.tools.StandardJavaFileManager; | 
|  | 32 | + | 
| 45 | 33 | import java.io.File; | 
| 46 | 34 | import java.io.PrintWriter; | 
| 47 | 35 | import java.io.StringWriter; | 
|  | 
| 56 | 44 | import java.util.ServiceLoader; | 
| 57 | 45 | import java.util.Set; | 
| 58 | 46 | 
 | 
|  | 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 | + | 
| 59 | 60 | /** | 
| 60 | 61 |  * | 
| 61 | 62 |  */ | 
| @@ -206,7 +207,14 @@ public CompilerResult performCompile( CompilerConfiguration config ) | 
| 206 | 207 | 
 | 
| 207 | 208 |  if ( processorPathEntries != null && processorPathEntries.size() > 0 ) | 
| 208 | 209 |  { | 
| 209 |  | - args.add( "-processorpath" ); | 
|  | 210 | + if ( isReplaceProcessorPath( config ) ) | 
|  | 211 | + { | 
|  | 212 | + args.add( "--processor-module-path" ); | 
|  | 213 | + } | 
|  | 214 | + else | 
|  | 215 | + { | 
|  | 216 | + args.add( "-processorpath" ); | 
|  | 217 | + } | 
| 210 | 218 |  args.add( getPathString( processorPathEntries ) ); | 
| 211 | 219 |  } | 
| 212 | 220 | 
 | 
| @@ -478,6 +486,22 @@ public void worked( int i, int i1 ) | 
| 478 | 486 |  } | 
| 479 | 487 |  } | 
| 480 | 488 | 
 | 
|  | 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 | + | 
| 481 | 505 |  static List<String> resortSourcesToPutModuleInfoFirst( List<String> allSources ) | 
| 482 | 506 |  { | 
| 483 | 507 |  ArrayList<String> resorted = new ArrayList<>(); | 
| @@ -538,46 +562,49 @@ static boolean processCustomArguments( CompilerConfiguration config, List<String | 
| 538 | 562 |  continue; | 
| 539 | 563 |  } | 
| 540 | 564 | 
 | 
| 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_ ) ) | 
| 574 | 566 |  { | 
| 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 | 
| 576 | 600 |  { | 
| 577 |  | - opt = "-" + opt; | 
|  | 601 | + if ( !opt.startsWith( "-" ) ) | 
|  | 602 | + { | 
|  | 603 | + opt = "-" + opt; | 
|  | 604 | + } | 
|  | 605 | + args.add( opt ); | 
|  | 606 | + args.add( optionValue ); | 
| 578 | 607 |  } | 
| 579 |  | - args.add( opt ); | 
| 580 |  | - args.add( optionValue ); | 
| 581 | 608 |  } | 
| 582 | 609 |  } | 
| 583 | 610 |  return result; | 
|  | 
0 commit comments