diff options
4 files changed, 49 insertions, 10 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/Batch.java b/sonar-batch/src/main/java/org/sonar/batch/Batch.java index 70c92d06097..d10b89398f9 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/Batch.java +++ b/sonar-batch/src/main/java/org/sonar/batch/Batch.java @@ -20,20 +20,29 @@ package org.sonar.batch; import org.apache.commons.configuration.Configuration; +import org.apache.commons.lang.StringUtils; import org.sonar.api.batch.bootstrap.ProjectReactor; import org.sonar.batch.bootstrap.BootstrapModule; import org.sonar.batch.bootstrap.Module; import org.sonar.batch.bootstrapper.Reactor; +import java.util.Iterator; +import java.util.Properties; + public final class Batch { private Module bootstrapModule; + public Batch(ProjectReactor reactor, Object... bootstrapperComponents) { + this.bootstrapModule = new BootstrapModule(reactor, bootstrapperComponents).init(); + } + /** - * @deprecated since 2.9. Replaced by the factory method. Use by Ant Task 1.1 + * @deprecated since 2.9 because commons-configuration is replaced by ProjectDefinition#properties. Used by Ant Task 1.1 */ @Deprecated - public Batch(Configuration configuration, Object... bootstrapperComponents) { + public Batch(Configuration configuration, Object... bootstrapperComponents) {//NOSONAR configuration is not needed + // because it's already included in ProjectDefinition. this.bootstrapModule = new BootstrapModule(extractProjectReactor(bootstrapperComponents), bootstrapperComponents).init(); } @@ -54,14 +63,28 @@ public final class Batch { return deprecatedReactor.toProjectReactor(); } - private Batch(ProjectReactor reactor, Object... bootstrapperComponents) { - this.bootstrapModule = new BootstrapModule(reactor, bootstrapperComponents).init(); - } - + /** + * Used by Gradle 1.0 + * @deprecated + */ + @Deprecated public static Batch create(ProjectReactor projectReactor, Configuration configuration, Object... bootstrapperComponents) { + projectReactor.getRoot().setProperties(convertToProperties(configuration)); return new Batch(projectReactor, bootstrapperComponents); } + 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; + } + /** * for unit tests */ diff --git a/sonar-batch/src/test/java/org/sonar/batch/BatchTest.java b/sonar-batch/src/test/java/org/sonar/batch/BatchTest.java index 094bbb71f87..97495c022dc 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/BatchTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/BatchTest.java @@ -19,9 +19,14 @@ */ package org.sonar.batch; +import org.apache.commons.configuration.PropertiesConfiguration; import org.junit.Test; +import org.sonar.api.batch.bootstrap.ProjectDefinition; +import org.sonar.api.batch.bootstrap.ProjectReactor; import org.sonar.batch.bootstrap.Module; +import java.util.Properties; + import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; @@ -59,4 +64,17 @@ public class BatchTest { } } + @Test + public void shouldConvertCommonsConfigurationToProperties() { + PropertiesConfiguration commonsConf = new PropertiesConfiguration(); + commonsConf.setProperty("foo", "Foo"); + commonsConf.setProperty("list", "One,Two"); + assertThat(commonsConf.getString("list"), is("One")); + assertThat(commonsConf.getStringArray("list")[0], is("One")); + assertThat(commonsConf.getStringArray("list")[1], is("Two")); + + Properties props = Batch.convertToProperties(commonsConf); + assertThat(props.getProperty("foo"), is("Foo")); + assertThat(props.getProperty("list"), is("One,Two")); + } } diff --git a/sonar-maven-plugin/src/main/java/org/sonar/maven/SonarMojo.java b/sonar-maven-plugin/src/main/java/org/sonar/maven/SonarMojo.java index 4b15f15076a..07f13ae115c 100644 --- a/sonar-maven-plugin/src/main/java/org/sonar/maven/SonarMojo.java +++ b/sonar-maven-plugin/src/main/java/org/sonar/maven/SonarMojo.java @@ -146,8 +146,7 @@ public final class SonarMojo extends AbstractMojo { ProjectDefinition def = MavenProjectConverter.convert(session.getSortedProjects(), project); ProjectReactor reactor = new ProjectReactor(def); - Batch batch = Batch.create(reactor, null, - session, getLog(), lifecycleExecutor, pluginManager, artifactFactory, + Batch batch = new Batch(reactor, session, getLog(), lifecycleExecutor, pluginManager, artifactFactory, localRepository, artifactMetadataSource, artifactCollector, dependencyTreeBuilder, projectBuilder, getEnvironmentInformation(), Maven2PluginExecutor.class); batch.execute(); diff --git a/sonar-maven3-plugin/src/main/java/org/sonar/maven3/SonarMojo.java b/sonar-maven3-plugin/src/main/java/org/sonar/maven3/SonarMojo.java index f8de98e99c6..469043bbf58 100644 --- a/sonar-maven3-plugin/src/main/java/org/sonar/maven3/SonarMojo.java +++ b/sonar-maven3-plugin/src/main/java/org/sonar/maven3/SonarMojo.java @@ -140,8 +140,7 @@ public final class SonarMojo extends AbstractMojo { ProjectDefinition def = MavenProjectConverter.convert(session.getSortedProjects(), project); ProjectReactor reactor = new ProjectReactor(def); - Batch batch = Batch.create(reactor, null, - session, getLog(), lifecycleExecutor, artifactFactory, + Batch batch = new Batch(reactor, session, getLog(), lifecycleExecutor, artifactFactory, localRepository, artifactMetadataSource, artifactCollector, dependencyTreeBuilder, projectBuilder, getEnvironmentInformation(), Maven3PluginExecutor.class); batch.execute(); |