Package org.sonar.api.measures

Examples of org.sonar.api.measures.CoverageMeasuresBuilder


 
  private void recTreeTopWalk(File fileName, SMInputCursor folder, final Map<String, CoverageMeasuresBuilder> coverageData)
      throws XMLStreamException {
    SMInputCursor child = folder.childElementCursor();
    while (child.getNext() != null) {
        CoverageMeasuresBuilder fileMeasuresBuilderIn = CoverageMeasuresBuilder.create();
               
        funcWalk(child, fileMeasuresBuilderIn);
           
        String normalPath = CxxUtils.normalizePath(fileName.getPath());
        if(normalPath != null){
View Full Code Here


        fileName = StringUtils.chop(fileName);

        if ((new File(fileName)).isAbsolute()) {
          refPath = "";
        }
        CoverageMeasuresBuilder fileMeasuresBuilderIn = CoverageMeasuresBuilder.create();
        fileWalk(child, fileMeasuresBuilderIn);
        String normalPath = CxxUtils.normalizePath(refPath + fileName);
        if(normalPath != null){
          coverageData.put(normalPath, fileMeasuresBuilderIn);
        }
View Full Code Here

    throws XMLStreamException {
    SMInputCursor sourceFile = sourceFiles.childElementCursor("source_file");
    while (sourceFile.getNext() != null) {
      String id = sourceFile.getAttrValue("id");
      String normalPath = CxxUtils.normalizePath(sourceFile.getAttrValue("path"));
      CoverageMeasuresBuilder builder = coverageData.remove(id);
      if (normalPath != null) {
        coverageData.put(normalPath, builder); // replace id with path
      }
    }
  }
View Full Code Here

  }

  private void collectRangeMeasures(SMInputCursor function, Map<String, CoverageMeasuresBuilder> coverageData, int conditions, int coveredConditions)
    throws XMLStreamException {
    SMInputCursor range = function.childElementCursor("ranges").advance().childElementCursor("range");
    CoverageMeasuresBuilder builder = null;
    String lastSourceId = "";

    while (range.getNext() != null) {
      String sourceId = range.getAttrValue("source_id");
      int startLine = Integer.parseInt(range.getAttrValue("start_line"));
      int endLine = Integer.parseInt(range.getAttrValue("end_line"));
      int covered = !range.getAttrValue("covered").equalsIgnoreCase("no") ? 1 : 0; // value: yes/no/partial

      if (!sourceId.equals(lastSourceId) || builder == null) {
        builder = coverageData.get(sourceId);
        if (builder == null) {
          builder = CoverageMeasuresBuilder.create();
          coverageData.put(sourceId, builder);
        }

        builder.setConditions(startLine - 1, conditions, coveredConditions);
        lastSourceId = sourceId;
      }

      while (startLine <= endLine) {
        builder.setHits(startLine, covered);
        startLine++;
      }
    }
  }
View Full Code Here

      throws XMLStreamException
  {
    while (clazz.getNext() != null) {
      String normalPath = CxxUtils.normalizePath(clazz.getAttrValue("filename"));
      if(normalPath != null){
        CoverageMeasuresBuilder builder = coverageData.get(normalPath);
        if (builder == null) {
          builder = CoverageMeasuresBuilder.create();
          coverageData.put(normalPath, builder);
        }
        collectFileData(clazz, builder);
View Full Code Here

        "BRDA:11,2,0,0",
        "BRDA:11,2,1,-",
        "end_of_record"));
    assertThat(result).hasSize(2);

    CoverageMeasuresBuilder fileCoverage = result.get(file1.getAbsolutePath());
    assertThat(fileCoverage.getLinesToCover()).isEqualTo(1);
    assertThat(fileCoverage.getCoveredLines()).isEqualTo(1);
    assertThat(fileCoverage.getConditions()).isEqualTo(0);
    assertThat(fileCoverage.getCoveredConditions()).isEqualTo(0);

    fileCoverage = result.get(file2.getAbsolutePath());
    assertThat(fileCoverage.getLinesToCover()).isEqualTo(2);
    assertThat(fileCoverage.getCoveredLines()).isEqualTo(1);
    assertThat(fileCoverage.getConditions()).isEqualTo(4);
    assertThat(fileCoverage.getCoveredConditions()).isEqualTo(2);
  }
View Full Code Here

      "BRDA:1,0,0,1",
      "BRDA:1,0,1,-",
      "DA:3,1",
      "end_of_record"));

    CoverageMeasuresBuilder fileCoverage = result.get(file.getAbsolutePath());
    assertThat(fileCoverage.getLinesToCover()).isEqualTo(2);
    assertThat(fileCoverage.getCoveredLines()).isEqualTo(2);
    assertThat(fileCoverage.getConditions()).isEqualTo(2);
    assertThat(fileCoverage.getCoveredConditions()).isEqualTo(2);
  }
View Full Code Here

      Integer currentValue = hits.get(lineNumber);
      hits.put(lineNumber, Objects.firstNonNull(currentValue, 0) + executionCount);
    }

    public CoverageMeasuresBuilder convert() {
      CoverageMeasuresBuilder result = CoverageMeasuresBuilder.create();
      for (Map.Entry<Integer, Integer> e : hits.entrySet()) {
        result.setHits(e.getKey(), e.getValue());
      }
      for (Map.Entry<Integer, Map<String, Integer>> e : branches.entrySet()) {
        int conditions = e.getValue().size();
        int covered = 0;
        for (Integer taken : e.getValue().values()) {
          if (taken > 0) {
            covered++;
          }
        }
        result.setConditions(e.getKey(), conditions, covered);
      }
      return result;
    }
View Full Code Here

    LCOVParser parser = new LCOVParser(moduleFileSystem.baseDir());
    Map<String, CoverageMeasuresBuilder> coveredFiles = parser.parseFile(lcovFile);

    for (File file : moduleFileSystem.files(FileQuery.onSource().onLanguage(JavaScript.KEY))) {
      try {
        CoverageMeasuresBuilder fileCoverage = coveredFiles.get(file.getAbsolutePath());
        org.sonar.api.resources.File resource = org.sonar.api.resources.File.fromIOFile(file, project);

        if (fileCoverage != null) {
          for (Measure measure : fileCoverage.createMeasures()) {
            context.saveMeasure(resource, measure);
          }
        } else {
          // colour all lines as not executed
          saveZeroValueForResource(resource, context);
View Full Code Here

    final org.sonar.api.resources.File dummyFile = new org.sonar.api.resources.File("dummy/test");
    final SensorContext context = mock(SensorContext.class);
    final ProjectFileSystem fileSystem = mock(ProjectFileSystem.class);
    final List<File> sourceDirs = new ArrayList<File>();
    final Map<String, CoverageMeasuresBuilder> measures = new HashMap<String, CoverageMeasuresBuilder>();
    final CoverageMeasuresBuilder measureBuilder = CoverageMeasuresBuilder.create();

    sourceDirs.add(new File("/dummy"));
    measures.put("/dummy/test", measureBuilder);
    measureBuilder.setHits(99, 99);
    measureBuilder.setConditions(99, 99, 1);

    when(fileSystem.getSourceDirs()).thenReturn(sourceDirs);
    when(context.getResource(any(Resource.class))).thenReturn(dummyFile);

    project.setFileSystem(fileSystem);

    final CoverageMeasuresPersistor testedPersistor = new CoverageMeasuresPersistor(project, context);
    testedPersistor.saveMeasures(measures);

    for (final Measure measure : measureBuilder.createMeasures()) {
      verify(context, times(1)).saveMeasure(eq(new org.sonar.api.resources.File("test")), eq(measure));
    }
  }
View Full Code Here

TOP

Related Classes of org.sonar.api.measures.CoverageMeasuresBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.