diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2017-08-02 13:51:17 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2017-08-04 14:58:16 +0200 |
commit | 343758acd64fd2318a35c5f55c6511cf8b2f6467 (patch) | |
tree | e43a20a33651b7aa3e9896d0acc8054ebba9d46d /sonar-scanner-engine | |
parent | bcae3c079bef995afef0ffc4dbe774fbdf0bf9ed (diff) | |
download | sonarqube-343758acd64fd2318a35c5f55c6511cf8b2f6467.tar.gz sonarqube-343758acd64fd2318a35c5f55c6511cf8b2f6467.zip |
Don't change PathResolver methods to static
This is an API breaking change
Diffstat (limited to 'sonar-scanner-engine')
4 files changed, 11 insertions, 12 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/DefaultInputModuleHierarchy.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/DefaultInputModuleHierarchy.java index 915504ba16c..4aeb1c4ffc1 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/DefaultInputModuleHierarchy.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/DefaultInputModuleHierarchy.java @@ -110,6 +110,6 @@ public class DefaultInputModuleHierarchy implements InputModuleHierarchy { Path parentBaseDir = parent.getBaseDir(); Path moduleBaseDir = inputModule.getBaseDir(); - return PathResolver.relativePath(parentBaseDir, moduleBaseDir); + return PathResolver.relativize(parentBaseDir, moduleBaseDir).orElse(null); } } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileIndexer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileIndexer.java index ea2b20fc4bc..09f774a0d32 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileIndexer.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileIndexer.java @@ -191,11 +191,8 @@ public class FileIndexer { private String getParentRelativePath(Path filePath) { Path parentDir = filePath.getParent(); - String relativePath = PathResolver.relativePath(module.getBaseDir(), parentDir); - if (relativePath == null) { - throw new IllegalStateException("Failed to compute relative path of file: " + parentDir); - } - return relativePath; + return PathResolver.relativize(module.getBaseDir(), parentDir) + .orElseThrow(() -> new IllegalStateException("Failed to compute relative path of file: " + parentDir)); } private void indexFileAndParentDir(InputFile inputFile, String parentRelativePath) { diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/InputComponentStore.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/InputComponentStore.java index ee1b34a8d95..cc9c3b34123 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/InputComponentStore.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/InputComponentStore.java @@ -149,7 +149,7 @@ public class InputComponentStore { } private String getProjectRelativePath(DefaultInputDir dir) { - return PathResolver.relativePath(getProjectBaseDir(), dir.path()); + return PathResolver.relativize(getProjectBaseDir(), dir.path()).orElseThrow(() -> new IllegalStateException("Dir " + dir.path() + " should be relative to project baseDir")); } private Path getProjectBaseDir() { diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ModuleFileSystemInitializer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ModuleFileSystemInitializer.java index f5828172008..8a3c2893dc6 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ModuleFileSystemInitializer.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ModuleFileSystemInitializer.java @@ -26,6 +26,7 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Locale; +import java.util.Optional; import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; import org.apache.commons.lang.StringUtils; @@ -59,10 +60,11 @@ public class ModuleFileSystemInitializer { private static List<Path> initSources(ProjectDefinition module, Path baseDir, String propertyKey, String logLabel) { List<Path> result = new ArrayList<>(); + PathResolver pathResolver = new PathResolver(); String srcPropValue = module.properties().get(propertyKey); if (srcPropValue != null) { for (String sourcePath : parseAsCsv(propertyKey, srcPropValue)) { - File dirOrFile = PathResolver.relativeFile(module.getBaseDir(), sourcePath); + File dirOrFile = pathResolver.relativeFile(module.getBaseDir(), sourcePath); if (dirOrFile.exists()) { result.add(dirOrFile.toPath()); } @@ -102,13 +104,13 @@ public class ModuleFileSystemInitializer { StringBuilder sb = new StringBuilder(label); for (Iterator<Path> it = paths.iterator(); it.hasNext();) { Path file = it.next(); - String relativePathToBaseDir = PathResolver.relativePath(baseDir, file); - if (relativePathToBaseDir == null) { + Optional<String> relativePathToBaseDir = PathResolver.relativize(baseDir, file); + if (!relativePathToBaseDir.isPresent()) { sb.append(file); - } else if (StringUtils.isBlank(relativePathToBaseDir)) { + } else if (StringUtils.isBlank(relativePathToBaseDir.get())) { sb.append("."); } else { - sb.append(relativePathToBaseDir); + sb.append(relativePathToBaseDir.get()); } if (it.hasNext()) { sb.append(", "); |