aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2019-09-03 15:59:11 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2019-09-05 10:03:19 +0200
commitdae4decaa165461d2cdd52860e93fc6c2dd0f493 (patch)
treec0390097f8c018e8bdf49709ff1788efa21b8822 /src
parent3091d1bb8bfdb695942afdac41a5fa7c79a8ebc8 (diff)
downloadsonar-scanner-cli-dae4decaa165461d2cdd52860e93fc6c2dd0f493.tar.gz
sonar-scanner-cli-dae4decaa165461d2cdd52860e93fc6c2dd0f493.zip
SQSCANNER-61 Consider 'project.settings' if set using SONARQUBE_SCANNER_PARAMS4.1.0.1829
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/sonarsource/scanner/cli/Conf.java21
-rw-r--r--src/test/java/org/sonarsource/scanner/cli/ConfTest.java15
2 files changed, 29 insertions, 7 deletions
diff --git a/src/main/java/org/sonarsource/scanner/cli/Conf.java b/src/main/java/org/sonarsource/scanner/cli/Conf.java
index 0a3da87..b914516 100644
--- a/src/main/java/org/sonarsource/scanner/cli/Conf.java
+++ b/src/main/java/org/sonarsource/scanner/cli/Conf.java
@@ -78,7 +78,13 @@ class Conf {
}
private Properties loadGlobalProperties() {
- Path settingsFile = locatePropertiesFile(cli.properties(), SCANNER_HOME, "conf/sonar-scanner.properties",
+ Properties knownPropsAtThatPoint = new Properties();
+
+ knownPropsAtThatPoint.putAll(System.getProperties());
+ knownPropsAtThatPoint.putAll(loadEnvironmentProperties());
+ knownPropsAtThatPoint.putAll(cli.properties());
+
+ Path settingsFile = locatePropertiesFile(knownPropsAtThatPoint, SCANNER_HOME, "conf/sonar-scanner.properties",
SCANNER_SETTINGS);
if (settingsFile != null && Files.isRegularFile(settingsFile)) {
logger.info("Scanner configuration file: " + settingsFile);
@@ -90,13 +96,14 @@ class Conf {
private Properties loadProjectProperties() {
Properties rootProps = new Properties();
- Properties knownProps = new Properties();
+ Properties knownPropsAtThatPoint = new Properties();
- knownProps.putAll(System.getProperties());
- knownProps.putAll(cli.properties());
+ knownPropsAtThatPoint.putAll(System.getProperties());
+ knownPropsAtThatPoint.putAll(loadEnvironmentProperties());
+ knownPropsAtThatPoint.putAll(cli.properties());
- Path defaultRootSettingsFile = getRootProjectBaseDir(knownProps).resolve(SONAR_PROJECT_PROPERTIES_FILENAME);
- Path rootSettingsFile = locatePropertiesFile(defaultRootSettingsFile, knownProps, PROJECT_SETTINGS);
+ Path defaultRootSettingsFile = getRootProjectBaseDir(knownPropsAtThatPoint).resolve(SONAR_PROJECT_PROPERTIES_FILENAME);
+ Path rootSettingsFile = locatePropertiesFile(defaultRootSettingsFile, knownPropsAtThatPoint, PROJECT_SETTINGS);
if (rootSettingsFile != null && Files.isRegularFile(rootSettingsFile)) {
logger.info("Project root configuration file: " + rootSettingsFile);
rootProps.putAll(toProperties(rootSettingsFile));
@@ -110,7 +117,7 @@ class Conf {
// root config file
projectProps.putAll(rootProps);
- rootProps.putAll(knownProps);
+ rootProps.putAll(knownPropsAtThatPoint);
rootProps.setProperty(PROPERTY_PROJECT_BASEDIR, getRootProjectBaseDir(rootProps).toString());
// projectProps will be overridden by any properties found in child
diff --git a/src/test/java/org/sonarsource/scanner/cli/ConfTest.java b/src/test/java/org/sonarsource/scanner/cli/ConfTest.java
index a966b50..1dbbbec 100644
--- a/src/test/java/org/sonarsource/scanner/cli/ConfTest.java
+++ b/src/test/java/org/sonarsource/scanner/cli/ConfTest.java
@@ -316,4 +316,19 @@ public class ConfTest {
properties = conf.properties();
assertThat(properties.get("sonar.prop")).isEqualTo("expected");
}
+
+ // SQSCANNER-61
+ @Test
+ public void should_load_project_settings_using_env() throws Exception {
+ Path home = Paths.get(getClass().getResource("ConfTest/shouldOverrideProjectSettingsPath/").toURI());
+ args.setProperty("project.home", home.toAbsolutePath().toString());
+
+ Properties properties = conf.properties();
+ assertThat(properties.get("sonar.prop")).isEqualTo("default");
+
+ env.put("SONARQUBE_SCANNER_PARAMS", "{\"project.settings\" : \"" + home.resolve("conf/sq-project.properties").toAbsolutePath().toString() + "\"}");
+
+ properties = conf.properties();
+ assertThat(properties.get("sonar.prop")).isEqualTo("expected");
+ }
}