diff options
5 files changed, 25 insertions, 6 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 2b88577b9f2..704a917aece 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 @@ -27,10 +27,16 @@ public class Metric { private final String valueType; - public Metric(int id, String key, String valueType) { + private final Double bestValue; + + private final boolean optimizedBestValue; + + public Metric(int id, String key, String valueType, Double bestValue, boolean optimizedBestValue) { this.id = id; this.key = key; this.valueType = valueType; + this.bestValue = bestValue; + this.optimizedBestValue = optimizedBestValue; } public int id() { @@ -45,4 +51,12 @@ public class Metric { return valueType; } + public Double bestValue() { + return bestValue; + } + + public boolean isOptimizedBestValue() { + return optimizedBestValue; + } + } 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 f7280858258..db914a091ec 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")); + ref.metrics().add(new Metric(1, "ncloc", "INT", 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}]," + "{timestamp:10,metrics:[{id:1,key:ncloc,valueType:INT,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/mediumtest/AnalyzerMediumTester.java b/sonar-batch/src/main/java/org/sonar/batch/mediumtest/AnalyzerMediumTester.java index fcd22b383ef..f20917fe971 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/AnalyzerMediumTester.java +++ b/sonar-batch/src/main/java/org/sonar/batch/mediumtest/AnalyzerMediumTester.java @@ -245,7 +245,7 @@ public class AnalyzerMediumTester { } public FakeProjectReferentialsLoader add(Metric metric) { - ref.metrics().add(new org.sonar.batch.protocol.input.Metric(metricId, metric.key(), metric.getType().name())); + ref.metrics().add(new org.sonar.batch.protocol.input.Metric(metricId, metric.key(), metric.getType().name(), metric.getBestValue(), metric.isOptimizedBestValue())); metricId++; return this; } 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 31fe1ff4ced..8467e5573d6 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 @@ -71,7 +71,7 @@ public class DefaultProjectReferentialsLoader implements ProjectReferentialsLoad public ProjectReferentials load(ProjectReactor reactor, Settings settings, Languages languages) { ProjectReferentials ref = new ProjectReferentials(); for (Metric m : sessionFactory.getSession().getResults(Metric.class, ENABLED, true)) { - ref.metrics().add(new org.sonar.batch.protocol.input.Metric(m.getId(), m.getKey(), m.getType().name())); + ref.metrics().add(new org.sonar.batch.protocol.input.Metric(m.getId(), m.getKey(), m.getType().name(), m.getBestValue(), m.isOptimizedBestValue())); } 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 00d8403a473..495eaef2e56 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 @@ -37,7 +37,12 @@ public final class DeprecatedMetricFinder implements MetricFinder { public DeprecatedMetricFinder(ProjectReferentials projectReferentials) { for (org.sonar.batch.protocol.input.Metric metric : projectReferentials.metrics()) { - metricsByKey.put(metric.key(), new org.sonar.api.measures.Metric.Builder(metric.key(), metric.key(), ValueType.valueOf(metric.valueType())).create().setId(metric.id())); + Metric hibernateMetric = new org.sonar.api.measures.Metric.Builder(metric.key(), metric.key(), ValueType.valueOf(metric.valueType())) + .setBestValue(metric.bestValue()) + .setOptimizedBestValue(metric.isOptimizedBestValue()) + .create() + .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())); } } |