From df06580805552cf4575031818a83d9f0f3520744 Mon Sep 17 00:00:00 2001 From: simonbrandhof Date: Fri, 25 Feb 2011 00:20:30 +0100 Subject: [PATCH] SONAR-2238 Remove the metric "uncovered_complexity_by_tests" --- .../org/sonar/plugins/core/CorePlugin.java | 1 - .../sensors/UncoveredComplexityDecorator.java | 74 ------------------- .../UncoveredComplexityDecoratorTest.java | 63 ---------------- .../org/sonar/api/measures/CoreMetrics.java | 12 --- .../main/webapp/WEB-INF/app/models/metric.rb | 1 - 5 files changed, 151 deletions(-) delete mode 100644 plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/UncoveredComplexityDecorator.java delete mode 100644 plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/UncoveredComplexityDecoratorTest.java diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java index 18113235d1d..4d6063a9d71 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java @@ -224,7 +224,6 @@ public class CorePlugin implements Plugin { extensions.add(LineCoverageDecorator.class); extensions.add(CoverageDecorator.class); extensions.add(BranchCoverageDecorator.class); - extensions.add(UncoveredComplexityDecorator.class); extensions.add(ApplyProjectRolesDecorator.class); extensions.add(ExcludedResourceFilter.class); extensions.add(CommentDensityDecorator.class); diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/UncoveredComplexityDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/UncoveredComplexityDecorator.java deleted file mode 100644 index 153b4d66a3d..00000000000 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/UncoveredComplexityDecorator.java +++ /dev/null @@ -1,74 +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.core.sensors; - -import org.sonar.api.batch.Decorator; -import org.sonar.api.batch.DecoratorContext; -import org.sonar.api.batch.DependedUpon; -import org.sonar.api.batch.DependsUpon; -import org.sonar.api.measures.CoreMetrics; -import org.sonar.api.measures.Measure; -import org.sonar.api.measures.MeasureUtils; -import org.sonar.api.measures.Metric; -import org.sonar.api.resources.Project; -import org.sonar.api.resources.Resource; -import org.sonar.api.utils.KeyValueFormat; - -import java.util.Arrays; -import java.util.List; - -/** - * @deprecated the metric CoreMetrics.UNCOVERED_COMPLEXITY_BY_TESTS is deprecated since v.1.11. - * It's replaced by uncovered_line and uncovered_conditions - */ -@Deprecated -public class UncoveredComplexityDecorator implements Decorator { - - @DependsUpon - public List dependsUponMetrics() { - return Arrays.asList(CoreMetrics.COVERAGE, CoreMetrics.COMPLEXITY); - } - - @DependedUpon - public Metric generatesMetric() { - return CoreMetrics.UNCOVERED_COMPLEXITY_BY_TESTS; - } - - public boolean shouldExecuteOnProject(Project project) { - return true; - } - - public void decorate(Resource resource, DecoratorContext context) { - Measure coverage = context.getMeasure(CoreMetrics.COVERAGE); - Measure complexity = context.getMeasure(CoreMetrics.COMPLEXITY); - - if (MeasureUtils.haveValues(coverage, complexity)) { - double value = complexity.getValue() - (complexity.getValue() * (coverage.getValue() / 100.0)); - String data = KeyValueFormat.format("CMP", complexity.getValue().intValue(), "COV", coverage.getValue()); - context.saveMeasure(new Measure(CoreMetrics.UNCOVERED_COMPLEXITY_BY_TESTS, value, data)); - } - } - - @Override - public String toString() { - return getClass().getSimpleName(); - } -} - diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/UncoveredComplexityDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/UncoveredComplexityDecoratorTest.java deleted file mode 100644 index e585691f730..00000000000 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/UncoveredComplexityDecoratorTest.java +++ /dev/null @@ -1,63 +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.core.sensors; - -import static org.hamcrest.core.IsNot.not; -import static org.hamcrest.number.OrderingComparisons.greaterThan; -import static org.junit.Assert.assertThat; -import org.junit.Test; -import static org.mockito.Matchers.anyObject; -import static org.mockito.Mockito.*; -import org.sonar.api.batch.DecoratorContext; -import org.sonar.api.measures.CoreMetrics; -import org.sonar.api.measures.Measure; -import org.sonar.api.test.IsMeasure; - -public class UncoveredComplexityDecoratorTest { - - @Test - public void nothingWhenNoMeasures() { - DecoratorContext context = mock(DecoratorContext.class); - UncoveredComplexityDecorator decorator = new UncoveredComplexityDecorator(); - decorator.decorate(null, context); - - verify(context, never()).saveMeasure((Measure) anyObject()); - } - - @Test - public void quotientWhenMeasures() { - DecoratorContext context = mock(DecoratorContext.class); - when(context.getMeasure(CoreMetrics.COMPLEXITY)).thenReturn(new Measure(CoreMetrics.COMPLEXITY, 1048.0)); - when(context.getMeasure(CoreMetrics.COVERAGE)).thenReturn(new Measure(CoreMetrics.COVERAGE, 32.5)); - - UncoveredComplexityDecorator decorator = new UncoveredComplexityDecorator(); - decorator.decorate(null, context); - - verify(context).saveMeasure(argThat(new IsMeasure(CoreMetrics.UNCOVERED_COMPLEXITY_BY_TESTS, 707.4))); - verify(context).saveMeasure(argThat(new IsMeasure(CoreMetrics.UNCOVERED_COMPLEXITY_BY_TESTS, "CMP=1048;COV=32.5"))); - } - - @Test - public void declareDependencies() { - UncoveredComplexityDecorator decorator = new UncoveredComplexityDecorator(); - assertThat(decorator.dependsUponMetrics().size(), greaterThan(0)); - assertThat(decorator.generatesMetric(), not(isNull())); - } -} 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 d7c94b4853b..2480b8ddb41 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 @@ -296,18 +296,6 @@ public final class CoreMetrics { .setDomain(DOMAIN_TESTS) .create(); - /** - * @deprecated replaced since 1.11 by UNCOVERED_LINES and UNCOVERED_CONDITIONS - */ - @Deprecated - public static final String UNCOVERED_COMPLEXITY_BY_TESTS_KEY = "uncovered_complexity_by_tests"; - /** - * @deprecated replaced since 1.11 by UNCOVERED_LINES and UNCOVERED_CONDITIONS - */ - @Deprecated - public static final Metric UNCOVERED_COMPLEXITY_BY_TESTS = new Metric(UNCOVERED_COMPLEXITY_BY_TESTS_KEY, "Uncovered complexity", - "Uncovered complexity", Metric.ValueType.INT, Metric.DIRECTION_WORST, false, DOMAIN_COMPLEXITY).setFormula(new SumChildValuesFormula( - false)); public static final String DUPLICATED_LINES_KEY = "duplicated_lines"; public static final Metric DUPLICATED_LINES = new Metric(DUPLICATED_LINES_KEY, "Duplicated lines", "Duplicated lines", diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/metric.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/metric.rb index dd22621af4f..d4bb9b2f58e 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/metric.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/metric.rb @@ -244,7 +244,6 @@ class Metric < ActiveRecord::Base AVG_CMPX_BY_FILE = 'file_complexity' CLASSES_CMPX_DISTRIBUTION = 'class_complexity_distribution' FUNCTIONS_CMPX_DISTRIBUTION = 'function_complexity_distribution' - UNCOVERED_CMPX_BY_TESTS = 'uncovered_complexity_by_tests' DUPLICATED_FILES = 'duplicated_files' DUPLICATED_LINES = 'duplicated_lines' -- 2.39.5