Skip to content

Commit

Permalink
Ugly hack to populate IT and Overall coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
mjdetullio committed Jan 22, 2016
1 parent 316e64b commit b12a1f9
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@
import org.codehaus.staxmate.in.SMInputCursor;
import org.sonar.api.batch.SensorContext;
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.CoverageMeasuresBuilder;
import org.sonar.api.measures.Measure;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
import org.sonar.api.utils.KeyValueFormat;
import org.sonar.api.utils.ParsingUtils;
import org.sonar.api.utils.StaxParser;
import org.sonar.api.utils.XmlParserException;
Expand Down Expand Up @@ -82,8 +84,11 @@ private void collectPackageMeasures(SMInputCursor pack) throws XMLStreamExceptio
String filePath = entry.getKey();
Resource resource = org.sonar.api.resources.File.fromIOFile(new File(fileSystem.baseDir(), filePath), project);
if (resourceExists(resource)) {
for (Measure measure : entry.getValue().createMeasures()) {
CoverageMeasuresBuilder builder = entry.getValue();
for (Measure measure : builder.createMeasures()) {
context.saveMeasure(resource, measure);
context.saveMeasure(resource, zeroForIt(builder, measure));
context.saveMeasure(resource, convertForOverall(measure));
}
}
}
Expand Down Expand Up @@ -126,4 +131,44 @@ private static void collectFileData(SMInputCursor clazz,
}
}
}

private static Measure zeroForIt(CoverageMeasuresBuilder builder, Measure measure) {
Measure itMeasure = null;
if (CoreMetrics.LINES_TO_COVER.equals(measure.getMetric())) {
itMeasure = new Measure(CoreMetrics.IT_LINES_TO_COVER, measure.getValue());
} else if (CoreMetrics.UNCOVERED_LINES.equals(measure.getMetric())) {
itMeasure = new Measure(CoreMetrics.IT_UNCOVERED_LINES, (double) builder.getLinesToCover());
} else if (CoreMetrics.COVERAGE_LINE_HITS_DATA.equals(measure.getMetric())) {
itMeasure = new Measure(CoreMetrics.IT_COVERAGE_LINE_HITS_DATA, KeyValueFormat.format(Maps.newTreeMap()));
} else if (CoreMetrics.CONDITIONS_TO_COVER.equals(measure.getMetric())) {
itMeasure = new Measure(CoreMetrics.IT_CONDITIONS_TO_COVER, measure.getValue());
} else if (CoreMetrics.UNCOVERED_CONDITIONS.equals(measure.getMetric())) {
itMeasure = new Measure(CoreMetrics.IT_UNCOVERED_CONDITIONS, (double) builder.getConditions());
} else if (CoreMetrics.COVERED_CONDITIONS_BY_LINE.equals(measure.getMetric())) {
itMeasure = new Measure(CoreMetrics.IT_COVERED_CONDITIONS_BY_LINE, KeyValueFormat.format(Maps.newTreeMap()));
} else if (CoreMetrics.CONDITIONS_BY_LINE.equals(measure.getMetric())) {
itMeasure = new Measure(CoreMetrics.IT_CONDITIONS_BY_LINE, KeyValueFormat.format(Maps.newTreeMap()));
}
return itMeasure;
}

private static Measure convertForOverall(Measure measure) {
Measure overallMeasure = null;
if (CoreMetrics.LINES_TO_COVER.equals(measure.getMetric())) {
overallMeasure = new Measure(CoreMetrics.OVERALL_LINES_TO_COVER, measure.getValue());
} else if (CoreMetrics.UNCOVERED_LINES.equals(measure.getMetric())) {
overallMeasure = new Measure(CoreMetrics.OVERALL_UNCOVERED_LINES, measure.getValue());
} else if (CoreMetrics.COVERAGE_LINE_HITS_DATA.equals(measure.getMetric())) {
overallMeasure = new Measure(CoreMetrics.OVERALL_COVERAGE_LINE_HITS_DATA, measure.getData());
} else if (CoreMetrics.CONDITIONS_TO_COVER.equals(measure.getMetric())) {
overallMeasure = new Measure(CoreMetrics.OVERALL_CONDITIONS_TO_COVER, measure.getValue());
} else if (CoreMetrics.UNCOVERED_CONDITIONS.equals(measure.getMetric())) {
overallMeasure = new Measure(CoreMetrics.OVERALL_UNCOVERED_CONDITIONS, measure.getValue());
} else if (CoreMetrics.COVERED_CONDITIONS_BY_LINE.equals(measure.getMetric())) {
overallMeasure = new Measure(CoreMetrics.OVERALL_COVERED_CONDITIONS_BY_LINE, measure.getData());
} else if (CoreMetrics.CONDITIONS_BY_LINE.equals(measure.getMetric())) {
overallMeasure = new Measure(CoreMetrics.OVERALL_CONDITIONS_BY_LINE, measure.getData());
}
return overallMeasure;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.sonar.api.batch.SensorContext;
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.config.Settings;
import org.sonar.api.measures.MeasuresFilter;
import org.sonar.api.resources.Project;
import org.sonar.api.scan.filesystem.PathResolver;

Expand Down

0 comments on commit b12a1f9

Please sign in to comment.