aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2013-01-04 17:55:37 +0100
committerJulien HENRY <julien.henry@sonarsource.com>2013-01-04 17:55:37 +0100
commit6dab6607834f50a037edf564181f03bfcbd6358e (patch)
treef245c3991a508b83e980e6bf3d6c41c3834fffb8
parente58e2abe96d73354ff9f25ef62a2ed51418aa8fb (diff)
downloadsonar-scanner-cli-6dab6607834f50a037edf564181f03bfcbd6358e.tar.gz
sonar-scanner-cli-6dab6607834f50a037edf564181f03bfcbd6358e.zip
SONARPLUGINS-2399 Comma is badly supported in sonar.projectName property
Removed use of commons-configuration.
-rw-r--r--pom.xml12
-rw-r--r--src/main/java/org/sonar/runner/internal/batch/Launcher.java58
-rw-r--r--src/test/java/org/sonar/runner/internal/batch/LauncherTest.java6
3 files changed, 32 insertions, 44 deletions
diff --git a/pom.xml b/pom.xml
index 91079d6..345358b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -83,6 +83,12 @@
<artifactId>sonar-plugin-api</artifactId>
<version>${sonar.buildVersion}</version>
<scope>provided</scope>
+ <exclusions>
+ <exclusion>
+ <artifactId>commons-configuration</artifactId>
+ <groupId>commons-configuration</groupId>
+ </exclusion>
+ </exclusions>
</dependency>
<!-- Unit tests -->
<dependency>
@@ -90,6 +96,12 @@
<artifactId>sonar-testing-harness</artifactId>
<version>${sonar.buildVersion}</version>
<scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <artifactId>commons-configuration</artifactId>
+ <groupId>commons-configuration</groupId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>org.easytesting</groupId>
diff --git a/src/main/java/org/sonar/runner/internal/batch/Launcher.java b/src/main/java/org/sonar/runner/internal/batch/Launcher.java
index 93626c2..2745d39 100644
--- a/src/main/java/org/sonar/runner/internal/batch/Launcher.java
+++ b/src/main/java/org/sonar/runner/internal/batch/Launcher.java
@@ -23,13 +23,7 @@ import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.joran.JoranConfigurator;
import ch.qos.logback.core.joran.spi.JoranException;
import com.google.common.annotations.VisibleForTesting;
-import org.apache.commons.configuration.CompositeConfiguration;
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.EnvironmentConfiguration;
-import org.apache.commons.configuration.MapConfiguration;
-import org.apache.commons.configuration.SystemConfiguration;
import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang.StringUtils;
import org.slf4j.LoggerFactory;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.bootstrap.ProjectReactor;
@@ -39,7 +33,6 @@ import org.sonar.batch.bootstrapper.EnvironmentInformation;
import org.sonar.runner.Runner;
import java.io.InputStream;
-import java.util.Iterator;
import java.util.List;
import java.util.Properties;
@@ -61,20 +54,18 @@ public class Launcher {
* Main entry point.
*/
public void execute() {
- ProjectDefinition project = SonarProjectBuilder.create(propertiesFromRunner).generateProjectDefinition();
- Configuration initialConfiguration = getInitialConfiguration(project);
- initLogging(initialConfiguration);
- executeBatch(project, initialConfiguration);
+ Properties configuration = getInitialConfiguration();
+ configuration.putAll(propertiesFromRunner);
+ ProjectDefinition project = SonarProjectBuilder.create(configuration).generateProjectDefinition();
+ initLogging(configuration);
+ executeBatch(project);
}
- private void executeBatch(ProjectDefinition project, Configuration initialConfiguration) {
+ private void executeBatch(ProjectDefinition project) {
setContainerExtensionsOnProject(project);
String envKey = propertiesFromRunner.getProperty(Runner.PROPERTY_ENVIRONMENT_INFORMATION_KEY);
String envVersion = propertiesFromRunner.getProperty(Runner.PROPERTY_ENVIRONMENT_INFORMATION_VERSION);
ProjectReactor projectReactor = new ProjectReactor(project);
- if (initialConfiguration != null) {
- projectReactor.getRoot().setProperties(convertToProperties(initialConfiguration));
- }
Batch batch = Batch.builder()
.setProjectReactor(new ProjectReactor(project))
.setEnvironment(new EnvironmentInformation(envKey, envVersion))
@@ -82,18 +73,6 @@ public class Launcher {
batch.execute();
}
- static Properties convertToProperties(Configuration configuration) {
- Properties props = new Properties();
- Iterator keys = configuration.getKeys();
- while (keys.hasNext()) {
- String key = (String) keys.next();
- // Configuration#getString() automatically splits strings by comma separator.
- String value = StringUtils.join(configuration.getStringArray(key), ",");
- props.setProperty(key, value);
- }
- return props;
- }
-
private void setContainerExtensionsOnProject(ProjectDefinition projectDefinition) {
for (Object extension : containerExtensions) {
projectDefinition.addContainerExtension(extension);
@@ -103,15 +82,15 @@ public class Launcher {
}
}
- private void initLogging(Configuration initialConfiguration) {
+ private void initLogging(Properties props) {
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
JoranConfigurator jc = new JoranConfigurator();
jc.setContext(context);
context.reset();
InputStream input = Batch.class.getResourceAsStream("/org/sonar/batch/logback.xml");
System.setProperty("ROOT_LOGGER_LEVEL", isDebug() ? "DEBUG" : "INFO");
- context.putProperty("SQL_LOGGER_LEVEL", getSqlLevel(initialConfiguration));
- context.putProperty("SQL_RESULTS_LOGGER_LEVEL", getSqlResultsLevel(initialConfiguration));
+ context.putProperty("SQL_LOGGER_LEVEL", getSqlLevel(props));
+ context.putProperty("SQL_RESULTS_LOGGER_LEVEL", getSqlResultsLevel(props));
try {
jc.doConfigure(input);
@@ -129,23 +108,22 @@ public class Launcher {
}
@VisibleForTesting
- protected static String getSqlLevel(Configuration config) {
- boolean showSql = config.getBoolean("sonar.showSql", false);
+ protected static String getSqlLevel(Properties props) {
+ boolean showSql = "true".equals(props.get("sonar.showSql"));
return showSql ? "DEBUG" : "WARN";
}
@VisibleForTesting
- protected static String getSqlResultsLevel(Configuration config) {
- boolean showSql = config.getBoolean("sonar.showSqlResults", false);
+ protected static String getSqlResultsLevel(Properties props) {
+ boolean showSql = "true".equals(props.get("sonar.showSqlResults"));
return showSql ? "DEBUG" : "WARN";
}
- private Configuration getInitialConfiguration(ProjectDefinition project) {
- CompositeConfiguration configuration = new CompositeConfiguration();
- configuration.addConfiguration(new SystemConfiguration());
- configuration.addConfiguration(new EnvironmentConfiguration());
- configuration.addConfiguration(new MapConfiguration(project.getProperties()));
- return configuration;
+ private Properties getInitialConfiguration() {
+ Properties props = new Properties();
+ props.putAll(System.getProperties());
+ props.putAll(System.getenv());
+ return props;
}
}
diff --git a/src/test/java/org/sonar/runner/internal/batch/LauncherTest.java b/src/test/java/org/sonar/runner/internal/batch/LauncherTest.java
index 71dfc52..b06ba86 100644
--- a/src/test/java/org/sonar/runner/internal/batch/LauncherTest.java
+++ b/src/test/java/org/sonar/runner/internal/batch/LauncherTest.java
@@ -20,8 +20,6 @@
package org.sonar.runner.internal.batch;
import com.google.common.collect.Lists;
-import org.apache.commons.configuration.BaseConfiguration;
-import org.apache.commons.configuration.Configuration;
import org.junit.Test;
import org.sonar.runner.Runner;
@@ -33,7 +31,7 @@ public class LauncherTest {
@Test
public void testGetSqlLevel() throws Exception {
- Configuration conf = new BaseConfiguration();
+ Properties conf = new Properties();
assertThat(Launcher.getSqlLevel(conf)).isEqualTo("WARN");
@@ -46,7 +44,7 @@ public class LauncherTest {
@Test
public void testGetSqlResultsLevel() throws Exception {
- Configuration conf = new BaseConfiguration();
+ Properties conf = new Properties();
assertThat(Launcher.getSqlResultsLevel(conf)).isEqualTo("WARN");