From 86d4f502115da9efe5fc56f600efb6f5abac56ef Mon Sep 17 00:00:00 2001 From: Josh-Dutton Date: Mon, 24 Jul 2017 17:37:53 -0700 Subject: [PATCH] Fix "new errors" bug. Fixes the "new errors" count being a diff instead of pinging off every new error. Calls "diffCurrentAndPrevious" if there was a job before to determine if any errors are considered "new". Will then return that count as the count of new errors. --- .../plugins/cppcheck/CppcheckPublisher.java | 2 +- .../plugins/cppcheck/CppcheckResult.java | 29 +++++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/jenkinsci/plugins/cppcheck/CppcheckPublisher.java b/src/main/java/org/jenkinsci/plugins/cppcheck/CppcheckPublisher.java index 895b95c..d530ee1 100644 --- a/src/main/java/org/jenkinsci/plugins/cppcheck/CppcheckPublisher.java +++ b/src/main/java/org/jenkinsci/plugins/cppcheck/CppcheckPublisher.java @@ -149,7 +149,7 @@ public boolean perform(AbstractBuild build, Launcher launcher, = new CppcheckSourceContainer(listener, build.getWorkspace(), build.getModuleRoot(), cppcheckReport.getAllErrors()); - CppcheckResult result = new CppcheckResult(cppcheckReport.getStatistics(), build); + CppcheckResult result = new CppcheckResult(cppcheckReport.getStatistics(), build, cppcheckSourceContainer); CppcheckConfigSeverityEvaluation severityEvaluation = cppcheckConfig.getConfigSeverityEvaluation(); diff --git a/src/main/java/org/jenkinsci/plugins/cppcheck/CppcheckResult.java b/src/main/java/org/jenkinsci/plugins/cppcheck/CppcheckResult.java index 5c579ca..a912cdf 100644 --- a/src/main/java/org/jenkinsci/plugins/cppcheck/CppcheckResult.java +++ b/src/main/java/org/jenkinsci/plugins/cppcheck/CppcheckResult.java @@ -25,6 +25,8 @@ */ public class CppcheckResult implements Serializable { private static final long serialVersionUID = 2L; + + private int newFailures = 0; /** * The Cppcheck report. @@ -70,6 +72,26 @@ public CppcheckResult(CppcheckStatistics statistics, AbstractBuild owner) this.owner = owner; } + /** + * Alternate Constructor. + * + * @param statistics + * the Cppcheck report statistics + * @param owner + * the build owner + * + * @param CppcheckSourcesContainer + * Container for check results + * + * Added to enable "new errors" to work off all new errors instead of the sum. + */ + + public CppcheckResult(CppcheckStatistics statistics, AbstractBuild owner, CppcheckSourceContainer cppcheckSourceContainer) { + this.statistics = statistics; + this.owner = owner; + this.cppcheckSourceContainer = cppcheckSourceContainer; + } + /** * Constructor. Only for backward compatibility with previous versions. * @@ -344,8 +366,9 @@ public int getNumberErrorsAccordingConfiguration( if (checkNewError) { if (previousResult != null) { - return nbErrors - nbPreviousError; - } else { + diffCurrentAndPrevious(null); + return this.newFailures; + } else { return 0; } } else { @@ -367,6 +390,7 @@ public int getNumberErrorsAccordingConfiguration( */ public Collection diffCurrentAndPrevious( Set filter) { + this.newFailures = 0; CppcheckSourceContainer cur = getCppcheckSourceContainer(); CppcheckResult prevResult = getPreviousResult(); List curValues @@ -429,6 +453,7 @@ public Collection diffCurrentAndPrevious( if(curFile.getDiffState() != null) { continue; } + this.newFailures += 1; curFile.setDiffState(CppcheckDiffState.NEW); }