]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5417 Add settings to batch protocol
authorJulien HENRY <julien.henry@sonarsource.com>
Fri, 18 Jul 2014 14:27:00 +0000 (16:27 +0200)
committerJulien HENRY <julien.henry@sonarsource.com>
Fri, 18 Jul 2014 14:28:06 +0000 (16:28 +0200)
sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/ProjectReferentials.java
sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/ProjectReferentialsTest.java

index c813b6c3f60e9fb67e29bfaf5cd8bb87fff53e4d..7a4231802e386031a65159f4429abcd1c5a6c3e8 100644 (file)
@@ -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;
index cb5bc33d23e01cf2227db1f599057df059edff9c..2703e39de3efddbf48a346be82cf8708df51c9d6 100644 (file)
@@ -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");
   }
 }