]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4783 Restore indexing methods to allow indexing of methods/paragraphs
authorJulien HENRY <julien.henry@sonarsource.com>
Thu, 9 Jan 2014 14:27:53 +0000 (15:27 +0100)
committerJulien HENRY <julien.henry@sonarsource.com>
Thu, 9 Jan 2014 14:27:53 +0000 (15:27 +0100)
sonar-batch/src/main/java/org/sonar/batch/DefaultSensorContext.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/SensorContext.java

index 4ca86170d38a9242ca13cc3b169709807bacbfc0..3376c65013b904e46b3eead0f10ecf1f99c855f6 100644 (file)
@@ -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) {
index 4616772b17fc0745603c479daa3b75201be03123..e4654dd08e3248ff4b50e4ef8d5ff975b2831967 100644 (file)
@@ -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);
 
   /**