diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2014-07-21 17:28:27 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2014-07-21 17:42:08 +0200 |
commit | 2b2c1f3bcfae1af11de717d395b0cdf702782a39 (patch) | |
tree | 343f51ecdbeb49841bd1db5db17728cefb6075b6 | |
parent | 718952272eb780ecb2b3f613a0f0337bacff75f6 (diff) | |
download | sonarqube-2b2c1f3bcfae1af11de717d395b0cdf702782a39.tar.gz sonarqube-2b2c1f3bcfae1af11de717d395b0cdf702782a39.zip |
SONAR-5417 Add additional metric attributes
4 files changed, 74 insertions, 4 deletions
diff --git a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/Metric.java b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/Metric.java index 21193575608..f09f3b34e81 100644 --- a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/Metric.java +++ b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/Metric.java @@ -30,14 +30,42 @@ public class Metric { private final String valueType; + private final String description; + + private final int direction; + + private final String name; + + private final boolean qualitative; + + private final boolean userManaged; + + private final Double worstValue; + private final Double bestValue; private final boolean optimizedBestValue; - public Metric(int id, String key, String valueType, @Nullable Double bestValue, boolean optimizedBestValue) { + public Metric(int id, + String key, + String valueType, + String description, + int direction, + String name, + boolean qualitative, + boolean userManaged, + @Nullable Double worstValue, + @Nullable Double bestValue, + boolean optimizedBestValue) { this.id = id; this.key = key; this.valueType = valueType; + this.description = description; + this.direction = direction; + this.name = name; + this.qualitative = qualitative; + this.userManaged = userManaged; + this.worstValue = worstValue; this.bestValue = bestValue; this.optimizedBestValue = optimizedBestValue; } @@ -54,6 +82,31 @@ public class Metric { return valueType; } + public String description() { + return description; + } + + public int direction() { + return direction; + } + + public String name() { + return name; + } + + public boolean isQualitative() { + return qualitative; + } + + public boolean isUserManaged() { + return userManaged; + } + + @CheckForNull + public Double worstValue() { + return worstValue; + } + @CheckForNull public Double bestValue() { return bestValue; diff --git a/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/ProjectReferentialsTest.java b/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/ProjectReferentialsTest.java index db914a091ec..deeca583cb5 100644 --- a/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/ProjectReferentialsTest.java +++ b/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/ProjectReferentialsTest.java @@ -34,7 +34,7 @@ public class ProjectReferentialsTest { @Test public void testToJson() throws Exception { ProjectReferentials ref = new ProjectReferentials(); - ref.metrics().add(new Metric(1, "ncloc", "INT", 1.0, true)); + ref.metrics().add(new Metric(1, "ncloc", "INT", "Description", -1, "NCLOC", true, false, 2.0, 1.0, true)); ref.addQProfile(new QProfile("squid-java", "Java", "java", new SimpleDateFormat("dd/MM/yyyy").parse("14/03/1984"))); ref.addSettings("foo", new HashMap<String, String>()); ref.settings("foo").put("prop", "value"); @@ -44,7 +44,7 @@ public class ProjectReferentialsTest { System.out.println(ref.toJson()); JSONAssert .assertEquals( - "{timestamp:10,metrics:[{id:1,key:ncloc,valueType:INT,bestValue:1.0,optimizedBestValue:true}]," + "{timestamp:10,metrics:[{id:1,key:ncloc,valueType:INT,description:Description,direction:-1,name:NCLOC,qualitative:true,userManaged:false,worstValue:2.0,bestValue:1.0,optimizedBestValue:true}]," + "qprofilesByLanguage:{java:{key:\"squid-java\",name:Java,language:java,rulesUpdatedAt:\"Mar 14, 1984 12:00:00 AM\"}}," + "activeRules:[{repositoryKey:repo,ruleKey:rule,severity:MAJOR,internalKey:rule,language:java,params:{}}]," + "settingsByModule:{foo:{prop:value}}}", diff --git a/sonar-batch/src/main/java/org/sonar/batch/referential/DefaultProjectReferentialsLoader.java b/sonar-batch/src/main/java/org/sonar/batch/referential/DefaultProjectReferentialsLoader.java index d0ada6e8b3c..558308bb8cb 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/referential/DefaultProjectReferentialsLoader.java +++ b/sonar-batch/src/main/java/org/sonar/batch/referential/DefaultProjectReferentialsLoader.java @@ -72,8 +72,19 @@ public class DefaultProjectReferentialsLoader implements ProjectReferentialsLoad ProjectReferentials ref = new ProjectReferentials(); for (Metric m : sessionFactory.getSession().getResults(Metric.class, ENABLED, true)) { Boolean optimizedBestValue = m.isOptimizedBestValue(); + Boolean qualitative = m.getQualitative(); + Boolean userManaged = m.getUserManaged(); ref.metrics().add( - new org.sonar.batch.protocol.input.Metric(m.getId(), m.getKey(), m.getType().name(), m.getBestValue(), optimizedBestValue != null ? optimizedBestValue : false)); + new org.sonar.batch.protocol.input.Metric(m.getId(), m.getKey(), + m.getType().name(), + m.getDescription(), + m.getDirection(), + m.getName(), + qualitative != null ? m.getQualitative() : false, + userManaged != null ? m.getUserManaged() : false, + m.getWorstValue(), + m.getBestValue(), + optimizedBestValue != null ? optimizedBestValue : false)); } String defaultName = settings.getString(ModuleQProfiles.SONAR_PROFILE_PROP); diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/measure/DeprecatedMetricFinder.java b/sonar-batch/src/main/java/org/sonar/batch/scan/measure/DeprecatedMetricFinder.java index b3e3f9cac18..3f1ab39668d 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/measure/DeprecatedMetricFinder.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/measure/DeprecatedMetricFinder.java @@ -39,8 +39,14 @@ public final class DeprecatedMetricFinder implements MetricFinder { for (org.sonar.batch.protocol.input.Metric metric : projectReferentials.metrics()) { Metric hibernateMetric = new org.sonar.api.measures.Metric.Builder(metric.key(), metric.key(), ValueType.valueOf(metric.valueType())) .create() + .setDirection(metric.direction()) + .setQualitative(metric.isQualitative()) + .setUserManaged(metric.isUserManaged()) + .setDescription(metric.description()) + .setName(metric.name()) .setOptimizedBestValue(metric.isOptimizedBestValue()) .setBestValue(metric.bestValue()) + .setWorstValue(metric.worstValue()) .setId(metric.id()); metricsByKey.put(metric.key(), hibernateMetric); metricsById.put(metric.id(), new org.sonar.api.measures.Metric.Builder(metric.key(), metric.key(), ValueType.valueOf(metric.valueType())).create().setId(metric.id())); |