From 547e8323146ec2f0f602ce6f4c325c9ed0ecbb18 Mon Sep 17 00:00:00 2001 From: Evgeny Mandrikov Date: Fri, 4 Feb 2011 17:54:57 +0300 Subject: Replace enum Environment by class EnvironmentInformation * Each environment should provide key and version * Plugins for Maven 2.x and Maven 3.x have same key "Maven" and provide a real version of Maven --- .../src/main/java/org/sonar/maven/SonarMojo.java | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'sonar-maven-plugin') 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 e78939fc39b..ab0123210f5 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 @@ -19,6 +19,8 @@ */ package org.sonar.maven; +import java.io.InputStream; + import ch.qos.logback.classic.LoggerContext; import ch.qos.logback.classic.joran.JoranConfigurator; import ch.qos.logback.core.joran.spi.JoranException; @@ -29,6 +31,7 @@ import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.resolver.ArtifactCollector; import org.apache.maven.execution.MavenSession; +import org.apache.maven.execution.RuntimeInformation; import org.apache.maven.lifecycle.LifecycleExecutor; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; @@ -38,11 +41,9 @@ import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectBuilder; import org.apache.maven.shared.dependency.tree.DependencyTreeBuilder; import org.slf4j.LoggerFactory; -import org.sonar.api.platform.Environment; import org.sonar.batch.Batch; import org.sonar.batch.MavenReactor; - -import java.io.InputStream; +import org.sonar.batch.bootstrapper.EnvironmentInformation; /** * @goal sonar @@ -129,6 +130,13 @@ public final class SonarMojo extends AbstractMojo { */ private MavenProjectBuilder projectBuilder; + /** + * @component + * @required + * @readonly + */ + private RuntimeInformation runtimeInformation; + public void execute() throws MojoExecutionException, MojoFailureException { initLogging(); executeBatch(); @@ -139,10 +147,15 @@ public final class SonarMojo extends AbstractMojo { Batch batch = new Batch(getInitialConfiguration(), reactor, session, project, getLog(), lifecycleExecutor, pluginManager, artifactFactory, localRepository, artifactMetadataSource, artifactCollector, dependencyTreeBuilder, - projectBuilder, Environment.MAVEN2, Maven2PluginExecutor.class); + projectBuilder, getEnvironmentInformation(), Maven2PluginExecutor.class); batch.execute(); } + private EnvironmentInformation getEnvironmentInformation() { + String mavenVersion = runtimeInformation.getApplicationVersion().toString(); + return new EnvironmentInformation("Maven", mavenVersion); + } + private void initLogging() throws MojoExecutionException { LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); JoranConfigurator jc = new JoranConfigurator(); -- cgit v1.2.3