aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch-protocol/src
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2014-07-22 09:51:55 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2014-07-22 09:56:29 +0200
commitd34d7b471485298abc3c268b171882c73fbd778d (patch)
tree60e5e98ff34455ea7e3e8b9262dea8a95fea4853 /sonar-batch-protocol/src
parentd2a6cb9963b8c6dd89620a7c50fcdc5b5645ec75 (diff)
downloadsonarqube-d34d7b471485298abc3c268b171882c73fbd778d.tar.gz
sonarqube-d34d7b471485298abc3c268b171882c73fbd778d.zip
SONAR-5477 Load global referentials earlier
Diffstat (limited to 'sonar-batch-protocol/src')
-rw-r--r--sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/GlobalReferentials.java64
-rw-r--r--sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/ProjectReferentials.java7
-rw-r--r--sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/GlobalReferentialsTest.java65
-rw-r--r--sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/ProjectReferentialsTest.java11
4 files changed, 134 insertions, 13 deletions
diff --git a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/GlobalReferentials.java b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/GlobalReferentials.java
new file mode 100644
index 00000000000..a1ad9e31a5a
--- /dev/null
+++ b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/GlobalReferentials.java
@@ -0,0 +1,64 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.batch.protocol.input;
+
+import com.google.gson.Gson;
+
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Container for all global data going from server to batch.
+ * This is not an API since server and batch always share the same version.
+ */
+public class GlobalReferentials {
+
+ private long timestamp;
+ private Collection<Metric> metrics = new ArrayList<Metric>();
+ private Map<String, String> globalSettings = new HashMap<String, String>();
+
+ public Map<String, String> globalSettings() {
+ return globalSettings;
+ }
+
+ public Collection<Metric> metrics() {
+ return metrics;
+ }
+
+ public long timestamp() {
+ return timestamp;
+ }
+
+ public void setTimestamp(long timestamp) {
+ this.timestamp = timestamp;
+ }
+
+ public String toJson() {
+ return new Gson().toJson(this);
+ }
+
+ public static GlobalReferentials fromJson(Reader input) {
+ return new Gson().fromJson(input, GlobalReferentials.class);
+ }
+
+}
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 7a4231802e3..a386a0eeac7 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
@@ -28,13 +28,12 @@ import java.util.HashMap;
import java.util.Map;
/**
- * Container for all data going from server to batch.
+ * Container for all project 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>>();
@@ -48,10 +47,6 @@ public class ProjectReferentials {
return this;
}
- public Collection<Metric> metrics() {
- return metrics;
- }
-
public Collection<QProfile> qProfiles() {
return qprofilesByLanguage.values();
}
diff --git a/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/GlobalReferentialsTest.java b/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/GlobalReferentialsTest.java
new file mode 100644
index 00000000000..3afd7662fc0
--- /dev/null
+++ b/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/GlobalReferentialsTest.java
@@ -0,0 +1,65 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.batch.protocol.input;
+
+import org.fest.assertions.MapAssert;
+import org.json.JSONException;
+import org.junit.Test;
+import org.skyscreamer.jsonassert.JSONAssert;
+
+import java.io.StringReader;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class GlobalReferentialsTest {
+
+ @Test
+ public void testToJson() throws Exception {
+ GlobalReferentials ref = new GlobalReferentials();
+ ref.metrics().add(new Metric(1, "ncloc", "INT", "Description", -1, "NCLOC", true, false, 2.0, 1.0, true));
+ ref.globalSettings().put("prop", "value");
+ ref.setTimestamp(10);
+
+ System.out.println(ref.toJson());
+ JSONAssert
+ .assertEquals(
+ "{timestamp:10,"
+ + "metrics:[{id:1,key:ncloc,valueType:INT,description:Description,direction:-1,name:NCLOC,qualitative:true,userManaged:false,worstValue:2.0,bestValue:1.0,optimizedBestValue:true}],"
+ + "globalSettings:{prop:value}}",
+ ref.toJson(), true);
+ }
+
+ @Test
+ public void testFromJson() throws JSONException {
+ GlobalReferentials ref = GlobalReferentials
+ .fromJson(new StringReader(
+ "{timestamp:1,"
+ + "metrics:[{id:1,key:ncloc,valueType:DATA,description:Description,direction:-1,name:NCLOC,qualitative:true,userManaged:false,worstValue:2.0,bestValue:1.0,optimizedBestValue:true}],"
+ + "globalSettings:{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");
+
+ assertThat(ref.globalSettings()).includes(MapAssert.entry("prop", "value"));
+ }
+}
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 deeca583cb5..831f5e12cef 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
@@ -19,6 +19,7 @@
*/
package org.sonar.batch.protocol.input;
+import org.fest.assertions.MapAssert;
import org.json.JSONException;
import org.junit.Test;
import org.skyscreamer.jsonassert.JSONAssert;
@@ -34,7 +35,6 @@ public class ProjectReferentialsTest {
@Test
public void testToJson() throws Exception {
ProjectReferentials ref = new ProjectReferentials();
- ref.metrics().add(new Metric(1, "ncloc", "INT", "Description", -1, "NCLOC", true, false, 2.0, 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,description:Description,direction:-1,name:NCLOC,qualitative:true,userManaged:false,worstValue:2.0,bestValue:1.0,optimizedBestValue:true}],"
+ "{timestamp:10,"
+ "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,18 +53,15 @@ public class ProjectReferentialsTest {
@Test
public void testFromJson() throws JSONException {
- ProjectReferentials ref = ProjectReferentials.fromJson(new StringReader("{timestamp:1,metrics:[{id:1,key:ncloc,valueType:DATA}],"
+ ProjectReferentials ref = ProjectReferentials.fromJson(new StringReader("{timestamp:1,"
+ "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");
assertThat(ref.activeRules().iterator().next().ruleKey()).isEqualTo("rule");
assertThat(ref.qProfiles().iterator().next().name()).isEqualTo("Java");
+ assertThat(ref.settings("foo")).includes(MapAssert.entry("prop", "value"));
}
}