From 5e7744ae006b41948359fe60841e8e66701fc5f9 Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Fri, 10 Oct 2014 13:27:20 +0200 Subject: [PATCH] SONAR-5330 Fix issue when source dirs are symbolic links --- .../sonar/batch/bootstrap/TempFolderProvider.java | 2 +- .../batch/mediumtest/fs/FileSystemMediumTest.java | 14 ++++++++++++++ .../mediumtest/xoo/sample-with-symlink/.gitignore | 1 + .../sample-with-symlink/sonar-project.properties | 6 ++++++ .../mediumtest/xoo/sample-with-symlink/testx | 1 + .../mediumtest/xoo/sample-with-symlink/xources | 1 + .../sonar/api/scan/filesystem/PathResolver.java | 3 ++- 7 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 sonar-batch/src/test/resources/mediumtest/xoo/sample-with-symlink/.gitignore create mode 100644 sonar-batch/src/test/resources/mediumtest/xoo/sample-with-symlink/sonar-project.properties create mode 120000 sonar-batch/src/test/resources/mediumtest/xoo/sample-with-symlink/testx create mode 120000 sonar-batch/src/test/resources/mediumtest/xoo/sample-with-symlink/xources 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); } -- 2.39.5