diff --git a/src/main/java/hudson/plugins/cobertura/CoberturaPublisher.java b/src/main/java/hudson/plugins/cobertura/CoberturaPublisher.java index 355a7416..47b941f8 100644 --- a/src/main/java/hudson/plugins/cobertura/CoberturaPublisher.java +++ b/src/main/java/hudson/plugins/cobertura/CoberturaPublisher.java @@ -385,6 +385,13 @@ public void perform(Run build, FilePath workspace, Launcher launcher, fina FilePath[] reports = null; try { reports = workspace.act(new ParseReportCallable(coberturaReportFile)); + + // if the build has failed, then there's not + // much point in reporting an error + if (buildResult != null && buildResult.isWorseOrEqualTo(Result.FAILURE) && reports.length == 0) { + return; + } + } catch (IOException e) { Util.displayIOException(e, listener); e.printStackTrace(listener.fatalError("Unable to find coverage results")); @@ -694,9 +701,10 @@ public boolean configure(StaplerRequest req, JSONObject formData) throws FormExc */ @Override public CoberturaPublisher newInstance(StaplerRequest req, JSONObject formData) throws FormException { - if (req == null) { - return null; - } + // Null check because findbugs insists, despite the API guaranteeing this is never null. + if (req == null) { + throw new FormException("req cannot be null", ""); + } CoberturaPublisher instance = req.bindJSON(CoberturaPublisher.class, formData); ConvertUtils.register(CoberturaPublisherTarget.CONVERTER, CoverageMetric.class); List targets = req diff --git a/src/main/java/hudson/plugins/cobertura/targets/CoverageTarget.java b/src/main/java/hudson/plugins/cobertura/targets/CoverageTarget.java index c4934f46..039430eb 100644 --- a/src/main/java/hudson/plugins/cobertura/targets/CoverageTarget.java +++ b/src/main/java/hudson/plugins/cobertura/targets/CoverageTarget.java @@ -106,13 +106,12 @@ public Map getRangeScores(CoverageTarget min, CoverageR } public Map getRangeScores(CoverageTarget min, Map results) { - Integer j; Map result = new EnumMap(CoverageMetric.class); for (Map.Entry target : this.targets.entrySet()) { Ratio observed = results.get(target.getKey()); if (observed != null) { - j = CoverageTarget.calcRangeScore(target.getValue() / 100000, min.targets.get(target.getKey()), observed.getPercentage()); - result.put(target.getKey(), j); + int j = CoverageTarget.calcRangeScore(target.getValue() / 100000, min.targets.get(target.getKey()), observed.getPercentage()); + result.put(target.getKey(), Integer.valueOf(j)); } } return result;