From 82e006da834823718fb6ac0b579dff772db2d599 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Fri, 13 Jan 2012 14:10:51 +0100 Subject: Sanitize batch bootstrapper - by default Logback is configured by batch, not by bootstrappers - ability to delegate logging to bootstrappers (require a SLF4J implementation) --- .../src/main/java/org/sonar/maven/SonarMojo.java | 48 ++++++++++------------ 1 file changed, 21 insertions(+), 27 deletions(-) (limited to 'sonar-maven-plugin/src/main/java') 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 9c3a42309ec..29200ffb1a0 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 @@ -35,11 +35,13 @@ import org.apache.maven.project.MavenProjectBuilder; import org.apache.maven.shared.dependency.tree.DependencyTreeBuilder; import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.batch.bootstrap.ProjectReactor; -import org.sonar.batch.Batch; import org.sonar.batch.MavenProjectConverter; +import org.sonar.batch.bootstrapper.Batch; import org.sonar.batch.bootstrapper.EnvironmentInformation; import org.sonar.batch.bootstrapper.LoggingConfiguration; +import java.util.Map; + /** * @goal sonar * @aggregator @@ -132,41 +134,33 @@ public final class SonarMojo extends AbstractMojo { */ private RuntimeInformation runtimeInformation; - /** - * @parameter expression="${sonar.verbose}" default-value="false" - */ - private boolean verbose; - - /** - * @parameter expression="${sonar.showSql}" default-value="false" - */ - private boolean showSql; - public void execute() throws MojoExecutionException, MojoFailureException { - configureLogging(); - executeBatch(); - } - - private void executeBatch() throws MojoExecutionException { ProjectDefinition def = MavenProjectConverter.convert(session.getSortedProjects(), project); ProjectReactor reactor = new ProjectReactor(def); - Batch batch = new Batch(reactor, session, getLog(), lifecycleExecutor, pluginManager, artifactFactory, - localRepository, artifactMetadataSource, artifactCollector, dependencyTreeBuilder, - projectBuilder, getEnvironmentInformation(), Maven2PluginExecutor.class); + Batch batch = Batch.builder() + .setEnvironment(getEnvironmentInformation()) + .setProjectReactor(reactor) + .addComponents( + session, getLog(), lifecycleExecutor, pluginManager, artifactFactory, + localRepository, artifactMetadataSource, artifactCollector, dependencyTreeBuilder, + projectBuilder, Maven2PluginExecutor.class) + .build(); + + configureLogging(batch.getLoggingConfiguration()); batch.execute(); } + private void configureLogging(LoggingConfiguration logging) { + logging.setProperties((Map) session.getExecutionProperties()); + logging.setFormat(LoggingConfiguration.FORMAT_MAVEN); + if (getLog().isDebugEnabled()) { + logging.setVerbose(true); + } + } + private EnvironmentInformation getEnvironmentInformation() { String mavenVersion = runtimeInformation.getApplicationVersion().toString(); return new EnvironmentInformation("Maven", mavenVersion); } - - private void configureLogging() { - LoggingConfiguration.create() - .setVerbose(verbose || getLog().isDebugEnabled()) - .setShowSql(showSql) - .setFormat(LoggingConfiguration.FORMAT_MAVEN) - .configure(); - } } -- cgit v1.2.3