@@ -106,7 +106,8 @@ static class BlazeEclipseBatchCompiler extends Main {
106
106
public BlazeEclipseBatchCompiler (PrintWriter outWriter , PrintWriter errWriter ,
107
107
ImmutableList <BlazeJavaCompilerPlugin > plugins , String sandboxPathPrefix ,
108
108
Map <Path , Path > sourceFilesByAbsoluteOrCanonicalPath ,
109
- UsedDependencyCollectionMode usedDependencyCollectionMode , Path problemSeverityPreferences ) {
109
+ UsedDependencyCollectionMode usedDependencyCollectionMode ,
110
+ Map <String , String > problemSeverityPreferences ) {
110
111
super (outWriter , errWriter , false /* systemExitWhenFinished */ , null /* customDefaultOptions */ ,
111
112
null /* compilationProgress */ );
112
113
this .usedDependencyCollectionMode = usedDependencyCollectionMode ;
@@ -121,7 +122,7 @@ public BlazeEclipseBatchCompiler(PrintWriter outWriter, PrintWriter errWriter,
121
122
this .noneDirectDependenciesMap = dependencyModule .getImplicitDependenciesMap ();
122
123
123
124
if (problemSeverityPreferences != null ) {
124
- this .options .putAll (loadProblemSeverityPreferences ( problemSeverityPreferences ) );
125
+ this .options .putAll (problemSeverityPreferences );
125
126
}
126
127
127
128
switch (dependencyModule .getStrictJavaDeps ()) {
@@ -297,15 +298,21 @@ public static BlazeJavacResult compile(BlazeJavacArguments arguments) {
297
298
298
299
// note, all -Xecj... are "blaze" specific javac options
299
300
String collectUsedDepsOption = getJavacOptionValue (arguments .blazeJavacOptions (), "-Xecj_collect_used_deps" );
300
- String problemSeverityPreferences = getJavacOptionValue (arguments .blazeJavacOptions (),
301
+ String problemSeverityPreferencesFile = getJavacOptionValue (arguments .blazeJavacOptions (),
301
302
"-Xecj_problem_severity_preferences" );
302
303
304
+ Map <String , String > problemSeverityPreferences = null ;
305
+ try {
306
+ if (problemSeverityPreferencesFile != null && !isDisabled (problemSeverityPreferencesFile )) {
307
+ problemSeverityPreferences = loadProblemSeverityPreferences (Path .of (problemSeverityPreferencesFile ));
308
+ }
309
+ } catch (Exception e ) {
310
+ return BlazeJavacResult .error (format ("Error reading problem severity preferences: %s" , e .toString ()));
311
+ }
312
+
303
313
BlazeEclipseBatchCompiler compiler = new BlazeEclipseBatchCompiler (errWriter , errWriter , arguments .plugins (),
304
314
sandboxPathPrefix , sourceFilesByAbsoluteOrCanonicalPath ,
305
- UsedDependencyCollectionMode .fromOptionValue (collectUsedDepsOption ),
306
- problemSeverityPreferences != null && !isDisabled (problemSeverityPreferences )
307
- ? Path .of (problemSeverityPreferences )
308
- : null );
315
+ UsedDependencyCollectionMode .fromOptionValue (collectUsedDepsOption ), problemSeverityPreferences );
309
316
310
317
List <String > ecjArguments = new ArrayList <>();
311
318
setLocations (ecjArguments , arguments , compiler .dependencyModule );
@@ -373,10 +380,12 @@ private static boolean isDisabled(String problemSeverityPreferences) {
373
380
}
374
381
375
382
/**
376
- * Go through the list of javac options and collect the value of the <b>last</b> option found.
383
+ * Go through the list of javac options and collect the value of the <b>last</b>
384
+ * option found.
377
385
* <p>
378
386
* The reason we go with last is that we assume it's the most specific.
379
387
* </p>
388
+ *
380
389
* @param javacOptions
381
390
* @param optionName
382
391
* @return
@@ -397,13 +406,10 @@ private static String getJavacOptionValue(List<String> javacOptions, String opti
397
406
return value ;
398
407
}
399
408
400
- static Map <String , String > loadProblemSeverityPreferences (Path compilerPreferencesFile ) {
409
+ static Map <String , String > loadProblemSeverityPreferences (Path compilerPreferencesFile ) throws IOException {
401
410
final Properties properties = new Properties ();
402
411
try (InputStream is = new BufferedInputStream (newInputStream (compilerPreferencesFile ))) {
403
412
properties .load (is );
404
- } catch (IOException e ) {
405
- throw new IllegalStateException (format ("Error loading problem severity preferences '%s': %s" ,
406
- compilerPreferencesFile , e .getMessage ()), e );
407
413
}
408
414
409
415
Set <String > warningOptions = Set .of (CompilerOptions .warningOptionNames ());
0 commit comments