aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFabrice Bellingard <fabrice.bellingard@sonarsource.com>2012-09-10 19:04:52 +0200
committerFabrice Bellingard <fabrice.bellingard@sonarsource.com>2012-09-11 09:18:23 +0200
commitfcd0b85e1c08caf84e6e07b992ccec1a76823320 (patch)
tree17215ebf404372f1133d62c608bfc8eeedaf771b /src
parent7ba663bea3a7a7e55b946de6de96237781bef01f (diff)
downloadsonar-scanner-cli-fcd0b85e1c08caf84e6e07b992ccec1a76823320.tar.gz
sonar-scanner-cli-fcd0b85e1c08caf84e6e07b992ccec1a76823320.zip
SONARPLUGINS-2202 sonar.projectKey not mandatory on a module def.
=> it is automatically generated from the module Id found in "sonar.modules"
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/sonar/runner/internal/Main.java7
-rw-r--r--src/main/java/org/sonar/runner/internal/batch/SonarProjectBuilder.java8
-rw-r--r--src/test/java/org/sonar/runner/internal/batch/SonarProjectBuilderTest.java14
3 files changed, 24 insertions, 5 deletions
diff --git a/src/main/java/org/sonar/runner/internal/Main.java b/src/main/java/org/sonar/runner/internal/Main.java
index 61d70ef..8b7566b 100644
--- a/src/main/java/org/sonar/runner/internal/Main.java
+++ b/src/main/java/org/sonar/runner/internal/Main.java
@@ -20,13 +20,10 @@
package org.sonar.runner.internal;
-import org.sonar.runner.internal.bootstrapper.BootstrapException;
-
import org.sonar.runner.Runner;
import org.sonar.runner.RunnerException;
-
+import org.sonar.runner.internal.bootstrapper.BootstrapException;
import org.sonar.runner.internal.bootstrapper.utils.PrivateIOUtils;
-
import org.sonar.runner.utils.SonarRunnerVersion;
import java.io.File;
@@ -120,7 +117,7 @@ public final class Main {
result.putAll(loadProjectProperties(commandLineProps));
result.putAll(commandLineProps);
- if (result.contains(PROJECT_HOME)) {
+ if (result.containsKey(PROJECT_HOME)) {
// the real property of the Sonar Runner is "sonar.projectDir"
String baseDir = result.getProperty(PROJECT_HOME);
result.remove(PROJECT_HOME);
diff --git a/src/main/java/org/sonar/runner/internal/batch/SonarProjectBuilder.java b/src/main/java/org/sonar/runner/internal/batch/SonarProjectBuilder.java
index e3b5c19..efbb3d2 100644
--- a/src/main/java/org/sonar/runner/internal/batch/SonarProjectBuilder.java
+++ b/src/main/java/org/sonar/runner/internal/batch/SonarProjectBuilder.java
@@ -169,6 +169,7 @@ public final class SonarProjectBuilder {
}
private ProjectDefinition loadChildProjectFromProperties(ProjectDefinition parentProject, Properties childProps, String moduleId) {
+ setProjectKeyIfNotDefined(childProps, moduleId);
checkMandatoryProperties(moduleId, childProps, MANDATORY_PROPERTIES_FOR_CHILD);
mergeParentProperties(childProps, parentProject.getProperties());
@@ -216,6 +217,13 @@ public final class SonarProjectBuilder {
}
@VisibleForTesting
+ protected static void setProjectKeyIfNotDefined(Properties childProps, String moduleId) {
+ if (!childProps.containsKey(PROPERTY_PROJECT_KEY)) {
+ childProps.put(PROPERTY_PROJECT_KEY, moduleId);
+ }
+ }
+
+ @VisibleForTesting
protected static void checkUnicityOfChildKey(ProjectDefinition childProject, ProjectDefinition parentProject) {
for (ProjectDefinition definition : parentProject.getSubProjects()) {
if (definition.getKey().equals(childProject.getKey())) {
diff --git a/src/test/java/org/sonar/runner/internal/batch/SonarProjectBuilderTest.java b/src/test/java/org/sonar/runner/internal/batch/SonarProjectBuilderTest.java
index b0d3d8f..2e7d596 100644
--- a/src/test/java/org/sonar/runner/internal/batch/SonarProjectBuilderTest.java
+++ b/src/test/java/org/sonar/runner/internal/batch/SonarProjectBuilderTest.java
@@ -363,4 +363,18 @@ public class SonarProjectBuilderTest {
SonarProjectBuilder.checkUnicityOfChildKey(mod2, root);
}
+ @Test
+ public void shouldSetProjectKeyIfNotPresent() {
+ Properties props = new Properties();
+ props.put("sonar.projectVersion", "1.0");
+
+ // should be set
+ SonarProjectBuilder.setProjectKeyIfNotDefined(props, "foo");
+ assertThat(props.getProperty("sonar.projectKey")).isEqualTo("foo");
+
+ // but not this 2nd time
+ SonarProjectBuilder.setProjectKeyIfNotDefined(props, "bar");
+ assertThat(props.getProperty("sonar.projectKey")).isEqualTo("foo");
+ }
+
}