aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine/src
diff options
context:
space:
mode:
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