aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine/src
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-08-24 16:56:40 +0200
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-09-19 10:34:53 +0200
commit8677caa79431fd4f9c2fb990c9db742a2157a8f4 (patch)
tree76a1e25b9bb5ab70346c058119304bf419620891 /sonar-scanner-engine/src
parentee9750c2fafc4e1e0f6d8e5e115ae759da4453c4 (diff)
downloadsonarqube-8677caa79431fd4f9c2fb990c9db742a2157a8f4.tar.gz
sonarqube-8677caa79431fd4f9c2fb990c9db742a2157a8f4.zip
SONAR-9283 Settings, Configuration and Props trim values at insert
Diffstat (limited to 'sonar-scanner-engine/src')
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalConfiguration.java5
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/MutableGlobalSettings.java6
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/config/DefaultConfiguration.java12
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/MutableModuleSettings.java6
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/MutableProjectSettings.java6
5 files changed, 26 insertions, 9 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalConfiguration.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalConfiguration.java
index b41cf7d4f0b..f22c14f4f99 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalConfiguration.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalConfiguration.java
@@ -20,7 +20,6 @@
package org.sonar.scanner.bootstrap;
import com.google.common.collect.ImmutableMap;
-import java.util.Collections;
import java.util.Map;
import javax.annotation.concurrent.Immutable;
import org.slf4j.Logger;
@@ -50,14 +49,14 @@ public class GlobalConfiguration extends DefaultConfiguration {
public GlobalConfiguration(PropertyDefinitions propertyDefinitions, Encryption encryption, GlobalAnalysisMode mode,
Map<String, String> settings, Map<String, String> serverSideSettings) {
super(propertyDefinitions, encryption, mode, settings);
- this.serverSideSettings = serverSideSettings;
+ this.serverSideSettings = unmodifiableMapWithTrimmedValues(propertyDefinitions, serverSideSettings);
get(CoreProperties.PERMANENT_SERVER_ID).ifPresent(v -> LOG.info("Server id: {}", v));
new DroppedPropertyChecker(getProperties(), DROPPED_PROPERTIES).checkDroppedProperties();
}
public Map<String, String> getServerSideSettings() {
- return Collections.unmodifiableMap(serverSideSettings);
+ return serverSideSettings;
}
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/MutableGlobalSettings.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/MutableGlobalSettings.java
index b3355a89228..6378bd3319e 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/MutableGlobalSettings.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/MutableGlobalSettings.java
@@ -25,6 +25,8 @@ import java.util.Optional;
import org.sonar.api.config.Settings;
import org.sonar.api.utils.MessageException;
+import static java.util.Objects.requireNonNull;
+
/**
* @deprecated since 6.5 {@link GlobalConfiguration} used to be mutable, so keep a mutable copy for backward compatibility.
*/
@@ -56,7 +58,9 @@ public class MutableGlobalSettings extends Settings {
@Override
protected void set(String key, String value) {
- mutableProperties.put(key, value);
+ mutableProperties.put(
+ requireNonNull(key, "key can't be null"),
+ requireNonNull(value, "value can't be null").trim());
}
@Override
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/config/DefaultConfiguration.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/config/DefaultConfiguration.java
index 3a5e18f2e3f..710b02bbee1 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/config/DefaultConfiguration.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/config/DefaultConfiguration.java
@@ -53,16 +53,22 @@ public abstract class DefaultConfiguration implements Configuration {
private final PropertyDefinitions definitions;
private final Encryption encryption;
private final GlobalAnalysisMode mode;
- private final Map<String, String> properties = new HashMap<>();
+ private final Map<String, String> properties;
public DefaultConfiguration(PropertyDefinitions propertyDefinitions, Encryption encryption, GlobalAnalysisMode mode, Map<String, String> props) {
this.definitions = requireNonNull(propertyDefinitions);
this.encryption = encryption;
this.mode = mode;
+ this.properties = unmodifiableMapWithTrimmedValues(definitions, props);
+ }
+
+ protected static Map<String, String> unmodifiableMapWithTrimmedValues(PropertyDefinitions definitions, Map<String, String> props) {
+ Map<String, String> map = new HashMap<>(props.size());
props.forEach((k, v) -> {
String validKey = definitions.validKey(k);
- properties.put(validKey, trim(v));
+ map.put(validKey, trim(v));
});
+ return Collections.unmodifiableMap(map);
}
public GlobalAnalysisMode getMode() {
@@ -78,7 +84,7 @@ public abstract class DefaultConfiguration implements Configuration {
}
public Map<String, String> getProperties() {
- return Collections.unmodifiableMap(properties);
+ return properties;
}
@Override
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/MutableModuleSettings.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/MutableModuleSettings.java
index f906f59f532..1a6768979bc 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/MutableModuleSettings.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/MutableModuleSettings.java
@@ -30,6 +30,8 @@ import org.sonar.api.utils.MessageException;
import org.sonar.scanner.bootstrap.MutableGlobalSettings;
import org.sonar.scanner.repository.ProjectRepositories;
+import static java.util.Objects.requireNonNull;
+
/**
* @deprecated since 6.5 {@link ModuleSettings} used to be mutable, so keep a mutable copy for backward compatibility.
*/
@@ -84,7 +86,9 @@ public class MutableModuleSettings extends Settings {
@Override
protected void set(String key, String value) {
- properties.put(key, value);
+ properties.put(
+ requireNonNull(key, "key can't be null"),
+ requireNonNull(value, "value can't be null").trim());
}
@Override
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/MutableProjectSettings.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/MutableProjectSettings.java
index 8c234a9ed33..63344b97736 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/MutableProjectSettings.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/MutableProjectSettings.java
@@ -29,6 +29,8 @@ import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
import org.sonar.scanner.bootstrap.MutableGlobalSettings;
import org.sonar.scanner.repository.ProjectRepositories;
+import static java.util.Objects.requireNonNull;
+
/**
* @deprecated since 6.5 {@link ProjectSettings} used to be mutable, so keep a mutable copy for backward compatibility.
*/
@@ -57,7 +59,9 @@ public class MutableProjectSettings extends Settings {
@Override
protected void set(String key, String value) {
- properties.put(key, value);
+ properties.put(
+ requireNonNull(key, "key can't be null"),
+ requireNonNull(value, "value can't be null").trim());
}
@Override