From: Julien HENRY Date: Thu, 9 Jan 2014 14:27:53 +0000 (+0100) Subject: SONAR-4783 Restore indexing methods to allow indexing of methods/paragraphs X-Git-Tag: 4.2~778 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=24905998ba2e6b91efa4dcbb8f017078030fbbcd;p=sonarqube.git SONAR-4783 Restore indexing methods to allow indexing of methods/paragraphs --- diff --git a/sonar-batch/src/main/java/org/sonar/batch/DefaultSensorContext.java b/sonar-batch/src/main/java/org/sonar/batch/DefaultSensorContext.java index 4ca86170d38..3376c65013b 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/DefaultSensorContext.java +++ b/sonar-batch/src/main/java/org/sonar/batch/DefaultSensorContext.java @@ -19,6 +19,8 @@ */ package org.sonar.batch; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.sonar.api.batch.Event; import org.sonar.api.batch.SensorContext; import org.sonar.api.batch.SonarIndex; @@ -29,7 +31,9 @@ import org.sonar.api.measures.Metric; import org.sonar.api.resources.Project; import org.sonar.api.resources.ProjectLink; import org.sonar.api.resources.Resource; +import org.sonar.api.resources.ResourceUtils; import org.sonar.api.rules.Violation; +import org.sonar.api.utils.SonarException; import org.sonar.core.measure.MeasurementFilters; import java.util.Collection; @@ -39,6 +43,8 @@ import java.util.Set; public class DefaultSensorContext implements SensorContext { + private static final Logger LOG = LoggerFactory.getLogger(DefaultSensorContext.class); + private SonarIndex index; private Project project; private MeasurementFilters filters; @@ -54,11 +60,26 @@ public class DefaultSensorContext implements SensorContext { } public boolean index(Resource resource) { - return true; + // SONAR-5006 + if (ResourceUtils.isPersistable(resource)) { + logWarning(); + return true; + } + return index.index(resource); } public boolean index(Resource resource, Resource parentReference) { - return true; + // SONAR-5006 + if (ResourceUtils.isPersistable(resource)) { + logWarning(); + return true; + } + return index.index(resource, parentReference); + } + + private void logWarning() { + LOG.debug("Plugins are no more allowed to index physical resources like directories and files. This is now handled by the platform.", new SonarException( + "Plugin should not index physical resources")); } public boolean isExcluded(Resource reference) { diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/SensorContext.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/SensorContext.java index 4616772b17f..e4654dd08e3 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/SensorContext.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/SensorContext.java @@ -42,9 +42,8 @@ public interface SensorContext { * * @return false if the resource is excluded * @since 2.6 - * @deprecated since 4.2 Resource indexing is done by the platform + * @since 4.2 Resource indexing is done by the platform for all physical resources. This method should only be used to index methods/paragraphs (see SONAR-5006) */ - @Deprecated boolean index(Resource resource); /** @@ -54,9 +53,8 @@ public interface SensorContext { * @param parentReference a reference to the parent. If null, the the resource is indexed as a direct child of project. * @return false if the parent is not indexed or if the resource is excluded * @since 2.6 - * @deprecated since 4.2 Resource indexing is done by the platform + * @since 4.2 Resource indexing is done by the platform for all physical resources. This method should only be used to index methods/paragraphs (see SONAR-5006) */ - @Deprecated boolean index(Resource resource, Resource parentReference); /**