aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch-protocol
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2014-07-17 15:08:04 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2014-07-17 16:27:11 +0200
commit51cc491410147364a9c81e870d40880189f62fd9 (patch)
treed652d1b1aa72e80153ef30874ba01aaf31d3ace4 /sonar-batch-protocol
parente5531f07ac51ace0dc6d957c9960fcec37c28783 (diff)
downloadsonarqube-51cc491410147364a9c81e870d40880189f62fd9.tar.gz
sonarqube-51cc491410147364a9c81e870d40880189f62fd9.zip
SONAR-5417 Initial version of batch protocol + refactoring of settings
Diffstat (limited to 'sonar-batch-protocol')
-rw-r--r--sonar-batch-protocol/pom.xml42
-rw-r--r--sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/Language.java42
-rw-r--r--sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/ProjectReferentials.java64
-rw-r--r--sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/QProfiles.java33
-rw-r--r--sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/ProjectReferentialsTest.java49
5 files changed, 230 insertions, 0 deletions
diff --git a/sonar-batch-protocol/pom.xml b/sonar-batch-protocol/pom.xml
new file mode 100644
index 00000000000..b57fa36fb4f
--- /dev/null
+++ b/sonar-batch-protocol/pom.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.codehaus.sonar</groupId>
+ <artifactId>sonar</artifactId>
+ <version>4.5-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>sonar-batch-protocol</artifactId>
+ <name>SonarQube :: Batch :: Protocol</name>
+
+ <description>Classes used for communication between batch and server</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>com.esotericsoftware.kryo</groupId>
+ <artifactId>kryo</artifactId>
+ <version>2.24.0</version>
+ </dependency>
+ <dependency>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
+ </dependency>
+
+ <!-- unit tests -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.easytesting</groupId>
+ <artifactId>fest-assert</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.skyscreamer</groupId>
+ <artifactId>jsonassert</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/Language.java b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/Language.java
new file mode 100644
index 00000000000..8e1bd467226
--- /dev/null
+++ b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/Language.java
@@ -0,0 +1,42 @@
+/*
+ * 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;
+
+public class Language {
+
+ private String key;
+
+ private String name;
+
+ private String[] suffixes;
+
+ public String key() {
+ return key;
+ }
+
+ public String name() {
+ return name;
+ }
+
+ public String[] suffixes() {
+ return suffixes;
+ }
+
+}
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
new file mode 100644
index 00000000000..5e672051a10
--- /dev/null
+++ b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/ProjectReferentials.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;
+
+public class ProjectReferentials {
+
+ private long timestamp;
+ private Collection<Language> languages = new ArrayList<Language>();
+ private Map<String, Map<String, String>> projectSettings = new HashMap<String, Map<String, String>>();
+
+ public Map<String, String> projectSettings(String projectOrSubProjectKey) {
+ return projectSettings.get(projectOrSubProjectKey);
+ }
+
+ public void setProjectSettings(String projectOrSubProjectKey, Map<String, String> projectSettings) {
+ this.projectSettings.put(projectOrSubProjectKey, projectSettings);
+ }
+
+ public Collection<Language> languages() {
+ return languages;
+ }
+
+ public long timestamp() {
+ return timestamp;
+ }
+
+ public void setTimestamp(long timestamp) {
+ this.timestamp = timestamp;
+ }
+
+ public String toJson() {
+ return new Gson().toJson(this);
+ }
+
+ public static ProjectReferentials fromJson(Reader input) {
+ return new Gson().fromJson(input, ProjectReferentials.class);
+ }
+
+}
diff --git a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/QProfiles.java b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/QProfiles.java
new file mode 100644
index 00000000000..66f4edf9e0a
--- /dev/null
+++ b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/QProfiles.java
@@ -0,0 +1,33 @@
+/*
+ * 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 java.util.Map;
+
+public class QProfiles {
+
+ public static class QProfile {
+
+ private String key, name, language;
+ }
+
+ private Map<String, QProfile> byLanguage;
+
+}
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
new file mode 100644
index 00000000000..037517958b4
--- /dev/null
+++ b/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/ProjectReferentialsTest.java
@@ -0,0 +1,49 @@
+/*
+ * 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.json.JSONException;
+import org.junit.Test;
+import org.skyscreamer.jsonassert.JSONAssert;
+
+import java.io.StringReader;
+import java.util.HashMap;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class ProjectReferentialsTest {
+
+ @Test
+ public void testToJson() throws JSONException {
+ ProjectReferentials ref = new ProjectReferentials();
+ HashMap<String, String> projectSettings = new HashMap<String, String>();
+ projectSettings.put("sonar.foo", "bar");
+ ref.setProjectSettings("foo", projectSettings);
+
+ JSONAssert.assertEquals("{languages: [], projectSettings: {foo: {'sonar.foo': 'bar'}}, timestamp: 0}", ref.toJson(), true);
+ }
+
+ @Test
+ public void testFromJson() throws JSONException {
+ ProjectReferentials ref = ProjectReferentials.fromJson(new StringReader("{languages: [], projectSettings: {foo: {'sonar.foo': 'bar'}}, timestamp: 1}"));
+
+ assertThat(ref.timestamp()).isEqualTo(1);
+ }
+}