@@ -187,11 +187,9 @@ protected static class Messages {
187
187
}
188
188
189
189
private static final Object LOCK = new Object ();
190
-
191
190
private static final String JAVAC_CLASSNAME = "com.sun.tools.javac.Main" ;
192
191
193
192
private volatile Class <?> javacClass ;
194
-
195
193
private final Deque <Class <?>> javacClasses = new ConcurrentLinkedDeque <>();
196
194
197
195
@ Inject
@@ -217,26 +215,22 @@ public String getCompilerId() {
217
215
@ Override
218
216
public CompilerResult performCompile (CompilerConfiguration config ) throws CompilerException {
219
217
File destinationDir = new File (config .getOutputLocation ());
220
-
221
218
if (!destinationDir .exists ()) {
222
219
destinationDir .mkdirs ();
223
220
}
224
221
225
222
String [] sourceFiles = getSourceFiles (config );
226
-
227
223
if ((sourceFiles == null ) || (sourceFiles .length == 0 )) {
228
224
return new CompilerResult ();
229
225
}
230
226
231
227
logCompiling (sourceFiles , config );
232
228
233
229
String [] args = buildCompilerArguments (config , sourceFiles );
234
-
235
230
CompilerResult result ;
236
231
237
232
if (config .isFork ()) {
238
233
String executable = config .getExecutable ();
239
-
240
234
if (StringUtils .isEmpty (executable )) {
241
235
try {
242
236
executable = getJavacExecutable ();
@@ -247,7 +241,6 @@ public CompilerResult performCompile(CompilerConfiguration config) throws Compil
247
241
executable = "javac" ;
248
242
}
249
243
}
250
-
251
244
result = compileOutOfProcess (config , executable , args );
252
245
} else {
253
246
if (isJava16 () && !config .isForceJavacCompilerUse ()) {
@@ -286,9 +279,7 @@ public static String[] buildCompilerArguments(CompilerConfiguration config, Stri
286
279
// ----------------------------------------------------------------------
287
280
288
281
File destinationDir = new File (config .getOutputLocation ());
289
-
290
282
args .add ("-d" );
291
-
292
283
args .add (destinationDir .getAbsolutePath ());
293
284
294
285
// ----------------------------------------------------------------------
@@ -298,14 +289,12 @@ public static String[] buildCompilerArguments(CompilerConfiguration config, Stri
298
289
List <String > classpathEntries = config .getClasspathEntries ();
299
290
if (classpathEntries != null && !classpathEntries .isEmpty ()) {
300
291
args .add ("-classpath" );
301
-
302
292
args .add (getPathString (classpathEntries ));
303
293
}
304
294
305
295
List <String > modulepathEntries = config .getModulepathEntries ();
306
296
if (modulepathEntries != null && !modulepathEntries .isEmpty ()) {
307
297
args .add ("--module-path" );
308
-
309
298
args .add (getPathString (modulepathEntries ));
310
299
}
311
300
@@ -314,7 +303,6 @@ public static String[] buildCompilerArguments(CompilerConfiguration config, Stri
314
303
// always pass source path, even if sourceFiles are declared,
315
304
// needed for jsr269 annotation processing, see MCOMPILER-98
316
305
args .add ("-sourcepath" );
317
-
318
306
args .add (getPathString (sourceLocations ));
319
307
}
320
308
if (!isJava16 () || config .isForceJavacCompilerUse () || config .isFork ()) {
@@ -326,7 +314,6 @@ public static String[] buildCompilerArguments(CompilerConfiguration config, Stri
326
314
327
315
if (config .getGeneratedSourcesDirectory () != null ) {
328
316
config .getGeneratedSourcesDirectory ().mkdirs ();
329
-
330
317
args .add ("-s" );
331
318
args .add (config .getGeneratedSourcesDirectory ().getAbsolutePath ());
332
319
}
@@ -341,7 +328,6 @@ public static String[] buildCompilerArguments(CompilerConfiguration config, Stri
341
328
if (i > 0 ) {
342
329
buffer .append ("," );
343
330
}
344
-
345
331
buffer .append (procs [i ]);
346
332
}
347
333
args .add (buffer .toString ());
@@ -452,13 +438,10 @@ public static String[] buildCompilerArguments(CompilerConfiguration config, Stri
452
438
}
453
439
454
440
args .add (key );
455
-
456
441
String value = entry .getValue ();
457
-
458
442
if (StringUtils .isEmpty (value )) {
459
443
continue ;
460
444
}
461
-
462
445
args .add (value );
463
446
}
464
447
@@ -499,11 +482,9 @@ private static boolean isPreJava16(CompilerConfiguration config) {
499
482
if (v == null ) {
500
483
v = config .getCompilerVersion ();
501
484
}
502
-
503
485
if (v == null ) {
504
486
v = config .getSourceVersion ();
505
487
}
506
-
507
488
if (v == null ) {
508
489
return true ;
509
490
}
@@ -523,11 +504,9 @@ private static boolean isPreJava18(CompilerConfiguration config) {
523
504
if (v == null ) {
524
505
v = config .getCompilerVersion ();
525
506
}
526
-
527
507
if (v == null ) {
528
508
v = config .getSourceVersion ();
529
509
}
530
-
531
510
if (v == null ) {
532
511
return true ;
533
512
}
@@ -545,17 +524,14 @@ private static boolean isPreJava18(CompilerConfiguration config) {
545
524
}
546
525
547
526
private static boolean isPreJava9 (CompilerConfiguration config ) {
548
-
549
527
String v = config .getReleaseVersion ();
550
528
551
529
if (v == null ) {
552
530
v = config .getCompilerVersion ();
553
531
}
554
-
555
532
if (v == null ) {
556
533
v = config .getSourceVersion ();
557
534
}
558
-
559
535
if (v == null ) {
560
536
return true ;
561
537
}
@@ -596,7 +572,6 @@ protected CompilerResult compileOutOfProcess(CompilerConfiguration config, Strin
596
572
Commandline cli = new Commandline ();
597
573
598
574
cli .setWorkingDirectory (config .getWorkingDirectory ().getAbsolutePath ());
599
-
600
575
cli .setExecutable (executable );
601
576
602
577
try {
@@ -608,7 +583,6 @@ protected CompilerResult compileOutOfProcess(CompilerConfiguration config, Strin
608
583
if (!StringUtils .isEmpty (config .getMaxmem ())) {
609
584
cli .addArguments (new String [] {"-J-Xmx" + config .getMaxmem ()});
610
585
}
611
-
612
586
if (!StringUtils .isEmpty (config .getMeminitial ())) {
613
587
cli .addArguments (new String [] {"-J-Xms" + config .getMeminitial ()});
614
588
}
@@ -623,9 +597,7 @@ protected CompilerResult compileOutOfProcess(CompilerConfiguration config, Strin
623
597
}
624
598
625
599
CommandLineUtils .StringStreamConsumer out = new CommandLineUtils .StringStreamConsumer ();
626
-
627
600
int returnCode ;
628
-
629
601
List <CompilerMessage > messages ;
630
602
631
603
if (getLog ().isDebugEnabled ()) {
@@ -700,16 +672,12 @@ protected CompilerResult compileInProcessWithProperClassloader(Class<?> javacCla
700
672
*/
701
673
private static CompilerResult compileInProcess0 (Class <?> javacClass , String [] args ) throws CompilerException {
702
674
StringWriter out = new StringWriter ();
703
-
704
675
Integer ok ;
705
-
706
676
List <CompilerMessage > messages ;
707
677
708
678
try {
709
679
Method compile = javacClass .getMethod ("compile" , new Class [] {String [].class , PrintWriter .class });
710
-
711
680
ok = (Integer ) compile .invoke (null , new Object [] {args , new PrintWriter (out )});
712
-
713
681
messages = parseModernStream (ok , new BufferedReader (new StringReader (out .toString ())));
714
682
} catch (NoSuchMethodException | IOException | InvocationTargetException | IllegalAccessException e ) {
715
683
throw new CompilerException ("Error while executing the compiler." , e );
@@ -926,7 +894,6 @@ static String getTextStartingWithPrefix(String text, String[] prefixes) {
926
894
*/
927
895
static CompilerMessage parseModernError (int exitCode , String error ) {
928
896
final StringTokenizer tokens = new StringTokenizer (error , ":" );
929
-
930
897
CompilerMessage .Kind messageKind = exitCode == 0 ? WARNING : ERROR ;
931
898
932
899
try {
@@ -1039,15 +1006,11 @@ private File createFileWithArguments(String[] args, String outputDirectory) thro
1039
1006
}
1040
1007
1041
1008
writer = new PrintWriter (new FileWriter (tempFile ));
1042
-
1043
1009
for (String arg : args ) {
1044
1010
String argValue = arg .replace (File .separatorChar , '/' );
1045
-
1046
1011
writer .write ("\" " + argValue + "\" " );
1047
-
1048
1012
writer .println ();
1049
1013
}
1050
-
1051
1014
writer .flush ();
1052
1015
1053
1016
return tempFile ;
@@ -1068,9 +1031,9 @@ private File createFileWithArguments(String[] args, String outputDirectory) thro
1068
1031
*/
1069
1032
private static String getJavacExecutable () throws IOException {
1070
1033
String javacCommand = "javac" + (Os .isFamily (Os .FAMILY_WINDOWS ) ? ".exe" : "" );
1071
-
1072
1034
String javaHome = System .getProperty ("java.home" );
1073
1035
File javacExe ;
1036
+
1074
1037
if (Os .isName ("AIX" )) {
1075
1038
javacExe = new File (javaHome + File .separator + ".." + File .separator + "sh" , javacCommand );
1076
1039
} else if (Os .isName ("Mac OS X" )) {
@@ -1092,7 +1055,6 @@ private static String getJavacExecutable() throws IOException {
1092
1055
throw new IOException ("The environment variable JAVA_HOME=" + javaHome
1093
1056
+ " doesn't exist or is not a valid directory." );
1094
1057
}
1095
-
1096
1058
javacExe = new File (env .getProperty ("JAVA_HOME" ) + File .separator + "bin" , javacCommand );
1097
1059
}
1098
1060
0 commit comments