Skip to content

Commit

Permalink
Add coverage metrics from VectorCAST (#153)
Browse files Browse the repository at this point in the history
Add coverage metrics from VectorCAST.
  • Loading branch information
TimSVector authored Jun 26, 2024
1 parent fb95edd commit bb12dae
Show file tree
Hide file tree
Showing 35 changed files with 3,209 additions and 132 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ The Jenkins Coverage Plug-in collects reports of code coverage or mutation cover
- [JaCoCo](https://www.jacoco.org/jacoco): Code Coverage
- [Cobertura](https://cobertura.github.io/cobertura/): Code Coverage
- [OpenCover](https://github.com/OpenCover/opencover): Code Coverage
- [VectorCAST](https://www.vector.com/int/en/products/products-a-z/software/vectorcast): Code Coverage including MC/DC, Function, Function Call coverages
- [PIT](https://pitest.org/): Mutation Coverage
- [JUnit](https://ant.apache.org/manual/Tasks/junitreport.html): Test Results
- [NUnit](https://nunit.org/): Test Results
Expand Down Expand Up @@ -107,6 +108,7 @@ The Coverage Plug-in supports the following report formats:
- [JaCoCo](https://www.jacoco.org/jacoco): Code Coverage
- [Cobertura](https://cobertura.github.io/cobertura/): Code Coverage
- [OpenCover](https://github.com/OpenCover/opencover): Code Coverage
- [VectorCAST](https://www.vector.com/int/en/products/products-a-z/software/vectorcast) Code Coverage including MC/DC, Function, Function Call coverages
- [PIT](https://pitest.org/): Mutation Coverage
- [JUnit](https://ant.apache.org/manual/Tasks/junitreport.html): Test Results
- [NUnit](https://nunit.org/): Test Results
Expand Down
2 changes: 1 addition & 1 deletion plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<gitHubRepo>jenkinsci/coverage-plugin</gitHubRepo>

<!-- Library Dependencies Versions -->
<coverage-model.version>0.45.0</coverage-model.version>
<coverage-model.version>0.46.0</coverage-model.version>
<jsoup.version>1.17.2</jsoup.version>

<!-- Jenkins Plug-in Dependencies Versions -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public class CoverageSeriesBuilder extends SeriesBuilder<CoverageStatistics> {
static final String BRANCH_COVERAGE = "branch";
static final String MUTATION_COVERAGE = "mutation";
static final String TEST_STRENGTH = "test-strength";
static final String MCDC_PAIR_COVERAGE = "mcdc-pair";
static final String FUNCTION_CALL_COVERAGE = "function-call";
static final String METHOD_COVERAGE = "method";

@Override
protected Map<String, Double> computeSeries(final CoverageStatistics statistics) {
Expand All @@ -29,6 +32,10 @@ protected Map<String, Double> computeSeries(final CoverageStatistics statistics)
add(statistics, Metric.BRANCH, BRANCH_COVERAGE, series);
add(statistics, Metric.MUTATION, MUTATION_COVERAGE, series);
add(statistics, Metric.TEST_STRENGTH, TEST_STRENGTH, series);
add(statistics, Metric.MCDC_PAIR, MCDC_PAIR_COVERAGE, series);
add(statistics, Metric.FUNCTION_CALL, FUNCTION_CALL_COVERAGE, series);
add(statistics, Metric.METHOD, METHOD_COVERAGE, series);

return series;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,26 @@
* @see JacksonFacade
*/
public class CoverageTrendChart {
/* Line Mode used to indicate whether is should be a filled line chart or line chart */
private static FilledMode lineMode;

/**
* Sets the line mode for the trend chart.
*
* @param dataSet
*
*/
private void setLineMode(final LinesDataSet dataSet) {
// If the dataset contains MCDC or Function Call Coverage
if (dataSet.containsSeries(CoverageSeriesBuilder.MCDC_PAIR_COVERAGE)
|| dataSet.containsSeries(CoverageSeriesBuilder.FUNCTION_CALL_COVERAGE)) {
lineMode = FilledMode.LINES;
}
else {
lineMode = FilledMode.FILLED;
}
}

/**
* Creates the chart for the specified results.
*
Expand All @@ -38,11 +58,13 @@ public LinesChartModel create(final Iterable<BuildResult<CoverageStatistics>> re
final ChartModelConfiguration configuration) {
CoverageSeriesBuilder builder = new CoverageSeriesBuilder();
LinesDataSet dataSet = builder.createDataSet(configuration, results);

setLineMode(dataSet);

LinesChartModel model = new LinesChartModel(dataSet);
if (dataSet.isNotEmpty()) {
LineSeries lineSeries = new LineSeries(Messages.Metric_LINE(),
JenkinsPalette.GREEN.normal(), StackedMode.SEPARATE_LINES, FilledMode.FILLED,
JenkinsPalette.GREEN.normal(), StackedMode.SEPARATE_LINES, lineMode,
dataSet.getSeries(CoverageSeriesBuilder.LINE_COVERAGE));
model.addSeries(lineSeries);
model.useContinuousRangeAxis();
Expand All @@ -55,6 +77,13 @@ public LinesChartModel create(final Iterable<BuildResult<CoverageStatistics>> re
JenkinsPalette.GREEN.dark());
addSeries(dataSet, model, Messages.Metric_TEST_STRENGTH(), CoverageSeriesBuilder.TEST_STRENGTH,
JenkinsPalette.GREEN.light());

addSeries(dataSet, model, Messages.Metric_MCDC_PAIR(), CoverageSeriesBuilder.MCDC_PAIR_COVERAGE,
JenkinsPalette.RED.light());
addSeries(dataSet, model, Messages.Metric_METHOD(), CoverageSeriesBuilder.METHOD_COVERAGE,
JenkinsPalette.RED.normal());
addSeries(dataSet, model, Messages.Metric_FUNCTION_CALL(), CoverageSeriesBuilder.FUNCTION_CALL_COVERAGE,
JenkinsPalette.RED.dark());
}
return model;
}
Expand All @@ -63,7 +92,7 @@ private static void addSeries(final LinesDataSet dataSet, final LinesChartModel
final String name, final String seriesId, final String color) {
if (dataSet.containsSeries(seriesId)) {
LineSeries branchSeries = new LineSeries(name,
color, StackedMode.SEPARATE_LINES, FilledMode.FILLED,
color, StackedMode.SEPARATE_LINES, lineMode,
dataSet.getSeries(seriesId));

model.addSeries(branchSeries);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,10 @@ public String getDisplayName(final Metric metric) {
return Messages.Metric_LOC();
case TESTS:
return Messages.Metric_TESTS();
case MCDC_PAIR:
return Messages.Metric_MCDC_PAIR();
case FUNCTION_CALL:
return Messages.Metric_FUNCTION_CALL();
default:
throw new NoSuchElementException("No display name found for metric " + metric);
}
Expand Down Expand Up @@ -472,6 +476,10 @@ public String getLabel(final Metric metric) {
return Messages.Metric_Short_LOC();
case TESTS:
return Messages.Metric_Short_TESTS();
case MCDC_PAIR:
return Messages.Metric_Short_MCDC_PAIR();
case FUNCTION_CALL:
return Messages.Metric_Short_FUNCTION_CALL();
default:
throw new NoSuchElementException("No label found for metric " + metric);
}
Expand Down Expand Up @@ -527,6 +535,8 @@ public ListBoxModel getMetricItems() {
add(options, Metric.COMPLEXITY_MAXIMUM);
add(options, Metric.LOC);
add(options, Metric.TESTS);
add(options, Metric.MCDC_PAIR);
add(options, Metric.FUNCTION_CALL);
return options;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
*/
class CoverageSourcePrinter implements Serializable {
private static final long serialVersionUID = -6044649044983631852L;
private static final Sanitizer SANITIZER = new Sanitizer();
protected static final Sanitizer SANITIZER = new Sanitizer();

static final String UNDEFINED = "noCover";
static final String NO_COVERAGE = "coverNone";
static final String FULL_COVERAGE = "coverFull";
static final String PARTIAL_COVERAGE = "coverPart";
private static final String NBSP = "&nbsp;";
protected static final String NBSP = "&nbsp;";

private final String path;
private final int[] linesToPaint;
Expand Down Expand Up @@ -54,7 +54,7 @@ public String renderLine(final int line, final String sourceCode) {
.render();
}

private String cleanupCode(final String content) {
protected String cleanupCode(final String content) {
return content.replace("\n", StringUtils.EMPTY)
.replace("\r", StringUtils.EMPTY)
.replace(" ", NBSP)
Expand Down Expand Up @@ -133,4 +133,8 @@ int getCounter(final int line, final int... counters) {
}
return 0;
}
}

public String getColumnHeader() {
return StringUtils.EMPTY;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ public void processSourceCodePainting(final Node rootNode, final List<FileNode>
private CoverageSourcePrinter createFileModel(final Node rootNode, final FileNode fileNode) {
if (rootNode.getValue(Metric.MUTATION).isPresent()) {
return new MutationSourcePrinter(fileNode);
}
else if (rootNode.getValue(Metric.MCDC_PAIR).isPresent()
|| rootNode.getValue(Metric.FUNCTION_CALL).isPresent()) {
return new VectorCastSourcePrinter(fileNode);
}
else {
return new CoverageSourcePrinter(fileNode);
Expand Down Expand Up @@ -206,6 +210,9 @@ private int paint(final CoverageSourcePrinter paint, final String relativePathId
Path fullSourcePath = paintedFilesFolder.resolve(sanitizedFileName);
try (BufferedWriter output = Files.newBufferedWriter(fullSourcePath)) {
List<String> lines = Files.readAllLines(Paths.get(resolvedPath.getRemote()), charset);

// added a header to display what is being shown in each column
output.write(paint.getColumnHeader());
for (int line = 0; line < lines.size(); line++) {
output.write(paint.renderLine(line + 1, lines.get(line)));
}
Expand Down
Loading

0 comments on commit bb12dae

Please sign in to comment.