aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch-protocol/src
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2014-09-23 10:51:34 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2014-10-02 17:52:23 +0200
commit043c278c2844bd09ce9bd5add89d67eb7311a21f (patch)
treed519ff02c813daa9f96df73e89b2bc94712d4ccc /sonar-batch-protocol/src
parent833e747cee8e1927972a1d30bd1fd9d16d9e55ba (diff)
downloadsonarqube-043c278c2844bd09ce9bd5add89d67eb7311a21f.tar.gz
sonarqube-043c278c2844bd09ce9bd5add89d67eb7311a21f.zip
SONAR-5644, SONAR-5473 Create new SCM extension point and fetch SCM data using WS
Diffstat (limited to 'sonar-batch-protocol/src')
-rw-r--r--sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/FileData.java59
-rw-r--r--sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/ProjectReferentials.java12
-rw-r--r--sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/ProjectReferentialsTest.java19
3 files changed, 85 insertions, 5 deletions
diff --git a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/FileData.java b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/FileData.java
new file mode 100644
index 00000000000..fc7e7beca02
--- /dev/null
+++ b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/FileData.java
@@ -0,0 +1,59 @@
+/*
+ * 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 javax.annotation.Nullable;
+
+public class FileData {
+
+ private final String hash;
+ private final String scmLastCommitDatetimesByLine;
+ private final String scmRevisionsByLine;
+ private final String scmAuthorsByLine;
+
+ public FileData(@Nullable String hash, @Nullable String scmLastCommitDatetimesByLine, @Nullable String scmRevisionsByLine, @Nullable String scmAuthorsByLine) {
+ this.hash = hash;
+ this.scmLastCommitDatetimesByLine = scmLastCommitDatetimesByLine;
+ this.scmRevisionsByLine = scmRevisionsByLine;
+ this.scmAuthorsByLine = scmAuthorsByLine;
+ }
+
+ @CheckForNull
+ public String hash() {
+ return hash;
+ }
+
+ @CheckForNull
+ public String scmLastCommitDatetimesByLine() {
+ return scmLastCommitDatetimesByLine;
+ }
+
+ @CheckForNull
+ public String scmRevisionsByLine() {
+ return scmRevisionsByLine;
+ }
+
+ @CheckForNull
+ public String scmAuthorsByLine() {
+ return scmAuthorsByLine;
+ }
+
+}
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 6a8d5c8691e..5e2bfafd59d 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
@@ -21,6 +21,8 @@ package org.sonar.batch.protocol.input;
import com.google.gson.Gson;
+import javax.annotation.CheckForNull;
+
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -37,6 +39,7 @@ public class ProjectReferentials {
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>>();
+ private Map<String, FileData> fileDataPerPath = new HashMap<String, FileData>();
public Map<String, String> settings(String projectKey) {
return settingsByModule.containsKey(projectKey) ? settingsByModule.get(projectKey) : Collections.<String, String>emptyMap();
@@ -70,6 +73,15 @@ public class ProjectReferentials {
return this;
}
+ public Map<String, FileData> fileDataPerPath() {
+ return fileDataPerPath;
+ }
+
+ @CheckForNull
+ public FileData fileDataPerPath(String path) {
+ return fileDataPerPath.get(path);
+ }
+
public long timestamp() {
return timestamp;
}
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 9196a831ec9..ed98c51e46b 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
@@ -49,6 +49,7 @@ public class ProjectReferentialsTest {
activeRule.addParam("param1", "value1");
ref.addActiveRule(activeRule);
ref.setTimestamp(10);
+ ref.fileDataPerPath().put("src/main/java/Foo.java", new FileData("xyz", "1=12345,2=3456", "1=345,2=345", "1=henryju,2=gaudin"));
System.out.println(ref.toJson());
JSONAssert
@@ -56,16 +57,19 @@ public class ProjectReferentialsTest {
"{timestamp:10,"
+ "qprofilesByLanguage:{java:{key:\"squid-java\",name:Java,language:java,rulesUpdatedAt:\"Mar 14, 1984 12:00:00 AM\"}},"
+ "activeRules:[{repositoryKey:repo,ruleKey:rule,name:Rule,severity:MAJOR,internalKey:rule,language:java,params:{param1:value1}}],"
- + "settingsByModule:{foo:{prop1:value1,prop2:value2,prop:value}}}",
+ + "settingsByModule:{foo:{prop1:value1,prop2:value2,prop:value}},"
+ + "fileDataPerPath:{\"src/main/java/Foo.java\":{hash:xyz,scmLastCommitDatetimesByLine:\"1\u003d12345,2\u003d3456\",scmRevisionsByLine:\"1\u003d345,2\u003d345\",scmAuthorsByLine:\"1\u003dhenryju,2\u003dgaudin\"}}}",
ref.toJson(), true);
}
@Test
public void testFromJson() throws JSONException, ParseException {
- ProjectReferentials ref = ProjectReferentials.fromJson("{timestamp:1,"
- + "qprofilesByLanguage:{java:{key:\"squid-java\",name:Java,language:java,rulesUpdatedAt:\"Mar 14, 1984 12:00:00 AM\"}},"
- + "activeRules:[{repositoryKey:repo,ruleKey:rule,name:Rule,severity:MAJOR,internalKey:rule1,language:java,params:{param1:value1}}],"
- + "settingsByModule:{foo:{prop:value}}}");
+ ProjectReferentials ref = ProjectReferentials
+ .fromJson("{timestamp:1,"
+ + "qprofilesByLanguage:{java:{key:\"squid-java\",name:Java,language:java,rulesUpdatedAt:\"Mar 14, 1984 12:00:00 AM\"}},"
+ + "activeRules:[{repositoryKey:repo,ruleKey:rule,name:Rule,severity:MAJOR,internalKey:rule1,language:java,params:{param1:value1}}],"
+ + "settingsByModule:{foo:{prop:value}},"
+ + "fileDataPerPath:{\"src/main/java/Foo.java\":{hash:xyz,scmLastCommitDatetimesByLine:\"1\u003d12345,2\u003d3456\",scmRevisionsByLine:\"1\u003d345,2\u003d345\",scmAuthorsByLine:\"1\u003dhenryju,2\u003dgaudin\"}}}");
assertThat(ref.timestamp()).isEqualTo(1);
@@ -83,5 +87,10 @@ public class ProjectReferentialsTest {
assertThat(qProfile.name()).isEqualTo("Java");
assertThat(qProfile.rulesUpdatedAt()).isEqualTo(new SimpleDateFormat("dd/MM/yyyy").parse("14/03/1984"));
assertThat(ref.settings("foo")).includes(MapAssert.entry("prop", "value"));
+
+ assertThat(ref.fileDataPerPath("src/main/java/Foo.java").hash()).isEqualTo("xyz");
+ assertThat(ref.fileDataPerPath("src/main/java/Foo.java").scmAuthorsByLine()).isEqualTo("1=henryju,2=gaudin");
+ assertThat(ref.fileDataPerPath("src/main/java/Foo.java").scmLastCommitDatetimesByLine()).isEqualTo("1=12345,2=3456");
+ assertThat(ref.fileDataPerPath("src/main/java/Foo.java").scmRevisionsByLine()).isEqualTo("1=345,2=345");
}
}