*/
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;
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;
public class DefaultSensorContext implements SensorContext {
+ private static final Logger LOG = LoggerFactory.getLogger(DefaultSensorContext.class);
+
private SonarIndex index;
private Project project;
private MeasurementFilters filters;
}
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) {
*
* @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);
/**
* @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);
/**