aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch/src
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2014-01-29 17:07:42 +0100
committerJulien HENRY <julien.henry@sonarsource.com>2014-01-29 17:13:52 +0100
commit1e1f6092f9171a19ff2b8b9194417666d0d481ab (patch)
tree6bf1353a43dd67208286d85cbb4f34ed7b0e2221 /sonar-batch/src
parent75fd4f9a5653b25188918b9c2d7f6cb77f9ab3bd (diff)
downloadsonarqube-1e1f6092f9171a19ff2b8b9194417666d0d481ab.tar.gz
sonarqube-1e1f6092f9171a19ff2b8b9194417666d0d481ab.zip
SONAR-926 JavaFile is now considered as equivalent to File
and creating a violation on a not indexed resource will no more result in indexing the resource.
Diffstat (limited to 'sonar-batch/src')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java3
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java25
2 files changed, 25 insertions, 3 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java
index 459b1af63f9..d4cb7c0e95e 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java
@@ -384,8 +384,9 @@ public class DefaultIndex extends SonarIndex {
return;
}
- Bucket bucket = checkIndexed(resource);
+ Bucket bucket = getBucket(resource, true);
if (bucket == null || bucket.isExcluded()) {
+ LOG.warn("Resource is not indexed. Ignoring violation {}", violation);
return;
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java
index 466d67747c1..68a085c6439 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java
@@ -30,7 +30,13 @@ import org.sonar.api.measures.Measure;
import org.sonar.api.measures.MeasuresFilters;
import org.sonar.api.measures.MetricFinder;
import org.sonar.api.profiles.RulesProfile;
-import org.sonar.api.resources.*;
+import org.sonar.api.resources.Directory;
+import org.sonar.api.resources.File;
+import org.sonar.api.resources.Java;
+import org.sonar.api.resources.Library;
+import org.sonar.api.resources.Project;
+import org.sonar.api.resources.Qualifiers;
+import org.sonar.api.resources.Resource;
import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RuleFinder;
import org.sonar.api.rules.Violation;
@@ -97,7 +103,7 @@ public class DefaultIndexTest {
rule = Rule.create("repoKey", "ruleKey", "Rule");
rule.setId(1);
rulesProfile.activateRule(rule, null);
- index.setCurrentProject(project, new ResourceFilters(new ResourceFilter[]{filter}), mock(ModuleIssues.class));
+ index.setCurrentProject(project, new ResourceFilters(new ResourceFilter[] {filter}), mock(ModuleIssues.class));
index.doStart(project);
}
@@ -209,12 +215,25 @@ public class DefaultIndexTest {
Violation violation = Violation.create(rule, file);
when(deprecatedViolations.get(anyString())).thenReturn(newArrayList(violation));
+ index.index(file);
index.addViolation(violation);
assertThat(index.getViolations(file)).hasSize(1);
}
@Test
+ public void should_not_save_violation_if_resource_not_indexed() {
+ Rule rule = Rule.create("repoKey", "ruleKey", "Rule");
+ File file = File.create("src/org/foo/Bar.java", "org/foo/Bar.java", null, false);
+ Violation violation = Violation.create(rule, file);
+ when(deprecatedViolations.get(anyString())).thenReturn(newArrayList(violation));
+
+ index.addViolation(violation);
+
+ assertThat(index.getViolations(file)).hasSize(0);
+ }
+
+ @Test
public void should_get_filtered_violation_with_off_switch_mode() {
Rule rule = Rule.create("repoKey", "ruleKey", "Rule");
File file = File.create("src/org/foo/Bar.java", "org/foo/Bar.java", null, false);
@@ -222,6 +241,7 @@ public class DefaultIndexTest {
when(deprecatedViolations.get(anyString())).thenReturn(newArrayList(violation));
+ index.index(file);
index.addViolation(violation);
assertThat(index.getViolations(ViolationQuery.create().forResource(file).setSwitchMode(ViolationQuery.SwitchMode.OFF))).hasSize(1);
@@ -235,6 +255,7 @@ public class DefaultIndexTest {
when(deprecatedViolations.get(anyString())).thenReturn(newArrayList(violation));
+ index.index(file);
index.addViolation(violation);
assertThat(index.getViolations(ViolationQuery.create().forResource(file).setSwitchMode(ViolationQuery.SwitchMode.ON))).hasSize(1);