From ce227110b0670bd0df0485fdced7b8758e5b1f67 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Fri, 21 Feb 2014 17:10:55 +0100 Subject: [PATCH] SONAR-926 Fix org.sonar.api.resources.InputFile#getRelativePath() Contrary to org.sonar.api.batch.fs.InputFile#relativePath(), it's the path relative to source dir --- .../org/sonar/api/batch/fs/internal/DefaultInputFile.java | 3 ++- .../sonar/api/batch/fs/internal/DefaultInputFileTest.java | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java index 226a975765c..63e3c9ec01d 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java @@ -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 diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputFileTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputFileTest.java index afbc74f2928..ff77bfe2565 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputFileTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputFileTest.java @@ -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(); -- 2.39.5