Skip to content

Commit

Permalink
Update dependencies in pom.xml
Browse files Browse the repository at this point in the history
Bump the parent POM version from 10.2.0 to 10.4.0 and add a specific
version (6.0.0) for the plugin-util-api dependency.
  • Loading branch information
uhafner committed Feb 17, 2025
1 parent f393c05 commit f308856
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 71 deletions.
8 changes: 6 additions & 2 deletions plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,14 @@
<dependency>
<groupId>io.jenkins.plugins</groupId>
<artifactId>forensics-api</artifactId>
<!-- TODO: remove the version when a matching BOM is available -->
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>io.jenkins.plugins</groupId>
<artifactId>plugin-util-api</artifactId>
<version>6.0.0-rc1032.7b_1a_930a_1e66</version>
<!-- TODO: remove the version when a matching BOM is available -->
<version>6.0.0</version>
</dependency>
<dependency>
<groupId>io.jenkins.plugins</groupId>
Expand All @@ -165,7 +168,8 @@
<dependency>
<groupId>io.jenkins.plugins</groupId>
<artifactId>plugin-util-api</artifactId>
<version>6.0.0-rc1032.7b_1a_930a_1e66</version>
<!-- TODO: remove the version when a matching BOM is available -->
<version>6.0.0</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package io.jenkins.plugins.coverage.metrics.color;

import edu.umd.cs.findbugs.annotations.NonNull;

import java.awt.*;
import java.util.HashMap;
import java.util.EnumMap;
import java.util.Map;
import java.util.Objects;

import edu.umd.cs.findbugs.annotations.NonNull;

/**
* Loads a color palette and provides these colors and operations on them. The colors are provided as a tuple of fill
* color and line color, mapped by the id of the fill color.
Expand Down Expand Up @@ -34,7 +34,7 @@ public class ColorProvider {
* The color mapping to be used
*/
ColorProvider(final Map<ColorId, DisplayColors> colorMapping) {
availableColors = new HashMap<>(colorMapping);
availableColors = new EnumMap<>(colorMapping);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.awt.*;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.EnumMap;
import java.util.Map;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -45,7 +45,7 @@ public static ColorProvider createColorProvider(final Map<String, String> colors
if (!colors.keySet().equals(CoverageColorJenkinsId.getAll()) || !verifyHexCodes(colors.values())) {
return createDefaultColorProvider();
}
Map<ColorId, DisplayColors> colorMap = new HashMap<>();
Map<ColorId, DisplayColors> colorMap = new EnumMap<>();
// TODO: use dynamic text color (not provided yet)
colorMap.put(ColorId.INSUFFICIENT,
createDisplayColor(colors.get(CoverageColorJenkinsId.RED.getJenkinsColorId()), "#ffffff"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
*
* @author Ullrich Hafner
*/
@SuppressWarnings({"PMD.GodClass", "PMD.CyclomaticComplexity", "checkstyle:ClassDataAbstractionCoupling", "checkstyle:ClassFanOutComplexity"})
@SuppressWarnings({"PMD.GodClass", "PMD.CyclomaticComplexity", "PMD.CouplingBetweenObjects", "checkstyle:ClassDataAbstractionCoupling", "checkstyle:ClassFanOutComplexity"})
public final class CoverageBuildAction extends BuildAction<Node> implements StaplerProxy {
@Serial
private static final long serialVersionUID = -6023811049340671399L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
import java.util.Collection;
import java.util.Locale;

import org.apache.commons.lang3.math.Fraction;

import edu.hm.hafner.coverage.Metric;
import edu.hm.hafner.coverage.Value;

import io.jenkins.plugins.coverage.metrics.model.CoverageStatistics;
import io.jenkins.plugins.coverage.metrics.model.ElementFormatter;
import io.jenkins.plugins.util.QualityGateEvaluator;
Expand All @@ -20,8 +15,6 @@
* @author Johannes Walter
*/
class CoverageQualityGateEvaluator extends QualityGateEvaluator<CoverageQualityGate> {
private static final Fraction HUNDRED = Fraction.getFraction("100.0");

private static final ElementFormatter FORMATTER = new ElementFormatter();
private final CoverageStatistics statistics;

Expand All @@ -37,8 +30,7 @@ protected void evaluate(final CoverageQualityGate qualityGate, final QualityGate
var baseline = qualityGate.getBaseline();
var possibleValue = statistics.getValue(baseline, qualityGate.getMetric());
if (possibleValue.isPresent()) {
var actualValue = convertActualValue(possibleValue.get());

var actualValue = possibleValue.get();
var status = actualValue.isOutOfValidRange(
qualityGate.getThreshold()) ? qualityGate.getStatus() : QualityGateStatus.PASSED;
result.add(qualityGate, status, FORMATTER.format(possibleValue.get(), Locale.ENGLISH));
Expand All @@ -47,31 +39,4 @@ protected void evaluate(final CoverageQualityGate qualityGate, final QualityGate
result.add(qualityGate, QualityGateStatus.INACTIVE, "n/a");
}
}

/**
* Converts the actual value to a percentage if necessary. Delta values are internally stored as fractions, but
* users expect percentages when they are displayed or used in thresholds.
*
* @param value
* the actual stored value
*
* @return the converted value
*/
private Value convertActualValue(final Value value) {
var metric = value.getMetric();
if (metric.equals(Metric.CYCLOMATIC_COMPLEXITY)
|| metric.equals(Metric.LOC)) {
return value; // ignore integer based metrics
}
// FIXME: still needed?
// if (value instanceof FractionValue) { // delta percentage
// return new Value(metric, covertToPercentage((FractionValue) value));
// }

return value;
}

// private Fraction covertToPercentage(final FractionValue value) {
// return new SafeFraction(value.getFraction()).multiplyBy(HUNDRED);
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.EnumMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -475,7 +475,7 @@ private static void failStage(final ResultHandler resultHandler, final LogHandle

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

for (CoverageTool tool : tools) {
Parser parser = tool.getParser();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package io.jenkins.plugins.coverage.metrics;

import java.util.HashMap;
import java.util.Map;

import org.junit.jupiter.api.BeforeAll;

import edu.hm.hafner.coverage.FileNode;
import edu.hm.hafner.coverage.Metric;
import edu.hm.hafner.coverage.Node;

import java.util.EnumMap;
import java.util.HashMap;
import java.util.Map;

import io.jenkins.plugins.coverage.metrics.steps.FileChangesProcessor;
import io.jenkins.plugins.forensics.delta.Change;
import io.jenkins.plugins.forensics.delta.ChangeEditType;
Expand Down Expand Up @@ -62,15 +62,16 @@ static void initFileChanges() {
var replace = new Change(ChangeEditType.REPLACE, 10, 11, 20, 22);
var delete = new Change(ChangeEditType.DELETE, 16, 19, 26, 26);
var fileChanges = new FileChanges(TEST_FILE_MODIFIED_PATH, TEST_FILE_MODIFIED_PATH_OLD,
"test", FileEditType.RENAME, new HashMap<>());
"test", FileEditType.RENAME, new EnumMap<>(ChangeEditType.class));
fileChanges.addChange(insert1);
fileChanges.addChange(insert2);
fileChanges.addChange(insert3);
fileChanges.addChange(replace);
fileChanges.addChange(delete);
CODE_CHANGES.put(TEST_FILE_MODIFIED_PATH, fileChanges);
CODE_CHANGES.put(TEST_FILE_NOT_MODIFIED,
new FileChanges("empty", "empty", "", FileEditType.MODIFY, new HashMap<>()));
new FileChanges("empty", "empty", "", FileEditType.MODIFY,
new EnumMap<>(ChangeEditType.class)));
OLD_PATH_MAPPING.put(TEST_FILE_MODIFIED_PATH, TEST_FILE_MODIFIED_PATH_OLD);
}

Expand All @@ -85,13 +86,6 @@ protected Node createCoverageTree() {
var reference = readJacocoResult(TEST_REPORT_BEFORE);
var tree = readJacocoResult(TEST_REPORT_AFTER);

var value = tree.findFile("Test1.java")
.get()
.getValue(Metric.LINE);
var refValue = reference.findFile("Test1.java")
.get()
.getValue(Metric.LINE);

fileChangesProcessor.attachChangedCodeLines(tree, CODE_CHANGES);
fileChangesProcessor.attachFileCoverageDeltas(tree, reference, OLD_PATH_MAPPING);
fileChangesProcessor.attachIndirectCoveragesChanges(tree, reference, CODE_CHANGES, OLD_PATH_MAPPING);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package io.jenkins.plugins.coverage.metrics.steps;

import java.util.List;
import java.util.NoSuchElementException;

import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test;

Expand All @@ -11,6 +8,9 @@
import edu.hm.hafner.coverage.Node;
import edu.hm.hafner.util.FilteredLog;

import java.util.List;
import java.util.NoSuchElementException;

import hudson.model.Run;

import io.jenkins.plugins.coverage.metrics.AbstractCoverageTest;
Expand Down Expand Up @@ -55,7 +55,7 @@ void shouldReportOverview() {
ensureValidPercentages(overview.getCoveredPercentages());

var expectedMissed = List.of(0, 1, 1, 5, 29, 7, 90);
assertThat(overview.getMissed()).containsExactlyElementsOf(expectedMissed);
assertThat(overview.getMissed()).containsExactlyElementsOf(expectedMissed);
ensureValidPercentages(overview.getMissedPercentages());

assertThatJson(overview).node("metrics").isArray().containsExactly(expectedMetrics);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,4 +306,4 @@ private List<? extends Value> createCoverages() {
Value.valueOf("LOC: 123")
);
}
}
} // NOPMD
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import edu.hm.hafner.coverage.Coverage.CoverageBuilder;
import edu.hm.hafner.coverage.FileNode;
import edu.hm.hafner.coverage.Metric;
import edu.hm.hafner.coverage.Node;
import edu.hm.hafner.coverage.Value;

Expand Down Expand Up @@ -119,7 +118,7 @@ private void verifyPitProjectValues(final CoverageBuildAction pit) {
.withCovered(222)
.withMissed(246 - 222)
.build(),
new Value(Metric.LOC, 211));
new Value(LOC, 211));
}

private static void verifyFirstBuild(final Run<?, ?> firstBuild) {
Expand All @@ -135,8 +134,8 @@ private static void verifyFirstBuild(final Run<?, ?> firstBuild) {
.withCovered(1544 + 109)
.withMissed(1865 - (1544 + 109))
.build(),
new Value(Metric.LOC, JACOCO_ANALYSIS_MODEL_TOTAL + JACOCO_CODING_STYLE_TOTAL),
new Value(Metric.CYCLOMATIC_COMPLEXITY, 2718));
new Value(LOC, JACOCO_ANALYSIS_MODEL_TOTAL + JACOCO_CODING_STYLE_TOTAL),
new Value(CYCLOMATIC_COMPLEXITY, 2718));
}

private void verifyJaCoCoProjectValues(final CoverageBuildAction action) {
Expand All @@ -150,8 +149,8 @@ private void verifyJaCoCoProjectValues(final CoverageBuildAction action) {
.withCovered(109)
.withMissed(7)
.build(),
new Value(Metric.LOC, JACOCO_CODING_STYLE_TOTAL),
new Value(Metric.CYCLOMATIC_COMPLEXITY, 160));
new Value(LOC, JACOCO_CODING_STYLE_TOTAL),
new Value(CYCLOMATIC_COMPLEXITY, 160));
}

/**
Expand Down

0 comments on commit f308856

Please sign in to comment.