diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2014-07-18 16:27:00 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2014-07-18 16:28:06 +0200 |
commit | 839e1016b530ad3b817531528582d1da5ac49d2b (patch) | |
tree | b85d03ad2233a002666cdf4e6a290bc4aa991606 | |
parent | da86cf4808159ae70677f20b3d2b16383e2045ac (diff) | |
download | sonarqube-839e1016b530ad3b817531528582d1da5ac49d2b.tar.gz sonarqube-839e1016b530ad3b817531528582d1da5ac49d2b.zip |
SONAR-5417 Add settings to batch protocol
2 files changed, 31 insertions, 7 deletions
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<Metric> metrics = new ArrayList<Metric>(); private Map<String, QProfile> qprofilesByLanguage = new HashMap<String, QProfile>(); private Collection<ActiveRule> activeRules = new ArrayList<ActiveRule>(); + private Map<String, Map<String, String>> settingsByModule = new HashMap<String, Map<String, String>>(); + + public Map<String, String> settings(String projectKey) { + return settingsByModule.get(projectKey); + } + + public ProjectReferentials addSettings(String projectKey, Map<String, String> settings) { + settingsByModule.put(projectKey, settings); + return this; + } public Collection<Metric> 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<String, String>()); + 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"); } } |