]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-926 * Deprecated FileSystemFilter in favor of InputFileFilter
authorJulien HENRY <julien.henry@sonarsource.com>
Mon, 10 Feb 2014 14:12:30 +0000 (15:12 +0100)
committerJulien HENRY <julien.henry@sonarsource.com>
Mon, 10 Feb 2014 14:14:39 +0000 (15:14 +0100)
 * Return a fake language for Project::getLanguage to avoid some NPE in plugins
 * Try to remove use of deprecated InputFile attributes

17 files changed:
sonar-batch/src/main/java/org/sonar/batch/DefaultFileLinesContextFactory.java
sonar-batch/src/main/java/org/sonar/batch/DefaultSensorContext.java
sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java
sonar-batch/src/main/java/org/sonar/batch/phases/ProjectInitializer.java
sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/AttributeFilter.java
sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ComponentIndexer.java
sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DeprecatedFileFilters.java
sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ExclusionFilter.java
sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileIndex.java
sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileQueryFilter.java
sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/InclusionFilter.java
sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/FileQueryFilterTest.java
sonar-plugin-api/src/main/java/org/sonar/api/resources/File.java
sonar-plugin-api/src/main/java/org/sonar/api/resources/Project.java
sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/FileSystemFilter.java
sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/InputFileFilter.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/internal/InputFileFilter.java [deleted file]

index 438c698abdac031e3d984ed72bba5b2b420ae1e9..5d3b49e8e9faa16a812b72bb689a12dcacd87217 100644 (file)
@@ -23,11 +23,8 @@ import org.sonar.api.batch.SonarIndex;
 import org.sonar.api.measures.FileLinesContext;
 import org.sonar.api.measures.FileLinesContextFactory;
 import org.sonar.api.resources.File;
-import org.sonar.api.resources.Java;
-import org.sonar.api.resources.JavaFile;
 import org.sonar.api.resources.Resource;
 import org.sonar.api.scan.filesystem.InputFile;
-import org.sonar.api.scan.filesystem.internal.DefaultInputFile;
 
 public class DefaultFileLinesContextFactory implements FileLinesContextFactory {
 
@@ -46,15 +43,7 @@ public class DefaultFileLinesContextFactory implements FileLinesContextFactory {
 
   @Override
   public FileLinesContext createFor(InputFile inputFile) {
-    // FIXME remove that once DefaultFileLinesContext accept an InputFile
-    String languageKey = inputFile.attribute(InputFile.ATTRIBUTE_LANGUAGE);
-    boolean unitTest = InputFile.TYPE_TEST.equals(inputFile.attribute(InputFile.ATTRIBUTE_TYPE));
-    Resource sonarFile;
-    if (Java.KEY.equals(languageKey)) {
-      sonarFile = JavaFile.create(inputFile.path(), inputFile.attribute(DefaultInputFile.ATTRIBUTE_SOURCE_RELATIVE_PATH), unitTest);
-    } else {
-      sonarFile = File.create(inputFile.path(), inputFile.attribute(DefaultInputFile.ATTRIBUTE_SOURCE_RELATIVE_PATH), null, unitTest);
-    }
+    File sonarFile = File.create(inputFile.path());
     // Reload resource from index
     sonarFile = index.getResource(sonarFile);
     return new DefaultFileLinesContext(index, sonarFile);
index be1cedaaf91ff0b2983c5af28fddce16c5eafa77..26640dba5a3ef145c69df40274e33172124e8088 100644 (file)
@@ -19,9 +19,6 @@
  */
 package org.sonar.batch;
 
-import org.sonar.api.scan.filesystem.internal.DefaultInputFile;
-
-import org.sonar.api.scan.filesystem.InputFile;
 import org.apache.commons.lang.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -33,14 +30,13 @@ import org.sonar.api.measures.Measure;
 import org.sonar.api.measures.MeasuresFilter;
 import org.sonar.api.measures.Metric;
 import org.sonar.api.resources.File;
-import org.sonar.api.resources.Java;
-import org.sonar.api.resources.JavaFile;
 import org.sonar.api.resources.Languages;
 import org.sonar.api.resources.Project;
 import org.sonar.api.resources.ProjectLink;
 import org.sonar.api.resources.Resource;
 import org.sonar.api.resources.Scopes;
 import org.sonar.api.rules.Violation;
+import org.sonar.api.scan.filesystem.InputFile;
 import org.sonar.api.utils.SonarException;
 import org.sonar.core.measure.MeasurementFilters;
 
@@ -259,12 +255,6 @@ public class DefaultSensorContext implements SensorContext {
   }
 
   private Resource fromInputFile(InputFile inputFile) {
-    String languageKey = inputFile.attribute(InputFile.ATTRIBUTE_LANGUAGE);
-    boolean unitTest = InputFile.TYPE_TEST.equals(inputFile.attribute(InputFile.ATTRIBUTE_TYPE));
-    if (Java.KEY.equals(languageKey)) {
-      return JavaFile.create(inputFile.path(), inputFile.attribute(DefaultInputFile.ATTRIBUTE_SOURCE_RELATIVE_PATH), unitTest);
-    } else {
-      return File.create(inputFile.path(), inputFile.attribute(DefaultInputFile.ATTRIBUTE_SOURCE_RELATIVE_PATH), languages.get(languageKey), unitTest);
-    }
+    return File.create(inputFile.path());
   }
 }
index 61315db2d63a7b9814a65e9bfc33a2cfbf8ba8fd..3397d3a05d8dbc15e4c62a578205ce569238dd17 100644 (file)
@@ -25,9 +25,14 @@ import org.apache.commons.lang.StringUtils;
 import org.sonar.api.database.DatabaseSession;
 import org.sonar.api.database.model.ResourceModel;
 import org.sonar.api.database.model.Snapshot;
-import org.sonar.api.resources.*;
+import org.sonar.api.resources.File;
+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.ResourceUtils;
+import org.sonar.api.resources.Scopes;
 import org.sonar.api.scan.filesystem.InputFile;
-import org.sonar.api.scan.filesystem.internal.DefaultInputFile;
 import org.sonar.api.security.ResourcePermissions;
 import org.sonar.api.utils.SonarException;
 
@@ -135,13 +140,7 @@ public final class DefaultResourcePersister implements ResourcePersister {
   }
 
   private Resource fromInputFile(InputFile inputFile) {
-    String languageKey = inputFile.attribute(InputFile.ATTRIBUTE_LANGUAGE);
-    boolean unitTest = InputFile.TYPE_TEST.equals(inputFile.attribute(InputFile.ATTRIBUTE_TYPE));
-    if (Java.KEY.equals(languageKey)) {
-      return JavaFile.create(inputFile.path(), inputFile.attribute(DefaultInputFile.ATTRIBUTE_SOURCE_RELATIVE_PATH), unitTest);
-    } else {
-      return File.create(inputFile.path(), inputFile.attribute(DefaultInputFile.ATTRIBUTE_SOURCE_RELATIVE_PATH), null, unitTest);
-    }
+    return File.create(inputFile.path());
   }
 
   /**
index e4d76a7c89919a82b8db5202b4d4f5b29f8adfdf..5cca74cdd034f2d9d01d66a869cc3641c1551338 100644 (file)
@@ -54,6 +54,8 @@ public class ProjectInitializer implements BatchComponent {
         throw new SonarException("Language with key '" + languageKey + "' not found");
       }
       project.setLanguage(language);
+    } else {
+      project.setLanguage(Project.NONE_LANGUAGE);
     }
   }
 }
index 1276c11168a7c060f403d1f2cf318d3a763eb898..1e5e37cae09492a7aa427792d75abd82c1796935 100644 (file)
  */
 package org.sonar.batch.scan.filesystem;
 
-import org.sonar.api.scan.filesystem.InputFile;
+import org.sonar.api.scan.filesystem.InputFileFilter;
 
+import org.sonar.api.scan.filesystem.InputFile;
 import com.google.common.annotations.VisibleForTesting;
-import org.sonar.api.scan.filesystem.internal.InputFileFilter;
 
 import java.util.Collection;
 
index 380f7ca026bb6415092baa5cae7a1436c49687b7..a06718189215cb52287e8e8e928afad6d54684de 100644 (file)
@@ -27,7 +27,12 @@ import org.sonar.api.BatchComponent;
 import org.sonar.api.CoreProperties;
 import org.sonar.api.batch.SonarIndex;
 import org.sonar.api.config.Settings;
-import org.sonar.api.resources.*;
+import org.sonar.api.resources.File;
+import org.sonar.api.resources.Java;
+import org.sonar.api.resources.JavaFile;
+import org.sonar.api.resources.Languages;
+import org.sonar.api.resources.Project;
+import org.sonar.api.resources.Resource;
 import org.sonar.api.scan.filesystem.FileQuery;
 import org.sonar.api.scan.filesystem.InputFile;
 import org.sonar.api.scan.filesystem.internal.DefaultInputFile;
@@ -120,7 +125,7 @@ public class ComponentIndexer implements BatchComponent {
       } else if (moduleLanguages.keys().size() > 1) {
         dto.setLanguage(StringUtils.join(moduleLanguages.keys(), ","));
       } else {
-        dto.setLanguage("none");
+        dto.setLanguage(Project.NONE_LANGUAGE.getKey());
       }
       resourceDao.insertOrUpdate(dto);
     }
index 5ce265370167ef4435e365af8caf761acc9a54b6..146d309268ea46ee8d9429e02539945839f47217 100644 (file)
  */
 package org.sonar.batch.scan.filesystem;
 
-import org.sonar.api.scan.filesystem.internal.DefaultInputFile;
+import org.sonar.api.scan.filesystem.InputFileFilter;
 
+import org.sonar.api.scan.filesystem.internal.DefaultInputFile;
 import org.sonar.api.scan.filesystem.*;
-import org.sonar.api.scan.filesystem.internal.InputFileFilter;
 
 import java.io.File;
 
index 8ce2feff037ec886efac0b3fa2bf30f5f743f76f..27ec3f53f7b7253ac810ce07e694c01a63caf714 100644 (file)
@@ -19,9 +19,9 @@
  */
 package org.sonar.batch.scan.filesystem;
 
-import org.sonar.api.scan.filesystem.InputFile;
+import org.sonar.api.scan.filesystem.InputFileFilter;
 
-import org.sonar.api.scan.filesystem.internal.InputFileFilter;
+import org.sonar.api.scan.filesystem.InputFile;
 
 class ExclusionFilter implements InputFileFilter {
   private final PathPattern pattern;
index 1a0f0a9d08ba88cee04d4c2c4048f09c26c9bc4c..a6af93b12470dabaf60088248f30140e0c7d297e 100644 (file)
@@ -33,11 +33,11 @@ import org.sonar.api.resources.JavaFile;
 import org.sonar.api.resources.Project;
 import org.sonar.api.scan.filesystem.InputDir;
 import org.sonar.api.scan.filesystem.InputFile;
+import org.sonar.api.scan.filesystem.InputFileFilter;
 import org.sonar.api.scan.filesystem.ModuleFileSystem;
 import org.sonar.api.scan.filesystem.PathResolver;
 import org.sonar.api.scan.filesystem.internal.DefaultInputDir;
 import org.sonar.api.scan.filesystem.internal.DefaultInputFile;
-import org.sonar.api.scan.filesystem.internal.InputFileFilter;
 import org.sonar.api.utils.PathUtils;
 import org.sonar.api.utils.SonarException;
 
index 38affb34c3ebe054b7511cda79821ab6baa1333a..e7e5a07396cd23df65410766fc336ccc1a2eefd1 100644 (file)
  */
 package org.sonar.batch.scan.filesystem;
 
-import org.sonar.api.scan.filesystem.InputFile;
+import org.sonar.api.scan.filesystem.InputFileFilter;
 
+import org.sonar.api.scan.filesystem.InputFile;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.Lists;
 import org.sonar.api.scan.filesystem.FileQuery;
-import org.sonar.api.scan.filesystem.internal.InputFileFilter;
 import org.sonar.batch.bootstrap.AnalysisMode;
 
 import java.util.Collection;
index c9fe825027c8e8a97ca2d4b8d8a8ca3cf7b89d69..38b56313cc4aff75606a0fd47b711d5b20052e97 100644 (file)
@@ -19,9 +19,9 @@
  */
 package org.sonar.batch.scan.filesystem;
 
-import org.sonar.api.scan.filesystem.InputFile;
+import org.sonar.api.scan.filesystem.InputFileFilter;
 
-import org.sonar.api.scan.filesystem.internal.InputFileFilter;
+import org.sonar.api.scan.filesystem.InputFile;
 
 class InclusionFilter implements InputFileFilter {
   private final PathPattern pattern;
index 791ec2f251b3f6492c88711c5925205b52fa9442..443f7061f44b4847c656f72cddcc6821ade5fdab 100644 (file)
  */
 package org.sonar.batch.scan.filesystem;
 
-import org.sonar.api.scan.filesystem.InputFile;
+import org.sonar.api.scan.filesystem.InputFileFilter;
 
+import org.sonar.api.scan.filesystem.InputFile;
 import org.junit.Before;
 import org.junit.Test;
 import org.sonar.api.scan.filesystem.FileQuery;
-import org.sonar.api.scan.filesystem.internal.InputFileFilter;
 import org.sonar.batch.bootstrap.AnalysisMode;
 import static org.fest.assertions.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
index 57c4f585c2c7666f7a657ebd102ce0d43509389f..f7445188f6c149dc71fdb34945a91fa731059935 100644 (file)
@@ -243,8 +243,9 @@ public class File extends Resource {
    * Create a File that is partially initialized. But that's enough to call for example
    * {@link SensorContext#saveMeasure(Resource, org.sonar.api.measures.Measure)} when resources are already indexed.
    * Internal use only.
+   * @since 4.2
    */
-  private static File create(String relativePathFromBasedir) {
+  public static File create(String relativePathFromBasedir) {
     File file = new File();
     String normalizedPath = normalize(relativePathFromBasedir);
     file.setKey(normalizedPath);
index e6287d1cf02e56cebd29bd442b3c546178dbfbf3..a4aaf28b34292e39e3db58e1b2d9fbdb7d345312 100644 (file)
@@ -40,6 +40,16 @@ import java.util.List;
  */
 public class Project extends Resource implements Component {
 
+  /**
+   * Internal use
+   */
+  public static final Language NONE_LANGUAGE = new AbstractLanguage("none", "None") {
+    @Override
+    public String[] getFileSuffixes() {
+      return null;
+    }
+  };
+
   private static final String MAVEN_KEY_FORMAT = "%s:%s";
   private static final String BRANCH_KEY_FORMAT = "%s:%s";
 
@@ -239,6 +249,9 @@ public class Project extends Resource implements Component {
     return language;
   }
 
+  /**
+   * Internal use
+   */
   public Project setLanguage(Language language) {
     this.language = language;
     return this;
index 599b7db8595ac19bcd3482703bcf2a8934ae3c57..2eacaf99bb4f2280265a576f24359d79bb81671e 100644 (file)
@@ -31,7 +31,9 @@ import java.io.File;
  * </ul>
  *
  * @since 3.5
+ * @deprecated since 4.2 use {@link InputFileFilter}
  */
+@Deprecated
 public interface FileSystemFilter extends BatchExtension {
 
   /**
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/InputFileFilter.java b/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/InputFileFilter.java
new file mode 100644 (file)
index 0000000..7c58519
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * 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.api.scan.filesystem;
+
+import org.sonar.api.BatchExtension;
+
+/**
+ * Implement this extension to limit the set of files to be analyzed. Global file inclusion/exclusion patterns
+ * are already applied.
+ *
+ * @since 4.2
+ */
+public interface InputFileFilter extends BatchExtension {
+
+  boolean accept(InputFile inputFile);
+
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/internal/InputFileFilter.java b/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/internal/InputFileFilter.java
deleted file mode 100644 (file)
index d9c9adc..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * 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.api.scan.filesystem.internal;
-
-import org.sonar.api.scan.filesystem.InputFile;
-
-import org.sonar.api.BatchExtension;
-
-/**
- * TODO document lifecycle -> executed when initializing project
- *
- * @since 4.0
- */
-public interface InputFileFilter extends BatchExtension {
-
-  boolean accept(InputFile inputFile);
-
-}