aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch-protocol
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2014-07-18 12:18:39 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2014-07-18 15:43:39 +0200
commitc3174fada2ab193d03661209bee3291772b8f347 (patch)
tree2c421a541d108f24bbab0c861c6ab9aaedfa7bdc /sonar-batch-protocol
parent274e9cefeb16fab1d5e35088289338f12993b208 (diff)
downloadsonarqube-c3174fada2ab193d03661209bee3291772b8f347.tar.gz
sonarqube-c3174fada2ab193d03661209bee3291772b8f347.zip
SONAR-5417 Get active rules using batch protocol
Diffstat (limited to 'sonar-batch-protocol')
-rw-r--r--sonar-batch-protocol/pom.xml4
-rw-r--r--sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/ActiveRule.java73
-rw-r--r--sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/ProjectReferentials.java27
-rw-r--r--sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/QProfile.java (renamed from sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/Language.java)39
-rw-r--r--sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/package-info.java (renamed from sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/QProfiles.java)13
-rw-r--r--sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/ProjectReferentialsTest.java15
6 files changed, 146 insertions, 25 deletions
diff --git a/sonar-batch-protocol/pom.xml b/sonar-batch-protocol/pom.xml
index b57fa36fb4f..e596ef0ab90 100644
--- a/sonar-batch-protocol/pom.xml
+++ b/sonar-batch-protocol/pom.xml
@@ -22,6 +22,10 @@
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
+ <dependency>
+ <groupId>com.google.code.findbugs</groupId>
+ <artifactId>jsr305</artifactId>
+ </dependency>
<!-- unit tests -->
<dependency>
diff --git a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/ActiveRule.java b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/ActiveRule.java
new file mode 100644
index 00000000000..144a34b292b
--- /dev/null
+++ b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/ActiveRule.java
@@ -0,0 +1,73 @@
+/*
+ * 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 javax.annotation.CheckForNull;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class ActiveRule {
+ private final String repositoryKey, ruleKey;
+ private final String severity, internalKey, language;
+ private final Map<String, String> params = new HashMap<String, String>();
+
+ public ActiveRule(String repositoryKey, String ruleKey, String severity, String internalKey, String language) {
+ this.repositoryKey = repositoryKey;
+ this.ruleKey = ruleKey;
+ this.severity = severity;
+ this.internalKey = internalKey;
+ this.language = language;
+ }
+
+ public String repositoryKey() {
+ return repositoryKey;
+ }
+
+ public String ruleKey() {
+ return ruleKey;
+ }
+
+ public String severity() {
+ return severity;
+ }
+
+ public String language() {
+ return language;
+ }
+
+ @CheckForNull
+ public String param(String key) {
+ return params.get(key);
+ }
+
+ public ActiveRule addParam(String key, String value) {
+ params.put(key, value);
+ return this;
+ }
+
+ public Map<String, String> params() {
+ return params;
+ }
+
+ public String internalKey() {
+ return internalKey;
+ }
+}
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 bff1a434069..c813b6c3f60 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
@@ -24,21 +24,38 @@ 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 Collection<Metric> metrics = new ArrayList<Metric>();
-
- public Collection<Language> languages() {
- return languages;
- }
+ private Map<String, QProfile> qprofilesByLanguage = new HashMap<String, QProfile>();
+ private Collection<ActiveRule> activeRules = new ArrayList<ActiveRule>();
public Collection<Metric> metrics() {
return metrics;
}
+ public Collection<QProfile> qProfiles() {
+ return qprofilesByLanguage.values();
+ }
+
+ public ProjectReferentials addQProfile(QProfile qProfile) {
+ qprofilesByLanguage.put(qProfile.language(), qProfile);
+ return this;
+ }
+
+ public Collection<ActiveRule> activeRules() {
+ return activeRules;
+ }
+
+ public ProjectReferentials addActiveRule(ActiveRule activeRule) {
+ activeRules.add(activeRule);
+ return this;
+ }
+
public long timestamp() {
return timestamp;
}
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/QProfile.java
index 8e1bd467226..4c6b0191046 100644
--- 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/QProfile.java
@@ -19,13 +19,19 @@
*/
package org.sonar.batch.protocol.input;
-public class Language {
+import java.util.Date;
- private String key;
+public class QProfile {
- private String name;
+ private final String key, name, language;
+ private final Date rulesUpdatedAt;
- private String[] suffixes;
+ public QProfile(String key, String name, String language, Date rulesUpdatedAt) {
+ this.key = key;
+ this.name = name;
+ this.language = language;
+ this.rulesUpdatedAt = rulesUpdatedAt;
+ }
public String key() {
return key;
@@ -35,8 +41,29 @@ public class Language {
return name;
}
- public String[] suffixes() {
- return suffixes;
+ public String language() {
+ return language;
+ }
+
+ public Date rulesUpdatedAt() {
+ return rulesUpdatedAt;
}
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ QProfile qProfile = (QProfile) o;
+ return key.equals(qProfile.key);
+ }
+
+ @Override
+ public int hashCode() {
+ return key.hashCode();
+ }
}
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/package-info.java
index 66f4edf9e0a..a545fa5fdde 100644
--- 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/package-info.java
@@ -17,17 +17,8 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+@ParametersAreNonnullByDefault
package org.sonar.batch.protocol.input;
-import java.util.Map;
+import javax.annotation.ParametersAreNonnullByDefault;
-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
index e4d5142f10d..cb5bc33d23e 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
@@ -24,23 +24,32 @@ import org.junit.Test;
import org.skyscreamer.jsonassert.JSONAssert;
import java.io.StringReader;
+import java.text.SimpleDateFormat;
import static org.fest.assertions.Assertions.assertThat;
public class ProjectReferentialsTest {
@Test
- public void testToJson() throws JSONException {
+ public void testToJson() throws Exception {
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")));
System.out.println(ref.toJson());
- JSONAssert.assertEquals("{timestamp:0,languages:[],metrics:[{key:ncloc,valueType:INT}]}", ref.toJson(), true);
+ 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:[]}",
+ ref.toJson(), true);
}
@Test
public void testFromJson() throws JSONException {
- ProjectReferentials ref = ProjectReferentials.fromJson(new StringReader("{timestamp:1,languages:[],metrics:[{key:ncloc,valueType:INT}]}"));
+ ProjectReferentials ref = ProjectReferentials.fromJson(new StringReader("{timestamp:1,metrics:[{key:ncloc,valueType:INT}]}"));
assertThat(ref.timestamp()).isEqualTo(1);
Metric metric = ref.metrics().iterator().next();