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() {
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