]> source.dussan.org Git - sonarqube.git/commitdiff
Fix ProjectFileSystemAdapter to also returns files that are outside source folders
authorJulien HENRY <julien.henry@sonarsource.com>
Mon, 10 Feb 2014 16:06:04 +0000 (17:06 +0100)
committerJulien HENRY <julien.henry@sonarsource.com>
Mon, 10 Feb 2014 16:07:36 +0000 (17:07 +0100)
sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ProjectFileSystemAdapter.java

index 39c139315c5a3752f22a7ba4ace5af62b3ad3c5d..de2dc83f85cc303401eeafd11f228c73b3527493 100644 (file)
@@ -24,13 +24,19 @@ import com.google.common.collect.Lists;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang.CharEncoding;
 import org.apache.maven.project.MavenProject;
-import org.sonar.api.resources.*;
 import org.sonar.api.resources.InputFile;
+import org.sonar.api.resources.InputFileUtils;
+import org.sonar.api.resources.Java;
+import org.sonar.api.resources.Language;
+import org.sonar.api.resources.Project;
+import org.sonar.api.resources.ProjectFileSystem;
+import org.sonar.api.resources.Resource;
 import org.sonar.api.scan.filesystem.FileQuery;
 import org.sonar.api.scan.filesystem.PathResolver;
 import org.sonar.api.utils.SonarException;
 
 import javax.annotation.Nullable;
+
 import java.io.File;
 import java.io.IOException;
 import java.nio.charset.Charset;
@@ -47,7 +53,6 @@ public class ProjectFileSystemAdapter implements ProjectFileSystem {
   private final PathResolver pathResolver = new PathResolver();
   private final MavenProject pom;
 
-
   public ProjectFileSystemAdapter(DefaultModuleFileSystem target, Project project, @Nullable MavenProject pom) {
     this.target = target;
     this.pom = pom;
@@ -137,7 +142,7 @@ public class ProjectFileSystemAdapter implements ProjectFileSystem {
   public List<File> getSourceFiles(Language... langs) {
     List<File> result = Lists.newArrayList();
     for (Language lang : langs) {
-      result.addAll(target.files(FileQuery.onSource().onLanguage(lang.getKey())));
+      result.addAll(target.files(FileQuery.onMain().onLanguage(lang.getKey())));
     }
     return result;
   }
@@ -186,12 +191,14 @@ public class ProjectFileSystemAdapter implements ProjectFileSystem {
 
   public List<InputFile> mainFiles(String... langs) {
     List<InputFile> result = Lists.newArrayList();
-    Iterable<org.sonar.api.scan.filesystem.InputFile> files = target.inputFiles(FileQuery.onSource().onLanguage(langs));
+    Iterable<org.sonar.api.scan.filesystem.InputFile> files = target.inputFiles(FileQuery.onMain().onLanguage(langs));
     for (org.sonar.api.scan.filesystem.InputFile file : files) {
       String sourceDir = file.attribute(org.sonar.api.scan.filesystem.internal.DefaultInputFile.ATTRIBUTE_SOURCEDIR_PATH);
       String sourceRelativePath = file.attribute(org.sonar.api.scan.filesystem.internal.DefaultInputFile.ATTRIBUTE_SOURCE_RELATIVE_PATH);
       if (sourceDir != null && sourceRelativePath != null) {
         result.add(InputFileUtils.create(new File(sourceDir), sourceRelativePath));
+      } else {
+        result.add(InputFileUtils.create(target.baseDir(), file.path()));
       }
     }
     return result;
@@ -205,6 +212,8 @@ public class ProjectFileSystemAdapter implements ProjectFileSystem {
       String sourceRelativePath = file.attribute(org.sonar.api.scan.filesystem.internal.DefaultInputFile.ATTRIBUTE_SOURCE_RELATIVE_PATH);
       if (sourceDir != null && sourceRelativePath != null) {
         result.add(InputFileUtils.create(new File(sourceDir), sourceRelativePath));
+      } else {
+        result.add(InputFileUtils.create(target.baseDir(), file.path()));
       }
     }
     return result;