aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2019-09-03 15:36:13 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2019-09-05 10:03:19 +0200
commit3091d1bb8bfdb695942afdac41a5fa7c79a8ebc8 (patch)
treef3635ce9877ea9384b340d6f6adffee62b8d57ec /src
parent7d253e8dc460e1858d5756211f0f16dafd724eae (diff)
downloadsonar-scanner-cli-3091d1bb8bfdb695942afdac41a5fa7c79a8ebc8.tar.gz
sonar-scanner-cli-3091d1bb8bfdb695942afdac41a5fa7c79a8ebc8.zip
SQSCANNER-24 Always consider project.settings, if set
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/sonarsource/scanner/cli/Conf.java19
-rw-r--r--src/test/java/org/sonarsource/scanner/cli/ConfTest.java15
-rw-r--r--src/test/resources/org/sonarsource/scanner/cli/ConfTest/shouldOverrideProjectSettingsPath/conf/sq-project.properties1
-rw-r--r--src/test/resources/org/sonarsource/scanner/cli/ConfTest/shouldOverrideProjectSettingsPath/sonar-project.properties1
4 files changed, 25 insertions, 11 deletions
diff --git a/src/main/java/org/sonarsource/scanner/cli/Conf.java b/src/main/java/org/sonarsource/scanner/cli/Conf.java
index fd33baf..0a3da87 100644
--- a/src/main/java/org/sonarsource/scanner/cli/Conf.java
+++ b/src/main/java/org/sonarsource/scanner/cli/Conf.java
@@ -30,9 +30,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
-
import javax.annotation.Nullable;
-
import org.sonarsource.scanner.api.Utils;
class Conf {
@@ -63,7 +61,7 @@ class Conf {
result.putAll(loadEnvironmentProperties());
result.putAll(cli.properties());
result = resolve(result);
-
+
// root project base directory must be present and be absolute
result.setProperty(PROPERTY_PROJECT_BASEDIR, getRootProjectBaseDir(result).toString());
result.remove(PROJECT_HOME);
@@ -204,8 +202,7 @@ class Conf {
return moduleProps;
}
- private static Path locatePropertiesFile(Properties props, String homeKey, String relativePathFromHome,
- String settingsKey) {
+ private static Path locatePropertiesFile(Properties props, String homeKey, String relativePathFromHome, String settingsKey) {
Path settingsFile = null;
String scannerHome = props.getProperty(homeKey, "");
if (!"".equals(scannerHome)) {
@@ -216,12 +213,12 @@ class Conf {
}
private static Path locatePropertiesFile(@Nullable Path defaultPath, Properties props, String settingsKey) {
- Path settingsFile = defaultPath;
- if (settingsFile == null || !Files.exists(settingsFile)) {
- String settingsPath = props.getProperty(settingsKey, "");
- if (!"".equals(settingsPath)) {
- settingsFile = Paths.get(settingsPath);
- }
+ Path settingsFile;
+ String settingsPath = props.getProperty(settingsKey, "");
+ if (!"".equals(settingsPath)) {
+ settingsFile = Paths.get(settingsPath);
+ } else {
+ settingsFile = defaultPath;
}
if (settingsFile != null) {
diff --git a/src/test/java/org/sonarsource/scanner/cli/ConfTest.java b/src/test/java/org/sonarsource/scanner/cli/ConfTest.java
index 371a6ba..a966b50 100644
--- a/src/test/java/org/sonarsource/scanner/cli/ConfTest.java
+++ b/src/test/java/org/sonarsource/scanner/cli/ConfTest.java
@@ -301,4 +301,19 @@ public class ConfTest {
Files.delete(linkProjectHome);
}
}
+
+ // SQSCANNER-24
+ @Test
+ public void should_load_project_settings_using_property() 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");
+
+ args.setProperty("project.settings", home.resolve("conf/sq-project.properties").toAbsolutePath().toString());
+
+ properties = conf.properties();
+ assertThat(properties.get("sonar.prop")).isEqualTo("expected");
+ }
}
diff --git a/src/test/resources/org/sonarsource/scanner/cli/ConfTest/shouldOverrideProjectSettingsPath/conf/sq-project.properties b/src/test/resources/org/sonarsource/scanner/cli/ConfTest/shouldOverrideProjectSettingsPath/conf/sq-project.properties
new file mode 100644
index 0000000..fa1dbbd
--- /dev/null
+++ b/src/test/resources/org/sonarsource/scanner/cli/ConfTest/shouldOverrideProjectSettingsPath/conf/sq-project.properties
@@ -0,0 +1 @@
+sonar.prop=expected
diff --git a/src/test/resources/org/sonarsource/scanner/cli/ConfTest/shouldOverrideProjectSettingsPath/sonar-project.properties b/src/test/resources/org/sonarsource/scanner/cli/ConfTest/shouldOverrideProjectSettingsPath/sonar-project.properties
new file mode 100644
index 0000000..32f39c9
--- /dev/null
+++ b/src/test/resources/org/sonarsource/scanner/cli/ConfTest/shouldOverrideProjectSettingsPath/sonar-project.properties
@@ -0,0 +1 @@
+sonar.prop=default