Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-72566] Use reference job API with forensics plugin #77

Merged
merged 33 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
f76efed
[JENKINS-72059] Add new quality gate options to alter the stage only.
uhafner Dec 29, 2023
67c2268
Update API changes.
uhafner Dec 29, 2023
2cd2e2e
Move quality gate API to plugin-util.
uhafner Jan 1, 2024
baad004
Make API method of quality result accessible.
uhafner Jan 2, 2024
7614fe2
Fix quality gates in remote API.
uhafner Jan 2, 2024
9527924
Add integer based threshold to quality gate.
uhafner Jan 4, 2024
a1dc15a
Use new data-bound properties of QualityGate.
uhafner Jan 6, 2024
cde999b
Fix compile error due to changed API call.
uhafner Jan 6, 2024
5b45fc6
[JENKINS-72595] Use BOMInputStream to read XML files.
uhafner Jan 24, 2024
68bc727
Bump version of analysis-pom to 7.0.0 and Jenkins to 2.426.3.
uhafner Jan 24, 2024
a8a816a
Fix some warnings.
uhafner Jan 24, 2024
c95fe56
Simplify BOM assertion to be compatible on Windows.
uhafner Jan 24, 2024
eb16a7b
Merge remote-tracking branch 'origin/main' into bom
uhafner Jan 24, 2024
2c6cbc8
Ignore BOM test on Windows.
uhafner Jan 24, 2024
6a09e1a
Remove BOM assertion.
uhafner Jan 24, 2024
d2fc41c
Merge remote-tracking branch 'origin/main' into stage-result
uhafner Jan 25, 2024
e9035fd
Fix warnings.
uhafner Jan 25, 2024
8f064ce
Merge remote-tracking branch 'origin/bom' into stage-result
uhafner Jan 31, 2024
ec15c3d
Merge remote-tracking branch 'origin/main' into stage-result
uhafner Jan 31, 2024
9a3699a
Use the new reference job API of the forensics plugin.
uhafner Feb 5, 2024
d1cb41f
Bump version of forensics to 2.4.0-rc1560.b_4b_993ec6a_9f.
uhafner Feb 5, 2024
fd5ca60
Bump version of Git forensics plugin.
uhafner Feb 5, 2024
601697f
Fix handling of required status.
uhafner Feb 6, 2024
d8f5d8f
Bump version og Git forensics plugin.
uhafner Feb 7, 2024
13c542d
Bump version og Git forensics plugin.
uhafner Feb 7, 2024
4d723e1
Fix plugin version.
uhafner Feb 7, 2024
e740539
Merge remote-tracking branch 'origin/main' into reference-job
uhafner Feb 20, 2024
2e1a631
Bump version of forensics-api to 2.4.0-rc1565.4c3ec58d800d.
uhafner Feb 20, 2024
8123fab
Merge branch 'csp-refactoring' into reference-job
uhafner Feb 20, 2024
749f0f5
Improve documentation.
uhafner Feb 21, 2024
e76c1cf
Bump version of plugin-util to 4.1.0.
uhafner Feb 23, 2024
37cc482
Bump version of git-forensics to 2.1.0.
uhafner Feb 23, 2024
68ad6fa
Merge remote-tracking branch 'origin/main' into reference-job
uhafner Feb 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
/**
* 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);

Check warning on line 41 in plugin/src/main/java/io/jenkins/plugins/coverage/metrics/steps/CoverageQualityGate.java

View check run for this annotation

ci.jenkins.io / Java Compiler

compiler:compile

NORMAL: possible 'this' escape before subclass is fully initialized
}

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

setThreshold(threshold);

Check warning on line 47 in plugin/src/main/java/io/jenkins/plugins/coverage/metrics/steps/CoverageQualityGate.java

View check run for this annotation

ci.jenkins.io / Java Compiler

compiler:compile

NORMAL: previous possible 'this' escape happens here via invocation

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 @@
}

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 @@
}

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 @@
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);

Check warning on line 466 in plugin/src/main/java/io/jenkins/plugins/coverage/metrics/steps/CoverageRecorder.java

View workflow job for this annotation

GitHub Actions / pitest

A change can be made to line 466 without causing a test to fail

removed call to io/jenkins/plugins/util/ResultHandler::publishResult (no tests cover this line VoidMethodCallMutator)
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 @@
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);

Check warning on line 498 in plugin/src/main/java/io/jenkins/plugins/coverage/metrics/steps/CoverageRecorder.java

View workflow job for this annotation

GitHub Actions / pitest

A change can be made to line 498 without causing a test to fail

removed call to io/jenkins/plugins/util/ResultHandler::publishResult (no tests cover this line VoidMethodCallMutator)
}
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
Loading