aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvgeny Mandrikov <mandrikov@gmail.com>2011-04-27 15:39:59 +0400
committerEvgeny Mandrikov <mandrikov@gmail.com>2011-04-27 15:40:08 +0400
commit70c03e6ac1e0f24277655f9e7666142d9418d270 (patch)
tree5ed11a7c494df28a3da19f1354e04eda14760a76
parent91b014e384b0c4d776c807cbd27dc92a70e708d3 (diff)
downloadsonarqube-70c03e6ac1e0f24277655f9e7666142d9418d270.tar.gz
sonarqube-70c03e6ac1e0f24277655f9e7666142d9418d270.zip
SONAR-2266 ProjectFileSystem should return only existing source and test directories
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/DefaultProjectFileSystem2.java14
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/resources/DefaultProjectFileSystem.java14
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/resources/ProjectFileSystem.java4
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/resources/DefaultProjectFileSystemTest.java12
-rw-r--r--sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/nonexistent-dirs/pom.xml8
-rw-r--r--sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/nonexistent-dirs/src/main/java0
6 files changed, 44 insertions, 8 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/DefaultProjectFileSystem2.java b/sonar-batch/src/main/java/org/sonar/batch/DefaultProjectFileSystem2.java
index 1270074570c..00c85b67ccb 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/DefaultProjectFileSystem2.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/DefaultProjectFileSystem2.java
@@ -19,6 +19,8 @@
*/
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;
@@ -83,12 +85,14 @@ public class DefaultProjectFileSystem2 extends 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));
}
/**
@@ -111,12 +115,14 @@ public class DefaultProjectFileSystem2 extends DefaultProjectFileSystem {
* 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));
}
/**
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/DefaultProjectFileSystem.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/DefaultProjectFileSystem.java
index 6b3737ac39d..40a0915ce48 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/DefaultProjectFileSystem.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/DefaultProjectFileSystem.java
@@ -19,6 +19,9 @@
*/
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;
@@ -48,6 +51,13 @@ import java.util.List;
@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();
@@ -92,7 +102,7 @@ public class DefaultProjectFileSystem implements ProjectFileSystem {
* 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));
}
/**
@@ -111,7 +121,7 @@ public class DefaultProjectFileSystem implements ProjectFileSystem {
* 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));
}
/**
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/ProjectFileSystem.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/ProjectFileSystem.java
index c6840a40c91..60022bbe72b 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/ProjectFileSystem.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/ProjectFileSystem.java
@@ -53,7 +53,7 @@ public interface ProjectFileSystem extends BatchComponent {
File getBuildOutputDir();
/**
- * The list of directories for sources
+ * The list of existing directories with sources
*/
List<File> getSourceDirs();
@@ -68,7 +68,7 @@ public interface ProjectFileSystem extends BatchComponent {
ProjectFileSystem addSourceDir(File dir);
/**
- * The list of directories for tests
+ * The list of existing directories with tests
*/
List<File> getTestDirs();
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/resources/DefaultProjectFileSystemTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/resources/DefaultProjectFileSystemTest.java
index 72e88d2979e..a867392245b 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/resources/DefaultProjectFileSystemTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/resources/DefaultProjectFileSystemTest.java
@@ -50,6 +50,18 @@ public class DefaultProjectFileSystemTest {
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);
diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/nonexistent-dirs/pom.xml b/sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/nonexistent-dirs/pom.xml
new file mode 100644
index 00000000000..f219368e824
--- /dev/null
+++ b/sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/nonexistent-dirs/pom.xml
@@ -0,0 +1,8 @@
+<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
diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/nonexistent-dirs/src/main/java b/sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/nonexistent-dirs/src/main/java
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sonar-plugin-api/src/test/resources/org/sonar/api/resources/DefaultProjectFileSystemTest/nonexistent-dirs/src/main/java