diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2014-10-29 21:16:38 +0100 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2014-10-29 21:30:49 +0100 |
commit | 9b7bcaaf80d652e92d9326367952e7ede77bd44b (patch) | |
tree | 283fb892b3d620446b101d517e6ef4d1e6dfb506 | |
parent | bbac6378c0ae04b5c2906858c4799989276883e6 (diff) | |
download | sonarqube-9b7bcaaf80d652e92d9326367952e7ede77bd44b.tar.gz sonarqube-9b7bcaaf80d652e92d9326367952e7ede77bd44b.zip |
SONAR-5375 Do not load source in issue tracking when there is zero issue
2 files changed, 22 insertions, 3 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/IssueTracking.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/IssueTracking.java index d5dbcccc83f..0e26a7904cc 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/IssueTracking.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/IssueTracking.java @@ -60,6 +60,9 @@ public class IssueTracking implements BatchExtension { } private void setChecksumOnNewIssues(Collection<DefaultIssue> issues, SourceHashHolder sourceHashHolder) { + if (issues.isEmpty()) { + return; + } List<String> checksums = SourceChecksum.lineChecksumsOfFile(sourceHashHolder.getSource()); for (DefaultIssue issue : issues) { issue.setChecksum(SourceChecksum.getChecksumForLine(checksums, issue.line())); diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/IssueTrackingTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/IssueTrackingTest.java index 761ca65210e..4b14f77c5b5 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/IssueTrackingTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/IssueTrackingTest.java @@ -35,10 +35,12 @@ import org.sonar.core.issue.db.IssueDto; import java.io.IOException; import java.util.Arrays; +import java.util.Collections; import static com.google.common.collect.Lists.newArrayList; import static org.fest.assertions.Assertions.assertThat; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; public class IssueTrackingTest { @@ -313,16 +315,19 @@ public class IssueTrackingTest { IssueDto referenceIssue1 = newReferenceIssue("Avoid unused local variables such as 'j'.", 6, "squid", "AvoidCycle", "63c11570fc0a76434156be5f8138fa03"); IssueDto referenceIssue2 = newReferenceIssue("Avoid unused private methods such as 'myMethod()'.", 13, "squid", "NullDeref", "ef23288705d1ef1e512448ace287586e"); - IssueDto referenceIssue3 = newReferenceIssue("Method 'avoidUtilityClass' is not designed for extension - needs to be abstract, final or empty.", 9, "pmd", "UnusedLocalVariable", "ed5cdd046fda82727d6fedd1d8e3a310"); + IssueDto referenceIssue3 = newReferenceIssue("Method 'avoidUtilityClass' is not designed for extension - needs to be abstract, final or empty.", 9, "pmd", + "UnusedLocalVariable", "ed5cdd046fda82727d6fedd1d8e3a310"); // New issue DefaultIssue newIssue1 = newDefaultIssue("Avoid unused local variables such as 'msg'.", 18, RuleKey.of("squid", "AvoidCycle"), "a24254126be2bf1a9b9a8db43f633733"); // Same as referenceIssue2 DefaultIssue newIssue2 = newDefaultIssue("Avoid unused private methods such as 'myMethod()'.", 13, RuleKey.of("squid", "NullDeref"), "ef23288705d1ef1e512448ace287586e"); // Same as referenceIssue3 - DefaultIssue newIssue3 = newDefaultIssue("Method 'avoidUtilityClass' is not designed for extension - needs to be abstract, final or empty.", 9, RuleKey.of("pmd", "UnusedLocalVariable"), "ed5cdd046fda82727d6fedd1d8e3a310"); + DefaultIssue newIssue3 = newDefaultIssue("Method 'avoidUtilityClass' is not designed for extension - needs to be abstract, final or empty.", 9, + RuleKey.of("pmd", "UnusedLocalVariable"), "ed5cdd046fda82727d6fedd1d8e3a310"); // New issue - DefaultIssue newIssue4 = newDefaultIssue("Method 'newViolation' is not designed for extension - needs to be abstract, final or empty.", 17, RuleKey.of("pmd", "UnusedLocalVariable"), "7d58ac9040c27e4ca2f11a0269e251e2"); + DefaultIssue newIssue4 = newDefaultIssue("Method 'newViolation' is not designed for extension - needs to be abstract, final or empty.", 17, + RuleKey.of("pmd", "UnusedLocalVariable"), "7d58ac9040c27e4ca2f11a0269e251e2"); // Same as referenceIssue1 DefaultIssue newIssue5 = newDefaultIssue("Avoid unused local variables such as 'j'.", 6, RuleKey.of("squid", "AvoidCycle"), "4432a2675ec3e1620daefe38386b51ef"); @@ -339,6 +344,17 @@ public class IssueTrackingTest { assertThat(result.matching(newIssue5)).isSameAs(referenceIssue1); } + @Test + public void dont_load_checksum_if_no_new_issue() throws Exception { + sourceHashHolder = mock(SourceHashHolder.class); + + IssueDto referenceIssue = newReferenceIssue("2 branches need to be covered", null, "squid", "AvoidCycle", null); + + tracking.track(sourceHashHolder, newArrayList(referenceIssue), Collections.<DefaultIssue>emptyList()); + + verifyZeroInteractions(lastSnapshots, sourceHashHolder); + } + private static String load(String name) throws IOException { return Resources.toString(IssueTrackingTest.class.getResource("IssueTrackingTest/" + name + ".txt"), Charsets.UTF_8); } |