Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion 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>5.31.0</version>
<version>5.32.0</version>
<relativePath />
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
*/
@SuppressWarnings("PMD.GodClass")
public class CoverageBuildAction extends BuildAction<CoverageNode> implements HealthReportingAction, StaplerProxy {

/** Relative URL to the details of the code coverage results. */
public static final String DETAILS_URL = "coverage";
/** The coverage report icon. */
Expand All @@ -51,9 +50,14 @@ public class CoverageBuildAction extends BuildAction<CoverageNode> implements He
private final String referenceBuildId;

// since 3.0.0
/** The delta of this build's coverages with respect to the reference build. */
private SortedMap<CoverageMetric, CoveragePercentage> difference;
/** The coverages filtered by changed lines of the associated change request. */
// FIXME: actually we need the coverages?
private SortedMap<CoverageMetric, CoveragePercentage> changeCoverage;
/** The delta of the coverages of the associated change request with respect to the reference build. */
private SortedMap<CoverageMetric, CoveragePercentage> changeCoverageDifference;
/** The indirect coverage changes of the associated change request with respect to the reference build. */
private SortedMap<CoverageMetric, CoveragePercentage> indirectCoverageChanges;

@SuppressWarnings("unused")
Expand Down Expand Up @@ -86,13 +90,13 @@ public CoverageBuildAction(final Run<?, ?> owner, final CoverageNode result, fin
* @param referenceBuildId
* the ID of the reference build
* @param delta
* the delta coverage with respect to the reference build
* delta of this build's coverages with respect to the reference build
* @param changeCoverage
* the change coverage with respect to the reference build
* the coverages filtered by changed lines of the associated change request
* @param changeCoverageDifference
* the change coverage delta with respect to the reference build
* the delta of the coverages of the associated change request with respect to the reference build
* @param indirectCoverageChanges
* the indirect coverage changes with respect to the reference build
* the indirect coverage changes of the associated change request with respect to the reference build
*/
@SuppressWarnings("checkstyle:ParameterNumber")
public CoverageBuildAction(final Run<?, ?> owner, final CoverageNode result,
Expand All @@ -112,7 +116,8 @@ public CoverageBuildAction(final Run<?, ?> owner, final CoverageNode result,
final SortedMap<CoverageMetric, CoveragePercentage> delta,
final SortedMap<CoverageMetric, CoveragePercentage> changeCoverage,
final SortedMap<CoverageMetric, CoveragePercentage> changeCoverageDifference,
final SortedMap<CoverageMetric, CoveragePercentage> indirectCoverageChanges, final boolean canSerialize) {
final SortedMap<CoverageMetric, CoveragePercentage> indirectCoverageChanges,
final boolean canSerialize) {
super(owner, result, canSerialize);

lineCoverage = result.getCoverage(CoverageMetric.LINE);
Expand All @@ -130,8 +135,7 @@ public CoverageBuildAction(final Run<?, ?> owner, final CoverageNode result,
protected Object readResolve() {
if (difference == null) {
difference = StreamEx.of(delta.entrySet())
.toSortedMap(Entry::getKey,
e -> CoveragePercentage.valueOf(e.getValue()));
.toSortedMap(Entry::getKey, e -> CoveragePercentage.valueOf(e.getValue()));
}
if (changeCoverage == null) {
changeCoverage = new TreeMap<>();
Expand All @@ -154,26 +158,39 @@ public Coverage getBranchCoverage() {
}

/**
* Returns whether the {@link Coverage} for the passed metric exists.
* Returns whether a {@link Coverage} for the specified metric exists.
*
* @param coverageMetric
* the metric to check
* the coverage metric
*
* @return {@code true} if a coverage is available for the specified metric
* @return {@code true} if a coverage is available for the specified metric, {@code false} otherwise
*/
public boolean hasCoverage(final CoverageMetric coverageMetric) {
if (coverageMetric.equals(CoverageMetric.LINE)) {
return lineCoverage.isSet();
}
if (coverageMetric.equals(CoverageMetric.BRANCH)) {
return branchCoverage.isSet();
}

return getResult().getCoverage(coverageMetric).isSet();
}

/**
* Gets the {@link Coverage} for the passed metric.
* Returns the {@link Coverage} for the specified metric.
*
* @param coverageMetric
* The coverage metric
* the coverage metric
*
* @return the coverage
*/
public Coverage getCoverage(final CoverageMetric coverageMetric) {
if (coverageMetric.equals(CoverageMetric.LINE)) {
return lineCoverage;
}
if (coverageMetric.equals(CoverageMetric.BRANCH)) {
return branchCoverage;
}
return getResult().getCoverage(coverageMetric);
}

Expand All @@ -183,7 +200,7 @@ public Coverage getCoverage(final CoverageMetric coverageMetric) {
* @return {@code true} if the change coverage exist, else {@code false}
*/
public boolean hasChangeCoverage() {
return getResult().hasChangeCoverage();
return hasChangeCoverage(CoverageMetric.LINE) || hasChangeCoverage(CoverageMetric.BRANCH);
}

/**
Expand All @@ -195,7 +212,7 @@ public boolean hasChangeCoverage() {
* @return {@code true} if the change coverage exist for the metric, else {@code false}
*/
public boolean hasChangeCoverage(final CoverageMetric coverageMetric) {
return getResult().hasChangeCoverage(coverageMetric);
return changeCoverage.containsKey(coverageMetric);
}

/**
Expand All @@ -207,6 +224,7 @@ public boolean hasChangeCoverage(final CoverageMetric coverageMetric) {
* @return the change coverage
*/
public Coverage getChangeCoverage(final CoverageMetric coverageMetric) {
// FIXME: is percentage sufficient?
return getResult().getChangeCoverageTree().getCoverage(coverageMetric);
}

Expand All @@ -216,7 +234,7 @@ public Coverage getChangeCoverage(final CoverageMetric coverageMetric) {
* @return {@code true} if indirect coverage changes exist, else {@code false}
*/
public boolean hasIndirectCoverageChanges() {
return getResult().hasIndirectCoverageChanges();
return hasIndirectCoverageChanges(CoverageMetric.LINE) || hasIndirectCoverageChanges(CoverageMetric.BRANCH);
}

/**
Expand All @@ -228,7 +246,7 @@ public boolean hasIndirectCoverageChanges() {
* @return {@code true} if indirect coverage changes exist for the metric, else {@code false}
*/
public boolean hasIndirectCoverageChanges(final CoverageMetric coverageMetric) {
return getResult().hasIndirectCoverageChanges(coverageMetric);
return indirectCoverageChanges.containsKey(coverageMetric);
}

/**
Expand All @@ -240,6 +258,7 @@ public boolean hasIndirectCoverageChanges(final CoverageMetric coverageMetric) {
* @return the indirect coverage changes
*/
public Coverage getIndirectCoverageChanges(final CoverageMetric coverageMetric) {
// FIXME: is percentage sufficient?
return getResult().getIndirectCoverageChangesTree().getCoverage(coverageMetric);
}

Expand Down Expand Up @@ -347,7 +366,7 @@ public String formatIndirectCoverageChanges(final CoverageMetric metric) {
private String formatCoverageForMetric(final CoverageMetric metric,
final Map<CoverageMetric, CoveragePercentage> coverages) {
String coverage = Messages.Coverage_Not_Available();
if (coverages != null && coverages.containsKey(metric)) {
if (coverages.containsKey(metric)) {
coverage = coverages.get(metric).formatPercentage(Functions.getCurrentLocale());
}
return metric.getName() + ": " + coverage;
Expand Down Expand Up @@ -473,8 +492,7 @@ private String getFormattedChangesOverview(final long lineAmount, final int file
*/
@SuppressWarnings("unused") // Called by jelly view
public String formatCoverage(final CoverageMetric metric) {
String coverage = getResult().printCoverageFor(metric, Functions.getCurrentLocale());
return metric.getName() + ": " + coverage;
return metric.getName() + ": " + getCoverage(metric).formatCoveredPercentage(Functions.getCurrentLocale());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ public void run(final CoverageResult rootResult, final Run<?, ?> build, final Fi
}

action = new CoverageBuildAction(build, rootNode, healthReport,
referenceAction.getOwner().getExternalizableId(), coverageDelta,
referenceAction.getOwner().getExternalizableId(),
coverageDelta,
changeCoverageRoot.getMetricPercentages(),
changeCoverageDelta,
indirectCoverageChangesTree.getMetricPercentages());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package io.jenkins.plugins.coverage;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;

import org.junit.BeforeClass;
import org.junit.Test;
import org.junitpioneer.jupiter.DefaultLocale;

import org.jvnet.localizer.Localizable;
import hudson.model.HealthReport;
Expand All @@ -25,6 +24,7 @@
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;

@DefaultLocale("en")
public class CoverageChecksPublisherTest {
private static final String JENKINS_BASE_URL = "http://127.0.0.1:8080";
private static final String COVERAGE_URL_NAME = "coverage";
Expand All @@ -33,11 +33,6 @@ public class CoverageChecksPublisherTest {
private static final String LAST_SUCCESSFUL_BUILD_LINK = "http://127.0.0.1:8080/job/pipeline-coding-style/view/change-requests/job/PR-3/110/";
private static final String HEALTH_REPORT = "Coverage Healthy score is 100%";

@BeforeClass
public static void enforceEnglishLocale() {
Locale.setDefault(Locale.ENGLISH);
}

@Test
public void shouldConstructChecksDetailsWithLineAndMethodCoverage() {
ChecksDetails expectedDetails = new ChecksDetailsBuilder()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package io.jenkins.plugins.coverage.model;

import java.util.Locale;

import org.junit.jupiter.api.BeforeAll;
import org.junitpioneer.jupiter.DefaultLocale;

import edu.hm.hafner.util.ResourceTest;

Expand All @@ -17,6 +15,7 @@
*
* @author Ullrich Hafner
*/
@DefaultLocale("en")
public abstract class AbstractCoverageTest extends ResourceTest {
static final CoverageMetric MODULE = CoverageMetric.MODULE;
static final CoverageMetric PACKAGE = CoverageMetric.PACKAGE;
Expand All @@ -27,11 +26,6 @@ public abstract class AbstractCoverageTest extends ResourceTest {
static final CoverageMetric INSTRUCTION = CoverageMetric.INSTRUCTION;
static final CoverageMetric BRANCH = CoverageMetric.BRANCH;

@BeforeAll
static void beforeAll() {
Locale.setDefault(Locale.ENGLISH);
}

/**
* Reads the {@link CoverageResult} from a coverage report.
*
Expand Down
Loading