]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5330 Fix issue when source dirs are symbolic links
authorJulien HENRY <julien.henry@sonarsource.com>
Fri, 10 Oct 2014 11:27:20 +0000 (13:27 +0200)
committerJulien HENRY <julien.henry@sonarsource.com>
Tue, 14 Oct 2014 09:59:58 +0000 (11:59 +0200)
sonar-batch/src/main/java/org/sonar/batch/bootstrap/TempFolderProvider.java
sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/FileSystemMediumTest.java
sonar-batch/src/test/resources/mediumtest/xoo/sample-with-symlink/.gitignore [new file with mode: 0644]
sonar-batch/src/test/resources/mediumtest/xoo/sample-with-symlink/sonar-project.properties [new file with mode: 0644]
sonar-batch/src/test/resources/mediumtest/xoo/sample-with-symlink/testx [new symlink]
sonar-batch/src/test/resources/mediumtest/xoo/sample-with-symlink/xources [new symlink]
sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/PathResolver.java

index fbf973640ed2ab31ab6c6fcfefc6e56fea52d0d2..b665d9d32796e602a4a2f88bf137203fce4b952c 100644 (file)
@@ -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);
index 19d7aea020a8f0d9fe46f3f9cbb9f4ea15be2f72..0d171bcfc098f96ceaf5bd3a684831de5d67555a 100644 (file)
@@ -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 (file)
index 0000000..ecbefd4
--- /dev/null
@@ -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 (file)
index 0000000..8810e37
--- /dev/null
@@ -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 (symlink)
index 0000000..7385ebd
--- /dev/null
@@ -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 (symlink)
index 0000000..15dca9d
--- /dev/null
@@ -0,0 +1 @@
+../sample/xources/
\ No newline at end of file
index 1dbaeaeca110b35eac75146db22e3f8f06ea7aba..6da18e4a04902fc84bac8e569ae085354ca0b082 100644 (file)
@@ -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);
       }