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-core-maven-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-core-maven-plugin')
-rw-r--r-- | sonar-core-maven-plugin/src/main/java/org/sonar/maven2/Maven2PluginExecutor.java | 44 | ||||
-rw-r--r-- | sonar-core-maven-plugin/src/test/java/org/sonar/maven2/Maven2PluginExecutorTest.java | 62 |
2 files changed, 9 insertions, 97 deletions
diff --git a/sonar-core-maven-plugin/src/main/java/org/sonar/maven2/Maven2PluginExecutor.java b/sonar-core-maven-plugin/src/main/java/org/sonar/maven2/Maven2PluginExecutor.java index 858f2e52a95..3e0099a4a94 100644 --- a/sonar-core-maven-plugin/src/main/java/org/sonar/maven2/Maven2PluginExecutor.java +++ b/sonar-core-maven-plugin/src/main/java/org/sonar/maven2/Maven2PluginExecutor.java @@ -19,19 +19,15 @@ */ package org.sonar.maven2; -import org.apache.commons.lang.StringUtils; 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; @@ -41,18 +37,10 @@ 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; - } - - public void execute(Project project, String goal) { - try { - ReactorManager reactor = new ReactorManager(Arrays.asList(project.getPom())); - MavenSession clonedSession = new MavenSession(mavenSession.getContainer(), + @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(), @@ -60,22 +48,8 @@ public class Maven2PluginExecutor implements MavenPluginExecutor { 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); - - } + mavenSession.getStartTime()); + lifecycleExecutor.execute(clonedSession, reactor, clonedSession.getEventDispatcher()); } - protected static String getGoal(String groupId, String artifactId, String version, String goal) { - return new StringBuilder() - .append(groupId).append(":") - .append(artifactId).append(":") - .append(StringUtils.defaultString(version, "")).append(":") - .append(goal) - .toString(); - } } diff --git a/sonar-core-maven-plugin/src/test/java/org/sonar/maven2/Maven2PluginExecutorTest.java b/sonar-core-maven-plugin/src/test/java/org/sonar/maven2/Maven2PluginExecutorTest.java deleted file mode 100644 index f59f98df3f9..00000000000 --- a/sonar-core-maven-plugin/src/test/java/org/sonar/maven2/Maven2PluginExecutorTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * Sonar 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. - * - * Sonar 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 Sonar; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 - */ -package org.sonar.maven2; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; -import org.junit.Test; -import org.sonar.api.batch.maven.MavenPlugin; -import org.sonar.api.batch.maven.MavenPluginHandler; -import org.sonar.api.resources.Project; - -public class Maven2PluginExecutorTest { - - @Test - public void pluginVersionIsOptional() { - assertThat(Maven2PluginExecutor.getGoal("group", "artifact", null, "goal"), is("group:artifact::goal")); - } - - static class FakeCheckstyleMavenPluginHandler implements MavenPluginHandler { - - public String getGroupId() { - return "org.apache.maven.plugins"; - } - - public String getArtifactId() { - return "maven-checkstyle-plugin"; - } - - public String getVersion() { - return "2.2"; - } - - public boolean isFixedVersion() { - return false; - } - - public String[] getGoals() { - return new String[]{"checkstyle"}; - } - - public void configure(Project project, MavenPlugin plugin) { - - } - } -} |