diff options
author | Evgeny Mandrikov <mandrikov@gmail.com> | 2011-01-28 23:59:48 +0300 |
---|---|---|
committer | Evgeny Mandrikov <mandrikov@gmail.com> | 2011-01-29 00:42:29 +0300 |
commit | dfbaa4c9d060f5dd32b0c49470d11d8cf51c50f7 (patch) | |
tree | 2aae714608edef95a2d46c178ea5d0ae92231d10 /sonar-maven3-plugin | |
parent | 73e6ee80edae3e5f2a543df88776e1039b425462 (diff) | |
download | sonarqube-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-maven3-plugin')
-rw-r--r-- | sonar-maven3-plugin/src/main/java/org/sonar/maven3/Maven3PluginExecutor.java | 56 |
1 files changed, 13 insertions, 43 deletions
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 index b72710b13f9..31fdb5f875b 100644 --- a/sonar-maven3-plugin/src/main/java/org/sonar/maven3/Maven3PluginExecutor.java +++ b/sonar-maven3-plugin/src/main/java/org/sonar/maven3/Maven3PluginExecutor.java @@ -21,16 +21,12 @@ package org.sonar.maven3; import org.apache.maven.execution.MavenSession; 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.api.utils.TimeProfiler; -import org.sonar.batch.MavenPluginExecutor; +import org.apache.maven.project.MavenProject; +import org.sonar.batch.AbstractMavenPluginExecutor; import java.util.Arrays; -public class Maven3PluginExecutor implements MavenPluginExecutor { +public class Maven3PluginExecutor extends AbstractMavenPluginExecutor { private LifecycleExecutor lifecycleExecutor; private MavenSession mavenSession; @@ -40,42 +36,16 @@ public class Maven3PluginExecutor 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) { + 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); } - public void execute(Project project, String goalOrPhase) { - TimeProfiler profiler = new TimeProfiler().start("Execute " + goalOrPhase); - try { - MavenSession projectSession = mavenSession.clone(); - projectSession.setCurrentProject(project.getPom()); - projectSession.setProjects(Arrays.asList(project.getPom())); - projectSession.getRequest().setRecursive(false); - projectSession.getRequest().setPom(project.getPom().getFile()); - projectSession.getRequest().setGoals(Arrays.asList(goalOrPhase)); - projectSession.getRequest().setInteractiveMode(false); - lifecycleExecutor.execute(projectSession); - - } catch (Exception e) { - throw new SonarException("Unable to execute maven plugin", e); - - } finally { - profiler.stop(); - } - } - - 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(); - } } |