aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-maven3-plugin
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2013-06-17 10:34:10 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2013-06-19 13:49:11 +0200
commita52fbd8cd565f58464635906c54db7db87b3be77 (patch)
tree4bdbb503b519d17d179082b9e3bcc5041dc0684c /sonar-maven3-plugin
parent759ac46aaf07593fc0dca30466a440df5cd830c7 (diff)
downloadsonarqube-a52fbd8cd565f58464635906c54db7db87b3be77.tar.gz
sonarqube-a52fbd8cd565f58464635906c54db7db87b3be77.zip
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
Diffstat (limited to 'sonar-maven3-plugin')
-rw-r--r--sonar-maven3-plugin/pom.xml58
-rw-r--r--sonar-maven3-plugin/src/main/java/org/sonar/maven3/Maven3PluginExecutor.java55
-rw-r--r--sonar-maven3-plugin/src/main/java/org/sonar/maven3/SonarMojo.java158
3 files changed, 8 insertions, 263 deletions
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 @@
<version>3.7-SNAPSHOT</version>
</parent>
<artifactId>sonar-maven3-plugin</artifactId>
- <packaging>maven-plugin</packaging>
+ <packaging>pom</packaging>
<name>Sonar :: Maven3 Plugin</name>
-
- <properties>
- <maven.version>3.0</maven.version>
- </properties>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.maven.shared</groupId>
- <artifactId>maven-dependency-tree</artifactId>
- <version>1.2</version>
- </dependency>
- <dependency>
- <groupId>org.codehaus.sonar</groupId>
- <artifactId>sonar-batch</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- </dependency>
- <dependency>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-classic</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-plugin-api</artifactId>
- <version>${maven.version}</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-core</artifactId>
- <version>${maven.version}</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-compat</artifactId>
- <version>${maven.version}</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-settings</artifactId>
- <version>${maven.version}</version>
- <scope>provided</scope>
- </dependency>
- </dependencies>
+ <!-- Since Sonar 3.7 there is no more difference between Maven 2 and Maven 3 so relocate to Maven 2 plugin to avoid duplication -->
+ <distributionManagement>
+ <relocation>
+ <artifactId>sonar-maven-plugin</artifactId>
+ </relocation>
+ </distributionManagement>
+
</project>
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);
- }
-
-}