@@ -106,7 +106,8 @@ static class BlazeEclipseBatchCompiler extends Main {
106106 public BlazeEclipseBatchCompiler (PrintWriter outWriter , PrintWriter errWriter ,
107107 ImmutableList <BlazeJavaCompilerPlugin > plugins , String sandboxPathPrefix ,
108108 Map <Path , Path > sourceFilesByAbsoluteOrCanonicalPath ,
109- UsedDependencyCollectionMode usedDependencyCollectionMode , Path problemSeverityPreferences ) {
109+ UsedDependencyCollectionMode usedDependencyCollectionMode ,
110+ Map <String , String > problemSeverityPreferences ) {
110111 super (outWriter , errWriter , false /* systemExitWhenFinished */ , null /* customDefaultOptions */ ,
111112 null /* compilationProgress */ );
112113 this .usedDependencyCollectionMode = usedDependencyCollectionMode ;
@@ -121,7 +122,7 @@ public BlazeEclipseBatchCompiler(PrintWriter outWriter, PrintWriter errWriter,
121122 this .noneDirectDependenciesMap = dependencyModule .getImplicitDependenciesMap ();
122123
123124 if (problemSeverityPreferences != null ) {
124- this .options .putAll (loadProblemSeverityPreferences ( problemSeverityPreferences ) );
125+ this .options .putAll (problemSeverityPreferences );
125126 }
126127
127128 switch (dependencyModule .getStrictJavaDeps ()) {
@@ -297,15 +298,21 @@ public static BlazeJavacResult compile(BlazeJavacArguments arguments) {
297298
298299 // note, all -Xecj... are "blaze" specific javac options
299300 String collectUsedDepsOption = getJavacOptionValue (arguments .blazeJavacOptions (), "-Xecj_collect_used_deps" );
300- String problemSeverityPreferences = getJavacOptionValue (arguments .blazeJavacOptions (),
301+ String problemSeverityPreferencesFile = getJavacOptionValue (arguments .blazeJavacOptions (),
301302 "-Xecj_problem_severity_preferences" );
302303
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+
303313 BlazeEclipseBatchCompiler compiler = new BlazeEclipseBatchCompiler (errWriter , errWriter , arguments .plugins (),
304314 sandboxPathPrefix , sourceFilesByAbsoluteOrCanonicalPath ,
305- UsedDependencyCollectionMode .fromOptionValue (collectUsedDepsOption ),
306- problemSeverityPreferences != null && !isDisabled (problemSeverityPreferences )
307- ? Path .of (problemSeverityPreferences )
308- : null );
315+ UsedDependencyCollectionMode .fromOptionValue (collectUsedDepsOption ), problemSeverityPreferences );
309316
310317 List <String > ecjArguments = new ArrayList <>();
311318 setLocations (ecjArguments , arguments , compiler .dependencyModule );
@@ -373,10 +380,12 @@ private static boolean isDisabled(String problemSeverityPreferences) {
373380 }
374381
375382 /**
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.
377385 * <p>
378386 * The reason we go with last is that we assume it's the most specific.
379387 * </p>
388+ *
380389 * @param javacOptions
381390 * @param optionName
382391 * @return
@@ -397,13 +406,10 @@ private static String getJavacOptionValue(List<String> javacOptions, String opti
397406 return value ;
398407 }
399408
400- static Map <String , String > loadProblemSeverityPreferences (Path compilerPreferencesFile ) {
409+ static Map <String , String > loadProblemSeverityPreferences (Path compilerPreferencesFile ) throws IOException {
401410 final Properties properties = new Properties ();
402411 try (InputStream is = new BufferedInputStream (newInputStream (compilerPreferencesFile ))) {
403412 properties .load (is );
404- } catch (IOException e ) {
405- throw new IllegalStateException (format ("Error loading problem severity preferences '%s': %s" ,
406- compilerPreferencesFile , e .getMessage ()), e );
407413 }
408414
409415 Set <String > warningOptions = Set .of (CompilerOptions .warningOptionNames ());
0 commit comments