aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2014-10-10 13:27:20 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2014-10-14 11:59:58 +0200
commit5e7744ae006b41948359fe60841e8e66701fc5f9 (patch)
treefecb72b1730957c41b58e5bdb6d83d206ed265d6
parent0d2a019b933e3a90de9c8365bfa4037b9d44d943 (diff)
downloadsonarqube-5e7744ae006b41948359fe60841e8e66701fc5f9.tar.gz
sonarqube-5e7744ae006b41948359fe60841e8e66701fc5f9.zip
SONAR-5330 Fix issue when source dirs are symbolic links
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/TempFolderProvider.java2
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/FileSystemMediumTest.java14
-rw-r--r--sonar-batch/src/test/resources/mediumtest/xoo/sample-with-symlink/.gitignore1
-rw-r--r--sonar-batch/src/test/resources/mediumtest/xoo/sample-with-symlink/sonar-project.properties6
l---------sonar-batch/src/test/resources/mediumtest/xoo/sample-with-symlink/testx1
l---------sonar-batch/src/test/resources/mediumtest/xoo/sample-with-symlink/xources1
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/PathResolver.java3
7 files changed, 26 insertions, 2 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/TempFolderProvider.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/TempFolderProvider.java
index fbf973640ed..b665d9d3279 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/TempFolderProvider.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/TempFolderProvider.java
@@ -36,7 +36,7 @@ public class TempFolderProvider extends ProviderAdapter {
public TempFolder provide(BootstrapProperties bootstrapProps) {
if (tempFolder == null) {
String workingDirPath = StringUtils.defaultIfBlank(bootstrapProps.property(CoreProperties.WORKING_DIRECTORY), CoreProperties.WORKING_DIRECTORY_DEFAULT_VALUE);
- File workingDir = new File(workingDirPath);
+ File workingDir = new File(workingDirPath).getAbsoluteFile();
File tempDir = new File(workingDir, ".sonartmp");
try {
FileUtils.forceMkdir(tempDir);
diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/FileSystemMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/FileSystemMediumTest.java
index 19d7aea020a..0d171bcfc09 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/FileSystemMediumTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/FileSystemMediumTest.java
@@ -29,6 +29,7 @@ import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.utils.MessageException;
+import org.sonar.api.utils.System2;
import org.sonar.batch.mediumtest.BatchMediumTester;
import org.sonar.batch.mediumtest.BatchMediumTester.TaskResult;
import org.sonar.batch.protocol.input.ActiveRule;
@@ -38,6 +39,7 @@ import java.io.File;
import java.io.IOException;
import static org.fest.assertions.Assertions.assertThat;
+import static org.junit.Assume.assumeFalse;
public class FileSystemMediumTest {
@@ -169,4 +171,16 @@ public class FileSystemMediumTest {
}
+ // SONAR-5330
+ @Test
+ public void scanProjectWithSourceSymlink() throws Exception {
+ assumeFalse(System2.INSTANCE.isOsWindows());
+ File projectDir = new File("src/test/resources/mediumtest/xoo/sample-with-symlink");
+ TaskResult result = tester
+ .newScanTask(new File(projectDir, "sonar-project.properties"))
+ .start();
+
+ assertThat(result.inputFiles()).hasSize(3);
+ }
+
}
diff --git a/sonar-batch/src/test/resources/mediumtest/xoo/sample-with-symlink/.gitignore b/sonar-batch/src/test/resources/mediumtest/xoo/sample-with-symlink/.gitignore
new file mode 100644
index 00000000000..ecbefd4f19d
--- /dev/null
+++ b/sonar-batch/src/test/resources/mediumtest/xoo/sample-with-symlink/.gitignore
@@ -0,0 +1 @@
+.sonar
diff --git a/sonar-batch/src/test/resources/mediumtest/xoo/sample-with-symlink/sonar-project.properties b/sonar-batch/src/test/resources/mediumtest/xoo/sample-with-symlink/sonar-project.properties
new file mode 100644
index 00000000000..8810e376701
--- /dev/null
+++ b/sonar-batch/src/test/resources/mediumtest/xoo/sample-with-symlink/sonar-project.properties
@@ -0,0 +1,6 @@
+sonar.projectKey=sample
+sonar.projectName=Sample
+sonar.projectVersion=0.1-SNAPSHOT
+sonar.sources=xources
+sonar.tests=testx
+sonar.language=xoo
diff --git a/sonar-batch/src/test/resources/mediumtest/xoo/sample-with-symlink/testx b/sonar-batch/src/test/resources/mediumtest/xoo/sample-with-symlink/testx
new file mode 120000
index 00000000000..7385ebd51cf
--- /dev/null
+++ b/sonar-batch/src/test/resources/mediumtest/xoo/sample-with-symlink/testx
@@ -0,0 +1 @@
+../sample/testx/ \ No newline at end of file
diff --git a/sonar-batch/src/test/resources/mediumtest/xoo/sample-with-symlink/xources b/sonar-batch/src/test/resources/mediumtest/xoo/sample-with-symlink/xources
new file mode 120000
index 00000000000..15dca9d90d2
--- /dev/null
+++ b/sonar-batch/src/test/resources/mediumtest/xoo/sample-with-symlink/xources
@@ -0,0 +1 @@
+../sample/xources/ \ No newline at end of file
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/PathResolver.java b/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/PathResolver.java
index 1dbaeaeca11..6da18e4a049 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/PathResolver.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/PathResolver.java
@@ -26,6 +26,7 @@ import org.sonar.api.BatchComponent;
import org.sonar.api.utils.PathUtils;
import javax.annotation.CheckForNull;
+
import java.io.File;
import java.util.Collection;
import java.util.List;
@@ -40,7 +41,7 @@ public class PathResolver implements BatchComponent {
File file = new File(path);
if (!file.isAbsolute()) {
try {
- file = new File(dir, path).getCanonicalFile();
+ file = new File(dir, path).getAbsoluteFile();
} catch (Exception e) {
throw new IllegalStateException("Fail to resolve path '" + path + "' relative to: " + dir.getAbsolutePath(), e);
}