diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2015-06-23 16:50:53 +0200 |
---|---|---|
committer | Duarte Meneses <duarte.meneses@sonarsource.com> | 2015-06-23 16:50:53 +0200 |
commit | 6e07e1bdf4af1e4a5449a502b07271d35cc61085 (patch) | |
tree | 15bcb19ba78a794861a13e93746b746d68b2b980 | |
parent | 272a81d0cfed6dc0121b0c8e27bf91a2a486e68a (diff) | |
download | sonarqube-6e07e1bdf4af1e4a5449a502b07271d35cc61085.tar.gz sonarqube-6e07e1bdf4af1e4a5449a502b07271d35cc61085.zip |
Fix project temp folder
-rw-r--r-- | sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectTempFolderProvider.java | 22 | ||||
-rw-r--r-- | sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectTempFolderProviderTest.java | 7 |
2 files changed, 22 insertions, 7 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectTempFolderProvider.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectTempFolderProvider.java index bcaf8ec8666..5e2cf79e97e 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectTempFolderProvider.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectTempFolderProvider.java @@ -33,11 +33,17 @@ public class ProjectTempFolderProvider extends LifecycleProviderAdapter { static final String TMP_NAME = ".sonartmp"; private DefaultTempFolder projectTempFolder; - public TempFolder provide(BootstrapProperties bootstrapProps) { + public TempFolder provide(AnalysisProperties props) { if (projectTempFolder == null) { - String workingDirPath = StringUtils.defaultIfBlank(bootstrapProps.property(CoreProperties.WORKING_DIRECTORY), CoreProperties.WORKING_DIRECTORY_DEFAULT_VALUE); - Path workingDir = Paths.get(workingDirPath); - Path tempDir = workingDir.resolve(TMP_NAME).normalize(); + String workingDirPath = StringUtils.defaultIfBlank(props.property(CoreProperties.WORKING_DIRECTORY), CoreProperties.WORKING_DIRECTORY_DEFAULT_VALUE); + Path workingDir = Paths.get(workingDirPath).normalize(); + + if(!workingDir.isAbsolute()) { + Path base = getBasePath(props); + workingDir = base.resolve(workingDir); + } + + Path tempDir = workingDir.resolve(TMP_NAME); try { Files.createDirectories(tempDir); } catch (IOException e) { @@ -48,4 +54,12 @@ public class ProjectTempFolderProvider extends LifecycleProviderAdapter { } return projectTempFolder; } + + private Path getBasePath(AnalysisProperties props) { + String baseDir = props.property("sonar.projectBaseDir"); + if(baseDir == null) { + throw new IllegalStateException("sonar.projectBaseDir needs to be specified"); + } + return Paths.get(baseDir); + } } diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectTempFolderProviderTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectTempFolderProviderTest.java index 2b7a0435240..d92b32d8f30 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectTempFolderProviderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectTempFolderProviderTest.java @@ -46,7 +46,7 @@ public class ProjectTempFolderProviderTest { File workingDir = temp.newFolder(); File tmpDir = new File(workingDir, ProjectTempFolderProvider.TMP_NAME); - TempFolder tempFolder = tempFolderProvider.provide(new BootstrapProperties(ImmutableMap.of(CoreProperties.WORKING_DIRECTORY, workingDir.getAbsolutePath()))); + TempFolder tempFolder = tempFolderProvider.provide(new AnalysisProperties(ImmutableMap.of(CoreProperties.WORKING_DIRECTORY, workingDir.getAbsolutePath()), "")); tempFolder.newDir(); tempFolder.newFile(); assertThat(tmpDir).exists(); @@ -55,10 +55,11 @@ public class ProjectTempFolderProviderTest { @Test public void createTempFolder() throws IOException { - File defaultDir = new File(CoreProperties.WORKING_DIRECTORY_DEFAULT_VALUE, ProjectTempFolderProvider.TMP_NAME); + File workingDir = temp.newFolder(); + File defaultDir = new File(new File(workingDir, CoreProperties.WORKING_DIRECTORY_DEFAULT_VALUE), ProjectTempFolderProvider.TMP_NAME); try { - TempFolder tempFolder = tempFolderProvider.provide(new BootstrapProperties(Collections.<String, String>emptyMap())); + TempFolder tempFolder = tempFolderProvider.provide(new AnalysisProperties(ImmutableMap.of("sonar.projectBaseDir", workingDir.getAbsolutePath()), "")); tempFolder.newDir(); tempFolder.newFile(); assertThat(defaultDir).exists(); |