From 839e1016b530ad3b817531528582d1da5ac49d2b Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Fri, 18 Jul 2014 16:27:00 +0200 Subject: SONAR-5417 Add settings to batch protocol --- .../batch/protocol/input/ProjectReferentials.java | 14 +++++++++++++ .../protocol/input/ProjectReferentialsTest.java | 24 +++++++++++++++------- 2 files changed, 31 insertions(+), 7 deletions(-) (limited to 'sonar-batch-protocol') diff --git a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/ProjectReferentials.java b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/ProjectReferentials.java index c813b6c3f60..7a4231802e3 100644 --- a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/ProjectReferentials.java +++ b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/ProjectReferentials.java @@ -27,12 +27,26 @@ import java.util.Collection; import java.util.HashMap; import java.util.Map; +/** + * Container for all data going from server to batch. + * This is not an API since server and batch always share the same version. + */ public class ProjectReferentials { private long timestamp; private Collection metrics = new ArrayList(); private Map qprofilesByLanguage = new HashMap(); private Collection activeRules = new ArrayList(); + private Map> settingsByModule = new HashMap>(); + + public Map settings(String projectKey) { + return settingsByModule.get(projectKey); + } + + public ProjectReferentials addSettings(String projectKey, Map settings) { + settingsByModule.put(projectKey, settings); + return this; + } public Collection metrics() { return metrics; 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 cb5bc33d23e..2703e39de3e 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 @@ -25,6 +25,7 @@ import org.skyscreamer.jsonassert.JSONAssert; import java.io.StringReader; import java.text.SimpleDateFormat; +import java.util.HashMap; import static org.fest.assertions.Assertions.assertThat; @@ -35,25 +36,34 @@ public class ProjectReferentialsTest { ProjectReferentials ref = new ProjectReferentials(); ref.metrics().add(new Metric("ncloc", "INT")); ref.addQProfile(new QProfile("squid-java", "Java", "java", new SimpleDateFormat("dd/MM/yyyy").parse("14/03/1984"))); + ref.addSettings("foo", new HashMap()); + ref.settings("foo").put("prop", "value"); + ref.addActiveRule(new ActiveRule("repo", "rule", "MAJOR", "rule", "java")); + ref.setTimestamp(10); System.out.println(ref.toJson()); JSONAssert .assertEquals( - "{timestamp:0,metrics:[{key:ncloc,valueType:INT}]," - + "qprofilesByLanguage:{java:{key:\"squid-java\"," - + "name:Java," - + "language:java,rulesUpdatedAt:\"Mar 14, 1984 12:00:00 AM\"}}," - + "activeRules:[]}", + "{timestamp:10,metrics:[{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}}}", ref.toJson(), true); } @Test public void testFromJson() throws JSONException { - ProjectReferentials ref = ProjectReferentials.fromJson(new StringReader("{timestamp:1,metrics:[{key:ncloc,valueType:INT}]}")); + ProjectReferentials ref = ProjectReferentials.fromJson(new StringReader("{timestamp:1,metrics:[{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.key()).isEqualTo("ncloc"); - assertThat(metric.valueType()).isEqualTo("INT"); + assertThat(metric.valueType()).isEqualTo("DATA"); + + assertThat(ref.activeRules().iterator().next().ruleKey()).isEqualTo("rule"); + assertThat(ref.qProfiles().iterator().next().name()).isEqualTo("Java"); } } -- cgit v1.2.3