]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-926 Fix org.sonar.api.resources.InputFile#getRelativePath()
authorSimon Brandhof <simon.brandhof@gmail.com>
Fri, 21 Feb 2014 16:10:55 +0000 (17:10 +0100)
committerSimon Brandhof <simon.brandhof@gmail.com>
Fri, 21 Feb 2014 16:11:07 +0000 (17:11 +0100)
Contrary to org.sonar.api.batch.fs.InputFile#relativePath(), it's the path relative to source dir

sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java
sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputFileTest.java

index 226a975765c0024d922649daea69d4ca011c09ad..63e3c9ec01d5021110c7dcc9e2fbf31faf0b41bf 100644 (file)
@@ -20,6 +20,7 @@
 package org.sonar.api.batch.fs.internal;
 
 import org.apache.commons.io.FilenameUtils;
+import org.apache.commons.lang.StringUtils;
 import org.sonar.api.batch.fs.InputFile;
 import org.sonar.api.utils.PathUtils;
 
@@ -239,7 +240,7 @@ public class DefaultInputFile implements InputFile, org.sonar.api.resources.Inpu
   @Deprecated
   @Override
   public String getRelativePath() {
-    return relativePath();
+    return pathRelativeToSourceDir;
   }
 
   @Override
index afbc74f29286d446fa9f4417ff78e3ce5a7add1d..ff77bfe256576a7b36dd87259e8adebd0edb808b 100644 (file)
@@ -43,10 +43,12 @@ public class DefaultInputFileTest {
       .setLines(42)
       .setLanguage("php")
       .setStatus(InputFile.Status.ADDED)
-      .setType(InputFile.Type.TEST);
+      .setType(InputFile.Type.TEST)
+      .setPathRelativeToSourceDir("Foo.php");
 
     assertThat(inputFile.relativePath()).isEqualTo("src/Foo.php");
-    assertThat(inputFile.getRelativePath()).isEqualTo("src/Foo.php");
+    // deprecated method is different -> path relative to source dir
+    assertThat(inputFile.getRelativePath()).isEqualTo("Foo.php");
     assertThat(new File(inputFile.relativePath())).isRelative();
     assertThat(inputFile.absolutePath()).endsWith("Foo.php");
     assertThat(new File(inputFile.absolutePath())).isAbsolute();