From 42cab973f76e48d80b2d5fb621aaa983ad940254 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Fri, 27 Sep 2013 14:06:47 +0200 Subject: SONAR-4715 Compute the new "Technical Debt" metric --- .../main/java/org/sonar/api/CoreProperties.java | 6 +++++ .../java/org/sonar/api/measures/CoreMetrics.java | 29 ++++++++++++++++++++++ .../org/sonar/api/resources/CoreMetricsTest.java | 2 +- 3 files changed, 36 insertions(+), 1 deletion(-) (limited to 'sonar-plugin-api/src') diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java b/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java index cc2cfaebf7b..b410c6bc295 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java @@ -121,6 +121,12 @@ public interface CoreProperties { */ String CATEGORY_LICENSES = "licenses"; + /** + * @since 4.0 + */ + String CATEGORY_TECHNICAL_DEBT = "technicalDebt"; + + /* Global settings */ String SONAR_HOME = "SONAR_HOME"; String PROJECT_BRANCH_PROPERTY = "sonar.branch"; 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 8cba132e0dd..5616e6a5690 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 @@ -55,6 +55,11 @@ public final class CoreMetrics { public static String DOMAIN_DUPLICATION = "Duplication"; public static String DOMAIN_DESIGN = "Design"; + /** + * @since 4.0 + */ + public static String DOMAIN_TECHNICAL_DEBT = "Technical Debt"; + public static final String LINES_KEY = "lines"; public static final Metric LINES = new Metric.Builder(LINES_KEY, "Lines", Metric.ValueType.INT) .setDescription("Lines") @@ -2009,6 +2014,30 @@ public final class CoreMetrics { .setHidden(true) .create(); + + // -------------------------------------------------------------------------------------------------------------------- + // + // TECHNICAL DEBT + // + // -------------------------------------------------------------------------------------------------------------------- + + /** + * @since 4.0 + */ + public static final String TECHNICAL_DEBT_KEY = "technical_debt"; + + /** + * @since 4.0 + */ + public static final Metric TECHNICAL_DEBT = new Metric.Builder(TECHNICAL_DEBT_KEY, "Technical Debt", Metric.ValueType.FLOAT) + .setDomain(DOMAIN_TECHNICAL_DEBT) + .setDirection(Metric.DIRECTION_WORST) + .setOptimizedBestValue(true) + .setBestValue(0.0) + .setQualitative(true) + .create(); + + // -------------------------------------------------------------------------------------------------------------------- // // FILE DATA 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 4f6e1a9e618..14abb67a8be 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 @@ -31,7 +31,7 @@ public class CoreMetricsTest { @Test public void shouldReadMetricsFromClassReflection() { List metrics = CoreMetrics.getMetrics(); - assertThat(metrics).hasSize(148); + assertThat(metrics).hasSize(149); assertThat(metrics).contains(CoreMetrics.NCLOC, CoreMetrics.DIRECTORIES); } } -- cgit v1.2.3