*/
package org.sonar.batch;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterables;
import org.apache.commons.io.FileUtils;
import org.apache.maven.project.MavenProject;
import org.sonar.api.resources.DefaultProjectFileSystem;
}
public List<File> getSourceDirs() {
+ List<File> unfiltered;
if (pom != null) {
// Maven can modify source directories during Sonar execution - see MavenPhaseExecutor.
- return resolvePaths(pom.getCompileSourceRoots());
+ unfiltered = resolvePaths(pom.getCompileSourceRoots());
} else {
- return resolvePaths(def.getSourceDirs());
+ unfiltered = resolvePaths(def.getSourceDirs());
}
+ return ImmutableList.copyOf(Iterables.filter(unfiltered, DIRECTORY_EXISTS));
}
/**
* Maven can modify test directories during Sonar execution - see MavenPhaseExecutor.
*/
public List<File> getTestDirs() {
+ List<File> unfiltered;
if (pom != null) {
// Maven can modify test directories during Sonar execution - see MavenPhaseExecutor.
- return resolvePaths(pom.getTestCompileSourceRoots());
+ unfiltered = resolvePaths(pom.getTestCompileSourceRoots());
} else {
- return resolvePaths(def.getTestDirs());
+ unfiltered = resolvePaths(def.getTestDirs());
}
+ return ImmutableList.copyOf(Iterables.filter(unfiltered, DIRECTORY_EXISTS));
}
/**
*/
package org.sonar.api.resources;
+import com.google.common.base.Predicate;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
@Deprecated
public class DefaultProjectFileSystem implements ProjectFileSystem {
+ protected static final Predicate<File> DIRECTORY_EXISTS = new Predicate<File>() {
+ public boolean apply(File input) {
+ System.out.println(input.toString() + " " + input.exists());
+ return input.exists() && input.isDirectory();
+ }
+ };
+
private Project project;
private Languages languages;
private List<IOFileFilter> filters = Lists.newArrayList();
* Maven can modify source directories during Sonar execution - see MavenPhaseExecutor.
*/
public List<File> getSourceDirs() {
- return resolvePaths(project.getPom().getCompileSourceRoots());
+ return ImmutableList.copyOf(Iterables.filter(resolvePaths(project.getPom().getCompileSourceRoots()), DIRECTORY_EXISTS));
}
/**
* Maven can modify test directories during Sonar execution - see MavenPhaseExecutor.
*/
public List<File> getTestDirs() {
- return resolvePaths(project.getPom().getTestCompileSourceRoots());
+ return ImmutableList.copyOf(Iterables.filter(resolvePaths(project.getPom().getTestCompileSourceRoots()), DIRECTORY_EXISTS));
}
/**
File getBuildOutputDir();
/**
- * The list of directories for sources
+ * The list of existing directories with sources
*/
List<File> getSourceDirs();
ProjectFileSystem addSourceDir(File dir);
/**
- * The list of directories for tests
+ * The list of existing directories with tests
*/
List<File> getTestDirs();
project = MavenTestUtils.loadProjectFromPom(DefaultProjectFileSystemTest.class, "sample/pom.xml");
}
+ /**
+ * See http://jira.codehaus.org/browse/SONAR-2266
+ */
+ @Test
+ public void shouldReturnOnlyExistingSourceAndTestDirectories() {
+ // in this example : "src/main/java" is a file, "src/test/java" doesn't exists
+ project = MavenTestUtils.loadProjectFromPom(DefaultProjectFileSystemTest.class, "nonexistent-dirs/pom.xml");
+ DefaultProjectFileSystem fs = newDefaultProjectFileSystem(project);
+ assertThat(fs.getSourceDirs().size(), is(0));
+ assertThat(fs.getTestDirs().size(), is(0));
+ }
+
@Test
public void getJavaSourceFiles() {
final DefaultProjectFileSystem fs = newDefaultProjectFileSystem(project);
--- /dev/null
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>foo</groupId>
+ <artifactId>foo</artifactId>
+ <packaging>jar</packaging>
+
+</project>
\ No newline at end of file