]> source.dussan.org Git - sonar-scanner-cli.git/commitdiff
SONARPLUGINS-1230 Configure the location of working directory
authorFabrice Bellingard <bellingard@gmail.com>
Thu, 19 Jul 2012 14:39:01 +0000 (14:39 +0000)
committerFabrice Bellingard <bellingard@gmail.com>
Thu, 19 Jul 2012 14:39:01 +0000 (14:39 +0000)
pom.xml
src/main/java/org/sonar/runner/Main.java
src/main/java/org/sonar/runner/Runner.java
src/test/java/org/sonar/runner/MainTest.java
src/test/java/org/sonar/runner/RunnerTest.java

diff --git a/pom.xml b/pom.xml
index 1953a11590fe5137fbb5cf8cbc2bbf0685904e94..91e9404c37883f91688681f8d48fd59ba8e60ce8 100644 (file)
--- a/pom.xml
+++ b/pom.xml
       <version>${sonar.buildVersion}</version>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.easytesting</groupId>
+      <artifactId>fest-assert</artifactId>
+      <version>1.4</version>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
   <build>
index 009bf0e0cf0bee7e124e0bc9261adaad4aa70b86..aedfc8ae54e3a2da48ff56d940fc8e96e1d2913c 100644 (file)
@@ -170,7 +170,7 @@ public final class Main {
         printUsage();
 
       } else if ("-X".equals(arg) || "--debug".equals(arg)) {
-        props.setProperty(Runner.VERBOSE, "true");
+        props.setProperty(Runner.PROPERTY_VERBOSE, "true");
         debugMode = true;
 
       } else if ("-D".equals(arg) || "--define".equals(arg)) {
index 65fdaf3ac4fe2f55621b32670291a119835512df..b4cb17ee28a262e895a2008b409138db3ff52b97 100644 (file)
@@ -42,21 +42,27 @@ public final class Runner {
    */
   @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;
@@ -103,7 +109,7 @@ public final class Runner {
     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() {
@@ -125,7 +131,7 @@ public final class Runner {
   }
 
   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() {
@@ -146,14 +152,14 @@ public final class Runner {
     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());
   }
 
index ab324cbd40432b816e759249801782c39851a483..36960913e3d4ca29b8c0a3cd114d26961e704687 100644 (file)
@@ -49,13 +49,13 @@ public class MainTest {
   @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
index 42c3dc98cde4f1ef2c17656af25b5f8c5f337a06..d7fde1cb03ca70a5d3220a8eb94563560323c115 100644 (file)
 
 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;
@@ -27,11 +33,6 @@ import static org.hamcrest.Matchers.not;
 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
@@ -95,7 +96,7 @@ public class RunnerTest {
     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));
   }
 
@@ -126,4 +127,15 @@ public class RunnerTest {
     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"));
+  }
+
 }