Add property for outputting configuration html report

This also removes the parsing of the -printblastradius directive.

Change-Id: I82d393c02142bdc443937228b1f69c1076694f26
diff --git a/src/libanalyzer/java/com/android/tools/r8/libanalyzer/LibraryAnalyzer.java b/src/libanalyzer/java/com/android/tools/r8/libanalyzer/LibraryAnalyzer.java
index 029e47f..543d3fc 100644
--- a/src/libanalyzer/java/com/android/tools/r8/libanalyzer/LibraryAnalyzer.java
+++ b/src/libanalyzer/java/com/android/tools/r8/libanalyzer/LibraryAnalyzer.java
@@ -155,9 +155,8 @@
           r8Options -> {
             r8Options.libraryAnalyzerSubCompilation = true;
             r8Options.ignoreUnusedProguardRules = true;
-            if (options.blastRadiusOutputPath != null) {
-              r8Options.getBlastRadiusOptions().outputPath =
-                  options.blastRadiusOutputPath.toString();
+            if (options.blastRadiusDataOutputPath != null) {
+              r8Options.getBlastRadiusOptions().dataOutputPath = options.blastRadiusDataOutputPath;
             }
             r8Options.getBlastRadiusOptions().blastRadiusConsumer =
                 (appView, appInfo, blastRadius) ->
diff --git a/src/libanalyzer/java/com/android/tools/r8/libanalyzer/LibraryAnalyzerCommand.java b/src/libanalyzer/java/com/android/tools/r8/libanalyzer/LibraryAnalyzerCommand.java
index c61c643..33ce7ae 100644
--- a/src/libanalyzer/java/com/android/tools/r8/libanalyzer/LibraryAnalyzerCommand.java
+++ b/src/libanalyzer/java/com/android/tools/r8/libanalyzer/LibraryAnalyzerCommand.java
@@ -25,7 +25,7 @@
 public final class LibraryAnalyzerCommand {
 
   private final AndroidApp app;
-  private final Path blastRadiusOutputPath;
+  private final Path blastRadiusDataOutputPath;
   private final AndroidApiLevel minApiLevel;
   private final Consumer<LibraryAnalyzerResult> outputConsumer;
   private final Reporter reporter;
@@ -35,13 +35,13 @@
 
   private LibraryAnalyzerCommand(
       AndroidApp app,
-      Path blastRadiusOutputPath,
+      Path blastRadiusDataOutputPath,
       AndroidApiLevel minApiLevel,
       Consumer<LibraryAnalyzerResult> outputConsumer,
       Reporter reporter,
       int threadCount) {
     this.app = app;
-    this.blastRadiusOutputPath = blastRadiusOutputPath;
+    this.blastRadiusDataOutputPath = blastRadiusDataOutputPath;
     this.minApiLevel = minApiLevel;
     this.outputConsumer = outputConsumer;
     this.reporter = reporter;
@@ -52,7 +52,7 @@
 
   private LibraryAnalyzerCommand(boolean printHelp, boolean printVersion) {
     this.app = null;
-    this.blastRadiusOutputPath = null;
+    this.blastRadiusDataOutputPath = null;
     this.minApiLevel = null;
     this.outputConsumer = null;
     this.reporter = new Reporter();
@@ -67,7 +67,7 @@
 
   LibraryAnalyzerOptions getInternalOptions() {
     return new LibraryAnalyzerOptions(
-        blastRadiusOutputPath, minApiLevel, outputConsumer, reporter, threadCount);
+        blastRadiusDataOutputPath, minApiLevel, outputConsumer, reporter, threadCount);
   }
 
   boolean isPrintHelp() {
@@ -90,7 +90,7 @@
   public static class Builder {
 
     private final AndroidApp.Builder appBuilder;
-    private Path blastRadiusOutputPath;
+    private Path blastRadiusDataOutputPath;
     private AndroidApiLevel minApiLevel = AndroidApiLevel.getDefault();
     private Consumer<LibraryAnalyzerResult> outputConsumer;
     private final Reporter reporter;
@@ -140,8 +140,8 @@
       return this;
     }
 
-    public Builder setBlastRadiusOutputPath(Path blastRadiusOutputPath) {
-      this.blastRadiusOutputPath = blastRadiusOutputPath;
+    public Builder setBlastRadiusOutputPath(Path blastRadiusDataOutputPath) {
+      this.blastRadiusDataOutputPath = blastRadiusDataOutputPath;
       return this;
     }
 
@@ -203,7 +203,7 @@
       validate();
       return new LibraryAnalyzerCommand(
           appBuilder.build(),
-          blastRadiusOutputPath,
+          blastRadiusDataOutputPath,
           minApiLevel,
           outputConsumer,
           reporter,
diff --git a/src/libanalyzer/java/com/android/tools/r8/libanalyzer/utils/LibraryAnalyzerOptions.java b/src/libanalyzer/java/com/android/tools/r8/libanalyzer/utils/LibraryAnalyzerOptions.java
index 7aad3e5..c35b190 100644
--- a/src/libanalyzer/java/com/android/tools/r8/libanalyzer/utils/LibraryAnalyzerOptions.java
+++ b/src/libanalyzer/java/com/android/tools/r8/libanalyzer/utils/LibraryAnalyzerOptions.java
@@ -12,7 +12,7 @@
 
 public class LibraryAnalyzerOptions {
 
-  public final Path blastRadiusOutputPath;
+  public final Path blastRadiusDataOutputPath;
   public final AndroidApiLevel minApiLevel;
   public final Consumer<LibraryAnalyzerResult> outputConsumer;
   public final Reporter reporter;
@@ -21,12 +21,12 @@
   private ThreadingModule lazyThreadingModule = null;
 
   public LibraryAnalyzerOptions(
-      Path blastRadiusOutputPath,
+      Path blastRadiusDataOutputPath,
       AndroidApiLevel minApiLevel,
       Consumer<LibraryAnalyzerResult> outputConsumer,
       Reporter reporter,
       int threadCount) {
-    this.blastRadiusOutputPath = blastRadiusOutputPath;
+    this.blastRadiusDataOutputPath = blastRadiusDataOutputPath;
     this.minApiLevel = minApiLevel;
     this.outputConsumer = outputConsumer;
     this.reporter = reporter;
diff --git a/src/main/java/com/android/tools/r8/blastradius/BlastRadiusOptions.java b/src/main/java/com/android/tools/r8/blastradius/BlastRadiusOptions.java
index 23b843a..635caff 100644
--- a/src/main/java/com/android/tools/r8/blastradius/BlastRadiusOptions.java
+++ b/src/main/java/com/android/tools/r8/blastradius/BlastRadiusOptions.java
@@ -4,24 +4,31 @@
 package com.android.tools.r8.blastradius;
 
 import com.android.tools.r8.DexIndexedConsumer;
+import com.android.tools.r8.StringConsumer;
 import com.android.tools.r8.blastradius.proto.BlastRadiusContainer;
 import com.android.tools.r8.graph.AppInfoWithClassHierarchy;
 import com.android.tools.r8.graph.AppView;
 import com.android.tools.r8.shaking.AppInfoWithLiveness;
-import com.android.tools.r8.shaking.ProguardConfiguration;
 import com.android.tools.r8.utils.InternalOptions;
 import com.android.tools.r8.utils.SystemPropertyUtils;
 import java.nio.file.Path;
-import java.nio.file.Paths;
 import java.util.function.Consumer;
 
 public class BlastRadiusOptions {
 
   public BlastRadiusConsumer blastRadiusConsumer;
   public Consumer<BlastRadiusContainer> blastRadiusContainerConsumer;
-  public final String outputDirectory =
-      System.getProperty("com.android.tools.r8.dumpblastradiustodirectory");
-  public String outputPath = System.getProperty("com.android.tools.r8.dumpblastradiustofile");
+  public final Path dataOutputDirectory =
+      SystemPropertyUtils.parsePathFromSystemProperty(
+          "com.android.tools.r8.dumpblastradiustodirectory");
+  public Path dataOutputPath =
+      SystemPropertyUtils.parsePathFromSystemProperty("com.android.tools.r8.dumpblastradiustofile");
+  public final Path htmlOutputDirectory =
+      SystemPropertyUtils.parsePathFromSystemProperty(
+          "com.android.tools.r8.dumpblastradiushtmltodirectory");
+  public Path htmlOutputPath =
+      SystemPropertyUtils.parsePathFromSystemProperty(
+          "com.android.tools.r8.dumpblastradiushtmltofile");
   public final boolean enableSubsumptionAnalysis =
       SystemPropertyUtils.parseSystemPropertyOrDefault(
           "com.android.tools.r8.blastradius.enablesubsumptionanalysis", true);
@@ -42,29 +49,35 @@
 
   public Consumer<BlastRadiusContainer> getBlastRadiusContainerConsumer() {
     Consumer<BlastRadiusContainer> result = blastRadiusContainerConsumer;
-    Path outputPath = getOutputPath();
-    if (outputPath != null) {
-      Consumer<BlastRadiusContainer> writeToFile =
-          container -> BlastRadiusContainerUtils.writeToFile(container, outputPath);
-      result = result != null ? result.andThen(writeToFile) : writeToFile;
+    Path dataOutputPath = getDataOutputPath();
+    if (dataOutputPath != null) {
+      Consumer<BlastRadiusContainer> writeDataToFile =
+          container -> BlastRadiusContainerUtils.writeToFile(container, dataOutputPath);
+      result = result != null ? result.andThen(writeDataToFile) : writeDataToFile;
+    }
+    Path htmlOutputPath = getHtmlOutputPath();
+    if (htmlOutputPath != null) {
+      Consumer<BlastRadiusContainer> writeHtmlToFile =
+          container ->
+              BlastRadiusContainerUtils.writeHtmlToConsumer(
+                  container, new StringConsumer.FileConsumer(htmlOutputPath), options.reporter);
+      result = result != null ? result.andThen(writeHtmlToFile) : writeHtmlToFile;
     }
     return result;
   }
 
-  public Path getOutputPath() {
-    if (outputDirectory != null) {
-      return Paths.get(outputDirectory).resolve("blastradius" + System.nanoTime() + ".pb");
+  public Path getDataOutputPath() {
+    if (dataOutputDirectory != null) {
+      return dataOutputDirectory.resolve("blastradius" + System.nanoTime() + ".pb");
     }
-    if (outputPath != null) {
-      return Paths.get(outputPath);
+    return dataOutputPath;
+  }
+
+  public Path getHtmlOutputPath() {
+    if (htmlOutputDirectory != null) {
+      return htmlOutputDirectory.resolve("report" + System.nanoTime() + ".html");
     }
-    if (options.hasProguardConfiguration()) {
-      ProguardConfiguration configuration = options.getProguardConfiguration();
-      if (configuration.isPrintBlastRadius()) {
-        return configuration.getPrintBlastRadiusFile();
-      }
-    }
-    return null;
+    return htmlOutputPath;
   }
 
   public boolean shouldExitEarly() {
diff --git a/src/main/java/com/android/tools/r8/processkeeprules/FilteredKeepRulesBuilder.java b/src/main/java/com/android/tools/r8/processkeeprules/FilteredKeepRulesBuilder.java
index a7426d4..86a4da5 100644
--- a/src/main/java/com/android/tools/r8/processkeeprules/FilteredKeepRulesBuilder.java
+++ b/src/main/java/com/android/tools/r8/processkeeprules/FilteredKeepRulesBuilder.java
@@ -316,15 +316,6 @@
   }
 
   @Override
-  public void enablePrintBlastRadius(
-      Path printBlastRadiusFile,
-      ProguardConfigurationSourceParser parser,
-      Position position,
-      TextPosition positionStart) {
-    writeComment(parser, positionStart);
-  }
-
-  @Override
   public void enablePrintConfiguration(
       Path printConfigurationFile,
       ProguardConfigurationSourceParser parser,
diff --git a/src/main/java/com/android/tools/r8/processkeeprules/ValidateLibraryConsumerRulesKeepRuleProcessor.java b/src/main/java/com/android/tools/r8/processkeeprules/ValidateLibraryConsumerRulesKeepRuleProcessor.java
index 26d19bc..33fadb9 100644
--- a/src/main/java/com/android/tools/r8/processkeeprules/ValidateLibraryConsumerRulesKeepRuleProcessor.java
+++ b/src/main/java/com/android/tools/r8/processkeeprules/ValidateLibraryConsumerRulesKeepRuleProcessor.java
@@ -217,15 +217,6 @@
       TextPosition positionStart) {}
 
   @Override
-  public void enablePrintBlastRadius(
-      Path printBlastRadiusFile,
-      ProguardConfigurationSourceParser parser,
-      Position position,
-      TextPosition positionStart) {
-    handleRule(parser, position, "-printblastradius");
-  }
-
-  @Override
   public void enablePrintConfiguration(
       Path printConfigurationFile,
       ProguardConfigurationSourceParser parser,
diff --git a/src/main/java/com/android/tools/r8/shaking/ProguardConfiguration.java b/src/main/java/com/android/tools/r8/shaking/ProguardConfiguration.java
index 63a41c3..c199630 100644
--- a/src/main/java/com/android/tools/r8/shaking/ProguardConfiguration.java
+++ b/src/main/java/com/android/tools/r8/shaking/ProguardConfiguration.java
@@ -63,8 +63,6 @@
     private final List<DontOptimizeRule> dontOptimizeRules = new ArrayList<>();
     private final List<DontRepackageRule> dontRepackageRules = new ArrayList<>();
     private final List<DontShrinkRule> dontShrinkRules = new ArrayList<>();
-    private boolean printBlastRadius;
-    private Path printBlastRadiusFile;
     private boolean printConfiguration;
     private Path printConfigurationFile;
     private boolean printUsage;
@@ -248,16 +246,6 @@
     }
 
     @Override
-    public void enablePrintBlastRadius(
-        Path printBlastRadiusFile,
-        ProguardConfigurationSourceParser parser,
-        Position position,
-        TextPosition positionStart) {
-      this.printBlastRadius = true;
-      this.printBlastRadiusFile = printBlastRadiusFile;
-    }
-
-    @Override
     public void enablePrintConfiguration(
         Path printConfigurationFile,
         ProguardConfigurationSourceParser parser,
@@ -547,8 +535,6 @@
               dontOptimizeRules,
               dontRepackageRules,
               dontShrinkRules,
-              printBlastRadius,
-              printBlastRadiusFile,
               printConfiguration,
               printConfigurationFile,
               printUsage,
@@ -592,8 +578,6 @@
   private final List<DontOptimizeRule> dontOptimizeRules;
   private final List<DontRepackageRule> dontRepackageRules;
   private final List<DontShrinkRule> dontShrinkRules;
-  private final boolean printBlastRadius;
-  private final Path printBlastRadiusFile;
   private final boolean printConfiguration;
   private final Path printConfigurationFile;
   private final boolean printUsage;
@@ -636,8 +620,6 @@
       List<DontOptimizeRule> dontOptimizeRules,
       List<DontRepackageRule> dontRepackageRules,
       List<DontShrinkRule> dontShrinkRules,
-      boolean printBlastRadius,
-      Path printBlastRadiusFile,
       boolean printConfiguration,
       Path printConfigurationFile,
       boolean printUsage,
@@ -676,8 +658,6 @@
     this.dontOptimizeRules = dontOptimizeRules;
     this.dontRepackageRules = dontRepackageRules;
     this.dontShrinkRules = dontShrinkRules;
-    this.printBlastRadius = printBlastRadius;
-    this.printBlastRadiusFile = printBlastRadiusFile;
     this.printConfiguration = printConfiguration;
     this.printConfigurationFile = printConfigurationFile;
     this.printUsage = printUsage;
@@ -778,15 +758,6 @@
     return dontShrinkRules.isEmpty();
   }
 
-  public boolean isPrintBlastRadius() {
-    return printBlastRadius;
-  }
-
-  public Path getPrintBlastRadiusFile() {
-    assert isPrintBlastRadius();
-    return printBlastRadiusFile;
-  }
-
   public boolean isPrintConfiguration() {
     return printConfiguration;
   }
diff --git a/src/main/java/com/android/tools/r8/shaking/ProguardConfigurationParser.java b/src/main/java/com/android/tools/r8/shaking/ProguardConfigurationParser.java
index d91df53..8e731b4 100644
--- a/src/main/java/com/android/tools/r8/shaking/ProguardConfigurationParser.java
+++ b/src/main/java/com/android/tools/r8/shaking/ProguardConfigurationParser.java
@@ -448,10 +448,6 @@
         configurationConsumer.disableRepackaging(this, getPosition(optionStart));
       } else if (acceptString("dontshrink")) {
         configurationConsumer.disableShrinking(this, getPosition(optionStart));
-      } else if (acceptString("printblastradius")) {
-        skipWhitespace();
-        configurationConsumer.enablePrintBlastRadius(
-            parseOptionalFileName(), this, getPosition(optionStart), optionStart);
       } else if (acceptString("printconfiguration")) {
         skipWhitespace();
         configurationConsumer.enablePrintConfiguration(
diff --git a/src/main/java/com/android/tools/r8/shaking/ProguardConfigurationParserConsumer.java b/src/main/java/com/android/tools/r8/shaking/ProguardConfigurationParserConsumer.java
index ee55534..8edd1c0 100644
--- a/src/main/java/com/android/tools/r8/shaking/ProguardConfigurationParserConsumer.java
+++ b/src/main/java/com/android/tools/r8/shaking/ProguardConfigurationParserConsumer.java
@@ -68,12 +68,6 @@
       ProguardConfigurationSourceParser parser,
       TextPosition positionStart);
 
-  void enablePrintBlastRadius(
-      Path printBlastRadiusFile,
-      ProguardConfigurationSourceParser parser,
-      Position position,
-      TextPosition positionStart);
-
   void enablePrintConfiguration(
       Path printConfigurationFile,
       ProguardConfigurationSourceParser parser,
diff --git a/src/test/java/com/android/tools/r8/blastradius/BlastRadiusEarlyExitTest.java b/src/test/java/com/android/tools/r8/blastradius/BlastRadiusEarlyExitTest.java
index a3a789c..57821d4 100644
--- a/src/test/java/com/android/tools/r8/blastradius/BlastRadiusEarlyExitTest.java
+++ b/src/test/java/com/android/tools/r8/blastradius/BlastRadiusEarlyExitTest.java
@@ -46,7 +46,7 @@
         .addProgramClasses(Main.class)
         .addOptionsModification(
             options -> {
-              options.getBlastRadiusOptions().outputPath = outputPath.toString();
+              options.getBlastRadiusOptions().dataOutputPath = outputPath;
               options.getTestingOptions().waveModifier = waves -> seenWaves.set();
               if (earlyExit) {
                 // Signal finished to the test program consumer.