aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-maven3-plugin
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2013-06-17 17:45:56 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2013-06-17 17:45:56 +0200
commit32ec8599d050066e41e12acd4b554febd3920197 (patch)
treef06a136a4e426e4b8ef8491627e1eb52fb1529c6 /sonar-maven3-plugin
parenta07ebb829958f3aa566b6246e4643dad91b96b6c (diff)
downloadsonarqube-32ec8599d050066e41e12acd4b554febd3920197.tar.gz
sonarqube-32ec8599d050066e41e12acd4b554febd3920197.zip
Revert "SONAR-3979, SONAR-4047 Fix Sonar Maven goal to support Maven 3.1"
This reverts commit ceaddeb0db54d29fd67d11f23488f61f85041446.
Diffstat (limited to 'sonar-maven3-plugin')
-rw-r--r--sonar-maven3-plugin/pom.xml10
-rw-r--r--sonar-maven3-plugin/src/main/java/org/sonar/maven3/SonarMaven3ProjectBuilder.java21
-rw-r--r--sonar-maven3-plugin/src/main/java/org/sonar/maven3/SonarMojo.java65
3 files changed, 32 insertions, 64 deletions
diff --git a/sonar-maven3-plugin/pom.xml b/sonar-maven3-plugin/pom.xml
index 79415af2b4d..2e5cf98cd49 100644
--- a/sonar-maven3-plugin/pom.xml
+++ b/sonar-maven3-plugin/pom.xml
@@ -18,11 +18,7 @@
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-dependency-tree</artifactId>
- </dependency>
- <dependency>
- <groupId>org.codehaus.sonar.runner</groupId>
- <artifactId>sonar-runner-api</artifactId>
- <version>2.2.2</version>
+ <version>1.2</version>
</dependency>
<dependency>
<groupId>org.codehaus.sonar</groupId>
@@ -34,6 +30,10 @@
<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>
diff --git a/sonar-maven3-plugin/src/main/java/org/sonar/maven3/SonarMaven3ProjectBuilder.java b/sonar-maven3-plugin/src/main/java/org/sonar/maven3/SonarMaven3ProjectBuilder.java
deleted file mode 100644
index 50843f90c8d..00000000000
--- a/sonar-maven3-plugin/src/main/java/org/sonar/maven3/SonarMaven3ProjectBuilder.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package org.sonar.maven3;
-
-import org.apache.maven.execution.MavenSession;
-import org.sonar.api.batch.bootstrap.ProjectBuilder;
-import org.sonar.api.batch.bootstrap.ProjectBuilderContext;
-import org.sonar.batch.scan.maven.MavenProjectConverter;
-
-public class SonarMaven3ProjectBuilder extends ProjectBuilder {
-
- private MavenSession session;
-
- public SonarMaven3ProjectBuilder(MavenSession session) {
- this.session = session;
- }
-
- @Override
- public void build(ProjectBuilderContext context) {
- MavenProjectConverter.configure(context.getProjectReactor().getRoot(), session.getProjects(), session.getTopLevelProject());
- }
-
-}
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 0558954d7dd..63ee50dc889 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
@@ -19,8 +19,7 @@
*/
package org.sonar.maven3;
-import org.apache.commons.lang.ObjectUtils;
-import org.apache.commons.lang.StringUtils;
+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;
@@ -34,14 +33,12 @@ 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.maven.MavenUtils;
+import org.sonar.api.batch.bootstrap.ProjectDefinition;
+import org.sonar.api.batch.bootstrap.ProjectReactor;
import org.sonar.batch.scan.maven.MavenProjectConverter;
-import org.sonar.runner.api.EmbeddedRunner;
-import org.sonar.runner.api.RunnerProperties;
-import org.sonar.runner.api.ScanProperties;
-
-import java.util.Map.Entry;
-import java.util.Set;
+import org.sonar.batch.bootstrapper.Batch;
+import org.sonar.batch.bootstrapper.EnvironmentInformation;
+import org.sonar.batch.bootstrapper.LoggingConfiguration;
/**
* @goal sonar
@@ -130,40 +127,32 @@ public final class SonarMojo extends AbstractMojo {
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();
+ }
- EmbeddedRunner runner = EmbeddedRunner.create()
- .setApp("Maven", getMavenVersion());
- // Workaround for SONARPLUGINS-2947
- // TODO remove when it will be fixed
- runner.setProperty("sonarRunner.userAgent", "Maven");
- runner.setProperty("sonarRunner.userAgentVersion", getMavenVersion());
- Set<Entry<Object, Object>> properties = project.getModel().getProperties().entrySet();
- for (Entry<Object, Object> entry : properties) {
- runner.setProperty(ObjectUtils.toString(entry.getKey()), ObjectUtils.toString(entry.getValue()));
- }
- String encoding = MavenUtils.getSourceEncoding(project);
- if (encoding != null) {
- runner.setProperty(ScanProperties.PROJECT_SOURCE_ENCODING, encoding);
- }
- runner.setProperty(ScanProperties.PROJECT_KEY, MavenProjectConverter.getSonarKey(project))
- .setProperty(RunnerProperties.WORK_DIR, MavenProjectConverter.getSonarWorkDir(project).getAbsolutePath())
- .setProperty(ScanProperties.PROJECT_BASEDIR, project.getBasedir().getAbsolutePath())
- .setProperty(ScanProperties.PROJECT_VERSION, StringUtils.defaultString(project.getVersion()))
- .setProperty(ScanProperties.PROJECT_NAME, StringUtils.defaultString(project.getName()))
- .setProperty(ScanProperties.PROJECT_DESCRIPTION, StringUtils.defaultString(project.getDescription()))
- .setProperty(ScanProperties.PROJECT_SOURCE_DIRS, ".")
- // Required to share ProjectBuilder extension between SonarMavenProjectBuilder and Sonar classloader
- .setUnmaskedPackages("org.sonar.api.batch.bootstrap")
- .addExtensions(session, getLog(), lifecycleExecutor, artifactFactory, localRepository, artifactMetadataSource, artifactCollector,
- dependencyTreeBuilder, projectBuilder, Maven3PluginExecutor.class, new SonarMaven3ProjectBuilder(session));
+ private void configureLogging(LoggingConfiguration logging) {
+ logging.setProperties(Maps.fromProperties(session.getSystemProperties()));
+ logging.setFormat(LoggingConfiguration.FORMAT_MAVEN);
if (getLog().isDebugEnabled()) {
- runner.setProperty("sonar.verbose", "true");
+ logging.setVerbose(true);
}
- runner.execute();
}
- private String getMavenVersion() {
- return runtimeInformation.getApplicationVersion().toString();
+ private EnvironmentInformation getEnvironmentInformation() {
+ String mavenVersion = runtimeInformation.getApplicationVersion().toString();
+ return new EnvironmentInformation("Maven", mavenVersion);
}
}