aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/Metric.java9
-rw-r--r--sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/ProjectReferentialsTest.java7
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/mediumtest/AnalyzerMediumTester.java5
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/referential/DefaultProjectReferentialsLoader.java2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/measure/DeprecatedMetricFinder.java6
5 files changed, 21 insertions, 8 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 58f6ea49119..2b88577b9f2 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
@@ -21,15 +21,22 @@ package org.sonar.batch.protocol.input;
public class Metric {
+ private final int id;
+
private final String key;
private final String valueType;
- public Metric(String key, String valueType) {
+ public Metric(int id, String key, String valueType) {
+ this.id = id;
this.key = key;
this.valueType = valueType;
}
+ public int id() {
+ return id;
+ }
+
public String key() {
return key;
}
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 2703e39de3e..f7280858258 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("ncloc", "INT"));
+ ref.metrics().add(new Metric(1, "ncloc", "INT"));
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:[{key:ncloc,valueType:INT}],"
+ "{timestamp:10,metrics:[{id:1,key:ncloc,valueType:INT}],"
+ "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}}}",
@@ -53,13 +53,14 @@ public class ProjectReferentialsTest {
@Test
public void testFromJson() throws JSONException {
- ProjectReferentials ref = ProjectReferentials.fromJson(new StringReader("{timestamp:1,metrics:[{key:ncloc,valueType:DATA}],"
+ ProjectReferentials ref = ProjectReferentials.fromJson(new StringReader("{timestamp:1,metrics:[{id:1,key:ncloc,valueType:DATA}],"
+ "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}}}"));
assertThat(ref.timestamp()).isEqualTo(1);
Metric metric = ref.metrics().iterator().next();
+ assertThat(metric.id()).isEqualTo(1);
assertThat(metric.key()).isEqualTo("ncloc");
assertThat(metric.valueType()).isEqualTo("DATA");
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 8aa68596d07..fcd22b383ef 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
@@ -230,6 +230,8 @@ public class AnalyzerMediumTester {
private static class FakeProjectReferentialsLoader implements ProjectReferentialsLoader {
+ private int metricId = 1;
+
private ProjectReferentials ref = new ProjectReferentials();
@Override
@@ -243,7 +245,8 @@ public class AnalyzerMediumTester {
}
public FakeProjectReferentialsLoader add(Metric metric) {
- ref.metrics().add(new org.sonar.batch.protocol.input.Metric(metric.key(), metric.getType().name()));
+ ref.metrics().add(new org.sonar.batch.protocol.input.Metric(metricId, metric.key(), metric.getType().name()));
+ 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 d4f15f1fa3f..31fe1ff4ced 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.getKey(), m.getType().name()));
+ ref.metrics().add(new org.sonar.batch.protocol.input.Metric(m.getId(), m.getKey(), m.getType().name()));
}
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 c2a8a7e6399..00d8403a473 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
@@ -33,16 +33,18 @@ import java.util.Map;
public final class DeprecatedMetricFinder implements MetricFinder {
private Map<String, Metric> metricsByKey = Maps.newLinkedHashMap();
+ private Map<Integer, Metric> metricsById = Maps.newLinkedHashMap();
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());
+ metricsByKey.put(metric.key(), new org.sonar.api.measures.Metric.Builder(metric.key(), metric.key(), ValueType.valueOf(metric.valueType())).create().setId(metric.id()));
+ metricsById.put(metric.id(), new org.sonar.api.measures.Metric.Builder(metric.key(), metric.key(), ValueType.valueOf(metric.valueType())).create().setId(metric.id()));
}
}
@Override
public Metric findById(int metricId) {
- throw new UnsupportedOperationException("Metric id is not available on batch side");
+ return metricsById.get(metricId);
}
@Override