Skip to content

Commit

Permalink
Fix some warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Feb 17, 2025
1 parent df77c07 commit deb2842
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 39 deletions.
6 changes: 2 additions & 4 deletions plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<groupId>io.jenkins.plugins</groupId>
<artifactId>coverage</artifactId>
<version>${revision}${changelist}</version>
<version>2.0.0-SNAPSHOT</version>
<packaging>hpi</packaging>

<name>Coverage Plugin</name>
Expand All @@ -20,16 +20,14 @@
<url>https://github.com/jenkinsci/coverage-plugin</url>

<properties>
<revision>2.0.0</revision>
<changelist>-SNAPSHOT</changelist>
<gitHubRepo>jenkinsci/coverage-plugin</gitHubRepo>

<!-- Library Dependencies Versions -->
<coverage-model.version>0.53.0</coverage-model.version>
<jsoup.version>1.18.3</jsoup.version>

<!-- Jenkins Plug-in Dependencies Versions -->
<git-forensics.version>2.2.1</git-forensics.version>
<git-forensics.version>3.1.0</git-forensics.version>

<!-- Test Library Dependencies Versions -->
<xmlunit.version>2.10.0</xmlunit.version>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package io.jenkins.plugins.coverage.metrics.charts;

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

import edu.hm.hafner.coverage.Metric;
import edu.hm.hafner.echarts.line.SeriesBuilder;

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

import io.jenkins.plugins.coverage.metrics.model.Baseline;
import io.jenkins.plugins.coverage.metrics.model.CoverageStatistics;

Expand Down Expand Up @@ -34,8 +34,8 @@ protected Map<String, Double> computeSeries(final CoverageStatistics statistics)
add(statistics, Metric.MCDC_PAIR, MCDC_PAIR_COVERAGE, series);
add(statistics, Metric.FUNCTION_CALL, FUNCTION_CALL_COVERAGE, series);

if (statistics.containsValue(Baseline.PROJECT, Metric.MCDC_PAIR)
|| statistics.containsValue(Baseline.PROJECT, Metric.FUNCTION_CALL)) {
if (statistics.containsValue(Metric.MCDC_PAIR, Baseline.PROJECT)
|| statistics.containsValue(Metric.FUNCTION_CALL, Baseline.PROJECT)) {
// Method coverage is only relevant if MC/DC pair or function call coverage is available
add(statistics, Metric.METHOD, METHOD_COVERAGE, series);
}
Expand All @@ -45,7 +45,7 @@ protected Map<String, Double> computeSeries(final CoverageStatistics statistics)

private void add(final CoverageStatistics statistics, final Metric metric, final String chartId,
final Map<String, Double> series) {
if (statistics.containsValue(Baseline.PROJECT, metric)) {
if (statistics.containsValue(metric, Baseline.PROJECT)) {
series.put(chartId, statistics.roundValue(Baseline.PROJECT, metric));
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package io.jenkins.plugins.coverage.metrics.model;

import java.util.List;
import java.util.NavigableMap;
import java.util.NoSuchElementException;
import java.util.Optional;

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

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

/**
* Provides statistics for values and differences for all Base the different mappings of coverage metric and baseline to actual values.
*/
Expand Down Expand Up @@ -110,21 +109,17 @@ public double roundValue(final Metric metric) {
return roundValue(Baseline.PROJECT, metric);
}

private Optional<Value> getValue(final Metric metric, final NavigableMap<Metric, Difference> mapping) {
return Optional.ofNullable(mapping.get(metric));
}

/**
* Returns whether a value for the specified metric and baseline is available.
*
* @param baseline
* the baseline of the value
* @param metric
* the metric of the value
* @param baseline
* the baseline of the value
*
* @return {@code true}, if a value is available, {@code false} otherwise
*/
public boolean containsValue(final Baseline baseline, final Metric metric) {
public boolean containsValue(final Metric metric, final Baseline baseline) {
return getValue(baseline, metric).isPresent();
}

Expand All @@ -136,8 +131,7 @@ public boolean containsValue(final Baseline baseline, final Metric metric) {
*
* @return {@code true}, if a value is available, {@code false} otherwise
*/
// FIXME: reoder overloaded name
public boolean containsValue(final Metric metric) {
return containsValue(Baseline.PROJECT, metric);
return containsValue(metric, Baseline.PROJECT);

Check warning on line 135 in plugin/src/main/java/io/jenkins/plugins/coverage/metrics/model/CoverageStatistics.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 109-135 are not covered by tests
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import edu.hm.hafner.util.FilteredLog;
import edu.hm.hafner.util.VisibleForTesting;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import java.io.Serial;
import java.util.ArrayList;
Expand Down Expand Up @@ -78,6 +79,7 @@ public final class CoverageBuildAction extends BuildAction<Node> implements Stap

/** The delta of this build's coverages with respect to the reference build. */
@SuppressWarnings("MismatchedQueryAndUpdateOfCollection")
@SuppressFBWarnings(value = "NP_NONNULL_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", justification = "Not used anymore")
private transient NavigableMap<Metric, Difference> difference;
private /* almost final */ List<Difference> differences; // since 2.0.0

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

View check run for this annotation

ci.jenkins.io / Java Compiler

compiler:compile

NORMAL: non-transient instance field of a serializable class declared with a non-serializable type

Expand All @@ -86,6 +88,7 @@ public final class CoverageBuildAction extends BuildAction<Node> implements Stap

/** The coverage delta of the associated change request with respect to the reference build. */
@SuppressWarnings("MismatchedQueryAndUpdateOfCollection")
@SuppressFBWarnings(value = "NP_NONNULL_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", justification = "Not used anymore")
private transient NavigableMap<Metric, Difference> modifiedLinesCoverageDifference;
private /* almost final */ List<Difference> modifiedLinesDifferences; // since 2.0.0

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

View check run for this annotation

ci.jenkins.io / Java Compiler

compiler:compile

NORMAL: non-transient instance field of a serializable class declared with a non-serializable type

Expand All @@ -94,6 +97,7 @@ public final class CoverageBuildAction extends BuildAction<Node> implements Stap

/** The coverage delta of the modified lines. */
@SuppressWarnings("MismatchedQueryAndUpdateOfCollection")
@SuppressFBWarnings(value = "NP_NONNULL_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", justification = "Not used anymore")
private transient NavigableMap<Metric, Difference> modifiedFilesCoverageDifference;
private /* almost final */ List<Difference> modifiedFilesDifferences; // since 2.0.0

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

View check run for this annotation

ci.jenkins.io / Java Compiler

compiler:compile

NORMAL: non-transient instance field of a serializable class declared with a non-serializable type

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package io.jenkins.plugins.coverage.metrics.steps;

import java.util.List;
import java.util.Optional;
import java.util.Set;

import edu.hm.hafner.coverage.Coverage;
import edu.hm.hafner.coverage.Difference;
import edu.hm.hafner.coverage.FileNode;
import edu.hm.hafner.coverage.Metric;
import edu.hm.hafner.coverage.Node;
import edu.hm.hafner.coverage.Value;
import edu.hm.hafner.util.FilteredLog;

import java.util.List;
import java.util.Optional;
import java.util.Set;

import hudson.FilePath;
import hudson.model.Run;
import hudson.model.TaskListener;
Expand Down Expand Up @@ -197,7 +198,7 @@ private boolean hasModifiedLinesCoverage(final Node modifiedLinesCoverageRoot) {
}

private boolean hasLineCoverageSet(final Value value) {
return ((edu.hm.hafner.coverage.Coverage) value).isSet();
return value instanceof Coverage coverage && coverage.isSet();

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

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 201 is not covered by tests
}

private Optional<CoverageBuildAction> getReferenceBuildAction(final Run<?, ?> build, final String id,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.jenkins.plugins.coverage.metrics.steps;
package io.jenkins.plugins.coverage.metrics.steps; // NOPMD

import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -69,15 +69,9 @@ void shouldRestoreAction() throws IOException {
Assertions.assertThat(restored).isInstanceOfSatisfying(CoverageBuildAction.class,
a -> Assertions.assertThat(a.getAllValues(Baseline.PROJECT))
.map(Object::toString).containsExactlyInAnyOrder("MODULE: 100.00% (1/1)",
"PACKAGE: 75.00% (3/4)",
"FILE: 100.00% (32/32)",
"CLASS: 94.23% (49/52)",
"METHOD: 95.79% (569/594)",
"LINE: 96.35% (2164/2246)",
"BRANCH: 92.92% (932/1003)",
"INSTRUCTION: 96.44% (10534/10923)",
"TESTS: 305",
"CYCLOMATIC_COMPLEXITY: 1105",
"PACKAGE: 75.00% (3/4)", "FILE: 100.00% (32/32)", "CLASS: 94.23% (49/52)",
"METHOD: 95.79% (569/594)", "LINE: 96.35% (2164/2246)", "BRANCH: 92.92% (932/1003)",
"INSTRUCTION: 96.44% (10534/10923)", "TESTS: 305", "CYCLOMATIC_COMPLEXITY: 1105",
"LOC: 2246"));
}

Expand Down

0 comments on commit deb2842

Please sign in to comment.