Exemplo n.º 1
0
 private static void collectPackageMeasures(SMInputCursor pack, SensorContext context)
     throws XMLStreamException {
   while (pack.getNext() != null) {
     Map<String, CoverageMeasuresBuilder> builderByFilename = Maps.newHashMap();
     collectFileMeasures(pack.descendantElementCursor("class"), builderByFilename);
     for (Map.Entry<String, CoverageMeasuresBuilder> entry : builderByFilename.entrySet()) {
       org.sonar.api.resources.File file = new org.sonar.api.resources.File(entry.getKey());
       if (fileExists(context, file)) {
         for (Measure measure : entry.getValue().createMeasures()) {
           context.saveMeasure(file, measure);
         }
       }
     }
   }
 }
  private CoverageFileData collectCoverageData(SMInputCursor fileCursor) {
    try {
      String fileName = fileCursor.getAttrValue("name");

      InputFile sourceFile = delphiProjectHelper.findFileInDirectories(fileName);

      int totalLines = 0;
      int coveredLines = 0;

      CoverageFileData data = new CoverageFileData(sourceFile);
      SMInputCursor lineCursor = fileCursor.descendantElementCursor("line");
      while (lineCursor.getNext() != null) {
        if (!lineCursor.asEvent().isStartElement()) {
          continue;
        }
        String lineNumber = lineCursor.getAttrValue("number");
        boolean isCovered = Boolean.valueOf(lineCursor.getAttrValue("covered"));
        data.getLineHitsBuilder().add(lineNumber, isCovered ? 1 : 0);
        coveredLines += isCovered ? 1 : 0;
        ++totalLines;
      }

      data.setTotalLines(totalLines);
      data.setUncoveredLines(totalLines - coveredLines);
      DelphiUtils.LOG.debug(
          "Coverage ("
              + fileName
              + "): "
              + coveredLines
              + "/"
              + totalLines
              + "("
              + data.getCoverage()
              + "%)");
      return data;
    } catch (Exception e) {
      throw new RuntimeException("Failure trying collect coverage data.", e);
    }
  }