From a52fbd8cd565f58464635906c54db7db87b3be77 Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Mon, 17 Jun 2013 10:34:10 +0200 Subject: SONAR-3979, SONAR-4047 Fix Sonar Maven goal to support Maven 3.1 * now use Sonar Runner embedded to run Sonar * also updated Maven plugins to make Sonar build pass with Maven 3.1 --- sonar-maven3-plugin/pom.xml | 58 ++------ .../org/sonar/maven3/Maven3PluginExecutor.java | 55 ------- .../src/main/java/org/sonar/maven3/SonarMojo.java | 158 --------------------- 3 files changed, 8 insertions(+), 263 deletions(-) delete mode 100644 sonar-maven3-plugin/src/main/java/org/sonar/maven3/Maven3PluginExecutor.java delete mode 100644 sonar-maven3-plugin/src/main/java/org/sonar/maven3/SonarMojo.java (limited to 'sonar-maven3-plugin') diff --git a/sonar-maven3-plugin/pom.xml b/sonar-maven3-plugin/pom.xml index 2e5cf98cd49..18dd0a9c87e 100644 --- a/sonar-maven3-plugin/pom.xml +++ b/sonar-maven3-plugin/pom.xml @@ -7,55 +7,13 @@ 3.7-SNAPSHOT sonar-maven3-plugin - maven-plugin + pom Sonar :: Maven3 Plugin - - - 3.0 - - - - - org.apache.maven.shared - maven-dependency-tree - 1.2 - - - org.codehaus.sonar - sonar-batch - ${project.version} - - - org.slf4j - slf4j-api - - - ch.qos.logback - logback-classic - - - org.apache.maven - maven-plugin-api - ${maven.version} - provided - - - org.apache.maven - maven-core - ${maven.version} - provided - - - org.apache.maven - maven-compat - ${maven.version} - provided - - - org.apache.maven - maven-settings - ${maven.version} - provided - - + + + + sonar-maven-plugin + + + diff --git a/sonar-maven3-plugin/src/main/java/org/sonar/maven3/Maven3PluginExecutor.java b/sonar-maven3-plugin/src/main/java/org/sonar/maven3/Maven3PluginExecutor.java deleted file mode 100644 index 10dee626d3f..00000000000 --- a/sonar-maven3-plugin/src/main/java/org/sonar/maven3/Maven3PluginExecutor.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2013 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.maven3; - -import java.util.Arrays; - -import org.apache.maven.execution.MavenSession; -import org.apache.maven.lifecycle.LifecycleExecutor; -import org.apache.maven.project.MavenProject; -import org.sonar.api.utils.SonarException; -import org.sonar.batch.scan.maven.AbstractMavenPluginExecutor; - -public class Maven3PluginExecutor extends AbstractMavenPluginExecutor { - - private LifecycleExecutor lifecycleExecutor; - private MavenSession mavenSession; - - public Maven3PluginExecutor(LifecycleExecutor le, MavenSession mavenSession) { - this.lifecycleExecutor = le; - this.mavenSession = mavenSession; - } - - @Override - public void concreteExecute(MavenProject pom, String goal) { - MavenSession projectSession = mavenSession.clone(); - projectSession.setCurrentProject(pom); - projectSession.setProjects(Arrays.asList(pom)); - projectSession.getRequest().setRecursive(false); - projectSession.getRequest().setPom(pom.getFile()); - projectSession.getRequest().setGoals(Arrays.asList(goal)); - projectSession.getRequest().setInteractiveMode(false); - lifecycleExecutor.execute(projectSession); - if (projectSession.getResult().hasExceptions()) { - throw new SonarException("Exception during execution of " + goal); - } - } - -} 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 deleted file mode 100644 index 63ee50dc889..00000000000 --- a/sonar-maven3-plugin/src/main/java/org/sonar/maven3/SonarMojo.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2013 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.maven3; - -import com.google.common.collect.Maps; -import org.apache.maven.artifact.factory.ArtifactFactory; -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; -import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.project.MavenProject; -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.scan.maven.MavenProjectConverter; -import org.sonar.batch.bootstrapper.Batch; -import org.sonar.batch.bootstrapper.EnvironmentInformation; -import org.sonar.batch.bootstrapper.LoggingConfiguration; - -/** - * @goal sonar - * @aggregator - * @requiresDependencyResolution test - */ -public final class SonarMojo extends AbstractMojo { - - /** - * @parameter expression="${session}" - * @required - * @readonly - */ - private MavenSession session; - - /** - * @parameter expression="${project}" - * @required - * @readonly - */ - private MavenProject project; - - /** - * @component - * @required - */ - private LifecycleExecutor lifecycleExecutor; - - /** - * The artifact factory to use. - * - * @component - * @required - * @readonly - */ - private ArtifactFactory artifactFactory; - - /** - * The artifact repository to use. - * - * @parameter expression="${localRepository}" - * @required - * @readonly - */ - private ArtifactRepository localRepository; - - /** - * The artifact metadata source to use. - * - * @component - * @required - * @readonly - */ - private ArtifactMetadataSource artifactMetadataSource; - - /** - * The artifact collector to use. - * - * @component - * @required - * @readonly - */ - private ArtifactCollector artifactCollector; - - /** - * The dependency tree builder to use. - * - * @component - * @required - * @readonly - */ - private DependencyTreeBuilder dependencyTreeBuilder; - - /** - * @component - * @required - * @readonly - */ - private MavenProjectBuilder projectBuilder; - - /** - * @component - * @required - * @readonly - */ - private RuntimeInformation runtimeInformation; - - public void execute() throws MojoExecutionException, MojoFailureException { - ProjectDefinition def = MavenProjectConverter.convert(session.getProjects(), project); - ProjectReactor reactor = new ProjectReactor(def); - - Batch batch = Batch.builder() - .setEnvironment(getEnvironmentInformation()) - .setProjectReactor(reactor) - .addComponents( - session, getLog(), lifecycleExecutor, artifactFactory, localRepository, artifactMetadataSource, artifactCollector, - dependencyTreeBuilder, projectBuilder, Maven3PluginExecutor.class) - .build(); - - configureLogging(batch.getLoggingConfiguration()); - batch.execute(); - } - - private void configureLogging(LoggingConfiguration logging) { - logging.setProperties(Maps.fromProperties(session.getSystemProperties())); - logging.setFormat(LoggingConfiguration.FORMAT_MAVEN); - if (getLog().isDebugEnabled()) { - logging.setVerbose(true); - } - } - - private EnvironmentInformation getEnvironmentInformation() { - String mavenVersion = runtimeInformation.getApplicationVersion().toString(); - return new EnvironmentInformation("Maven", mavenVersion); - } - -} -- cgit v1.2.3