aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabrice Bellingard <fabrice.bellingard@sonarsource.com>2012-09-07 10:21:17 +0200
committerFabrice Bellingard <fabrice.bellingard@sonarsource.com>2012-09-07 10:21:17 +0200
commit9eb116afd392b896d1c68ddacb0330eeb207cfa1 (patch)
treeafe53124be9e1d25e773954363c3ceb91bc6542a
parent84cf7f1fb4491a955dcd6b4e10a9510f06666db8 (diff)
downloadsonar-scanner-cli-9eb116afd392b896d1c68ddacb0330eeb207cfa1.tar.gz
sonar-scanner-cli-9eb116afd392b896d1c68ddacb0330eeb207cfa1.zip
Allows to overwrite environment information on the Runner
-rw-r--r--src/main/java/org/sonar/runner/Runner.java22
-rw-r--r--src/main/java/org/sonar/runner/model/Launcher.java5
-rw-r--r--src/test/java/org/sonar/runner/RunnerTest.java16
3 files changed, 37 insertions, 6 deletions
diff --git a/src/main/java/org/sonar/runner/Runner.java b/src/main/java/org/sonar/runner/Runner.java
index a24ae84..dc75115 100644
--- a/src/main/java/org/sonar/runner/Runner.java
+++ b/src/main/java/org/sonar/runner/Runner.java
@@ -37,7 +37,8 @@ import java.util.Properties;
public final class Runner {
public static final String PROPERTY_PROJECT_DIR = "sonar.runner.projectDir";
- public static final String PROPERTY_RUNNER_VERSION = "sonar.runner.version";
+ public static final String PROPERTY_ENVIRONMENT_INFORMATION_KEY = "sonar.environment.information.key";
+ public static final String PROPERTY_ENVIRONMENT_INFORMATION_VERSION = "sonar.environment.information.version";
/**
* @deprecated Replaced by sonar.verbose since 1.2
@@ -67,6 +68,10 @@ public final class Runner {
private Runner(Properties props) {
this.properties = props;
+ // set the default values for the Sonar Runner - they can be overriden with #setEnvironmentInformation
+ this.properties.put(PROPERTY_ENVIRONMENT_INFORMATION_KEY, "Runner");
+ this.properties.put(PROPERTY_ENVIRONMENT_INFORMATION_VERSION, SonarRunnerVersion.getVersion());
+ // and init the directories
initDirs();
}
@@ -75,9 +80,7 @@ public final class Runner {
}
public void execute() {
- String sonarRunnerVersion = SonarRunnerVersion.getVersion();
- properties.put(PROPERTY_RUNNER_VERSION, sonarRunnerVersion);
- Bootstrapper bootstrapper = new Bootstrapper("SonarRunner/" + sonarRunnerVersion, getSonarServerURL(), getWorkDir());
+ Bootstrapper bootstrapper = new Bootstrapper("SonarRunner/" + SonarRunnerVersion.getVersion(), getSonarServerURL(), getWorkDir());
checkSonarVersion(bootstrapper);
delegateExecution(createClassLoader(bootstrapper));
}
@@ -185,4 +188,15 @@ public final class Runner {
Thread.currentThread().setContextClassLoader(oldContextClassLoader);
}
}
+
+ /**
+ * Allows to overwrite the environment information when Sonar Runner is embedded in a specific tool (for instance, with the Sonar Ant Task).
+ *
+ * @param key the key of the tool that embeds Sonar Runner
+ * @param version the version of this tool
+ */
+ public void setEnvironmentInformation(String key, String version) {
+ this.properties.put(PROPERTY_ENVIRONMENT_INFORMATION_KEY, key);
+ this.properties.put(PROPERTY_ENVIRONMENT_INFORMATION_VERSION, version);
+ }
}
diff --git a/src/main/java/org/sonar/runner/model/Launcher.java b/src/main/java/org/sonar/runner/model/Launcher.java
index 24202a3..cfa14b3 100644
--- a/src/main/java/org/sonar/runner/model/Launcher.java
+++ b/src/main/java/org/sonar/runner/model/Launcher.java
@@ -68,8 +68,9 @@ public class Launcher {
private void executeBatch(ProjectDefinition project, Configuration initialConfiguration) {
ProjectReactor reactor = new ProjectReactor(project);
- String runnerVersion = propertiesFromRunner.getProperty(Runner.PROPERTY_RUNNER_VERSION);
- Batch batch = Batch.create(reactor, initialConfiguration, new EnvironmentInformation("Runner", runnerVersion));
+ String envKey = propertiesFromRunner.getProperty(Runner.PROPERTY_ENVIRONMENT_INFORMATION_KEY);
+ String envVersion = propertiesFromRunner.getProperty(Runner.PROPERTY_ENVIRONMENT_INFORMATION_VERSION);
+ Batch batch = Batch.create(reactor, initialConfiguration, new EnvironmentInformation(envKey, envVersion));
batch.execute();
}
diff --git a/src/test/java/org/sonar/runner/RunnerTest.java b/src/test/java/org/sonar/runner/RunnerTest.java
index abcd46d..c5b1b7b 100644
--- a/src/test/java/org/sonar/runner/RunnerTest.java
+++ b/src/test/java/org/sonar/runner/RunnerTest.java
@@ -38,6 +38,22 @@ public class RunnerTest {
public ExpectedException thrown = ExpectedException.none();
@Test
+ public void shouldHaveDefaultEnvironmentInformationValues() {
+ Runner runner = Runner.create(new Properties());
+ assertThat(runner.getProperties().getProperty(Runner.PROPERTY_ENVIRONMENT_INFORMATION_KEY)).isEqualTo("Runner");
+ assertThat(runner.getProperties().getProperty(Runner.PROPERTY_ENVIRONMENT_INFORMATION_VERSION)).contains(".");
+ assertThat(runner.getProperties().getProperty(Runner.PROPERTY_ENVIRONMENT_INFORMATION_VERSION)).doesNotContain("$");
+ }
+
+ @Test
+ public void shouldOverwriteDefaultEnvironmentInformationValues() {
+ Runner runner = Runner.create(new Properties());
+ runner.setEnvironmentInformation("Ant", "1.2.3");
+ assertThat(runner.getProperties().getProperty(Runner.PROPERTY_ENVIRONMENT_INFORMATION_KEY)).isEqualTo("Ant");
+ assertThat(runner.getProperties().getProperty(Runner.PROPERTY_ENVIRONMENT_INFORMATION_VERSION)).isEqualTo("1.2.3");
+ }
+
+ @Test
public void shouldCheckVersion() {
assertThat(Runner.isUnsupportedVersion("1.0")).isTrue();
assertThat(Runner.isUnsupportedVersion("2.0")).isTrue();