From b25c8001084885c77c9ae45a8a86fbc007063277 Mon Sep 17 00:00:00 2001 From: simonbrandhof Date: Wed, 23 Mar 2011 15:31:47 +0100 Subject: [PATCH] Fix Clover coverage on new code at project and package levels --- .../sensors/AbstractCoverageDecorator.java | 40 ++++++++++--------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/AbstractCoverageDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/AbstractCoverageDecorator.java index d5a6e95c047..da22d828c36 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/AbstractCoverageDecorator.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/AbstractCoverageDecorator.java @@ -50,32 +50,36 @@ public abstract class AbstractCoverageDecorator implements Decorator { } protected boolean shouldDecorate(final Resource resource, final DecoratorContext context) { - return context.getMeasure(getGeneratedMetric()) == null && !ResourceUtils.isUnitTestClass(resource); + return !ResourceUtils.isUnitTestClass(resource); } private void computeMeasure(DecoratorContext context) { - Long elements = countElements(context); - if (elements != null && elements > 0L) { - Long coveredElements = countCoveredElements(context); - context.saveMeasure(getGeneratedMetric(), calculateCoverage(coveredElements, elements)); + if (context.getMeasure(getGeneratedMetric()) == null) { + Long elements = countElements(context); + if (elements != null && elements > 0L) { + Long coveredElements = countCoveredElements(context); + context.saveMeasure(getGeneratedMetric(), calculateCoverage(coveredElements, elements)); + } } } private void computeMeasureForNewCode(DecoratorContext context) { - Measure measure = new Measure(getGeneratedMetricForNewCode()); - boolean hasValue = false; - /* TODO remove this magic number */ - for (int periodIndex = 1; periodIndex <= 5; periodIndex++) { - Long elements = countElementsForNewCode(context, periodIndex); - - if (elements != null && elements > 0L) { - long coveredElements = countCoveredElementsForNewCode(context, periodIndex); - measure.setVariation(periodIndex, calculateCoverage(coveredElements, elements)); - hasValue = true; + if (context.getMeasure(getGeneratedMetricForNewCode()) == null) { + Measure measure = new Measure(getGeneratedMetricForNewCode()); + boolean hasValue = false; + /* TODO remove this magic number */ + for (int periodIndex = 1; periodIndex <= 5; periodIndex++) { + Long elements = countElementsForNewCode(context, periodIndex); + + if (elements != null && elements > 0L) { + long coveredElements = countCoveredElementsForNewCode(context, periodIndex); + measure.setVariation(periodIndex, calculateCoverage(coveredElements, elements)); + hasValue = true; + } + } + if (hasValue) { + context.saveMeasure(measure); } - } - if (hasValue) { - context.saveMeasure(measure); } } -- 2.39.5