diff options
-rw-r--r-- | src/main/java/org/sonar/runner/Runner.java | 17 | ||||
-rw-r--r-- | src/test/java/org/sonar/runner/RunnerTest.java | 11 |
2 files changed, 27 insertions, 1 deletions
diff --git a/src/main/java/org/sonar/runner/Runner.java b/src/main/java/org/sonar/runner/Runner.java index 60b6a45..1a51496 100644 --- a/src/main/java/org/sonar/runner/Runner.java +++ b/src/main/java/org/sonar/runner/Runner.java @@ -109,7 +109,22 @@ public final class Runner { if (!projectDir.isDirectory() || !projectDir.exists()) { throw new IllegalArgumentException("Project home must be an existing directory: " + path); } - workDir = new File(projectDir, properties.getProperty(PROPERTY_WORK_DIRECTORY, DEF_VALUE_WORK_DIRECTORY)); + workDir = initWorkDir(); + } + + private File initWorkDir() { + String customWorkDir = properties.getProperty(PROPERTY_WORK_DIRECTORY); + if (customWorkDir == null || customWorkDir.trim().length() == 0) { + return new File(projectDir, DEF_VALUE_WORK_DIRECTORY); + } + return defineCustomizedWorkDir(new File(customWorkDir)); + } + + private File defineCustomizedWorkDir(File customWorkDir) { + if (customWorkDir.isAbsolute()) { + return customWorkDir; + } + return new File(projectDir, customWorkDir.getPath()); } public File getProjectDir() { diff --git a/src/test/java/org/sonar/runner/RunnerTest.java b/src/test/java/org/sonar/runner/RunnerTest.java index c0495fc..877e85d 100644 --- a/src/test/java/org/sonar/runner/RunnerTest.java +++ b/src/test/java/org/sonar/runner/RunnerTest.java @@ -153,9 +153,20 @@ public class RunnerTest { Runner runner = Runner.create(properties); assertThat(runner.getWorkDir()).isEqualTo(new File(".", ".sonar")); + // empty string + properties.setProperty(Runner.PROPERTY_WORK_DIRECTORY, " "); + runner = Runner.create(properties); + assertThat(runner.getWorkDir()).isEqualTo(new File(".", ".sonar")); + + // real relative path properties.setProperty(Runner.PROPERTY_WORK_DIRECTORY, "temp-dir"); runner = Runner.create(properties); assertThat(runner.getWorkDir()).isEqualTo(new File(".", "temp-dir")); + + // real asbolute path + properties.setProperty(Runner.PROPERTY_WORK_DIRECTORY, new File("target").getAbsolutePath()); + runner = Runner.create(properties); + assertThat(runner.getWorkDir()).isEqualTo(new File("target").getAbsoluteFile()); } @Test |