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;
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;
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;
}
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;
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;