aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/ResourceFilters.java35
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/Bucket.java4
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java72
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java1
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/ResourceFiltersTest.java47
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java48
-rw-r--r--sonar-deprecated/src/main/java/org/sonar/api/batch/ResourceFilter.java (renamed from sonar-plugin-api/src/main/java/org/sonar/api/batch/ResourceFilter.java)2
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/resources/Resource.java7
8 files changed, 85 insertions, 131 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/ResourceFilters.java b/sonar-batch/src/main/java/org/sonar/batch/ResourceFilters.java
index c32b0dbd68b..dde7e698198 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/ResourceFilters.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/ResourceFilters.java
@@ -19,50 +19,31 @@
*/
package org.sonar.batch;
+import com.google.common.base.Joiner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.batch.ResourceFilter;
-import org.sonar.api.resources.Resource;
-import org.sonar.api.resources.Scopes;
/**
* @since 1.12
*/
public class ResourceFilters {
- private static final Logger LOG = LoggerFactory.getLogger(ResourceFilters.class);
-
- private ResourceFilter[] filters;
-
public ResourceFilters(ResourceFilter[] filters) {
- this.filters = filters == null ? new ResourceFilter[0] : filters;
+ this(LoggerFactory.getLogger(ResourceFilters.class), filters);
}
public ResourceFilters() {
- this(null);
+ // perfect
}
- public ResourceFilter[] getFilters() {
- return filters;
+ ResourceFilters(Logger logger, ResourceFilter[] filters) {
+ check(logger, filters);
}
- /**
- * Return true if the violation must be saved. If false then it is ignored.
- */
- public boolean isExcluded(Resource resource) {
- boolean ignored = false;
- if (Scopes.isHigherThanOrEquals(resource, Scopes.FILE)) {
- int index = 0;
- while (!ignored && index < filters.length) {
- ResourceFilter filter = filters[index];
- ignored = filter.isIgnored(resource);
- if (ignored && LOG.isDebugEnabled()) {
- LOG.debug("Resource {} is excluded by the filter {}", resource, filter);
- }
- index++;
- }
+ private void check(Logger logger, ResourceFilter[] filters) {
+ if (filters.length > 0) {
+ logger.warn("ResourceFilters are not supported since version 4.2: " + Joiner.on(", ").join(filters));
}
- return ignored;
}
-
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/Bucket.java b/sonar-batch/src/main/java/org/sonar/batch/index/Bucket.java
index a7feab13006..7e47a1a3b5f 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/index/Bucket.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/index/Bucket.java
@@ -116,10 +116,6 @@ public final class Bucket {
return filter.filter(unfiltered);
}
- public boolean isExcluded() {
- return resource.isExcluded();
- }
-
@Override
public boolean equals(Object o) {
if (this == o) {
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 76f37e5d104..1fd9d4178c5 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
@@ -31,41 +31,20 @@ import org.sonar.api.batch.SonarIndex;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.database.model.Snapshot;
import org.sonar.api.design.Dependency;
-import org.sonar.api.measures.Measure;
-import org.sonar.api.measures.MeasuresFilter;
-import org.sonar.api.measures.MeasuresFilters;
-import org.sonar.api.measures.Metric;
-import org.sonar.api.measures.MetricFinder;
-import org.sonar.api.resources.Directory;
-import org.sonar.api.resources.File;
-import org.sonar.api.resources.JavaFile;
-import org.sonar.api.resources.JavaPackage;
-import org.sonar.api.resources.Project;
-import org.sonar.api.resources.ProjectLink;
-import org.sonar.api.resources.Qualifiers;
-import org.sonar.api.resources.Resource;
-import org.sonar.api.resources.ResourceUtils;
-import org.sonar.api.resources.Scopes;
+import org.sonar.api.measures.*;
+import org.sonar.api.resources.*;
import org.sonar.api.rules.Rule;
import org.sonar.api.rules.Violation;
import org.sonar.api.scan.filesystem.PathResolver;
import org.sonar.api.utils.SonarException;
import org.sonar.api.violations.ViolationQuery;
import org.sonar.batch.ProjectTree;
-import org.sonar.batch.ResourceFilters;
import org.sonar.batch.issue.DeprecatedViolations;
import org.sonar.batch.issue.ModuleIssues;
import org.sonar.core.component.ComponentKeys;
import org.sonar.core.component.ScanGraph;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
public class DefaultIndex extends SonarIndex {
@@ -75,9 +54,6 @@ public class DefaultIndex extends SonarIndex {
private MetricFinder metricFinder;
private final ScanGraph graph;
- // filters
- private ResourceFilters resourceFilters;
-
// caches
private Project currentProject;
private Map<Resource, Bucket> buckets = Maps.newHashMap();
@@ -144,11 +120,10 @@ public class DefaultIndex extends SonarIndex {
return currentProject;
}
- public void setCurrentProject(Project project, ResourceFilters resourceFilters, ModuleIssues moduleIssues) {
+ public void setCurrentProject(Project project, ModuleIssues moduleIssues) {
this.currentProject = project;
// the following components depend on the current module, so they need to be reloaded.
- this.resourceFilters = resourceFilters;
this.moduleIssues = moduleIssues;
}
@@ -204,7 +179,7 @@ public class DefaultIndex extends SonarIndex {
@Override
public Measure addMeasure(Resource resource, Measure measure) {
Bucket bucket = checkIndexed(resource);
- if (bucket != null && !bucket.isExcluded()) {
+ if (bucket != null) {
Metric metric = metricFinder.findByKey(measure.getMetricKey());
if (metric == null) {
throw new SonarException("Unknown metric: " + measure.getMetricKey());
@@ -249,7 +224,7 @@ public class DefaultIndex extends SonarIndex {
Bucket fromBucket = doIndex(dependency.getFrom());
Bucket toBucket = doIndex(dependency.getTo());
- if (fromBucket != null && !fromBucket.isExcluded() && toBucket != null && !toBucket.isExcluded()) {
+ if (fromBucket != null && toBucket != null) {
dependencies.add(dependency);
registerOutgoingDependency(dependency);
registerIncomingDependency(dependency);
@@ -392,7 +367,7 @@ public class DefaultIndex extends SonarIndex {
}
Bucket bucket = getBucket(resource, true);
- if (bucket == null || bucket.isExcluded()) {
+ if (bucket == null) {
LOG.warn("Resource is not indexed. Ignoring violation {}", violation);
return;
}
@@ -456,7 +431,7 @@ public class DefaultIndex extends SonarIndex {
@Override
public void setSource(Resource reference, String source) {
Bucket bucket = checkIndexed(reference);
- if (bucket != null && !bucket.isExcluded()) {
+ if (bucket != null) {
persistence.setSource(reference, source);
}
}
@@ -484,12 +459,6 @@ public class DefaultIndex extends SonarIndex {
return null;
}
- private boolean checkExclusion(Resource resource, Bucket parent) {
- boolean excluded = (parent != null && parent.isExcluded()) || (resourceFilters != null && resourceFilters.isExcluded(resource));
- resource.setExcluded(excluded);
- return excluded;
- }
-
@Override
public List<Resource> getChildren(Resource resource) {
return getChildren(resource, false);
@@ -500,9 +469,7 @@ public class DefaultIndex extends SonarIndex {
Bucket bucket = getBucket(resource, acceptExcluded);
if (bucket != null) {
for (Bucket childBucket : bucket.getChildren()) {
- if (acceptExcluded || !childBucket.isExcluded()) {
- children.add(childBucket.getResource());
- }
+ children.add(childBucket.getResource());
}
}
return children;
@@ -520,7 +487,7 @@ public class DefaultIndex extends SonarIndex {
@Override
public boolean index(Resource resource) {
Bucket bucket = doIndex(resource);
- return bucket != null && !bucket.isExcluded();
+ return bucket != null;
}
private Bucket doIndex(Resource resource) {
@@ -533,7 +500,7 @@ public class DefaultIndex extends SonarIndex {
@Override
public boolean index(Resource resource, Resource parentReference) {
Bucket bucket = doIndex(resource, parentReference);
- return bucket != null && !bucket.isExcluded();
+ return bucket != null;
}
private Bucket doIndex(Resource resource, Resource parentReference) {
@@ -563,13 +530,10 @@ public class DefaultIndex extends SonarIndex {
bucket = new Bucket(resource).setParent(parentBucket);
addBucket(resource, bucket);
- boolean excluded = checkExclusion(resource, parentBucket);
- if (!excluded) {
- Resource parentSnapshot = parentBucket != null ? parentBucket.getResource() : null;
- Snapshot snapshot = persistence.saveResource(currentProject, resource, parentSnapshot);
- if (ResourceUtils.isPersistable(resource) && !Qualifiers.LIBRARY.equals(resource.getQualifier())) {
- graph.addComponent(resource, snapshot);
- }
+ Resource parentSnapshot = parentBucket != null ? parentBucket.getResource() : null;
+ Snapshot snapshot = persistence.saveResource(currentProject, resource, parentSnapshot);
+ if (ResourceUtils.isPersistable(resource) && !Qualifiers.LIBRARY.equals(resource.getQualifier())) {
+ graph.addComponent(resource, snapshot);
}
return bucket;
@@ -587,8 +551,7 @@ public class DefaultIndex extends SonarIndex {
@Override
public boolean isExcluded(Resource reference) {
- Bucket bucket = getBucket(reference, true);
- return bucket != null && bucket.isExcluded();
+ return false;
}
@Override
@@ -600,9 +563,6 @@ public class DefaultIndex extends SonarIndex {
Bucket bucket = null;
if (resource != null) {
bucket = getBucket(resource);
- if (!acceptExcluded && bucket != null && bucket.isExcluded()) {
- bucket = null;
- }
}
return bucket;
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java
index b7d737f01cb..884dbc4a19a 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java
@@ -154,7 +154,6 @@ public class ModuleScanContainer extends ComponentContainer {
protected void doAfterStart() {
DefaultIndex index = getComponentByType(DefaultIndex.class);
index.setCurrentProject(module,
- getComponentByType(ResourceFilters.class),
getComponentByType(ModuleIssues.class));
getComponentByType(PhaseExecutor.class).execute(module);
diff --git a/sonar-batch/src/test/java/org/sonar/batch/ResourceFiltersTest.java b/sonar-batch/src/test/java/org/sonar/batch/ResourceFiltersTest.java
new file mode 100644
index 00000000000..8c4c58e413b
--- /dev/null
+++ b/sonar-batch/src/test/java/org/sonar/batch/ResourceFiltersTest.java
@@ -0,0 +1,47 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.batch;
+
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.sonar.api.batch.ResourceFilter;
+
+import static org.mockito.Matchers.startsWith;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+public class ResourceFiltersTest {
+ @Test
+ public void warn_on_resource_filters() throws Exception {
+ Logger logger = mock(Logger.class);
+ ResourceFilter[] filters = {mock(ResourceFilter.class)};
+ new ResourceFilters(logger, filters);
+ verify(logger).warn(startsWith("ResourceFilters are not supported since version 4.2"));
+
+ // verify that the standard constructor does not fail
+ new ResourceFilters(filters);
+ }
+
+ @Test
+ public void ok_if_no_resource_filters() throws Exception {
+ // just for verify that it does not fail. Should check that no warning is logged.
+ new ResourceFilters();
+ }
+}
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 68a085c6439..dd5da90948d 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
@@ -19,30 +19,21 @@
*/
package org.sonar.batch.index;
-import org.apache.commons.lang.StringUtils;
import org.junit.Before;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
-import org.sonar.api.batch.ResourceFilter;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.measures.CoreMetrics;
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.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.resources.*;
import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RuleFinder;
import org.sonar.api.rules.Violation;
import org.sonar.api.violations.ViolationQuery;
import org.sonar.batch.ProjectTree;
-import org.sonar.batch.ResourceFilters;
import org.sonar.batch.issue.DeprecatedViolations;
import org.sonar.batch.issue.ModuleIssues;
import org.sonar.core.component.ScanGraph;
@@ -60,18 +51,14 @@ public class DefaultIndexTest {
@org.junit.Rule
public TemporaryFolder temp = new TemporaryFolder();
- private DefaultIndex index = null;
- private DeprecatedViolations deprecatedViolations;
- private Rule rule;
- private RuleFinder ruleFinder;
-
- private Project project;
-
- private Project moduleA;
-
- private Project moduleB;
-
- private Project moduleB1;
+ DefaultIndex index = null;
+ DeprecatedViolations deprecatedViolations;
+ Rule rule;
+ RuleFinder ruleFinder;
+ Project project;
+ Project moduleA;
+ Project moduleB;
+ Project moduleB1;
@Before
public void createIndex() throws IOException {
@@ -93,17 +80,11 @@ public class DefaultIndexTest {
moduleB1 = new Project("moduleB1").setParent(moduleB);
when(projectTree.getProjectDefinition(moduleB1)).thenReturn(ProjectDefinition.create().setBaseDir(new java.io.File(baseDir, "moduleB/moduleB1")));
- ResourceFilter filter = new ResourceFilter() {
-
- public boolean isIgnored(Resource resource) {
- return StringUtils.containsIgnoreCase(resource.getKey(), "excluded");
- }
- };
RulesProfile rulesProfile = RulesProfile.create();
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, mock(ModuleIssues.class));
index.doStart(project);
}
@@ -165,15 +146,6 @@ public class DefaultIndexTest {
}
@Test
- public void shouldBeExcluded() {
- File file = File.create("src/org/foo/ExcludedBar.java", "org/foo/ExcludedBar.java", null, false);
- assertThat(index.index(file)).isFalse();
- assertThat(index.isIndexed(file, true)).isTrue();
- assertThat(index.isIndexed(file, false)).isFalse();
- assertThat(index.isExcluded(file)).isTrue();
- }
-
- @Test
public void shouldIndexResourceWhenAddingMeasure() {
Resource dir = Directory.create("src/org/foo", "org/foo");
index.addMeasure(dir, new Measure("ncloc").setValue(50.0));
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/ResourceFilter.java b/sonar-deprecated/src/main/java/org/sonar/api/batch/ResourceFilter.java
index 584ae2baf92..518584b1d59 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/ResourceFilter.java
+++ b/sonar-deprecated/src/main/java/org/sonar/api/batch/ResourceFilter.java
@@ -29,7 +29,9 @@ import org.sonar.api.resources.Resource;
* If the method start(), without parameters, exists, then it is executed at startup.
*
* @since 1.12
+ * @deprecated since 4.2. Analysis is file-system oriented. See {@link org.sonar.api.scan.filesystem.InputFileFilter}
*/
+@Deprecated
public interface ResourceFilter extends BatchExtension {
/**
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Resource.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Resource.java
index 4a71d5165e4..958f2246ce9 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Resource.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Resource.java
@@ -132,8 +132,6 @@ public abstract class Resource implements Serializable {
private String effectiveKey = null;
- private boolean isExcluded = false;
-
/**
* @return the resource key
*/
@@ -263,11 +261,11 @@ public abstract class Resource implements Serializable {
}
/**
- * @deprecated since 2.6 should use SensorContext#isExcluded(resource). It will make inheritance of Resource easier.
+ * @deprecated since 2.6.
*/
@Deprecated
public final boolean isExcluded() {
- return isExcluded;
+ return false;
}
/**
@@ -276,7 +274,6 @@ public abstract class Resource implements Serializable {
*/
@Deprecated
public final Resource setExcluded(boolean b) {
- isExcluded = b;
return this;
}