Example #1
0
  private String generateHtml(
      String title,
      TestResults actualResults,
      Map<String, Counter> scores,
      OverallResults or,
      int totalResults,
      File img,
      String actualResultsFileName)
      throws IOException, URISyntaxException {
    String template =
        new String(
            Files.readAllBytes(
                Paths.get(BenchmarkScore.pathToScorecardResources + "template.html")));

    // String template = new String(Files.readAllBytes(
    // Paths.get(this.getClass().getClassLoader()
    // .getResource("template.html")
    // .toURI())));

    String html = template;
    html = html.replace("${title}", title);
    html = html.replace("${tests}", Integer.toString(totalResults));
    html = html.replace("${time}", or.getTime());
    html = html.replace("${score}", "" + new DecimalFormat("#0.00%").format(or.getScore()));
    html = html.replace("${tool}", actualResults.getTool());
    html = html.replace("${version}", actualResults.getBenchmarkVersion());
    html = html.replace("${actualResultsFile}", actualResultsFileName);

    String imgTag = "<img align=\"middle\" src=\"" + img.getName() + "\" />";
    html = html.replace("${image}", imgTag);

    String table = generateTable(actualResults, scores, or);
    html = html.replace("${table}", table);

    return html;
  }
Example #2
0
  public Report(
      TestResults actualResults,
      Map<String, Counter> scores,
      OverallResults or,
      int totalResults,
      String actualResultsFileName,
      boolean isCommercial,
      ToolType toolType)
      throws IOException, URISyntaxException {
    this.isCommercial = isCommercial;
    this.toolType = toolType;
    this.toolName = actualResults.getTool();
    this.toolNameAndVersion = actualResults.getToolNameAndVersion();
    this.toolType = actualResults.toolType;
    this.benchmarkVersion = actualResults.getBenchmarkVersion();

    String fullTitle =
        "OWASP Benchmark Scorecard for "
            + actualResults.getToolNameAndVersion(); // + getToolName() + version;
    // If not in anonymous mode OR the tool is not commercial, add the type at the end of the name
    // It's not added to anonymous commercial tools, because it would be redundant.
    if (!BenchmarkScore.anonymousMode || !isCommercial) {
      fullTitle += " (" + actualResults.toolType + ")";
    }

    String shortTitle =
        "Benchmark v" + actualResults.getBenchmarkVersion() + " Scorecard for " + getToolName();
    this.filename =
        "Benchmark v"
            + actualResults.getBenchmarkVersion()
            + " Scorecard for "
            + actualResults.getToolNameAndVersion();
    this.filename = filename.replace(' ', '_');

    this.scores = scores;
    this.overallResults = or;

    this.reportPath = BenchmarkScore.scoreCardDirName + File.separator + filename + ".html";
    File img = new File(BenchmarkScore.scoreCardDirName + File.separator + filename + ".png");
    ScatterTools graph = new ScatterTools(shortTitle, 800, or);

    if (!(BenchmarkScore.showAveOnlyMode && this.isCommercial)) {
      graph.writeChartToFile(img, 800);
      String reportHtml =
          generateHtml(
              fullTitle, actualResults, scores, or, totalResults, img, actualResultsFileName);
      Files.write(Paths.get(reportPath), reportHtml.getBytes());
      System.out.println("Report written to: " + new File(reportPath).getAbsolutePath());
    }
  }