diff options
author | simonbrandhof <simon.brandhof@gmail.com> | 2011-11-01 22:07:27 +0100 |
---|---|---|
committer | simonbrandhof <simon.brandhof@gmail.com> | 2011-11-01 22:07:27 +0100 |
commit | 9842aa3d39e0892decdb69a60e6e731d1ff00a4b (patch) | |
tree | c2039897838ca73b13b45897f9a4ef3581bf883d | |
parent | 03f9d9b4411f993166df88c127d0d57f89266c1a (diff) | |
download | sonarqube-9842aa3d39e0892decdb69a60e6e731d1ff00a4b.tar.gz sonarqube-9842aa3d39e0892decdb69a60e6e731d1ff00a4b.zip |
SONAR-2952 add @since comments to new core metrics + remove dead code from jacoco plugin
5 files changed, 119 insertions, 250 deletions
diff --git a/plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/itcoverage/AbstractCoverageDecorator.java b/plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/itcoverage/AbstractCoverageDecorator.java deleted file mode 100644 index 71f5364dab1..00000000000 --- a/plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/itcoverage/AbstractCoverageDecorator.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2008-2011 SonarSource - * mailto:contact AT sonarsource DOT com - * - * Sonar is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * Sonar is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Sonar; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 - */ -package org.sonar.plugins.jacoco.itcoverage; - -import org.sonar.api.batch.Decorator; -import org.sonar.api.batch.DecoratorContext; -import org.sonar.api.batch.DependedUpon; -import org.sonar.api.measures.Metric; -import org.sonar.api.resources.Project; -import org.sonar.api.resources.Resource; -import org.sonar.api.resources.ResourceUtils; - -/** - * Copied from org.sonar.plugins.core.sensors.AbstractCoverageDecorator - */ -public abstract class AbstractCoverageDecorator implements Decorator { - - public boolean shouldExecuteOnProject(Project project) { - return project.getAnalysisType().isDynamic(true); - } - - @DependedUpon - public Metric generatesCoverage() { - return getTargetMetric(); - } - - public void decorate(final Resource resource, final DecoratorContext context) { - if (shouldDecorate(resource, context)) { - saveCoverage(context); - } - } - - protected boolean shouldDecorate(final Resource resource, final DecoratorContext context) { - return context.getMeasure(getTargetMetric()) == null && !ResourceUtils.isUnitTestClass(resource); - } - - private void saveCoverage(DecoratorContext context) { - Double elements = countElements(context); - Double coveredElements = countCoveredElements(context); - - if (elements != null && elements > 0.0 && coveredElements != null) { - context.saveMeasure(getTargetMetric(), calculateCoverage(coveredElements, elements)); - } - } - - private double calculateCoverage(final Double coveredElements, final Double elements) { - return (100.0 * coveredElements) / elements; - } - - protected abstract Metric getTargetMetric(); - - protected abstract Double countCoveredElements(DecoratorContext context); - - protected abstract Double countElements(DecoratorContext context); -} diff --git a/plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/itcoverage/ItBranchCoverageDecorator.java b/plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/itcoverage/ItBranchCoverageDecorator.java deleted file mode 100644 index 6c7da52a085..00000000000 --- a/plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/itcoverage/ItBranchCoverageDecorator.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2008-2011 SonarSource - * mailto:contact AT sonarsource DOT com - * - * Sonar is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * Sonar is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Sonar; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 - */ -package org.sonar.plugins.jacoco.itcoverage; - -import org.sonar.api.batch.DecoratorContext; -import org.sonar.api.batch.DependsUpon; -import org.sonar.api.measures.CoreMetrics; -import org.sonar.api.measures.MeasureUtils; -import org.sonar.api.measures.Metric; - -import java.util.Arrays; -import java.util.List; - -/** - * Copied from org.sonar.plugins.core.sensors.BranchCoverageDecorator - */ -public final class ItBranchCoverageDecorator extends AbstractCoverageDecorator { - @Override - protected Metric getTargetMetric() { - return CoreMetrics.IT_BRANCH_COVERAGE; - } - - @DependsUpon - public List<Metric> dependsUponMetrics() { - return Arrays.asList(CoreMetrics.IT_UNCOVERED_CONDITIONS, CoreMetrics.IT_CONDITIONS_TO_COVER); - } - - @Override - protected Double countCoveredElements(DecoratorContext context) { - double uncoveredConditions = MeasureUtils.getValue(context.getMeasure(CoreMetrics.IT_UNCOVERED_CONDITIONS), 0.0); - double conditions = MeasureUtils.getValue(context.getMeasure(CoreMetrics.IT_CONDITIONS_TO_COVER), 0.0); - return conditions - uncoveredConditions; - } - - @Override - protected Double countElements(DecoratorContext context) { - return MeasureUtils.getValue(context.getMeasure(CoreMetrics.IT_CONDITIONS_TO_COVER), 0.0); - } -} diff --git a/plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/itcoverage/ItCoverageDecorator.java b/plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/itcoverage/ItCoverageDecorator.java deleted file mode 100644 index f1bb7c63f4d..00000000000 --- a/plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/itcoverage/ItCoverageDecorator.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2008-2011 SonarSource - * mailto:contact AT sonarsource DOT com - * - * Sonar is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * Sonar is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Sonar; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 - */ -package org.sonar.plugins.jacoco.itcoverage; - -import org.sonar.api.batch.DecoratorContext; -import org.sonar.api.batch.DependsUpon; -import org.sonar.api.measures.CoreMetrics; -import org.sonar.api.measures.MeasureUtils; -import org.sonar.api.measures.Metric; - -import java.util.Arrays; -import java.util.List; - -/** - * Copied from org.sonar.plugins.core.sensors.CoverageDecorator - */ -public class ItCoverageDecorator extends AbstractCoverageDecorator { - - @Override - protected Metric getTargetMetric() { - return CoreMetrics.IT_COVERAGE; - } - - @DependsUpon - public List<Metric> dependsUponMetrics() { - return Arrays.asList(CoreMetrics.IT_LINES_TO_COVER, CoreMetrics.IT_UNCOVERED_LINES, CoreMetrics.IT_CONDITIONS_TO_COVER, CoreMetrics.IT_UNCOVERED_CONDITIONS); - } - - @Override - protected Double countCoveredElements(DecoratorContext context) { - double uncoveredLines = MeasureUtils.getValue(context.getMeasure(CoreMetrics.IT_UNCOVERED_LINES), 0.0); - double lines = MeasureUtils.getValue(context.getMeasure(CoreMetrics.IT_LINES_TO_COVER), 0.0); - double uncoveredConditions = MeasureUtils.getValue(context.getMeasure(CoreMetrics.IT_UNCOVERED_CONDITIONS), 0.0); - double conditions = MeasureUtils.getValue(context.getMeasure(CoreMetrics.IT_CONDITIONS_TO_COVER), 0.0); - return lines + conditions - uncoveredConditions - uncoveredLines; - } - - @Override - protected Double countElements(DecoratorContext context) { - double lines = MeasureUtils.getValue(context.getMeasure(CoreMetrics.IT_LINES_TO_COVER), 0.0); - double conditions = MeasureUtils.getValue(context.getMeasure(CoreMetrics.IT_CONDITIONS_TO_COVER), 0.0); - return lines + conditions; - } - -} diff --git a/plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/itcoverage/ItLineCoverageDecorator.java b/plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/itcoverage/ItLineCoverageDecorator.java deleted file mode 100644 index c5e8e3bde33..00000000000 --- a/plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/itcoverage/ItLineCoverageDecorator.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2008-2011 SonarSource - * mailto:contact AT sonarsource DOT com - * - * Sonar is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * Sonar is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Sonar; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 - */ -package org.sonar.plugins.jacoco.itcoverage; - -import org.sonar.api.batch.DecoratorContext; -import org.sonar.api.batch.DependsUpon; -import org.sonar.api.measures.CoreMetrics; -import org.sonar.api.measures.MeasureUtils; -import org.sonar.api.measures.Metric; - -import java.util.Arrays; -import java.util.List; - -/** - * Copied from org.sonar.plugins.core.sensors.LineCoverageDecorator - */ -public class ItLineCoverageDecorator extends AbstractCoverageDecorator { - @Override - protected Metric getTargetMetric() { - return CoreMetrics.IT_LINE_COVERAGE; - } - - @DependsUpon - public List<Metric> dependsUponMetrics() { - return Arrays.asList(CoreMetrics.IT_UNCOVERED_LINES, CoreMetrics.IT_LINES_TO_COVER); - } - - @Override - protected Double countCoveredElements(DecoratorContext context) { - double uncoveredLines = MeasureUtils.getValue(context.getMeasure(CoreMetrics.IT_UNCOVERED_LINES), 0.0); - double lines = MeasureUtils.getValue(context.getMeasure(CoreMetrics.IT_LINES_TO_COVER), 0.0); - return lines - uncoveredLines; - } - - @Override - protected Double countElements(DecoratorContext context) { - return MeasureUtils.getValue(context.getMeasure(CoreMetrics.IT_LINES_TO_COVER), 0.0); - } -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java index c498bc00ca9..cccbdbcf5eb 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java @@ -608,7 +608,14 @@ public final class CoreMetrics { // //-------------------------------------------------------------------------------------------------------------------- + /** + * @since 2.12 + */ public static final String IT_COVERAGE_KEY = "it_coverage"; + + /** + * @since 2.12 + */ public static final Metric IT_COVERAGE = new Metric.Builder(IT_COVERAGE_KEY, "IT Coverage", Metric.ValueType.PERCENT) .setDescription("Coverage by integration tests") .setDirection(Metric.DIRECTION_BETTER) @@ -618,7 +625,14 @@ public final class CoreMetrics { .setBestValue(100.0) .create(); -public static final String NEW_IT_COVERAGE_KEY = "new_it_coverage"; + /** + * @since 2.12 + */ + public static final String NEW_IT_COVERAGE_KEY = "new_it_coverage"; + + /** + * @since 2.12 + */ public static final Metric NEW_IT_COVERAGE = new Metric.Builder(NEW_IT_COVERAGE_KEY, "New IT coverage", Metric.ValueType.PERCENT) .setDescription("Integration Tests Coverage of new/changed code") .setDirection(Metric.DIRECTION_BETTER) @@ -628,8 +642,14 @@ public static final String NEW_IT_COVERAGE_KEY = "new_it_coverage"; .setBestValue(100.0) .create(); - + /** + * @since 2.12 + */ public static final String IT_LINES_TO_COVER_KEY = "it_lines_to_cover"; + + /** + * @since 2.12 + */ public static final Metric IT_LINES_TO_COVER = new Metric.Builder(IT_LINES_TO_COVER_KEY, "IT Lines to cover", Metric.ValueType.INT) .setDescription("Lines to cover by Integration Tests") .setDirection(Metric.DIRECTION_BETTER) @@ -639,7 +659,14 @@ public static final String NEW_IT_COVERAGE_KEY = "new_it_coverage"; .setHidden(true) .create(); -public static final String NEW_IT_LINES_TO_COVER_KEY = "new_it_lines_to_cover"; + /** + * @since 2.12 + */ + public static final String NEW_IT_LINES_TO_COVER_KEY = "new_it_lines_to_cover"; + + /** + * @since 2.12 + */ public static final Metric NEW_IT_LINES_TO_COVER = new Metric.Builder(NEW_IT_LINES_TO_COVER_KEY, "New lines to cover by IT", Metric.ValueType.INT) .setDescription("New lines to cover by Integration Tests") .setDirection(Metric.DIRECTION_WORST) @@ -648,8 +675,14 @@ public static final String NEW_IT_LINES_TO_COVER_KEY = "new_it_lines_to_cover"; .setFormula(new SumChildValuesFormula(false)) .create(); - + /** + * @since 2.12 + */ public static final String IT_UNCOVERED_LINES_KEY = "it_uncovered_lines"; + + /** + * @since 2.12 + */ public static final Metric IT_UNCOVERED_LINES = new Metric.Builder(IT_UNCOVERED_LINES_KEY, "IT Uncovered lines", Metric.ValueType.INT) .setDescription("IT uncovered lines") .setDirection(Metric.DIRECTION_WORST) @@ -658,7 +691,14 @@ public static final String NEW_IT_LINES_TO_COVER_KEY = "new_it_lines_to_cover"; .setFormula(new SumChildValuesFormula(false)) .create(); + /** + * @since 2.12 + */ public static final String NEW_IT_UNCOVERED_LINES_KEY = "new_it_uncovered_lines"; + + /** + * @since 2.12 + */ public static final Metric NEW_IT_UNCOVERED_LINES = new Metric.Builder(NEW_IT_UNCOVERED_LINES_KEY, "New uncovered lines by IT", Metric.ValueType.INT) .setDescription("New uncovered lines by Integration Tests") .setDirection(Metric.DIRECTION_WORST) @@ -667,7 +707,14 @@ public static final String NEW_IT_LINES_TO_COVER_KEY = "new_it_lines_to_cover"; .setBestValue(0.0) .create(); + /** + * @since 2.12 + */ public static final String IT_LINE_COVERAGE_KEY = "it_line_coverage"; + + /** + * @since 2.12 + */ public static final Metric IT_LINE_COVERAGE = new Metric.Builder(IT_LINE_COVERAGE_KEY, "IT Line coverage", Metric.ValueType.PERCENT) .setDescription("IT line coverage") .setDirection(Metric.DIRECTION_BETTER) @@ -675,7 +722,14 @@ public static final String NEW_IT_LINES_TO_COVER_KEY = "new_it_lines_to_cover"; .setDomain(DOMAIN_INTEGRATION_TESTS) .create(); + /** + * @since 2.12 + */ public static final String NEW_IT_LINE_COVERAGE_KEY = "new_it_line_coverage"; + + /** + * @since 2.12 + */ public static final Metric NEW_IT_LINE_COVERAGE = new Metric.Builder(NEW_IT_LINE_COVERAGE_KEY, "New line coverage by IT", Metric.ValueType.PERCENT) .setDescription("Line Coverage by Integration Tests of added/changed code") .setDirection(Metric.DIRECTION_BETTER) @@ -685,7 +739,14 @@ public static final String NEW_IT_LINES_TO_COVER_KEY = "new_it_lines_to_cover"; .setDomain(DOMAIN_INTEGRATION_TESTS) .create(); + /** + * @since 2.12 + */ public static final String IT_COVERAGE_LINE_HITS_DATA_KEY = "it_coverage_line_hits_data"; + + /** + * @since 2.12 + */ public static final Metric IT_COVERAGE_LINE_HITS_DATA = new Metric.Builder(IT_COVERAGE_LINE_HITS_DATA_KEY, "IT Coverage hits data", Metric.ValueType.DATA) .setDescription("IT Code coverage line hits data") .setDirection(Metric.DIRECTION_NONE) @@ -693,7 +754,14 @@ public static final String NEW_IT_LINES_TO_COVER_KEY = "new_it_lines_to_cover"; .setDomain(DOMAIN_INTEGRATION_TESTS) .create(); + /** + * @since 2.12 + */ public static final String IT_CONDITIONS_TO_COVER_KEY = "it_conditions_to_cover"; + + /** + * @since 2.12 + */ public static final Metric IT_CONDITIONS_TO_COVER = new Metric.Builder(IT_CONDITIONS_TO_COVER_KEY, "IT Branches to cover", Metric.ValueType.INT) .setDescription("IT Conditions to cover") .setDirection(Metric.DIRECTION_BETTER) @@ -703,14 +771,28 @@ public static final String NEW_IT_LINES_TO_COVER_KEY = "new_it_lines_to_cover"; .setHidden(true) .create(); + /** + * @since 2.12 + */ public static final String NEW_IT_CONDITIONS_TO_COVER_KEY = "new_it_conditions_to_cover"; + + /** + * @since 2.12 + */ public static final Metric NEW_IT_CONDITIONS_TO_COVER = new Metric.Builder(NEW_IT_CONDITIONS_TO_COVER_KEY, "New conditions to cover by IT", Metric.ValueType.INT) .setDescription("New conditions to cover by Integration Tests") .setDomain(DOMAIN_INTEGRATION_TESTS) .setFormula(new SumChildValuesFormula(false)) .create(); + /** + * @since 2.12 + */ public static final String IT_UNCOVERED_CONDITIONS_KEY = "it_uncovered_conditions"; + + /** + * @since 2.12 + */ public static final Metric IT_UNCOVERED_CONDITIONS = new Metric.Builder(IT_UNCOVERED_CONDITIONS_KEY, "IT Uncovered branches", Metric.ValueType.INT) .setDescription("IT Uncovered conditions") .setDirection(Metric.DIRECTION_WORST) @@ -718,7 +800,14 @@ public static final String NEW_IT_LINES_TO_COVER_KEY = "new_it_lines_to_cover"; .setFormula(new SumChildValuesFormula(false)) .create(); + /** + * @since 2.12 + */ public static final String NEW_IT_UNCOVERED_CONDITIONS_KEY = "new_it_uncovered_conditions"; + + /** + * @since 2.12 + */ public static final Metric NEW_IT_UNCOVERED_CONDITIONS = new Metric.Builder(NEW_IT_UNCOVERED_CONDITIONS_KEY, "New uncovered conditions by IT", Metric.ValueType.INT) .setDescription("New uncovered conditions by Integration Tests") .setDirection(Metric.DIRECTION_WORST) @@ -727,7 +816,14 @@ public static final String NEW_IT_LINES_TO_COVER_KEY = "new_it_lines_to_cover"; .setBestValue(0.0) .create(); + /** + * @since 2.12 + */ public static final String IT_BRANCH_COVERAGE_KEY = "it_branch_coverage"; + + /** + * @since 2.12 + */ public static final Metric IT_BRANCH_COVERAGE = new Metric.Builder(IT_BRANCH_COVERAGE_KEY, "IT Branch coverage", Metric.ValueType.PERCENT) .setDescription("IT Branch coverage") .setDirection(Metric.DIRECTION_BETTER) @@ -737,7 +833,14 @@ public static final String NEW_IT_LINES_TO_COVER_KEY = "new_it_lines_to_cover"; .setBestValue(100.0) .create(); + /** + * @since 2.12 + */ public static final String NEW_IT_BRANCH_COVERAGE_KEY = "new_it_branch_coverage"; + + /** + * @since 2.12 + */ public static final Metric NEW_IT_BRANCH_COVERAGE = new Metric.Builder(NEW_IT_BRANCH_COVERAGE_KEY, "New branch coverage by IT", Metric.ValueType.PERCENT) .setDescription("Branch coverage by Integration Tests of new/changed code") .setDirection(Metric.DIRECTION_BETTER) @@ -747,14 +850,26 @@ public static final String NEW_IT_LINES_TO_COVER_KEY = "new_it_lines_to_cover"; .setBestValue(100.0) .create(); + /** + * @since 2.12 + */ public static final String IT_CONDITIONS_BY_LINE_KEY = "it_conditions_by_line"; + /** + * @since 2.12 + */ public static final Metric IT_CONDITIONS_BY_LINE = new Metric.Builder(IT_CONDITIONS_BY_LINE_KEY, "IT Branches by line", Metric.ValueType.DATA) .setDomain(DOMAIN_INTEGRATION_TESTS) .create(); + /** + * @since 2.12 + */ public static final String IT_COVERED_CONDITIONS_BY_LINE_KEY = "it_covered_conditions_by_line"; + /** + * @since 2.12 + */ public static final Metric IT_COVERED_CONDITIONS_BY_LINE = new Metric.Builder(IT_COVERED_CONDITIONS_BY_LINE_KEY, "IT Covered branches by line", Metric.ValueType.DATA) .setDomain(DOMAIN_INTEGRATION_TESTS) .create(); |