From 2a52174013f4ab8407146888b0b0be2d35717d23 Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Wed, 19 Jun 2013 15:00:30 +0200 Subject: [PATCH] SONAR-4047 Move Maven specific classes to the new Maven Batch plugin --- plugins/sonar-maven-batch-plugin/pom.xml | 7 ++ .../sonar/plugins/maven/MavenBatchPlugin.java | 3 +- .../plugins}/maven/MavenProjectConverter.java | 2 +- ...utor.java => RealMavenPluginExecutor.java} | 52 ++++++++++++- .../maven/SonarMavenProjectBuilder.java | 1 - .../maven/MavenProjectConverterTest.java | 34 ++++----- .../maven/RealMavenPluginExecutorTest.java | 15 ++-- .../module/pom.xml | 0 .../module/pom_having_different_name.xml | 0 .../pom.xml | 0 .../path1/pom.xml | 0 .../path2/pom.xml | 0 .../moduleNameDifferentThanArtifactId/pom.xml | 0 .../module1/pom.xml | 0 .../module2/pom.xml | 0 .../moduleNameShouldEqualArtifactId/pom.xml | 0 .../projectWithLinks/pom.xml | 0 .../projectWithLinksAndProperties/pom.xml | 0 .../singleProjectWithoutModules/pom.xml | 0 .../sourceEncoding/pom.xml | 0 .../maven/AbstractMavenPluginExecutor.java | 76 ------------------- .../scan/maven/FakeMavenPluginExecutor.java | 6 +- .../batch/scan/maven/MavenPluginExecutor.java | 4 +- 23 files changed, 88 insertions(+), 112 deletions(-) rename {sonar-batch/src/main/java/org/sonar/batch/scan => plugins/sonar-maven-batch-plugin/src/main/java/org/sonar/plugins}/maven/MavenProjectConverter.java (99%) rename plugins/sonar-maven-batch-plugin/src/main/java/org/sonar/plugins/maven/{MavenPluginExecutor.java => RealMavenPluginExecutor.java} (63%) rename {sonar-batch/src/test/java/org/sonar/batch/scan => plugins/sonar-maven-batch-plugin/src/test/java/org/sonar/plugins}/maven/MavenProjectConverterTest.java (80%) rename sonar-batch/src/test/java/org/sonar/batch/scan/maven/AbstractMavenPluginExecutorTest.java => plugins/sonar-maven-batch-plugin/src/test/java/org/sonar/plugins/maven/RealMavenPluginExecutorTest.java (86%) rename {sonar-batch/src/test/resources/org/sonar/batch/scan => plugins/sonar-maven-batch-plugin/src/test/resources/org/sonar/plugins}/maven/MavenProjectConverterTest/mavenProjectFileNameNotEqualsToPomXml/module/pom.xml (100%) rename {sonar-batch/src/test/resources/org/sonar/batch/scan => plugins/sonar-maven-batch-plugin/src/test/resources/org/sonar/plugins}/maven/MavenProjectConverterTest/mavenProjectFileNameNotEqualsToPomXml/module/pom_having_different_name.xml (100%) rename {sonar-batch/src/test/resources/org/sonar/batch/scan => plugins/sonar-maven-batch-plugin/src/test/resources/org/sonar/plugins}/maven/MavenProjectConverterTest/mavenProjectFileNameNotEqualsToPomXml/pom.xml (100%) rename {sonar-batch/src/test/resources/org/sonar/batch/scan => plugins/sonar-maven-batch-plugin/src/test/resources/org/sonar/plugins}/maven/MavenProjectConverterTest/moduleNameDifferentThanArtifactId/path1/pom.xml (100%) rename {sonar-batch/src/test/resources/org/sonar/batch/scan => plugins/sonar-maven-batch-plugin/src/test/resources/org/sonar/plugins}/maven/MavenProjectConverterTest/moduleNameDifferentThanArtifactId/path2/pom.xml (100%) rename {sonar-batch/src/test/resources/org/sonar/batch/scan => plugins/sonar-maven-batch-plugin/src/test/resources/org/sonar/plugins}/maven/MavenProjectConverterTest/moduleNameDifferentThanArtifactId/pom.xml (100%) rename {sonar-batch/src/test/resources/org/sonar/batch/scan => plugins/sonar-maven-batch-plugin/src/test/resources/org/sonar/plugins}/maven/MavenProjectConverterTest/moduleNameShouldEqualArtifactId/module1/pom.xml (100%) rename {sonar-batch/src/test/resources/org/sonar/batch/scan => plugins/sonar-maven-batch-plugin/src/test/resources/org/sonar/plugins}/maven/MavenProjectConverterTest/moduleNameShouldEqualArtifactId/module2/pom.xml (100%) rename {sonar-batch/src/test/resources/org/sonar/batch/scan => plugins/sonar-maven-batch-plugin/src/test/resources/org/sonar/plugins}/maven/MavenProjectConverterTest/moduleNameShouldEqualArtifactId/pom.xml (100%) rename {sonar-batch/src/test/resources/org/sonar/batch/scan => plugins/sonar-maven-batch-plugin/src/test/resources/org/sonar/plugins}/maven/MavenProjectConverterTest/projectWithLinks/pom.xml (100%) rename {sonar-batch/src/test/resources/org/sonar/batch/scan => plugins/sonar-maven-batch-plugin/src/test/resources/org/sonar/plugins}/maven/MavenProjectConverterTest/projectWithLinksAndProperties/pom.xml (100%) rename {sonar-batch/src/test/resources/org/sonar/batch/scan => plugins/sonar-maven-batch-plugin/src/test/resources/org/sonar/plugins}/maven/MavenProjectConverterTest/singleProjectWithoutModules/pom.xml (100%) rename {sonar-batch/src/test/resources/org/sonar/batch/scan => plugins/sonar-maven-batch-plugin/src/test/resources/org/sonar/plugins}/maven/MavenProjectConverterTest/sourceEncoding/pom.xml (100%) delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/maven/AbstractMavenPluginExecutor.java diff --git a/plugins/sonar-maven-batch-plugin/pom.xml b/plugins/sonar-maven-batch-plugin/pom.xml index 8cdaa95f80e..58e073fe901 100644 --- a/plugins/sonar-maven-batch-plugin/pom.xml +++ b/plugins/sonar-maven-batch-plugin/pom.xml @@ -40,6 +40,13 @@ ${maven.version} provided + + + + org.codehaus.sonar + sonar-testing-harness + test + diff --git a/plugins/sonar-maven-batch-plugin/src/main/java/org/sonar/plugins/maven/MavenBatchPlugin.java b/plugins/sonar-maven-batch-plugin/src/main/java/org/sonar/plugins/maven/MavenBatchPlugin.java index d8a44dd84a1..257d9dcb1d3 100644 --- a/plugins/sonar-maven-batch-plugin/src/main/java/org/sonar/plugins/maven/MavenBatchPlugin.java +++ b/plugins/sonar-maven-batch-plugin/src/main/java/org/sonar/plugins/maven/MavenBatchPlugin.java @@ -27,7 +27,6 @@ import java.util.List; public final class MavenBatchPlugin extends SonarPlugin { public List getExtensions() { - return ImmutableList.builder().add(SonarMavenProjectBuilder.class, MavenPluginExecutor.class) - .build(); + return ImmutableList.of(SonarMavenProjectBuilder.class, RealMavenPluginExecutor.class); } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/maven/MavenProjectConverter.java b/plugins/sonar-maven-batch-plugin/src/main/java/org/sonar/plugins/maven/MavenProjectConverter.java similarity index 99% rename from sonar-batch/src/main/java/org/sonar/batch/scan/maven/MavenProjectConverter.java rename to plugins/sonar-maven-batch-plugin/src/main/java/org/sonar/plugins/maven/MavenProjectConverter.java index 41f0e8f72e1..5a884f3e628 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/maven/MavenProjectConverter.java +++ b/plugins/sonar-maven-batch-plugin/src/main/java/org/sonar/plugins/maven/MavenProjectConverter.java @@ -17,7 +17,7 @@ * 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.batch.scan.maven; +package org.sonar.plugins.maven; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Predicate; diff --git a/plugins/sonar-maven-batch-plugin/src/main/java/org/sonar/plugins/maven/MavenPluginExecutor.java b/plugins/sonar-maven-batch-plugin/src/main/java/org/sonar/plugins/maven/RealMavenPluginExecutor.java similarity index 63% rename from plugins/sonar-maven-batch-plugin/src/main/java/org/sonar/plugins/maven/MavenPluginExecutor.java rename to plugins/sonar-maven-batch-plugin/src/main/java/org/sonar/plugins/maven/RealMavenPluginExecutor.java index d11003cc9af..69a0d6b36f5 100644 --- a/plugins/sonar-maven-batch-plugin/src/main/java/org/sonar/plugins/maven/MavenPluginExecutor.java +++ b/plugins/sonar-maven-batch-plugin/src/main/java/org/sonar/plugins/maven/RealMavenPluginExecutor.java @@ -24,25 +24,69 @@ import org.apache.maven.execution.ReactorManager; import org.apache.maven.lifecycle.LifecycleExecutor; import org.apache.maven.project.MavenProject; import org.sonar.api.batch.SupportedEnvironment; -import org.sonar.api.task.TaskExtension; +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.scan.maven.AbstractMavenPluginExecutor; +import org.sonar.api.utils.TimeProfiler; +import org.sonar.batch.scan.filesystem.DefaultModuleFileSystem; +import org.sonar.batch.scan.maven.MavenPluginExecutor; import java.lang.reflect.Method; import java.util.Arrays; @SupportedEnvironment("maven") -public class MavenPluginExecutor extends AbstractMavenPluginExecutor implements TaskExtension { +public class RealMavenPluginExecutor implements MavenPluginExecutor { private LifecycleExecutor lifecycleExecutor; private MavenSession mavenSession; - public MavenPluginExecutor(LifecycleExecutor le, MavenSession mavenSession) { + public RealMavenPluginExecutor(LifecycleExecutor le, MavenSession mavenSession) { this.lifecycleExecutor = le; this.mavenSession = mavenSession; } @Override + public final MavenPluginHandler execute(Project project, DefaultModuleFileSystem fs, MavenPluginHandler handler) { + for (String goal : handler.getGoals()) { + MavenPlugin plugin = MavenPlugin.getPlugin(project.getPom(), handler.getGroupId(), handler.getArtifactId()); + execute(project, + fs, + getGoal(handler.getGroupId(), handler.getArtifactId(), (plugin != null && plugin.getPlugin() != null ? plugin.getPlugin().getVersion() : null), goal)); + } + return handler; + } + + @Override + public final void execute(Project project, DefaultModuleFileSystem fs, String goal) { + if (project.getPom() != null) { + TimeProfiler profiler = new TimeProfiler().start("Execute " + goal); + ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader(); + try { + concreteExecute(project.getPom(), goal); + } catch (Exception e) { + throw new SonarException("Unable to execute maven plugin", e); + } finally { + // Reset original ClassLoader that may have been changed during Maven Execution (see SONAR-1800) + Thread.currentThread().setContextClassLoader(currentClassLoader); + profiler.stop(); + } + + MavenProjectConverter.synchronizeFileSystem(project.getPom(), fs); + } + } + + 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(); + } + public void concreteExecute(MavenProject pom, String goal) throws Exception { Method executeMethod = null; for (Method m : lifecycleExecutor.getClass().getMethods()) { diff --git a/plugins/sonar-maven-batch-plugin/src/main/java/org/sonar/plugins/maven/SonarMavenProjectBuilder.java b/plugins/sonar-maven-batch-plugin/src/main/java/org/sonar/plugins/maven/SonarMavenProjectBuilder.java index d8b66f64743..0c576dc32cb 100644 --- a/plugins/sonar-maven-batch-plugin/src/main/java/org/sonar/plugins/maven/SonarMavenProjectBuilder.java +++ b/plugins/sonar-maven-batch-plugin/src/main/java/org/sonar/plugins/maven/SonarMavenProjectBuilder.java @@ -24,7 +24,6 @@ import org.apache.maven.project.MavenProject; import org.sonar.api.batch.SupportedEnvironment; import org.sonar.api.batch.bootstrap.ProjectBuilder; import org.sonar.api.batch.bootstrap.ProjectBuilderContext; -import org.sonar.batch.scan.maven.MavenProjectConverter; import java.util.List; diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/maven/MavenProjectConverterTest.java b/plugins/sonar-maven-batch-plugin/src/test/java/org/sonar/plugins/maven/MavenProjectConverterTest.java similarity index 80% rename from sonar-batch/src/test/java/org/sonar/batch/scan/maven/MavenProjectConverterTest.java rename to plugins/sonar-maven-batch-plugin/src/test/java/org/sonar/plugins/maven/MavenProjectConverterTest.java index f4fc136cab9..d1ae22d872e 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/scan/maven/MavenProjectConverterTest.java +++ b/plugins/sonar-maven-batch-plugin/src/test/java/org/sonar/plugins/maven/MavenProjectConverterTest.java @@ -17,7 +17,7 @@ * 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.batch.scan.maven; +package org.sonar.plugins.maven; import org.apache.commons.io.FileUtils; import org.apache.maven.model.Model; @@ -117,10 +117,10 @@ public class MavenProjectConverterTest { @Test public void moduleNameShouldEqualArtifactId() throws Exception { - File rootDir = TestUtils.getResource("/org/sonar/batch/scan/maven/MavenProjectConverterTest/moduleNameShouldEqualArtifactId/"); - MavenProject parent = loadPom("/org/sonar/batch/scan/maven/MavenProjectConverterTest/moduleNameShouldEqualArtifactId/pom.xml", true); - MavenProject module1 = loadPom("/org/sonar/batch/scan/maven/MavenProjectConverterTest/moduleNameShouldEqualArtifactId/module1/pom.xml", false); - MavenProject module2 = loadPom("/org/sonar/batch/scan/maven/MavenProjectConverterTest/moduleNameShouldEqualArtifactId/module2/pom.xml", false); + File rootDir = TestUtils.getResource("/org/sonar/plugins/maven/MavenProjectConverterTest/moduleNameShouldEqualArtifactId/"); + MavenProject parent = loadPom("/org/sonar/plugins/maven/MavenProjectConverterTest/moduleNameShouldEqualArtifactId/pom.xml", true); + MavenProject module1 = loadPom("/org/sonar/plugins/maven/MavenProjectConverterTest/moduleNameShouldEqualArtifactId/module1/pom.xml", false); + MavenProject module2 = loadPom("/org/sonar/plugins/maven/MavenProjectConverterTest/moduleNameShouldEqualArtifactId/module2/pom.xml", false); ProjectDefinition rootDef = MavenProjectConverter.convert(Arrays.asList(parent, module1, module2), parent); @@ -138,10 +138,10 @@ public class MavenProjectConverterTest { @Test public void moduleNameDifferentThanArtifactId() throws Exception { - File rootDir = TestUtils.getResource("/org/sonar/batch/scan/maven/MavenProjectConverterTest/moduleNameDifferentThanArtifactId/"); - MavenProject parent = loadPom("/org/sonar/batch/scan/maven/MavenProjectConverterTest/moduleNameDifferentThanArtifactId/pom.xml", true); - MavenProject module1 = loadPom("/org/sonar/batch/scan/maven/MavenProjectConverterTest/moduleNameDifferentThanArtifactId/path1/pom.xml", false); - MavenProject module2 = loadPom("/org/sonar/batch/scan/maven/MavenProjectConverterTest/moduleNameDifferentThanArtifactId/path2/pom.xml", false); + File rootDir = TestUtils.getResource("/org/sonar/plugins/maven/MavenProjectConverterTest/moduleNameDifferentThanArtifactId/"); + MavenProject parent = loadPom("/org/sonar/plugins/maven/MavenProjectConverterTest/moduleNameDifferentThanArtifactId/pom.xml", true); + MavenProject module1 = loadPom("/org/sonar/plugins/maven/MavenProjectConverterTest/moduleNameDifferentThanArtifactId/path1/pom.xml", false); + MavenProject module2 = loadPom("/org/sonar/plugins/maven/MavenProjectConverterTest/moduleNameDifferentThanArtifactId/path2/pom.xml", false); ProjectDefinition rootDef = MavenProjectConverter.convert(Arrays.asList(parent, module1, module2), parent); @@ -159,9 +159,9 @@ public class MavenProjectConverterTest { @Test public void should_find_module_with_maven_project_file_naming_different_from_pom_xml() throws Exception { - File rootDir = TestUtils.getResource("/org/sonar/batch/scan/maven/MavenProjectConverterTest/mavenProjectFileNameNotEqualsToPomXml/"); - MavenProject parent = loadPom("/org/sonar/batch/scan/maven/MavenProjectConverterTest/mavenProjectFileNameNotEqualsToPomXml/pom.xml", true); - MavenProject module = loadPom("/org/sonar/batch/scan/maven/MavenProjectConverterTest/mavenProjectFileNameNotEqualsToPomXml/module/pom_having_different_name.xml", false); + File rootDir = TestUtils.getResource("/org/sonar/plugins/maven/MavenProjectConverterTest/mavenProjectFileNameNotEqualsToPomXml/"); + MavenProject parent = loadPom("/org/sonar/plugins/maven/MavenProjectConverterTest/mavenProjectFileNameNotEqualsToPomXml/pom.xml", true); + MavenProject module = loadPom("/org/sonar/plugins/maven/MavenProjectConverterTest/mavenProjectFileNameNotEqualsToPomXml/module/pom_having_different_name.xml", false); ProjectDefinition rootDef = MavenProjectConverter.convert(Arrays.asList(parent, module), parent); @@ -179,8 +179,8 @@ public class MavenProjectConverterTest { @Test public void testSingleProjectWithoutModules() throws Exception { - File rootDir = TestUtils.getResource("/org/sonar/batch/scan/maven/MavenProjectConverterTest/singleProjectWithoutModules/"); - MavenProject pom = loadPom("/org/sonar/batch/scan/maven/MavenProjectConverterTest/singleProjectWithoutModules/pom.xml", true); + File rootDir = TestUtils.getResource("/org/sonar/plugins/maven/MavenProjectConverterTest/singleProjectWithoutModules/"); + MavenProject pom = loadPom("/org/sonar/plugins/maven/MavenProjectConverterTest/singleProjectWithoutModules/pom.xml", true); ProjectDefinition rootDef = MavenProjectConverter.convert(Arrays.asList(pom), pom); @@ -192,7 +192,7 @@ public class MavenProjectConverterTest { @Test public void shouldConvertLinksToProperties() throws Exception { - MavenProject pom = loadPom("/org/sonar/batch/scan/maven/MavenProjectConverterTest/projectWithLinks/pom.xml", true); + MavenProject pom = loadPom("/org/sonar/plugins/maven/MavenProjectConverterTest/projectWithLinks/pom.xml", true); ProjectDefinition rootDef = MavenProjectConverter.convert(Arrays.asList(pom), pom); @@ -206,7 +206,7 @@ public class MavenProjectConverterTest { @Test public void shouldNotConvertLinksToPropertiesIfPropertyAlreadyDefined() throws Exception { - MavenProject pom = loadPom("/org/sonar/batch/scan/maven/MavenProjectConverterTest/projectWithLinksAndProperties/pom.xml", true); + MavenProject pom = loadPom("/org/sonar/plugins/maven/MavenProjectConverterTest/projectWithLinksAndProperties/pom.xml", true); ProjectDefinition rootDef = MavenProjectConverter.convert(Arrays.asList(pom), pom); @@ -224,7 +224,7 @@ public class MavenProjectConverterTest { @Test public void shouldLoadSourceEncoding() throws Exception { - MavenProject pom = loadPom("/org/sonar/batch/scan/maven/MavenProjectConverterTest/sourceEncoding/pom.xml", true); + MavenProject pom = loadPom("/org/sonar/plugins/maven/MavenProjectConverterTest/sourceEncoding/pom.xml", true); ProjectDefinition rootDef = MavenProjectConverter.convert(Arrays.asList(pom), pom); diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/maven/AbstractMavenPluginExecutorTest.java b/plugins/sonar-maven-batch-plugin/src/test/java/org/sonar/plugins/maven/RealMavenPluginExecutorTest.java similarity index 86% rename from sonar-batch/src/test/java/org/sonar/batch/scan/maven/AbstractMavenPluginExecutorTest.java rename to plugins/sonar-maven-batch-plugin/src/test/java/org/sonar/plugins/maven/RealMavenPluginExecutorTest.java index 82462203e4e..ae359d9272e 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/scan/maven/AbstractMavenPluginExecutorTest.java +++ b/plugins/sonar-maven-batch-plugin/src/test/java/org/sonar/plugins/maven/RealMavenPluginExecutorTest.java @@ -1,3 +1,5 @@ +package org.sonar.plugins.maven; + /* * SonarQube, open source software quality management tool. * Copyright (C) 2008-2013 SonarSource @@ -17,7 +19,6 @@ * 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.batch.scan.maven; import org.apache.maven.project.MavenProject; import org.junit.Test; @@ -36,16 +37,16 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; -public class AbstractMavenPluginExecutorTest { +public class RealMavenPluginExecutorTest { @Test public void plugin_version_should_be_optional() { - assertThat(AbstractMavenPluginExecutor.getGoal("group", "artifact", null, "goal"), is("group:artifact::goal")); + assertThat(RealMavenPluginExecutor.getGoal("group", "artifact", null, "goal"), is("group:artifact::goal")); } @Test public void test_plugin_version() { - assertThat(AbstractMavenPluginExecutor.getGoal("group", "artifact", "3.54", "goal"), is("group:artifact:3.54:goal")); + assertThat(RealMavenPluginExecutor.getGoal("group", "artifact", "3.54", "goal"), is("group:artifact:3.54:goal")); } /** @@ -54,7 +55,7 @@ public class AbstractMavenPluginExecutorTest { */ @Test public void should_reset_file_system_after_execution() { - AbstractMavenPluginExecutor executor = new AbstractMavenPluginExecutor() { + RealMavenPluginExecutor executor = new RealMavenPluginExecutor(null, null) { @Override public void concreteExecute(MavenProject pom, String goal) throws Exception { pom.addCompileSourceRoot("src/java"); @@ -73,7 +74,7 @@ public class AbstractMavenPluginExecutorTest { @Test public void should_ignore_non_maven_projects() { - AbstractMavenPluginExecutor executor = new AbstractMavenPluginExecutor() { + RealMavenPluginExecutor executor = new RealMavenPluginExecutor(null, null) { @Override public void concreteExecute(MavenProject pom, String goal) throws Exception { pom.addCompileSourceRoot("src/java"); @@ -104,7 +105,7 @@ public class AbstractMavenPluginExecutorTest { } public String[] getGoals() { - return new String[]{"fake"}; + return new String[] {"fake"}; } public void configure(Project project, MavenPlugin plugin) { diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/maven/MavenProjectConverterTest/mavenProjectFileNameNotEqualsToPomXml/module/pom.xml b/plugins/sonar-maven-batch-plugin/src/test/resources/org/sonar/plugins/maven/MavenProjectConverterTest/mavenProjectFileNameNotEqualsToPomXml/module/pom.xml similarity index 100% rename from sonar-batch/src/test/resources/org/sonar/batch/scan/maven/MavenProjectConverterTest/mavenProjectFileNameNotEqualsToPomXml/module/pom.xml rename to plugins/sonar-maven-batch-plugin/src/test/resources/org/sonar/plugins/maven/MavenProjectConverterTest/mavenProjectFileNameNotEqualsToPomXml/module/pom.xml diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/maven/MavenProjectConverterTest/mavenProjectFileNameNotEqualsToPomXml/module/pom_having_different_name.xml b/plugins/sonar-maven-batch-plugin/src/test/resources/org/sonar/plugins/maven/MavenProjectConverterTest/mavenProjectFileNameNotEqualsToPomXml/module/pom_having_different_name.xml similarity index 100% rename from sonar-batch/src/test/resources/org/sonar/batch/scan/maven/MavenProjectConverterTest/mavenProjectFileNameNotEqualsToPomXml/module/pom_having_different_name.xml rename to plugins/sonar-maven-batch-plugin/src/test/resources/org/sonar/plugins/maven/MavenProjectConverterTest/mavenProjectFileNameNotEqualsToPomXml/module/pom_having_different_name.xml diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/maven/MavenProjectConverterTest/mavenProjectFileNameNotEqualsToPomXml/pom.xml b/plugins/sonar-maven-batch-plugin/src/test/resources/org/sonar/plugins/maven/MavenProjectConverterTest/mavenProjectFileNameNotEqualsToPomXml/pom.xml similarity index 100% rename from sonar-batch/src/test/resources/org/sonar/batch/scan/maven/MavenProjectConverterTest/mavenProjectFileNameNotEqualsToPomXml/pom.xml rename to plugins/sonar-maven-batch-plugin/src/test/resources/org/sonar/plugins/maven/MavenProjectConverterTest/mavenProjectFileNameNotEqualsToPomXml/pom.xml diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/maven/MavenProjectConverterTest/moduleNameDifferentThanArtifactId/path1/pom.xml b/plugins/sonar-maven-batch-plugin/src/test/resources/org/sonar/plugins/maven/MavenProjectConverterTest/moduleNameDifferentThanArtifactId/path1/pom.xml similarity index 100% rename from sonar-batch/src/test/resources/org/sonar/batch/scan/maven/MavenProjectConverterTest/moduleNameDifferentThanArtifactId/path1/pom.xml rename to plugins/sonar-maven-batch-plugin/src/test/resources/org/sonar/plugins/maven/MavenProjectConverterTest/moduleNameDifferentThanArtifactId/path1/pom.xml diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/maven/MavenProjectConverterTest/moduleNameDifferentThanArtifactId/path2/pom.xml b/plugins/sonar-maven-batch-plugin/src/test/resources/org/sonar/plugins/maven/MavenProjectConverterTest/moduleNameDifferentThanArtifactId/path2/pom.xml similarity index 100% rename from sonar-batch/src/test/resources/org/sonar/batch/scan/maven/MavenProjectConverterTest/moduleNameDifferentThanArtifactId/path2/pom.xml rename to plugins/sonar-maven-batch-plugin/src/test/resources/org/sonar/plugins/maven/MavenProjectConverterTest/moduleNameDifferentThanArtifactId/path2/pom.xml diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/maven/MavenProjectConverterTest/moduleNameDifferentThanArtifactId/pom.xml b/plugins/sonar-maven-batch-plugin/src/test/resources/org/sonar/plugins/maven/MavenProjectConverterTest/moduleNameDifferentThanArtifactId/pom.xml similarity index 100% rename from sonar-batch/src/test/resources/org/sonar/batch/scan/maven/MavenProjectConverterTest/moduleNameDifferentThanArtifactId/pom.xml rename to plugins/sonar-maven-batch-plugin/src/test/resources/org/sonar/plugins/maven/MavenProjectConverterTest/moduleNameDifferentThanArtifactId/pom.xml diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/maven/MavenProjectConverterTest/moduleNameShouldEqualArtifactId/module1/pom.xml b/plugins/sonar-maven-batch-plugin/src/test/resources/org/sonar/plugins/maven/MavenProjectConverterTest/moduleNameShouldEqualArtifactId/module1/pom.xml similarity index 100% rename from sonar-batch/src/test/resources/org/sonar/batch/scan/maven/MavenProjectConverterTest/moduleNameShouldEqualArtifactId/module1/pom.xml rename to plugins/sonar-maven-batch-plugin/src/test/resources/org/sonar/plugins/maven/MavenProjectConverterTest/moduleNameShouldEqualArtifactId/module1/pom.xml diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/maven/MavenProjectConverterTest/moduleNameShouldEqualArtifactId/module2/pom.xml b/plugins/sonar-maven-batch-plugin/src/test/resources/org/sonar/plugins/maven/MavenProjectConverterTest/moduleNameShouldEqualArtifactId/module2/pom.xml similarity index 100% rename from sonar-batch/src/test/resources/org/sonar/batch/scan/maven/MavenProjectConverterTest/moduleNameShouldEqualArtifactId/module2/pom.xml rename to plugins/sonar-maven-batch-plugin/src/test/resources/org/sonar/plugins/maven/MavenProjectConverterTest/moduleNameShouldEqualArtifactId/module2/pom.xml diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/maven/MavenProjectConverterTest/moduleNameShouldEqualArtifactId/pom.xml b/plugins/sonar-maven-batch-plugin/src/test/resources/org/sonar/plugins/maven/MavenProjectConverterTest/moduleNameShouldEqualArtifactId/pom.xml similarity index 100% rename from sonar-batch/src/test/resources/org/sonar/batch/scan/maven/MavenProjectConverterTest/moduleNameShouldEqualArtifactId/pom.xml rename to plugins/sonar-maven-batch-plugin/src/test/resources/org/sonar/plugins/maven/MavenProjectConverterTest/moduleNameShouldEqualArtifactId/pom.xml diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/maven/MavenProjectConverterTest/projectWithLinks/pom.xml b/plugins/sonar-maven-batch-plugin/src/test/resources/org/sonar/plugins/maven/MavenProjectConverterTest/projectWithLinks/pom.xml similarity index 100% rename from sonar-batch/src/test/resources/org/sonar/batch/scan/maven/MavenProjectConverterTest/projectWithLinks/pom.xml rename to plugins/sonar-maven-batch-plugin/src/test/resources/org/sonar/plugins/maven/MavenProjectConverterTest/projectWithLinks/pom.xml diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/maven/MavenProjectConverterTest/projectWithLinksAndProperties/pom.xml b/plugins/sonar-maven-batch-plugin/src/test/resources/org/sonar/plugins/maven/MavenProjectConverterTest/projectWithLinksAndProperties/pom.xml similarity index 100% rename from sonar-batch/src/test/resources/org/sonar/batch/scan/maven/MavenProjectConverterTest/projectWithLinksAndProperties/pom.xml rename to plugins/sonar-maven-batch-plugin/src/test/resources/org/sonar/plugins/maven/MavenProjectConverterTest/projectWithLinksAndProperties/pom.xml diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/maven/MavenProjectConverterTest/singleProjectWithoutModules/pom.xml b/plugins/sonar-maven-batch-plugin/src/test/resources/org/sonar/plugins/maven/MavenProjectConverterTest/singleProjectWithoutModules/pom.xml similarity index 100% rename from sonar-batch/src/test/resources/org/sonar/batch/scan/maven/MavenProjectConverterTest/singleProjectWithoutModules/pom.xml rename to plugins/sonar-maven-batch-plugin/src/test/resources/org/sonar/plugins/maven/MavenProjectConverterTest/singleProjectWithoutModules/pom.xml diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/maven/MavenProjectConverterTest/sourceEncoding/pom.xml b/plugins/sonar-maven-batch-plugin/src/test/resources/org/sonar/plugins/maven/MavenProjectConverterTest/sourceEncoding/pom.xml similarity index 100% rename from sonar-batch/src/test/resources/org/sonar/batch/scan/maven/MavenProjectConverterTest/sourceEncoding/pom.xml rename to plugins/sonar-maven-batch-plugin/src/test/resources/org/sonar/plugins/maven/MavenProjectConverterTest/sourceEncoding/pom.xml diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/maven/AbstractMavenPluginExecutor.java b/sonar-batch/src/main/java/org/sonar/batch/scan/maven/AbstractMavenPluginExecutor.java deleted file mode 100644 index f835c600ef3..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/maven/AbstractMavenPluginExecutor.java +++ /dev/null @@ -1,76 +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.batch.scan.maven; - -import org.apache.maven.project.MavenProject; -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.scan.filesystem.DefaultModuleFileSystem; - -/** - * Abstract implementation of {@link org.sonar.batch.scan.maven.MavenPluginExecutor} to reduce duplications in concrete implementations for different Maven versions. - */ -public abstract class AbstractMavenPluginExecutor implements MavenPluginExecutor { - - public final MavenPluginHandler execute(Project project, DefaultModuleFileSystem fs, MavenPluginHandler handler) { - for (String goal : handler.getGoals()) { - MavenPlugin plugin = MavenPlugin.getPlugin(project.getPom(), handler.getGroupId(), handler.getArtifactId()); - execute(project, - fs, - getGoal(handler.getGroupId(), handler.getArtifactId(), (plugin != null && plugin.getPlugin() != null ? plugin.getPlugin().getVersion() : null), goal)); - } - return handler; - } - - public final void execute(Project project, DefaultModuleFileSystem fs, String goal) { - if (project.getPom() != null) { - TimeProfiler profiler = new TimeProfiler().start("Execute " + goal); - ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader(); - try { - concreteExecute(project.getPom(), goal); - } catch (Exception e) { - throw new SonarException("Unable to execute maven plugin", e); - } finally { - // Reset original ClassLoader that may have been changed during Maven Execution (see SONAR-1800) - Thread.currentThread().setContextClassLoader(currentClassLoader); - profiler.stop(); - } - - MavenProjectConverter.synchronizeFileSystem(project.getPom(), fs); - } - } - - public abstract void concreteExecute(MavenProject pom, String goal) throws Exception; - - 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(); - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/maven/FakeMavenPluginExecutor.java b/sonar-batch/src/main/java/org/sonar/batch/scan/maven/FakeMavenPluginExecutor.java index 6de93f38130..df53510f444 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/maven/FakeMavenPluginExecutor.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/maven/FakeMavenPluginExecutor.java @@ -22,15 +22,17 @@ package org.sonar.batch.scan.maven; import org.sonar.api.batch.maven.MavenPluginHandler; import org.sonar.api.resources.Project; import org.sonar.batch.scan.filesystem.DefaultModuleFileSystem; -import org.sonar.batch.scan.maven.MavenPluginExecutor; public final class FakeMavenPluginExecutor implements MavenPluginExecutor { + + @Override public void execute(Project project, DefaultModuleFileSystem fs, String goal) { // do nothing } + @Override public MavenPluginHandler execute(Project project, DefaultModuleFileSystem fs, MavenPluginHandler handler) { // do nothing return handler; } -} \ No newline at end of file +} diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/maven/MavenPluginExecutor.java b/sonar-batch/src/main/java/org/sonar/batch/scan/maven/MavenPluginExecutor.java index 646f9c7ddbc..3ff7f0dabfa 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/maven/MavenPluginExecutor.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/maven/MavenPluginExecutor.java @@ -19,12 +19,12 @@ */ package org.sonar.batch.scan.maven; -import org.sonar.api.BatchComponent; import org.sonar.api.batch.maven.MavenPluginHandler; import org.sonar.api.resources.Project; +import org.sonar.api.task.TaskExtension; import org.sonar.batch.scan.filesystem.DefaultModuleFileSystem; -public interface MavenPluginExecutor extends BatchComponent { +public interface MavenPluginExecutor extends TaskExtension { void execute(Project project, DefaultModuleFileSystem def, String goal); -- 2.39.5