From 5e5a62d9b8cd898b67e34fb0852e5e4a62a31d16 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Wed, 19 Jun 2013 23:14:01 +0200 Subject: [PATCH] Remove code in CoreMetrics/Metric deprecated in 2.x --- .../org/sonar/api/measures/CoreMetrics.java | 82 +------------------ .../java/org/sonar/api/measures/Metric.java | 8 +- .../sonar/api/resources/CoreMetricsTest.java | 18 +--- 3 files changed, 8 insertions(+), 100 deletions(-) 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 68967655016..b471208660e 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 @@ -52,13 +52,6 @@ public final class CoreMetrics { @Deprecated public static String DOMAIN_REVIEWS = "Reviews"; public static String DOMAIN_ISSUES = "Issues"; - - /** - * @deprecated since 2.5 See SONAR-2007 - */ - @Deprecated - public static final String DOMAIN_RULE_CATEGORIES = "Rule categories"; - public static String DOMAIN_GENERAL = "General"; public static String DOMAIN_DUPLICATION = "Duplication"; public static String DOMAIN_DESIGN = "Design"; @@ -1328,77 +1321,6 @@ public final class CoreMetrics { // // -------------------------------------------------------------------------------------------------------------------- - /** - * @deprecated since 2.5 See SONAR-2007 - */ - @Deprecated - public static final String USABILITY_KEY = "usability"; - - /** - * @deprecated since 2.5 See SONAR-2007 - */ - @Deprecated - public static final Metric USABILITY = new Metric(USABILITY_KEY, "Usability", "Usability", Metric.ValueType.PERCENT, - Metric.DIRECTION_BETTER, true, DOMAIN_RULE_CATEGORIES).setBestValue(100.0).setOptimizedBestValue(true); - - /** - * @deprecated since 2.5 See SONAR-2007 - */ - @Deprecated - public static final String RELIABILITY_KEY = "reliability"; - - /** - * @deprecated since 2.5 See SONAR-2007 - */ - @Deprecated - public static final Metric RELIABILITY = new Metric(RELIABILITY_KEY, "Reliability", "Reliability", Metric.ValueType.PERCENT, - Metric.DIRECTION_BETTER, true, DOMAIN_RULE_CATEGORIES).setBestValue(100.0).setOptimizedBestValue(true); - - /** - * @deprecated since 2.5 See SONAR-2007 - */ - @Deprecated - public static final String EFFICIENCY_KEY = "efficiency"; - - /** - * @deprecated since 2.5 See SONAR-2007 - */ - @Deprecated - public static final Metric EFFICIENCY = new Metric(EFFICIENCY_KEY, "Efficiency", "Efficiency", Metric.ValueType.PERCENT, - Metric.DIRECTION_BETTER, true, DOMAIN_RULE_CATEGORIES).setBestValue(100.0).setOptimizedBestValue(true); - - /** - * @deprecated since 2.5 See SONAR-2007 - */ - @Deprecated - public static final String PORTABILITY_KEY = "portability"; - - /** - * @deprecated since 2.5 See SONAR-2007 - */ - @Deprecated - public static final Metric PORTABILITY = new Metric(PORTABILITY_KEY, "Portability", "Portability", Metric.ValueType.PERCENT, - Metric.DIRECTION_BETTER, true, DOMAIN_RULE_CATEGORIES).setBestValue(100.0).setOptimizedBestValue(true); - - /** - * @deprecated since 2.5 See SONAR-2007 - */ - @Deprecated - public static final String MAINTAINABILITY_KEY = "maintainability"; - - /** - * @deprecated since 2.5 See SONAR-2007 - */ - @Deprecated - public static final Metric MAINTAINABILITY = new Metric.Builder(MAINTAINABILITY_KEY, "Maintainability", Metric.ValueType.PERCENT) - .setDescription("Maintainability") - .setDirection(Metric.DIRECTION_BETTER) - .setQualitative(true) - .setDomain(DOMAIN_RULE_CATEGORIES) - .setBestValue(100.0) - .setOptimizedBestValue(true) - .create(); - public static final String WEIGHTED_VIOLATIONS_KEY = "weighted_violations"; public static final Metric WEIGHTED_VIOLATIONS = new Metric.Builder(WEIGHTED_VIOLATIONS_KEY, "Weighted issues", Metric.ValueType.INT) .setDescription("Weighted Issues") @@ -2116,9 +2038,7 @@ public final class CoreMetrics { if (Metric.class.isAssignableFrom(field.getType())) { try { Metric metric = (Metric) field.get(null); - if (!StringUtils.equals(metric.getDomain(), DOMAIN_RULE_CATEGORIES)) { - METRICS.add(metric); - } + METRICS.add(metric); } catch (IllegalAccessException e) { throw new SonarException("can not introspect " + CoreMetrics.class + " to get metrics", e); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/Metric.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/Metric.java index 440d816b15c..b6e845b5fba 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/Metric.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/Metric.java @@ -154,7 +154,7 @@ public class Metric implements ServerExtension, BatchExtension { } /** - * Creates an empty metric + * Creates an empty metric. Required for Hibernate. * * @deprecated in 1.12. Use the {@link Builder} factory. */ @@ -190,7 +190,7 @@ public class Metric implements ServerExtension, BatchExtension { * @deprecated since 2.7 use the {@link Builder} factory. */ @Deprecated - public Metric(String key, String name, String description, ValueType type, Integer direction, Boolean qualitative, String domain) { + private Metric(String key, String name, String description, ValueType type, Integer direction, Boolean qualitative, String domain) { this(key, name, description, type, direction, qualitative, domain, false); } @@ -211,7 +211,7 @@ public class Metric implements ServerExtension, BatchExtension { * @deprecated since 2.7 use the {@link Builder} factory. */ @Deprecated - public Metric(String key, String name, String description, ValueType type, Integer direction, Boolean qualitative, String domain, + private Metric(String key, String name, String description, ValueType type, Integer direction, Boolean qualitative, String domain, boolean userManaged) { this.key = key; this.description = description; @@ -246,7 +246,7 @@ public class Metric implements ServerExtension, BatchExtension { * @deprecated since 2.7 use the {@link Builder} factory. */ @Deprecated - public Metric(String key, String name, ValueType type, Integer direction, Boolean qualitative, String domain, Formula formula) { + private Metric(String key, String name, ValueType type, Integer direction, Boolean qualitative, String domain, Formula formula) { this.key = key; this.name = name; this.type = type; diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/resources/CoreMetricsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/resources/CoreMetricsTest.java index 88ae3dd2b06..4f6e1a9e618 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/resources/CoreMetricsTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/resources/CoreMetricsTest.java @@ -25,25 +25,13 @@ import org.sonar.api.measures.Metric; import java.util.List; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.fest.assertions.Assertions.assertThat; public class CoreMetricsTest { @Test public void shouldReadMetricsFromClassReflection() { List metrics = CoreMetrics.getMetrics(); - assertTrue(metrics.size() > 10); - assertTrue(metrics.contains(CoreMetrics.NCLOC)); - assertTrue(metrics.contains(CoreMetrics.DIRECTORIES)); - } - - @Test - public void shouldExcludeDeprecatedIsoMetrics() { - List metrics = CoreMetrics.getMetrics(); - assertFalse(metrics.contains(CoreMetrics.USABILITY)); - assertFalse(metrics.contains(CoreMetrics.EFFICIENCY)); - assertFalse(metrics.contains(CoreMetrics.RELIABILITY)); - assertFalse(metrics.contains(CoreMetrics.PORTABILITY)); - assertFalse(metrics.contains(CoreMetrics.MAINTAINABILITY)); + assertThat(metrics).hasSize(148); + assertThat(metrics).contains(CoreMetrics.NCLOC, CoreMetrics.DIRECTORIES); } } -- 2.39.5