*/
@Deprecated
public static final String DEBUG_MODE = "runner.debug";
-
+
/**
* @since 1.2
*/
- public static final String VERBOSE = "sonar.verbose";
+ public static final String PROPERTY_VERBOSE = "sonar.verbose";
+
+ /**
+ * @since 1.4
+ */
+ public static final String PROPERTY_WORK_DIRECTORY = "sonar.working.directory";
+ public static final String DEF_VALUE_WORK_DIRECTORY = ".sonar";
/**
* Array of prefixes of versions of Sonar without support of this runner.
*/
- private static final String[] UNSUPPORTED_VERSIONS = { "1", "2.0", "2.1", "2.2", "2.3", "2.4", "2.5" };
+ private static final String[] UNSUPPORTED_VERSIONS = {"1", "2.0", "2.1", "2.2", "2.3", "2.4", "2.5"};
/**
* Array of all mandatory properties required to execute runner.
*/
- private static final String[] MANDATORY_PROPERTIES = { "sonar.projectKey", "sonar.projectName", "sonar.projectVersion", "sources" };
+ private static final String[] MANDATORY_PROPERTIES = {"sonar.projectKey", "sonar.projectName", "sonar.projectVersion", "sources"};
private File projectDir;
private File workDir;
if (!projectDir.isDirectory() || !projectDir.exists()) {
throw new IllegalArgumentException("Project home must be an existing directory: " + path);
}
- workDir = new File(projectDir, ".sonar");
+ workDir = new File(projectDir, properties.getProperty(PROPERTY_WORK_DIRECTORY, DEF_VALUE_WORK_DIRECTORY));
}
public File getProjectDir() {
}
public boolean isDebug() {
- return Boolean.parseBoolean(properties.getProperty(VERBOSE, properties.getProperty(DEBUG_MODE, "false")));
+ return Boolean.parseBoolean(properties.getProperty(PROPERTY_VERBOSE, properties.getProperty(DEBUG_MODE, "false")));
}
public String getRunnerVersion() {
String serverVersion = bootstrapper.getServerVersion();
if (isUnsupportedVersion(serverVersion)) {
throw new BootstrapException("Sonar " + serverVersion
- + " does not support Standalone Runner. Please upgrade Sonar to version 2.6 or more.");
+ + " does not support Standalone Runner. Please upgrade Sonar to version 2.6 or more.");
}
}
private BootstrapClassLoader createClassLoader(Bootstrapper bootstrapper) {
URL url = Main.class.getProtectionDomain().getCodeSource().getLocation();
return bootstrapper.createClassLoader(
- new URL[]{url}, // Add JAR with Sonar Runner - it's a Jar which contains this class
+ new URL[] {url}, // Add JAR with Sonar Runner - it's a Jar which contains this class
getClass().getClassLoader());
}
@Test
public void shouldEnableDebugMode() {
Properties props = Main.parseArguments(new String[] { "-X" });
- assertThat(props.getProperty(Runner.VERBOSE), is("true"));
+ assertThat(props.getProperty(Runner.PROPERTY_VERBOSE), is("true"));
}
@Test
public void shouldDisableDebugModeByDefault() {
Properties props = Main.parseArguments(new String[] {});
- assertThat(props.getProperty(Runner.VERBOSE), nullValue());
+ assertThat(props.getProperty(Runner.PROPERTY_VERBOSE), nullValue());
}
@Test
package org.sonar.runner;
+import org.junit.Test;
+
+import java.io.File;
+import java.util.Properties;
+
+import static org.fest.assertions.Assertions.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
-import java.io.File;
-import java.util.Properties;
-
-import org.junit.Test;
-
public class RunnerTest {
@Test
Properties properties = new Properties();
Runner runner = Runner.create(properties);
assertThat("Default value", runner.isDebug(), is(false));
- properties.setProperty(Runner.VERBOSE, "true");
+ properties.setProperty(Runner.PROPERTY_VERBOSE, "true");
assertThat(runner.isDebug(), is(true));
}
assertThat(runner.getProjectDir().exists(), is(true));
}
+ @Test
+ public void shouldSpecifyWorkingDirectory() {
+ Properties properties = new Properties();
+ Runner runner = Runner.create(properties);
+ assertThat(runner.getWorkDir()).isEqualTo(new File(".", ".sonar"));
+
+ properties.setProperty(Runner.PROPERTY_WORK_DIRECTORY, "temp-dir");
+ runner = Runner.create(properties);
+ assertThat(runner.getWorkDir()).isEqualTo(new File(".", "temp-dir"));
+ }
+
}