aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2014-12-04 09:08:46 +0100
committerJulien HENRY <julien.henry@sonarsource.com>2014-12-04 11:47:22 +0100
commit421ca0d61503b7286175866608ec43a60acc7fc3 (patch)
tree05c8e9e93ab9564937bf1432e80fc9277b14bc15 /plugins
parent02951b2ffce8541070c3ad4c718fa248dc19d06b (diff)
downloadsonarqube-421ca0d61503b7286175866608ec43a60acc7fc3.tar.gz
sonarqube-421ca0d61503b7286175866608ec43a60acc7fc3.zip
Fix some quality flaws
Diffstat (limited to 'plugins')
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/IssueTracking.java18
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/IssueTrackingDecorator.java3
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/IssueTrackingDecoratorTest.java7
3 files changed, 17 insertions, 11 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 b470b424f84..884e298bd68 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
@@ -30,6 +30,7 @@ import org.sonar.api.BatchExtension;
import org.sonar.api.issue.internal.DefaultIssue;
import org.sonar.api.rule.RuleKey;
import org.sonar.core.issue.db.IssueDto;
+import org.sonar.plugins.core.issue.tracking.FileHashes;
import org.sonar.plugins.core.issue.tracking.IssueTrackingBlocksRecognizer;
import org.sonar.plugins.core.issue.tracking.RollingFileHashes;
@@ -63,14 +64,15 @@ public class IssueTracking implements BatchExtension {
return;
}
for (DefaultIssue issue : issues) {
- if (issue.line() != null) {
- issue.setChecksum(sourceHashHolder.getHashedSource().getHash(issue.line()));
+ Integer line = issue.line();
+ if (line != null) {
+ issue.setChecksum(sourceHashHolder.getHashedSource().getHash(line));
}
}
}
@VisibleForTesting
- void mapIssues(Collection<DefaultIssue> newIssues, @Nullable Collection<IssueDto> lastIssues, SourceHashHolder sourceHashHolder, IssueTrackingResult result) {
+ void mapIssues(Collection<DefaultIssue> newIssues, @Nullable Collection<IssueDto> lastIssues, @Nullable SourceHashHolder sourceHashHolder, IssueTrackingResult result) {
boolean hasLastScan = false;
if (lastIssues != null) {
@@ -81,7 +83,7 @@ public class IssueTracking implements BatchExtension {
// If each new issue matches an old one we can stop the matching mechanism
if (result.matched().size() != newIssues.size()) {
if (sourceHashHolder != null && sourceHashHolder.getHashedReference() != null && hasLastScan) {
- mapNewissues(sourceHashHolder, newIssues, result);
+ mapNewissues(sourceHashHolder.getHashedReference(), sourceHashHolder.getHashedSource(), newIssues, result);
}
mapIssuesOnSameRule(newIssues, result);
}
@@ -108,12 +110,12 @@ public class IssueTracking implements BatchExtension {
}
}
- private void mapNewissues(SourceHashHolder sourceHashHolder, Collection<DefaultIssue> newIssues, IssueTrackingResult result) {
+ private void mapNewissues(FileHashes hashedReference, FileHashes hashedSource, Collection<DefaultIssue> newIssues, IssueTrackingResult result) {
- IssueTrackingBlocksRecognizer rec = new IssueTrackingBlocksRecognizer(sourceHashHolder.getHashedReference(), sourceHashHolder.getHashedSource());
+ IssueTrackingBlocksRecognizer rec = new IssueTrackingBlocksRecognizer(hashedReference, hashedSource);
- RollingFileHashes a = RollingFileHashes.create(sourceHashHolder.getHashedReference(), 5);
- RollingFileHashes b = RollingFileHashes.create(sourceHashHolder.getHashedSource(), 5);
+ RollingFileHashes a = RollingFileHashes.create(hashedReference, 5);
+ RollingFileHashes b = RollingFileHashes.create(hashedSource, 5);
Multimap<Integer, DefaultIssue> newIssuesByLines = newIssuesByLines(newIssues, rec, result);
Multimap<Integer, IssueDto> lastIssuesByLines = lastIssuesByLines(result.unmatched(), rec);
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/IssueTrackingDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/IssueTrackingDecorator.java
index 7c39348de1f..a465c1b860c 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/IssueTrackingDecorator.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/IssueTrackingDecorator.java
@@ -129,6 +129,9 @@ public class IssueTrackingDecorator implements Decorator {
if (ResourceUtils.isFile(resource)) {
File sonarFile = (File) resource;
InputFile file = inputPathCache.getFile(project.getEffectiveKey(), sonarFile.getPath());
+ if (file == null) {
+ throw new IllegalStateException("Resource " + resource + " was not found in InputPath cache");
+ }
sourceHashHolder = new SourceHashHolder((DefaultInputFile) file, lastLineHashes);
}
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/IssueTrackingDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/IssueTrackingDecoratorTest.java
index 844b2a8dfd8..99d3cdcdd63 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/IssueTrackingDecoratorTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/IssueTrackingDecoratorTest.java
@@ -116,14 +116,14 @@ public class IssueTrackingDecoratorTest extends AbstractDaoTestCase {
@Test
public void should_process_open_issues() throws Exception {
- Resource file = new File("Action.java").setEffectiveKey("struts:Action.java").setId(123);
+ Resource file = File.create("Action.java").setEffectiveKey("struts:Action.java").setId(123);
final DefaultIssue issue = new DefaultIssue();
// INPUT : one issue, no open issues during previous scan, no filtering
when(issueCache.byComponent("struts:Action.java")).thenReturn(Arrays.asList(issue));
List<IssueDto> dbIssues = Collections.emptyList();
when(initialOpenIssues.selectAndRemoveIssues("struts:Action.java")).thenReturn(dbIssues);
-
+ when(inputPathCache.getFile("foo", "Action.java")).thenReturn(mock(DefaultInputFile.class));
decorator.doDecorate(file);
// Apply filters, track, apply transitions, notify extensions then update cache
@@ -142,7 +142,7 @@ public class IssueTrackingDecoratorTest extends AbstractDaoTestCase {
@Test
public void should_register_unmatched_issues_as_end_of_life() throws Exception {
// "Unmatched" issues existed in previous scan but not in current one -> they have to be closed
- Resource file = new File("Action.java").setEffectiveKey("struts:Action.java").setId(123);
+ Resource file = File.create("Action.java").setEffectiveKey("struts:Action.java").setId(123);
// INPUT : one issue existing during previous scan
IssueDto unmatchedIssue = new IssueDto().setKee("ABCDE").setResolution(null).setStatus("OPEN").setRuleKey("squid", "AvoidCycle");
@@ -151,6 +151,7 @@ public class IssueTrackingDecoratorTest extends AbstractDaoTestCase {
trackingResult.addUnmatched(unmatchedIssue);
when(tracking.track(isA(SourceHashHolder.class), anyCollection(), anyCollection())).thenReturn(trackingResult);
+ when(inputPathCache.getFile("foo", "Action.java")).thenReturn(mock(DefaultInputFile.class));
decorator.doDecorate(file);