aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-maven-plugin
diff options
context:
space:
mode:
authorEvgeny Mandrikov <mandrikov@gmail.com>2011-01-28 23:59:48 +0300
committerEvgeny Mandrikov <mandrikov@gmail.com>2011-01-29 00:42:29 +0300
commitdfbaa4c9d060f5dd32b0c49470d11d8cf51c50f7 (patch)
tree2aae714608edef95a2d46c178ea5d0ae92231d10 /sonar-maven-plugin
parent73e6ee80edae3e5f2a543df88776e1039b425462 (diff)
downloadsonarqube-dfbaa4c9d060f5dd32b0c49470d11d8cf51c50f7.tar.gz
sonarqube-dfbaa4c9d060f5dd32b0c49470d11d8cf51c50f7.zip
SONAR-1800: Fix issue with ClassLoader for Maven 3.x and Java 1.5
* Restore context ClassLoader after execution of Maven plugin. * Add abstract implementation of MavenPluginExecutor to reduce duplications in concrete implementations for different Maven versions.
Diffstat (limited to 'sonar-maven-plugin')
-rw-r--r--sonar-maven-plugin/src/main/java/org/sonar/maven/Maven2PluginExecutor.java59
1 files changed, 16 insertions, 43 deletions
diff --git a/sonar-maven-plugin/src/main/java/org/sonar/maven/Maven2PluginExecutor.java b/sonar-maven-plugin/src/main/java/org/sonar/maven/Maven2PluginExecutor.java
index e39a64415d6..c39c4ebedd2 100644
--- a/sonar-maven-plugin/src/main/java/org/sonar/maven/Maven2PluginExecutor.java
+++ b/sonar-maven-plugin/src/main/java/org/sonar/maven/Maven2PluginExecutor.java
@@ -22,15 +22,12 @@ package org.sonar.maven;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.execution.ReactorManager;
import org.apache.maven.lifecycle.LifecycleExecutor;
-import org.sonar.api.batch.maven.MavenPlugin;
-import org.sonar.api.batch.maven.MavenPluginHandler;
-import org.sonar.api.resources.Project;
-import org.sonar.api.utils.SonarException;
-import org.sonar.batch.MavenPluginExecutor;
+import org.apache.maven.project.MavenProject;
+import org.sonar.batch.AbstractMavenPluginExecutor;
import java.util.Arrays;
-public class Maven2PluginExecutor implements MavenPluginExecutor {
+public class Maven2PluginExecutor extends AbstractMavenPluginExecutor {
private LifecycleExecutor lifecycleExecutor;
private MavenSession mavenSession;
@@ -40,43 +37,19 @@ public class Maven2PluginExecutor implements MavenPluginExecutor {
this.mavenSession = mavenSession;
}
- public MavenPluginHandler execute(Project project, MavenPluginHandler handler) {
- for (String goal : handler.getGoals()) {
- MavenPlugin plugin = MavenPlugin.getPlugin(project.getPom(), handler.getGroupId(), handler.getArtifactId());
- execute(project, getGoal(handler.getGroupId(), handler.getArtifactId(), plugin.getPlugin().getVersion(), goal));
- }
- return handler;
+ @Override
+ public void concreteExecute(MavenProject pom, String goal) throws Exception {
+ ReactorManager reactor = new ReactorManager(Arrays.asList(pom));
+ MavenSession clonedSession = new MavenSession(mavenSession.getContainer(),
+ mavenSession.getSettings(),
+ mavenSession.getLocalRepository(),
+ mavenSession.getEventDispatcher(),
+ reactor,
+ Arrays.asList(goal),
+ mavenSession.getExecutionRootDirectory(),
+ mavenSession.getExecutionProperties(),
+ mavenSession.getStartTime());
+ lifecycleExecutor.execute(clonedSession, reactor, clonedSession.getEventDispatcher());
}
- public void execute(Project project, String goal) {
- try {
- ReactorManager reactor = new ReactorManager(Arrays.asList(project.getPom()));
- MavenSession clonedSession = new MavenSession(mavenSession.getContainer(),
- mavenSession.getSettings(),
- mavenSession.getLocalRepository(),
- mavenSession.getEventDispatcher(),
- reactor,
- Arrays.asList(goal),
- mavenSession.getExecutionRootDirectory(),
- mavenSession.getExecutionProperties(),
- mavenSession.getStartTime()
- );
- lifecycleExecutor.execute(clonedSession, reactor, clonedSession.getEventDispatcher());
-
- } catch (Exception e) {
- throw new SonarException("Unable to execute maven plugin", e);
-
- }
- }
-
- protected static String getGoal(String groupId, String artifactId, String version, String goal) {
- String defaultVersion = (version==null ? "" : version);
- return new StringBuilder()
- .append(groupId).append(":")
- .append(artifactId).append(":")
- .append(defaultVersion)
- .append(":")
- .append(goal)
- .toString();
- }
}