aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch-protocol
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2014-09-25 16:23:37 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2014-09-25 16:25:24 +0200
commitda96eeccbe28e91619d60b34ae91ad442de6ce08 (patch)
tree71ba7b694981fadcf92e4ec9ef8aaf43b3504c81 /sonar-batch-protocol
parenta4e76de07797ea2b9b809a0cc0b90286c90cd3cd (diff)
downloadsonarqube-da96eeccbe28e91619d60b34ae91ad442de6ce08.tar.gz
sonarqube-da96eeccbe28e91619d60b34ae91ad442de6ce08.zip
SONAR-5473 Fix fetching of remote SCM data
Diffstat (limited to 'sonar-batch-protocol')
-rw-r--r--sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/ProjectReferentials.java22
-rw-r--r--sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/ProjectReferentialsTest.java14
2 files changed, 23 insertions, 13 deletions
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 5e2bfafd59d..d967e933de4 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
@@ -39,7 +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>();
+ private Map<String, Map<String, FileData>> fileDataByModuleAndPath = new HashMap<String, Map<String, FileData>>();
public Map<String, String> settings(String projectKey) {
return settingsByModule.containsKey(projectKey) ? settingsByModule.get(projectKey) : Collections.<String, String>emptyMap();
@@ -49,9 +49,9 @@ public class ProjectReferentials {
Map<String, String> existingSettings = settingsByModule.get(projectKey);
if (existingSettings == null) {
existingSettings = new HashMap<String, String>();
+ settingsByModule.put(projectKey, existingSettings);
}
existingSettings.putAll(settings);
- settingsByModule.put(projectKey, existingSettings);
return this;
}
@@ -73,13 +73,23 @@ public class ProjectReferentials {
return this;
}
- public Map<String, FileData> fileDataPerPath() {
- return fileDataPerPath;
+ public Map<String, FileData> fileDataByPath(String projectKey) {
+ return fileDataByModuleAndPath.containsKey(projectKey) ? fileDataByModuleAndPath.get(projectKey) : Collections.<String, FileData>emptyMap();
+ }
+
+ public ProjectReferentials addFileData(String projectKey, String path, FileData fileData) {
+ Map<String, FileData> existingFileDataByPath = fileDataByModuleAndPath.get(projectKey);
+ if (existingFileDataByPath == null) {
+ existingFileDataByPath = new HashMap<String, FileData>();
+ fileDataByModuleAndPath.put(projectKey, existingFileDataByPath);
+ }
+ existingFileDataByPath.put(path, fileData);
+ return this;
}
@CheckForNull
- public FileData fileDataPerPath(String path) {
- return fileDataPerPath.get(path);
+ public FileData fileData(String projectKey, String path) {
+ return fileDataByPath(projectKey).get(path);
}
public long 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 ed98c51e46b..5e537a1f523 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,7 +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"));
+ ref.addFileData("foo", "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
@@ -58,7 +58,7 @@ public class ProjectReferentialsTest {
+ "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}},"
- + "fileDataPerPath:{\"src/main/java/Foo.java\":{hash:xyz,scmLastCommitDatetimesByLine:\"1\u003d12345,2\u003d3456\",scmRevisionsByLine:\"1\u003d345,2\u003d345\",scmAuthorsByLine:\"1\u003dhenryju,2\u003dgaudin\"}}}",
+ + "fileDataByModuleAndPath:{foo:{\"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);
}
@@ -69,7 +69,7 @@ public class ProjectReferentialsTest {
+ "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\"}}}");
+ + "fileDataByModuleAndPath:{foo:{\"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);
@@ -88,9 +88,9 @@ public class ProjectReferentialsTest {
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");
+ assertThat(ref.fileData("foo", "src/main/java/Foo.java").hash()).isEqualTo("xyz");
+ assertThat(ref.fileData("foo", "src/main/java/Foo.java").scmAuthorsByLine()).isEqualTo("1=henryju,2=gaudin");
+ assertThat(ref.fileData("foo", "src/main/java/Foo.java").scmLastCommitDatetimesByLine()).isEqualTo("1=12345,2=3456");
+ assertThat(ref.fileData("foo", "src/main/java/Foo.java").scmRevisionsByLine()).isEqualTo("1=345,2=345");
}
}