diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2014-09-26 10:22:10 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2014-09-26 10:22:10 +0200 |
commit | 4234c8d5b402e751dfd0c17732cfc843ba807fe0 (patch) | |
tree | b4fd81647c26834baae2d8f2457b85472d89602f | |
parent | 966878dbed44b73db1e5951056f9ee2bc617d652 (diff) | |
download | sonarqube-4234c8d5b402e751dfd0c17732cfc843ba807fe0.tar.gz sonarqube-4234c8d5b402e751dfd0c17732cfc843ba807fe0.zip |
Revert "SONAR-5473 Fix fetching of remote SCM data"
This reverts commit da96eeccbe28e91619d60b34ae91ad442de6ce08.
30 files changed, 118 insertions, 184 deletions
diff --git a/plugins/sonar-git-plugin/src/main/java/org/sonar/plugins/scm/git/GitBlameCommand.java b/plugins/sonar-git-plugin/src/main/java/org/sonar/plugins/scm/git/GitBlameCommand.java index a8c56b7ab9c..0d8b447cdd8 100644 --- a/plugins/sonar-git-plugin/src/main/java/org/sonar/plugins/scm/git/GitBlameCommand.java +++ b/plugins/sonar-git-plugin/src/main/java/org/sonar/plugins/scm/git/GitBlameCommand.java @@ -21,8 +21,6 @@ package org.sonar.plugins.scm.git; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.sonar.api.BatchComponent; -import org.sonar.api.batch.InstantiationStrategy; import org.sonar.api.batch.fs.FileSystem; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.scm.BlameCommand; @@ -32,8 +30,7 @@ import org.sonar.api.utils.command.StreamConsumer; import java.io.File; -@InstantiationStrategy(InstantiationStrategy.PER_BATCH) -public class GitBlameCommand implements BlameCommand, BatchComponent { +public class GitBlameCommand implements BlameCommand { private static final Logger LOG = LoggerFactory.getLogger(GitBlameCommand.class); private final CommandExecutor commandExecutor; diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/scm/XooBlameCommand.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/scm/XooBlameCommand.java index 4e743613788..7d492cc315b 100644 --- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/scm/XooBlameCommand.java +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/scm/XooBlameCommand.java @@ -23,8 +23,6 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Charsets; import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; -import org.sonar.api.BatchComponent; -import org.sonar.api.batch.InstantiationStrategy; import org.sonar.api.batch.fs.FileSystem; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.scm.BlameCommand; @@ -37,8 +35,7 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; -@InstantiationStrategy(InstantiationStrategy.PER_BATCH) -public class XooBlameCommand implements BlameCommand, BatchComponent { +public class XooBlameCommand implements BlameCommand { private static final String SCM_EXTENSION = ".scm"; @@ -587,12 +587,6 @@ <scope>test</scope> </dependency> <dependency> - <groupId>org.codehaus.sonar.plugins</groupId> - <artifactId>sonar-git-plugin</artifactId> - <version>${project.version}</version> - <type>sonar-plugin</type> - </dependency> - <dependency> <groupId>org.codehaus.sonar</groupId> <artifactId>sonar-squid</artifactId> <version>4.1</version> diff --git a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/not_returned_secured_settings_with_only_preview_permission.json b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/not_returned_secured_settings_with_only_preview_permission.json index cf8408bc74c..8037eff7213 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/not_returned_secured_settings_with_only_preview_permission.json +++ b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/not_returned_secured_settings_with_only_preview_permission.json @@ -13,6 +13,5 @@ "org.codehaus.sonar:sonar": { "sonar.jira.project.key": "SONAR" } - }, - "fileDataPerPath": {} + } } diff --git a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_active_rules.json b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_active_rules.json index 7662ed047f6..f7f8faf299b 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_active_rules.json +++ b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_active_rules.json @@ -21,6 +21,5 @@ } } ], - "settingsByModule": {}, - "fileDataPerPath": {} + "settingsByModule": {} } diff --git a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_project_settings.json b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_project_settings.json index 9d2a070ffc5..4b562891c28 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_project_settings.json +++ b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_project_settings.json @@ -14,6 +14,5 @@ "sonar.jira.project.key": "SONAR", "sonar.jira.login.secured": "john" } - }, - "fileDataPerPath": {} + } } diff --git a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_project_with_module_settings.json b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_project_with_module_settings.json index 705186dc248..d1b864aa7c4 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_project_with_module_settings.json +++ b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_project_with_module_settings.json @@ -19,6 +19,5 @@ "sonar.jira.login.secured": "john", "sonar.coverage.exclusions": "**/*.java" } - }, - "fileDataPerPath": {} + } } diff --git a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_project_with_module_settings_inherited_from_project.json b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_project_with_module_settings_inherited_from_project.json index ad8a65322b7..deaea79e1a3 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_project_with_module_settings_inherited_from_project.json +++ b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_project_with_module_settings_inherited_from_project.json @@ -18,6 +18,5 @@ "sonar.jira.project.key": "SONAR", "sonar.jira.login.secured": "john" } - }, - "fileDataPerPath": {} + } } diff --git a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_project_with_module_with_sub_module.json b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_project_with_module_with_sub_module.json index 12b74d0cb7c..ef8ef13fa12 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_project_with_module_with_sub_module.json +++ b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_project_with_module_with_sub_module.json @@ -24,6 +24,5 @@ "sonar.jira.login.secured": "john", "sonar.coverage.exclusions": "**/*.java" } - }, - "fileDataPerPath": {} + } } diff --git a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_project_with_two_modules.json b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_project_with_two_modules.json index c0816864ed6..302176c60f1 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_project_with_two_modules.json +++ b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_project_with_two_modules.json @@ -23,6 +23,5 @@ "sonar.jira.project.key": "SONAR-APPLICATION", "sonar.jira.login.secured": "john" } - }, - "fileDataPerPath": {} + } } diff --git a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_provisioned_project_profile.json b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_provisioned_project_profile.json index 2031cd6b1f0..282fafa5b33 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_provisioned_project_profile.json +++ b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_provisioned_project_profile.json @@ -9,6 +9,5 @@ } }, "activeRules": [], - "settingsByModule": {}, - "fileDataPerPath": {} + "settingsByModule": {} } diff --git a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_quality_profile_from_default_profile.json b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_quality_profile_from_default_profile.json index e9c873bb519..a1bb33bb01f 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_quality_profile_from_default_profile.json +++ b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_quality_profile_from_default_profile.json @@ -9,6 +9,5 @@ } }, "activeRules": [], - "settingsByModule": {}, - "fileDataPerPath": {} + "settingsByModule": {} } diff --git a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_quality_profile_from_given_profile_name.json b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_quality_profile_from_given_profile_name.json index e9c873bb519..a1bb33bb01f 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_quality_profile_from_given_profile_name.json +++ b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_quality_profile_from_given_profile_name.json @@ -9,6 +9,5 @@ } }, "activeRules": [], - "settingsByModule": {}, - "fileDataPerPath": {} + "settingsByModule": {} } diff --git a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_quality_profiles.json b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_quality_profiles.json index 2031cd6b1f0..282fafa5b33 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_quality_profiles.json +++ b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_quality_profiles.json @@ -9,6 +9,5 @@ } }, "activeRules": [], - "settingsByModule": {}, - "fileDataPerPath": {} + "settingsByModule": {} } diff --git a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_quality_profiles_even_when_project_does_not_exists.json b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_quality_profiles_even_when_project_does_not_exists.json index e9c873bb519..a1bb33bb01f 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_quality_profiles_even_when_project_does_not_exists.json +++ b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_quality_profiles_even_when_project_does_not_exists.json @@ -9,6 +9,5 @@ } }, "activeRules": [], - "settingsByModule": {}, - "fileDataPerPath": {} + "settingsByModule": {} } diff --git a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_sub_module_settings.json b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_sub_module_settings.json index 87515800786..f2a89a9895a 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_sub_module_settings.json +++ b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_sub_module_settings.json @@ -15,6 +15,5 @@ "sonar.jira.login.secured": "john", "sonar.coverage.exclusions": "**/*.java" } - }, - "fileDataPerPath": {} + } } diff --git a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_sub_module_settings_including_settings_from_parent_modules.json b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_sub_module_settings_including_settings_from_parent_modules.json index 87515800786..f2a89a9895a 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_sub_module_settings_including_settings_from_parent_modules.json +++ b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_sub_module_settings_including_settings_from_parent_modules.json @@ -15,6 +15,5 @@ "sonar.jira.login.secured": "john", "sonar.coverage.exclusions": "**/*.java" } - }, - "fileDataPerPath": {} + } } diff --git a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_sub_module_settings_inherited_from_project.json b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_sub_module_settings_inherited_from_project.json index 87515800786..f2a89a9895a 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_sub_module_settings_inherited_from_project.json +++ b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_sub_module_settings_inherited_from_project.json @@ -15,6 +15,5 @@ "sonar.jira.login.secured": "john", "sonar.coverage.exclusions": "**/*.java" } - }, - "fileDataPerPath": {} + } } diff --git a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_sub_module_settings_inherited_from_project_and_module.json b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_sub_module_settings_inherited_from_project_and_module.json index 5accba5c7e7..c99fd8e67db 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_sub_module_settings_inherited_from_project_and_module.json +++ b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_sub_module_settings_inherited_from_project_and_module.json @@ -15,6 +15,5 @@ "sonar.jira.login.secured": "john", "sonar.coverage.exclusions": "**/*.java" } - }, - "fileDataPerPath": {} + } } diff --git a/sonar-application/pom.xml b/sonar-application/pom.xml index b054c0bd128..914c60ebf5a 100644 --- a/sonar-application/pom.xml +++ b/sonar-application/pom.xml @@ -132,12 +132,6 @@ <scope>provided</scope> </dependency> <dependency> - <groupId>org.codehaus.sonar.plugins</groupId> - <artifactId>sonar-git-plugin</artifactId> - <type>sonar-plugin</type> - <scope>provided</scope> - </dependency> - <dependency> <groupId>org.sonatype.jsw-binaries</groupId> <artifactId>jsw-binaries</artifactId> <version>3.2.3.6</version> 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 d967e933de4..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 @@ -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, Map<String, FileData>> fileDataByModuleAndPath = new HashMap<String, Map<String, FileData>>(); + 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(); @@ -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,23 +73,13 @@ public class ProjectReferentials { return this; } - 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; + public Map<String, FileData> fileDataPerPath() { + return fileDataPerPath; } @CheckForNull - public FileData fileData(String projectKey, String path) { - return fileDataByPath(projectKey).get(path); + public FileData fileDataPerPath(String path) { + return fileDataPerPath.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 5e537a1f523..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,7 +49,7 @@ public class ProjectReferentialsTest { activeRule.addParam("param1", "value1"); ref.addActiveRule(activeRule); ref.setTimestamp(10); - ref.addFileData("foo", "src/main/java/Foo.java", new FileData("xyz", "1=12345,2=3456", "1=345,2=345", "1=henryju,2=gaudin")); + 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 @@ -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}}," - + "fileDataByModuleAndPath:{foo:{\"src/main/java/Foo.java\":{hash:xyz,scmLastCommitDatetimesByLine:\"1\u003d12345,2\u003d3456\",scmRevisionsByLine:\"1\u003d345,2\u003d345\",scmAuthorsByLine:\"1\u003dhenryju,2\u003dgaudin\"}}}}", + + "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); } @@ -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}}," - + "fileDataByModuleAndPath:{foo:{\"src/main/java/Foo.java\":{hash:xyz,scmLastCommitDatetimesByLine:\"1\u003d12345,2\u003d3456\",scmRevisionsByLine:\"1\u003d345,2\u003d345\",scmAuthorsByLine:\"1\u003dhenryju,2\u003dgaudin\"}}}}"); + + "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); @@ -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.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"); + 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"); } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/DefaultTimeMachine.java b/sonar-batch/src/main/java/org/sonar/batch/DefaultTimeMachine.java index 565417efad0..40df91b4ab4 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/DefaultTimeMachine.java +++ b/sonar-batch/src/main/java/org/sonar/batch/DefaultTimeMachine.java @@ -25,6 +25,7 @@ import org.sonar.api.batch.TimeMachine; import org.sonar.api.batch.TimeMachineQuery; import org.sonar.api.database.DatabaseSession; import org.sonar.api.database.model.MeasureModel; +import org.sonar.api.database.model.ResourceModel; import org.sonar.api.database.model.Snapshot; import org.sonar.api.measures.Measure; import org.sonar.api.measures.Metric; @@ -38,6 +39,7 @@ import org.sonar.batch.index.DefaultIndex; import javax.annotation.Nullable; import javax.persistence.Query; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Date; @@ -148,6 +150,41 @@ public class DefaultTimeMachine implements TimeMachine { return jpaQuery.getResultList(); } + // Temporary implementation for SONAR-5473 + public List<MeasureModel> query(String resourceKey, Integer... metricIds) { + StringBuilder sb = new StringBuilder(); + Map<String, Object> params = Maps.newHashMap(); + + sb.append("SELECT m"); + sb.append(" FROM ") + .append(MeasureModel.class.getSimpleName()) + .append(" m, ") + .append(ResourceModel.class.getSimpleName()) + .append(" r, ") + .append(Snapshot.class.getSimpleName()) + .append(" s WHERE m.snapshotId=s.id AND s.resourceId=r.id AND r.kee=:kee AND s.status=:status AND s.qualifier<>:lib"); + params.put("kee", resourceKey); + params.put("status", Snapshot.STATUS_PROCESSED); + params.put("lib", Qualifiers.LIBRARY); + + sb.append(" AND m.characteristicId IS NULL"); + sb.append(" AND m.personId IS NULL"); + sb.append(" AND m.ruleId IS NULL AND m.rulePriority IS NULL"); + if (metricIds.length > 0) { + sb.append(" AND m.metricId IN (:metricIds) "); + params.put("metricIds", Arrays.asList(metricIds)); + } + sb.append(" AND s.last=true "); + sb.append(" ORDER BY s.createdAt "); + + Query jpaQuery = session.createQuery(sb.toString()); + + for (Map.Entry<String, Object> entry : params.entrySet()) { + jpaQuery.setParameter(entry.getKey(), entry.getValue()); + } + return jpaQuery.getResultList(); + } + public Map<Integer, Metric> getMetricsById(TimeMachineQuery query) { Collection<Metric> metrics = metricFinder.findAll(query.getMetricKeys()); Map<Integer, Metric> result = Maps.newHashMap(); diff --git a/sonar-batch/src/main/java/org/sonar/batch/referential/DefaultProjectReferentialsLoader.java b/sonar-batch/src/main/java/org/sonar/batch/referential/DefaultProjectReferentialsLoader.java index d3a85a912a9..98c46ef1172 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/referential/DefaultProjectReferentialsLoader.java +++ b/sonar-batch/src/main/java/org/sonar/batch/referential/DefaultProjectReferentialsLoader.java @@ -20,33 +20,22 @@ package org.sonar.batch.referential; import com.google.common.collect.ImmutableList; -import com.google.common.collect.Maps; -import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.batch.bootstrap.ProjectReactor; -import org.sonar.api.database.DatabaseSession; import org.sonar.api.database.model.MeasureModel; -import org.sonar.api.database.model.ResourceModel; -import org.sonar.api.database.model.Snapshot; import org.sonar.api.measures.CoreMetrics; import org.sonar.api.measures.Metric; -import org.sonar.api.resources.Qualifiers; -import org.sonar.api.utils.KeyValueFormat; +import org.sonar.api.measures.MetricFinder; +import org.sonar.batch.DefaultTimeMachine; import org.sonar.batch.bootstrap.AnalysisMode; import org.sonar.batch.bootstrap.ServerClient; import org.sonar.batch.bootstrap.TaskProperties; import org.sonar.batch.protocol.input.FileData; import org.sonar.batch.protocol.input.ProjectReferentials; import org.sonar.batch.rule.ModuleQProfiles; -import org.sonar.core.source.SnapshotDataTypes; -import org.sonar.core.source.db.SnapshotDataDao; -import org.sonar.core.source.db.SnapshotDataDto; - -import javax.persistence.Query; +import org.sonar.batch.scan.filesystem.PreviousFileHashLoader; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; -import java.util.Arrays; -import java.util.Collection; import java.util.List; import java.util.Map; @@ -61,15 +50,17 @@ public class DefaultProjectReferentialsLoader implements ProjectReferentialsLoad private final ServerClient serverClient; private final AnalysisMode analysisMode; - private final SnapshotDataDao dao; - private final DatabaseSession session; + private final PreviousFileHashLoader fileHashLoader; + private final MetricFinder metricFinder; + private final DefaultTimeMachine defaultTimeMachine; - public DefaultProjectReferentialsLoader(DatabaseSession session, ServerClient serverClient, AnalysisMode analysisMode, - SnapshotDataDao dao) { - this.session = session; + public DefaultProjectReferentialsLoader(ServerClient serverClient, AnalysisMode analysisMode, PreviousFileHashLoader fileHashLoader, MetricFinder finder, + DefaultTimeMachine defaultTimeMachine) { this.serverClient = serverClient; this.analysisMode = analysisMode; - this.dao = dao; + this.fileHashLoader = fileHashLoader; + this.metricFinder = finder; + this.defaultTimeMachine = defaultTimeMachine; } @Override @@ -86,78 +77,28 @@ public class DefaultProjectReferentialsLoader implements ProjectReferentialsLoad url += "&preview=" + analysisMode.isPreview(); ProjectReferentials ref = ProjectReferentials.fromJson(serverClient.request(url)); - for (ProjectDefinition module : reactor.getProjects()) { - - for (Map.Entry<String, String> hashByPaths : hashByRelativePath(module.getKeyWithBranch()).entrySet()) { - String path = hashByPaths.getKey(); - String hash = hashByPaths.getValue(); - String lastCommits = null; - String revisions = null; - String authors = null; - List<Object[]> measuresByKey = query(projectKey + ":" + path, CoreMetrics.SCM_LAST_COMMIT_DATETIMES_BY_LINE_KEY, CoreMetrics.SCM_REVISIONS_BY_LINE_KEY, - CoreMetrics.SCM_AUTHORS_BY_LINE_KEY); - for (Object[] measureByKey : measuresByKey) { - if (measureByKey[0].equals(CoreMetrics.SCM_LAST_COMMIT_DATETIMES_BY_LINE_KEY)) { - lastCommits = ((MeasureModel) measureByKey[1]).getData(CoreMetrics.SCM_LAST_COMMIT_DATETIMES_BY_LINE); - } else if (measureByKey[0].equals(CoreMetrics.SCM_REVISIONS_BY_LINE_KEY)) { - revisions = ((MeasureModel) measureByKey[1]).getData(CoreMetrics.SCM_REVISIONS_BY_LINE); - } else if (measureByKey[0].equals(CoreMetrics.SCM_AUTHORS_BY_LINE_KEY)) { - authors = ((MeasureModel) measureByKey[1]).getData(CoreMetrics.SCM_AUTHORS_BY_LINE); - } + Integer lastCommitsId = metricFinder.findByKey(CoreMetrics.SCM_LAST_COMMIT_DATETIMES_BY_LINE.key()).getId(); + Integer revisionsId = metricFinder.findByKey(CoreMetrics.SCM_REVISIONS_BY_LINE.key()).getId(); + Integer authorsId = metricFinder.findByKey(CoreMetrics.SCM_AUTHORS_BY_LINE.key()).getId(); + for (Map.Entry<String, String> hashByPaths : fileHashLoader.hashByRelativePath().entrySet()) { + String path = hashByPaths.getKey(); + String hash = hashByPaths.getValue(); + String lastCommits = null; + String revisions = null; + String authors = null; + List<MeasureModel> measures = defaultTimeMachine.query(projectKey + ":" + path, lastCommitsId, revisionsId, authorsId); + for (MeasureModel m : measures) { + if (m.getMetricId() == lastCommitsId) { + lastCommits = m.getData(CoreMetrics.SCM_LAST_COMMIT_DATETIMES_BY_LINE); + } else if (m.getMetricId() == revisionsId) { + revisions = m.getData(CoreMetrics.SCM_REVISIONS_BY_LINE); + } + if (m.getMetricId() == authorsId) { + authors = m.getData(CoreMetrics.SCM_AUTHORS_BY_LINE); } - ref.addFileData(projectKey, path, new FileData(hash, lastCommits, revisions, authors)); } + ref.fileDataPerPath().put(path, new FileData(hash, lastCommits, revisions, authors)); } return ref; } - - public Map<String, String> hashByRelativePath(String projectKey) { - Map<String, String> map = Maps.newHashMap(); - Collection<SnapshotDataDto> selectSnapshotData = dao.selectSnapshotDataByComponentKey( - projectKey, - Arrays.asList(SnapshotDataTypes.FILE_HASHES) - ); - if (!selectSnapshotData.isEmpty()) { - SnapshotDataDto snapshotDataDto = selectSnapshotData.iterator().next(); - String data = snapshotDataDto.getData(); - map = KeyValueFormat.parse(data); - } - return map; - } - - public List<Object[]> query(String resourceKey, String... metricKeys) { - StringBuilder sb = new StringBuilder(); - Map<String, Object> params = Maps.newHashMap(); - - sb.append("SELECT met.key, m"); - sb.append(" FROM ") - .append(MeasureModel.class.getSimpleName()) - .append(" m, ") - .append(Metric.class.getSimpleName()) - .append(" met, ") - .append(ResourceModel.class.getSimpleName()) - .append(" r, ") - .append(Snapshot.class.getSimpleName()) - .append(" s WHERE met.id=m.metricId AND m.snapshotId=s.id AND s.resourceId=r.id AND r.key=:kee AND s.status=:status AND s.qualifier<>:lib"); - params.put("kee", resourceKey); - params.put("status", Snapshot.STATUS_PROCESSED); - params.put("lib", Qualifiers.LIBRARY); - - sb.append(" AND m.characteristicId IS NULL"); - sb.append(" AND m.personId IS NULL"); - sb.append(" AND m.ruleId IS NULL AND m.rulePriority IS NULL"); - if (metricKeys.length > 0) { - sb.append(" AND met.key IN (:metricKeys) "); - params.put("metricKeys", Arrays.asList(metricKeys)); - } - sb.append(" AND s.last=true "); - sb.append(" ORDER BY s.createdAt "); - - Query jpaQuery = session.createQuery(sb.toString()); - - for (Map.Entry<String, Object> entry : params.entrySet()) { - jpaQuery.setParameter(entry.getKey(), entry.getValue()); - } - return jpaQuery.getResultList(); - } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/InputFileBuilder.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/InputFileBuilder.java index cc099ba9f9c..4e8ed7eedc9 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/InputFileBuilder.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/InputFileBuilder.java @@ -98,7 +98,7 @@ class InputFileBuilder { FileMetadata.Metadata metadata = FileMetadata.INSTANCE.read(inputFile.file(), fs.encoding()); inputFile.setLines(metadata.lines); inputFile.setHash(metadata.hash); - inputFile.setStatus(statusDetection.status(inputFile.moduleKey(), inputFile.relativePath(), metadata.hash)); + inputFile.setStatus(statusDetection.status(inputFile.relativePath(), metadata.hash)); if (analysisMode.isIncremental() && inputFile.status() == InputFile.Status.SAME) { return null; } diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/StatusDetection.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/StatusDetection.java index 8843e604989..96840779d22 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/StatusDetection.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/StatusDetection.java @@ -32,8 +32,8 @@ class StatusDetection { this.projectReferentials = projectReferentials; } - InputFile.Status status(String projectKey, String relativePath, String hash) { - FileData fileDataPerPath = projectReferentials.fileData(projectKey, relativePath); + InputFile.Status status(String relativePath, String hash) { + FileData fileDataPerPath = projectReferentials.fileDataPerPath(relativePath); if (fileDataPerPath == null) { return InputFile.Status.ADDED; } diff --git a/sonar-batch/src/main/java/org/sonar/batch/scm/ScmActivitySensor.java b/sonar-batch/src/main/java/org/sonar/batch/scm/ScmActivitySensor.java index ba7a1fe0ee7..350135a0780 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scm/ScmActivitySensor.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scm/ScmActivitySensor.java @@ -21,7 +21,6 @@ package org.sonar.batch.scm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.batch.fs.FileSystem; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.InputFile.Status; @@ -52,14 +51,11 @@ public final class ScmActivitySensor implements Sensor { private static final Pattern NON_ASCII_CHARS = Pattern.compile("[^\\x00-\\x7F]"); private static final Pattern ACCENT_CODES = Pattern.compile("\\p{InCombiningDiacriticalMarks}+"); - private final ProjectDefinition projectDefinition; private final ScmActivityConfiguration configuration; private final FileSystem fs; private final ProjectReferentials projectReferentials; - public ScmActivitySensor(ProjectDefinition projectDefinition, ScmActivityConfiguration configuration, - ProjectReferentials projectReferentials, FileSystem fs) { - this.projectDefinition = projectDefinition; + public ScmActivitySensor(ScmActivityConfiguration configuration, ProjectReferentials projectReferentials, FileSystem fs) { this.configuration = configuration; this.projectReferentials = projectReferentials; this.fs = fs; @@ -85,7 +81,7 @@ public final class ScmActivitySensor implements Sensor { List<InputFile> filesToBlame = new LinkedList<InputFile>(); for (InputFile f : fs.inputFiles(fs.predicates().all())) { - FileData fileData = projectReferentials.fileData(projectDefinition.getKeyWithBranch(), f.relativePath()); + FileData fileData = projectReferentials.fileDataPerPath(f.relativePath()); if (f.status() == Status.SAME && fileData != null && fileData.scmAuthorsByLine() != null diff --git a/sonar-batch/src/test/java/org/sonar/batch/referential/DefaultProjectReferentialsLoaderTest.java b/sonar-batch/src/test/java/org/sonar/batch/referential/DefaultProjectReferentialsLoaderTest.java index d190df314c1..95821910b74 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/referential/DefaultProjectReferentialsLoaderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/referential/DefaultProjectReferentialsLoaderTest.java @@ -24,12 +24,14 @@ import org.junit.Before; import org.junit.Test; import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.batch.bootstrap.ProjectReactor; -import org.sonar.api.database.DatabaseSession; +import org.sonar.api.measures.Metric; +import org.sonar.api.measures.MetricFinder; +import org.sonar.batch.DefaultTimeMachine; import org.sonar.batch.bootstrap.AnalysisMode; import org.sonar.batch.bootstrap.ServerClient; import org.sonar.batch.bootstrap.TaskProperties; import org.sonar.batch.rule.ModuleQProfiles; -import org.sonar.core.source.db.SnapshotDataDao; +import org.sonar.batch.scan.filesystem.PreviousFileHashLoader; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.mock; @@ -48,7 +50,9 @@ public class DefaultProjectReferentialsLoaderTest { public void prepare() { serverClient = mock(ServerClient.class); analysisMode = mock(AnalysisMode.class); - loader = new DefaultProjectReferentialsLoader(mock(DatabaseSession.class), serverClient, analysisMode, mock(SnapshotDataDao.class)); + MetricFinder metricFinder = mock(MetricFinder.class); + when(metricFinder.findByKey(anyString())).thenReturn(new Metric().setId(1)); + loader = new DefaultProjectReferentialsLoader(serverClient, analysisMode, mock(PreviousFileHashLoader.class), metricFinder, mock(DefaultTimeMachine.class)); when(serverClient.request(anyString())).thenReturn(""); reactor = new ProjectReactor(ProjectDefinition.create().setKey("foo")); taskProperties = new TaskProperties(Maps.<String, String>newHashMap(), ""); diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputFileBuilderTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputFileBuilderTest.java index 91fcbfa0c78..067f1f99d58 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputFileBuilderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputFileBuilderTest.java @@ -62,7 +62,7 @@ public class InputFileBuilderTest { when(langDetection.language(any(InputFile.class))).thenReturn("java"); // status - when(statusDetection.status("foo", "src/main/java/foo/Bar.java", "6c1d64c0b3555892fe7273e954f6fb5a")) + when(statusDetection.status("src/main/java/foo/Bar.java", "6c1d64c0b3555892fe7273e954f6fb5a")) .thenReturn(InputFile.Status.ADDED); InputFileBuilder builder = new InputFileBuilder("struts", new PathResolver(), @@ -135,7 +135,7 @@ public class InputFileBuilderTest { when(langDetection.language(any(InputFile.class))).thenReturn("java"); // status - when(statusDetection.status("foo", "src/main/java/foo/Bar.java", "6c1d64c0b3555892fe7273e954f6fb5a")) + when(statusDetection.status("src/main/java/foo/Bar.java", "6c1d64c0b3555892fe7273e954f6fb5a")) .thenReturn(InputFile.Status.ADDED); InputFileBuilder builder = new InputFileBuilder("struts", new PathResolver(), @@ -164,7 +164,7 @@ public class InputFileBuilderTest { when(langDetection.language(any(InputFile.class))).thenReturn("php"); // status - when(statusDetection.status("foo", "src/Bar.php", "6c1d64c0b3555892fe7273e954f6fb5a")) + when(statusDetection.status("src/Bar.php", "6c1d64c0b3555892fe7273e954f6fb5a")) .thenReturn(InputFile.Status.ADDED); InputFileBuilder builder = new InputFileBuilder("struts", new PathResolver(), diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/StatusDetectionTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/StatusDetectionTest.java index e40df46c172..ecadbe3b1be 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/StatusDetectionTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/StatusDetectionTest.java @@ -30,12 +30,12 @@ public class StatusDetectionTest { @Test public void detect_status() throws Exception { ProjectReferentials ref = new ProjectReferentials(); - ref.addFileData("foo", "src/Foo.java", new FileData("ABCDE", null, null, null)); - ref.addFileData("foo", "src/Bar.java", new FileData("FGHIJ", null, null, null)); + ref.fileDataPerPath().put("src/Foo.java", new FileData("ABCDE", null, null, null)); + ref.fileDataPerPath().put("src/Bar.java", new FileData("FGHIJ", null, null, null)); StatusDetection statusDetection = new StatusDetection(ref); - assertThat(statusDetection.status("foo", "src/Foo.java", "ABCDE")).isEqualTo(InputFile.Status.SAME); - assertThat(statusDetection.status("foo", "src/Foo.java", "XXXXX")).isEqualTo(InputFile.Status.CHANGED); - assertThat(statusDetection.status("foo", "src/Other.java", "QWERT")).isEqualTo(InputFile.Status.ADDED); + assertThat(statusDetection.status("src/Foo.java", "ABCDE")).isEqualTo(InputFile.Status.SAME); + assertThat(statusDetection.status("src/Foo.java", "XXXXX")).isEqualTo(InputFile.Status.CHANGED); + assertThat(statusDetection.status("src/Other.java", "QWERT")).isEqualTo(InputFile.Status.ADDED); } } |