示例#1
0
  public static void main(String[] args) throws Exception {
    // findbugs
    // mvn clean compile findbugs:findbugs -Dbuildtime.output.csv=true
    // -Dbuildtime.output.csv.file=classes\out.csv
    // pmd
    // mvn pmd:pmd -Dbuildtime.output.csv=true
    // -Dbuildtime.output.csv.file=classes\out.csv
    // findbugs
    // mvn clean compile -Pfindsecbugs -Dbuildtime.output.csv=true
    // -Dbuildtime.output.csv.file=classes\out.csv
    // sonar
    // mvn sonar:sonar -Dbuildtime.output.csv=true
    // -Dbuildtime.output.csv.file=classes\out.csv
    // rewrite results file name with times and version
    // String toolName = "sonar";
    String toolName = "";
    String csvToolName = "";
    if (args.length < 1) {
      System.out.println(
          "Please provide the name of the tool.\n"
              + "Currently supported: PMD (pmd), FindBugs (findbugs), FindSecBugs (findbugs) and SonarQube (sonar).");
    } else {
      toolName = args[0];
    }
    // System.out.println("Tool: " + toolName);

    PropertiesManager propM = new PropertiesManager();
    WriteFiles wf = new WriteFiles();
    if (toolName.contains("sonar")) { // We need to generate the results
      // file from the webService
      wf.writeSonarResults();
    }

    if (toolName.equals("findsecbugs")) {
      csvToolName = "findbugs";
    } else if (toolName.equals("crawler")) {
      csvToolName = "exec-maven-plugin:java";
    } else {
      csvToolName = toolName;
    }

    propM.saveProperty(toolName, wf.getToolTime(csvToolName));
    propM.saveProperty("benchmark-version", wf.getbenchmarkVersion()); //
    // propM.displayProperties();

    wf.deletePreviousResults(
        toolName, wf.getVersionNumber(toolName), propM.getProperty("benchmark-version", ""));

    wf.resultsFileName(
        toolName,
        propM.getProperty("benchmark-version", ""),
        propM.getProperty(toolName, ""),
        wf.getVersionNumber(toolName));
  }
示例#2
0
  public String getVersionNumber(String toolName) {
    try {
      File findbugsFile = new File(FINDBUGS_FILE);
      DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
      // Prevent XXE
      docBuilderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
      DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
      InputSource is = null;
      Document doc = null;
      Node root = null;
      Reader reader = new Reader();

      switch (toolName) {
        case "findbugs":
          is = new InputSource(new FileInputStream(findbugsFile));
          doc = docBuilder.parse(is);
          root = doc.getDocumentElement();
          return reader.getAttributeValue("version", root);
        case "findsecbugs":
          return WriteFiles.getLine(new File("pom.xml"), "findsecbugs-plugin", true)
              .trim()
              .replace("<version>", "")
              .replace("</version>", "");
        case "pmd":
          is = new InputSource(new FileInputStream(new File(PMD_FILE)));
          doc = docBuilder.parse(is);
          root = doc.getDocumentElement();
          return reader.getAttributeValue("version", root);
        case "sonar":
          return "TBD";
      }
    } catch (Exception e) {
      System.out.println("An error ocurred during results file parsing.");
    }
    return "";
  }