|
52 | 52 | import java.util.Iterator;
|
53 | 53 | import java.util.List;
|
54 | 54 | import java.util.Locale;
|
55 |
| -import java.util.Map; |
56 | 55 | import java.util.Map.Entry;
|
57 | 56 | import java.util.ServiceLoader;
|
58 | 57 | import java.util.Set;
|
@@ -152,76 +151,7 @@ public CompilerResult performCompile( CompilerConfiguration config )
|
152 | 151 |
|
153 | 152 | // Set Eclipse-specific options
|
154 | 153 | // compiler-specific extra options override anything else in the config object...
|
155 |
| - Map<String, String> extras = config.getCustomCompilerArgumentsAsMap(); |
156 |
| - if ( extras.containsKey( "errorsAsWarnings" ) ) |
157 |
| - { |
158 |
| - extras.remove( "errorsAsWarnings" ); |
159 |
| - this.errorsAsWarnings = true; |
160 |
| - } |
161 |
| - else if ( extras.containsKey( "-errorsAsWarnings" ) ) |
162 |
| - { |
163 |
| - extras.remove( "-errorsAsWarnings" ); |
164 |
| - this.errorsAsWarnings = true; |
165 |
| - } |
166 |
| - |
167 |
| - //-- check for existence of the properties file manually |
168 |
| - String props = extras.get( "-properties" ); |
169 |
| - if ( null != props ) |
170 |
| - { |
171 |
| - File propFile = new File( props ); |
172 |
| - if ( !propFile.exists() || !propFile.isFile() ) |
173 |
| - { |
174 |
| - throw new IllegalArgumentException( |
175 |
| - "Properties file specified by -properties " + propFile + " does not exist" ); |
176 |
| - } |
177 |
| - } |
178 |
| - |
179 |
| - for ( Entry<String, String> entry : extras.entrySet() ) |
180 |
| - { |
181 |
| - /* |
182 |
| - * The compiler mojo makes quite a mess of passing arguments, depending on exactly WHICH |
183 |
| - * way is used to pass them. The method method using <compilerArguments> uses the tag names |
184 |
| - * of its contents to denote option names, and so the compiler mojo happily adds a '-' to |
185 |
| - * all of the names there and adds them to the "custom compiler arguments" map as a |
186 |
| - * name, value pair where the name always contains a single '-'. The Eclipse compiler (and |
187 |
| - * javac too, btw) has options with two dashes (like --add-modules for java 9). These cannot |
188 |
| - * be passed using a <compilerArguments> tag. |
189 |
| - * |
190 |
| - * The other method is to use <compilerArgs>, where each SINGLE argument needs to be passed |
191 |
| - * using an <arg>xxxx</arg> tag. In there the xxx is not manipulated by the compiler mojo, so |
192 |
| - * if it starts with a dash or more dashes these are perfectly preserved. But of course these |
193 |
| - * single <arg> entries are not a pair. So the compiler mojo adds them as pairs of (xxxx, null). |
194 |
| - * |
195 |
| - * We use that knowledge here: if a pair has a null value then do not mess up the key but |
196 |
| - * render it as a single value. This should ensure that something like: |
197 |
| - * <compilerArgs> |
198 |
| - * <arg>--add-modules</arg> |
199 |
| - * <arg>java.se.ee</arg> |
200 |
| - * </compilerArgs> |
201 |
| - * |
202 |
| - * is actually added to the command like as such. |
203 |
| - * |
204 |
| - * (btw: the above example will still give an error when using ecj <= 4.8M6: |
205 |
| - * invalid module name: java.se.ee |
206 |
| - * but that seems to be a bug in ecj). |
207 |
| - */ |
208 |
| - String opt = entry.getKey(); |
209 |
| - String optionValue = entry.getValue(); |
210 |
| - if ( null == optionValue ) |
211 |
| - { |
212 |
| - //-- We have an option from compilerArgs: use the key as-is as a single option value |
213 |
| - args.add( opt ); |
214 |
| - } |
215 |
| - else |
216 |
| - { |
217 |
| - if ( !opt.startsWith( "-" ) ) |
218 |
| - { |
219 |
| - opt = "-" + opt; |
220 |
| - } |
221 |
| - args.add( opt ); |
222 |
| - args.add( optionValue ); |
223 |
| - } |
224 |
| - } |
| 154 | + this.errorsAsWarnings = processCustomArguments(config, args); |
225 | 155 |
|
226 | 156 | // Output path
|
227 | 157 | args.add( "-d" );
|
@@ -275,13 +205,6 @@ else if ( extras.containsKey( "-errorsAsWarnings" ) )
|
275 | 205 | }
|
276 | 206 | }
|
277 | 207 |
|
278 |
| - //-- Write .class files even when error occur, but make sure methods with compile errors do abort when called |
279 |
| - if ( extras.containsKey( "-proceedOnError" ) ) |
280 |
| - { |
281 |
| - // Generate a class file even with errors, but make methods with errors fail when called |
282 |
| - args.add( "-proceedOnError:Fatal" ); |
283 |
| - } |
284 |
| - |
285 | 208 | //-- classpath
|
286 | 209 | List<String> classpathEntries = new ArrayList<>( config.getClasspathEntries() );
|
287 | 210 | classpathEntries.add( config.getOutputLocation() );
|
@@ -528,6 +451,88 @@ public void worked( int i, int i1 )
|
528 | 451 | }
|
529 | 452 | }
|
530 | 453 |
|
| 454 | + static boolean processCustomArguments( CompilerConfiguration config, List<String> args ) |
| 455 | + { |
| 456 | + boolean result = false; |
| 457 | + |
| 458 | + for ( Entry<String, String> entry : config.getCustomCompilerArgumentsEntries() ) |
| 459 | + { |
| 460 | + String opt = entry.getKey(); |
| 461 | + String optionValue = entry.getValue(); |
| 462 | + |
| 463 | + // handle errorsAsWarnings options |
| 464 | + if ( opt.equals("errorsAsWarnings") || opt.equals("-errorsAsWarnings") ) |
| 465 | + { |
| 466 | + result = true; |
| 467 | + continue; |
| 468 | + } |
| 469 | + |
| 470 | + if ( opt.equals( "-properties" ) ) |
| 471 | + { |
| 472 | + if ( null != optionValue ) |
| 473 | + { |
| 474 | + File propFile = new File( optionValue ); |
| 475 | + if ( !propFile.exists() || !propFile.isFile() ) |
| 476 | + { |
| 477 | + throw new IllegalArgumentException( |
| 478 | + "Properties file specified by -properties " + propFile + " does not exist" ); |
| 479 | + } |
| 480 | + } |
| 481 | + } |
| 482 | + |
| 483 | + //-- Write .class files even when error occur, but make sure methods with compile errors do abort when called |
| 484 | + if ( opt.equals( "-proceedOnError" ) ) |
| 485 | + { |
| 486 | + // Generate a class file even with errors, but make methods with errors fail when called |
| 487 | + args.add( "-proceedOnError:Fatal" ); |
| 488 | + continue; |
| 489 | + } |
| 490 | + |
| 491 | + /* |
| 492 | + * The compiler mojo makes quite a mess of passing arguments, depending on exactly WHICH |
| 493 | + * way is used to pass them. The method method using <compilerArguments> uses the tag names |
| 494 | + * of its contents to denote option names, and so the compiler mojo happily adds a '-' to |
| 495 | + * all of the names there and adds them to the "custom compiler arguments" map as a |
| 496 | + * name, value pair where the name always contains a single '-'. The Eclipse compiler (and |
| 497 | + * javac too, btw) has options with two dashes (like --add-modules for java 9). These cannot |
| 498 | + * be passed using a <compilerArguments> tag. |
| 499 | + * |
| 500 | + * The other method is to use <compilerArgs>, where each SINGLE argument needs to be passed |
| 501 | + * using an <arg>xxxx</arg> tag. In there the xxx is not manipulated by the compiler mojo, so |
| 502 | + * if it starts with a dash or more dashes these are perfectly preserved. But of course these |
| 503 | + * single <arg> entries are not a pair. So the compiler mojo adds them as pairs of (xxxx, null). |
| 504 | + * |
| 505 | + * We use that knowledge here: if a pair has a null value then do not mess up the key but |
| 506 | + * render it as a single value. This should ensure that something like: |
| 507 | + * <compilerArgs> |
| 508 | + * <arg>--add-modules</arg> |
| 509 | + * <arg>java.se.ee</arg> |
| 510 | + * </compilerArgs> |
| 511 | + * |
| 512 | + * is actually added to the command like as such. |
| 513 | + * |
| 514 | + * (btw: the above example will still give an error when using ecj <= 4.8M6: |
| 515 | + * invalid module name: java.se.ee |
| 516 | + * but that seems to be a bug in ecj). |
| 517 | + */ |
| 518 | + if ( null == optionValue ) |
| 519 | + { |
| 520 | + //-- We have an option from compilerArgs: use the key as-is as a single option value |
| 521 | + args.add( opt ); |
| 522 | + } |
| 523 | + else |
| 524 | + { |
| 525 | + if ( !opt.startsWith( "-" ) ) |
| 526 | + { |
| 527 | + opt = "-" + opt; |
| 528 | + } |
| 529 | + args.add( opt ); |
| 530 | + args.add( optionValue ); |
| 531 | + } |
| 532 | + } |
| 533 | + return result; |
| 534 | + } |
| 535 | + |
531 | 536 | private static boolean haveSourceOrReleaseArgument( List<String> args )
|
532 | 537 | {
|
533 | 538 | Iterator<String> allArgs = args.iterator();
|
|
0 commit comments