diff options
author | simonbrandhof <simon.brandhof@gmail.com> | 2011-03-23 15:31:47 +0100 |
---|---|---|
committer | simonbrandhof <simon.brandhof@gmail.com> | 2011-03-23 15:31:47 +0100 |
commit | b25c8001084885c77c9ae45a8a86fbc007063277 (patch) | |
tree | f98e42cfee51505530464f9b563f67edb9544d52 /plugins | |
parent | 1d414016d33384d4346b2464db3f1a32d22fa4aa (diff) | |
download | sonarqube-b25c8001084885c77c9ae45a8a86fbc007063277.tar.gz sonarqube-b25c8001084885c77c9ae45a8a86fbc007063277.zip |
Fix Clover coverage on new code at project and package levels
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/AbstractCoverageDecorator.java | 40 |
1 files 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); } } |