Skip to content

Commit

Permalink
Merge pull request #77 from jenkinsci/reference-job
Browse files Browse the repository at this point in the history
[JENKINS-72566] Use reference job API with forensics plugin
  • Loading branch information
uhafner authored Feb 23, 2024
2 parents 2f9cfe8 + 68ad6fa commit a633686
Show file tree
Hide file tree
Showing 23 changed files with 306 additions and 248 deletions.
8 changes: 6 additions & 2 deletions plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.jvnet.hudson.plugins</groupId>
<artifactId>analysis-pom</artifactId>
<version>6.17.0</version>
<version>7.2.0</version>
<relativePath />
</parent>

Expand All @@ -29,8 +29,10 @@
<jsoup.version>1.17.2</jsoup.version>

<!-- Jenkins Plug-in Dependencies Versions -->
<git-forensics.version>2.0.0</git-forensics.version>
<prism-api.version>1.29.0-8</prism-api.version>
<plugin-util-api.version>4.1.0</plugin-util-api.version>
<forensics-api.version>2.4.0</forensics-api.version>
<git-forensics.version>2.1.0</git-forensics.version>

<!-- Test Library Dependencies Versions -->
<xmlunit.version>2.9.1</xmlunit.version>
Expand Down Expand Up @@ -147,10 +149,12 @@
<dependency>
<groupId>io.jenkins.plugins</groupId>
<artifactId>forensics-api</artifactId>
<version>${forensics-api.version}</version>
</dependency>
<dependency>
<groupId>io.jenkins.plugins</groupId>
<artifactId>plugin-util-api</artifactId>
<version>${plugin-util-api.version}</version>
</dependency>
<dependency>
<groupId>io.jenkins.plugins</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* @author Florian Orendi
*/
public class ColorProvider {

/**
* Default color that is provided if no color is found in order to guarantee a proper colorization.
*/
Expand Down Expand Up @@ -167,11 +166,8 @@ public DisplayColors getBlendedDisplayColors(final double weightFirst, final dou

/**
* Wraps the fill color and the line color that should be used in order to visualize coverage values.
*
* @author Florian Orendi
*/
public static class DisplayColors {

private final Color lineColor;
private final Color fillColor;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
package io.jenkins.plugins.coverage.metrics.restapi;

import java.util.Collection;
import java.util.Locale;
import java.util.NavigableMap;
import java.util.TreeMap;
import java.util.stream.Collectors;

import edu.hm.hafner.coverage.Metric;

import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;
import hudson.model.Result;

import io.jenkins.plugins.coverage.metrics.model.Baseline;
import io.jenkins.plugins.coverage.metrics.model.CoverageStatistics;
import io.jenkins.plugins.coverage.metrics.model.ElementFormatter;
import io.jenkins.plugins.util.QualityGateResult;
import io.jenkins.plugins.util.QualityGateResult.QualityGateResultItem;
import io.jenkins.plugins.util.QualityGateResult.QualityGateResultApi;

/**
* Remote API to list the details of the coverage results.
Expand Down Expand Up @@ -127,61 +124,4 @@ private NavigableMap<String, String> mapToStrings(final Baseline baseline) {

return values;
}

/**
* Remote API to list the overview of the quality gate evaluation.
*/
@ExportedBean
public static class QualityGateResultApi {
private final QualityGateResult qualityGateResult;

QualityGateResultApi(final QualityGateResult qualityGateResult) {
this.qualityGateResult = qualityGateResult;
}

@Exported(inline = true)
public Result getOverallResult() {
return qualityGateResult.getOverallStatus().getResult();
}

@Exported(inline = true)
public Collection<QualityGateItemApi> getResultItems() {
return qualityGateResult.getResultItems()
.stream()
.map(QualityGateItemApi::new)
.collect(Collectors.toList());
}
}

/**
* Remote API to show the content of an individual quality gate item.
*/
@ExportedBean
public static class QualityGateItemApi {
private final QualityGateResultItem item;

QualityGateItemApi(final QualityGateResultItem item) {
this.item = item;
}

@Exported
public String getQualityGate() {
return item.getQualityGate().getName();
}

@Exported
public double getThreshold() {
return item.getQualityGate().getThreshold();
}

@Exported(inline = true)
public Result getResult() {
return item.getStatus().getResult();
}

@Exported
public String getValue() {
return item.getActualValue();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,9 @@ private ChecksConclusion getCheckConclusion(final QualityGateStatus status) {
case PASSED:
return ChecksConclusion.SUCCESS;
case FAILED:
case ERROR:
case WARNING:
case NOTE:
return ChecksConclusion.FAILURE;
default:
throw new IllegalArgumentException("Unsupported quality gate status: " + status);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,25 @@ public class CoverageQualityGate extends QualityGate {
/**
* Creates a new instance of {@link CoverageQualityGate}.
*
* @param threshold
* minimum or maximum value that triggers this quality gate
* @param metric
* the metric to compare
*/
@DataBoundConstructor
public CoverageQualityGate(final double threshold, final Metric metric) {
super(threshold);
public CoverageQualityGate(final Metric metric) {
this(metric, 0.0);
}

CoverageQualityGate(final Metric metric, final double threshold) {
super();

setThreshold(threshold);

this.metric = metric;
}

CoverageQualityGate(final double threshold, final Metric metric,
final Baseline baseline, final QualityGateCriticality criticality) {
this(threshold, metric);
this(metric, threshold);

setBaseline(baseline);
setCriticality(criticality);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
import io.jenkins.plugins.util.EnvironmentResolver;
import io.jenkins.plugins.util.JenkinsFacade;
import io.jenkins.plugins.util.LogHandler;
import io.jenkins.plugins.util.ResultHandler;
import io.jenkins.plugins.util.RunResultHandler;
import io.jenkins.plugins.util.StageResultHandler;
import io.jenkins.plugins.util.ValidationUtilities;

/**
Expand Down Expand Up @@ -383,7 +383,7 @@ public boolean perform(final AbstractBuild<?, ?> build, final Launcher launcher,
}

void perform(final Run<?, ?> run, final FilePath workspace, final TaskListener taskListener,
final StageResultHandler resultHandler) throws InterruptedException {
final ResultHandler resultHandler) throws InterruptedException {
Result overallResult = run.getResult();
LogHandler logHandler = new LogHandler(taskListener, "Coverage");
if (enabledForFailure || overallResult == null || overallResult.isBetterOrEqualTo(Result.UNSTABLE)) {
Expand All @@ -408,7 +408,7 @@ void perform(final Run<?, ?> run, final FilePath workspace, final TaskListener t
}

private void perform(final Run<?, ?> run, final FilePath workspace, final TaskListener taskListener,
final StageResultHandler resultHandler, final FilteredLog log, final LogHandler logHandler) throws InterruptedException {
final ResultHandler resultHandler, final FilteredLog log, final LogHandler logHandler) throws InterruptedException {
var results = recordCoverageResults(run, workspace, resultHandler, log, logHandler);
Node aggregatedResult = aggregateResults(log, results);

Expand Down Expand Up @@ -460,15 +460,15 @@ private String getIcon() {
return ICON;
}

private static void failStage(final StageResultHandler resultHandler, final LogHandler logHandler,
private static void failStage(final ResultHandler resultHandler, final LogHandler logHandler,
final FilteredLog log, final String message) {
log.logError(message);
resultHandler.setResult(Result.FAILURE, message);
resultHandler.publishResult(Result.FAILURE, message);
logHandler.log(log);
}

private Map<Parser, List<ModuleNode>> recordCoverageResults(final Run<?, ?> run, final FilePath workspace,
final StageResultHandler resultHandler, final FilteredLog log, final LogHandler logHandler) throws InterruptedException {
final ResultHandler resultHandler, final FilteredLog log, final LogHandler logHandler) throws InterruptedException {
Map<Parser, List<ModuleNode>> results = new HashMap<>();

for (CoverageTool tool : tools) {
Expand All @@ -495,7 +495,7 @@ private Map<Parser, List<ModuleNode>> recordCoverageResults(final Run<?, ?> run,
if (isFailOnError()) {
var errorMessage = "Failing build due to some errors during recording of the coverage";
log.logInfo(errorMessage);
resultHandler.setResult(Result.FAILURE, errorMessage);
resultHandler.publishResult(Result.FAILURE, errorMessage);
}
else {
log.logInfo("Ignore errors and continue processing");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package io.jenkins.plugins.coverage.metrics.steps;

import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Optional;

import org.apache.commons.io.input.BOMInputStream;

import edu.hm.hafner.coverage.CoverageParser;
import edu.hm.hafner.coverage.CoverageParser.ProcessingMode;
import edu.hm.hafner.coverage.ModuleNode;
Expand Down Expand Up @@ -55,9 +57,10 @@ public CoverageReportScanner(final Parser parser, final String filePattern, fina

@Override
protected Optional<ModuleNode> processFile(final Path file, final Charset charset, final FilteredLog log) {
try {
CoverageParser coverageParser = parser.createParser(processingMode);
ModuleNode node = coverageParser.parse(Files.newBufferedReader(file, charset), log);
CoverageParser coverageParser = parser.createParser(processingMode);
try (var inputStream = BOMInputStream.builder().setFile(file.toFile()).setCharset(charset).get();
var reader = new InputStreamReader(inputStream, charset)) {
ModuleNode node = coverageParser.parse(reader, log);
log.logInfo("Successfully parsed file '%s'", PATH_UTIL.getAbsolutePath(file));
node.aggregateValues().forEach(v -> log.logInfo("%s", v));
return Optional.of(node);
Expand Down
Loading

0 comments on commit a633686

Please sign in to comment.