diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2013-01-03 11:19:07 +0100 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2013-01-03 18:36:15 +0100 |
commit | bbea8ed02e8503360ac4d1808ec7fe700e5267ec (patch) | |
tree | 9d5bb4c27fa326724301964860ea978dbbbc4a00 | |
parent | 67feeef54e28e7f61fcb4458a7024d7320b79626 (diff) | |
download | sonar-scanner-cli-bbea8ed02e8503360ac4d1808ec7fe700e5267ec.tar.gz sonar-scanner-cli-bbea8ed02e8503360ac4d1808ec7fe700e5267ec.zip |
SONARPLUGINS-1233 Delete the Sonar working/temporary directory before starting analysis
-rw-r--r-- | src/main/java/org/sonar/runner/Runner.java | 11 | ||||
-rw-r--r-- | src/test/java/org/sonar/runner/RunnerTest.java | 18 |
2 files changed, 24 insertions, 5 deletions
diff --git a/src/main/java/org/sonar/runner/Runner.java b/src/main/java/org/sonar/runner/Runner.java index 6cf2d3a..964412e 100644 --- a/src/main/java/org/sonar/runner/Runner.java +++ b/src/main/java/org/sonar/runner/Runner.java @@ -19,6 +19,8 @@ */ package org.sonar.runner; +import org.apache.commons.io.FileUtils; + import java.io.File; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; @@ -167,11 +169,16 @@ public final class Runner { } private File initWorkDir() { + File workDir; String customWorkDir = properties.getProperty(PROPERTY_WORK_DIRECTORY); if (customWorkDir == null || "".equals(customWorkDir.trim())) { - return new File(getProjectDir(), DEF_VALUE_WORK_DIRECTORY); + workDir = new File(getProjectDir(), DEF_VALUE_WORK_DIRECTORY); + } + else { + workDir = defineCustomizedWorkDir(new File(customWorkDir)); } - return defineCustomizedWorkDir(new File(customWorkDir)); + FileUtils.deleteQuietly(workDir); + return workDir; } private File defineCustomizedWorkDir(File customWorkDir) { diff --git a/src/test/java/org/sonar/runner/RunnerTest.java b/src/test/java/org/sonar/runner/RunnerTest.java index 75685cf..d69cef8 100644 --- a/src/test/java/org/sonar/runner/RunnerTest.java +++ b/src/test/java/org/sonar/runner/RunnerTest.java @@ -146,10 +146,22 @@ public class RunnerTest { runner = Runner.create(properties); assertThat(runner.getWorkDir()).isEqualTo(new File(".", "temp-dir").getAbsoluteFile()); - // real asbolute path - properties.setProperty(Runner.PROPERTY_WORK_DIRECTORY, new File("target").getAbsolutePath()); + // real absolute path + properties.setProperty(Runner.PROPERTY_WORK_DIRECTORY, new File("target", "temp-dir2").getAbsolutePath()); runner = Runner.create(properties); - assertThat(runner.getWorkDir()).isEqualTo(new File("target").getAbsoluteFile()); + assertThat(runner.getWorkDir()).isEqualTo(new File("target", "temp-dir2").getAbsoluteFile()); + } + + @Test + public void shouldDeleteWorkingDirectory() { + Properties properties = new Properties(); + File workDir = new File("target", "temp-dir-should-be-deleted"); + workDir.mkdirs(); + assertThat(workDir.exists()).isTrue(); + // real absolute path + properties.setProperty(Runner.PROPERTY_WORK_DIRECTORY, workDir.getAbsolutePath()); + Runner.create(properties); + assertThat(workDir.exists()).isFalse(); } @Test |