Created
October 6, 2011 18:22
-
-
Save ifedorenko/1268182 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: pom.xml | |
=================================================================== | |
--- pom.xml (revision 1179654) | |
+++ pom.xml (working copy) | |
@@ -140,7 +140,7 @@ | |
</distributionManagement> | |
<properties> | |
- <mavenVersion>3.0-alpha-4</mavenVersion> | |
+ <mavenVersion>3.0</mavenVersion> | |
<plexusVersion>1.5.1</plexusVersion> | |
</properties> | |
@@ -168,16 +168,9 @@ | |
<artifactId>maven-plugin-api</artifactId> | |
<version>${mavenVersion}</version> | |
</dependency> | |
- | |
<dependency> | |
<groupId>org.codehaus.plexus</groupId> | |
- <artifactId>plexus-container-default</artifactId> | |
- <version>${plexusVersion}</version> | |
- </dependency> | |
- | |
- <dependency> | |
- <groupId>org.codehaus.plexus</groupId> | |
<artifactId>plexus-utils</artifactId> | |
<version>2.0.1</version> | |
</dependency> | |
Index: maven-plugin-testing-tools/src/main/java/org/apache/maven/shared/test/plugin/ComponentTestTool.java | |
=================================================================== | |
--- maven-plugin-testing-tools/src/main/java/org/apache/maven/shared/test/plugin/ComponentTestTool.java (revision 1179654) | |
+++ maven-plugin-testing-tools/src/main/java/org/apache/maven/shared/test/plugin/ComponentTestTool.java (working copy) | |
@@ -20,6 +20,8 @@ | |
*/ | |
import org.apache.maven.project.MavenProject; | |
+import org.codehaus.plexus.component.annotations.Component; | |
+import org.codehaus.plexus.component.annotations.Requirement; | |
import org.codehaus.plexus.util.FileUtils; | |
import java.io.File; | |
@@ -39,23 +41,19 @@ | |
* component's ancestor POMs cannot be resolved. | |
* </p> | |
* | |
- * @plexus.component role="org.apache.maven.shared.test.plugin.ComponentTestTool" role-hint="default" | |
* @author jdcasey | |
* @version $Id$ | |
*/ | |
+@Component( role = ComponentTestTool.class ) | |
public class ComponentTestTool | |
{ | |
/** Plexus role */ | |
public static final String ROLE = ComponentTestTool.class.getName(); | |
- /** | |
- * @plexus.requirement role-hint="default" | |
- */ | |
+ @Requirement | |
private ProjectTool projectTool; | |
- /** | |
- * @plexus.requirement role-hint="default" | |
- */ | |
+ @Requirement | |
private RepositoryTool repositoryTool; | |
/** | |
Index: maven-plugin-testing-tools/src/main/java/org/apache/maven/shared/test/plugin/ProjectTool.java | |
=================================================================== | |
--- maven-plugin-testing-tools/src/main/java/org/apache/maven/shared/test/plugin/ProjectTool.java (revision 1179654) | |
+++ maven-plugin-testing-tools/src/main/java/org/apache/maven/shared/test/plugin/ProjectTool.java (working copy) | |
@@ -50,22 +50,25 @@ | |
import org.apache.maven.project.ProjectBuildingException; | |
import org.apache.maven.project.ProjectBuildingRequest; | |
import org.apache.maven.project.artifact.ProjectArtifactMetadata; | |
+import org.codehaus.plexus.component.annotations.Component; | |
+import org.codehaus.plexus.component.annotations.Requirement; | |
import org.codehaus.plexus.util.FileUtils; | |
import org.codehaus.plexus.util.IOUtil; | |
import org.codehaus.plexus.util.ReaderFactory; | |
import org.codehaus.plexus.util.WriterFactory; | |
import org.codehaus.plexus.util.xml.Xpp3Dom; | |
import org.codehaus.plexus.util.xml.pull.XmlPullParserException; | |
+import org.sonatype.aether.util.DefaultRepositorySystemSession; | |
/** | |
* Testing tool used to read MavenProject instances from pom.xml files, and to create plugin jar | |
* files (package phase of the normal build process) for distribution to a test local repository | |
* directory. | |
* | |
- * @plexus.component role="org.apache.maven.shared.test.plugin.ProjectTool" role-hint="default" | |
* @author jdcasey | |
* @version $Id$ | |
*/ | |
+@Component( role = ProjectTool.class ) | |
public class ProjectTool | |
{ | |
/** Plexus role */ | |
@@ -73,34 +76,22 @@ | |
public static final String INTEGRATION_TEST_DEPLOYMENT_REPO_URL = "integration-test.deployment.repo.url"; | |
- /** | |
- * @plexus.requirement role-hint="default" | |
- */ | |
+ @Requirement | |
private BuildTool buildTool; | |
- /** | |
- * @plexus.requirement role-hint="default" | |
- */ | |
+ @Requirement | |
private RepositoryTool repositoryTool; | |
- /** | |
- * @plexus.requirement | |
- */ | |
+ @Requirement | |
private ProjectBuilder projectBuilder; | |
- /** | |
- * @plexus.requirement | |
- */ | |
+ @Requirement | |
private ArtifactHandlerManager artifactHandlerManager; | |
- /** | |
- * @plexus.requirement | |
- */ | |
+ @Requirement | |
private ArtifactFactory artifactFactory; | |
- /** | |
- * @plexus.requirement | |
- */ | |
+ @Requirement | |
private ArtifactRepositoryFactory artifactRepositoryFactory; | |
/** | |
@@ -250,6 +241,7 @@ | |
{ | |
ProjectBuildingRequest request = new DefaultProjectBuildingRequest(); | |
request.setLocalRepository( artifactRepositoryFactory.createArtifactRepository( "local", new File( "target/localrepo" ).getCanonicalFile().toURL().toExternalForm(), "default", null, null ) ); | |
+ request.setRepositorySession( new DefaultRepositorySystemSession() ); | |
MavenProject project = projectBuilder.build( pomInfo.getPomFile(), request ).getProject(); | |
Artifact artifact = artifactFactory.createArtifact( project.getGroupId(), project.getArtifactId(), project | |
Index: maven-plugin-testing-tools/src/main/java/org/apache/maven/shared/test/plugin/PluginTestTool.java | |
=================================================================== | |
--- maven-plugin-testing-tools/src/main/java/org/apache/maven/shared/test/plugin/PluginTestTool.java (revision 1179654) | |
+++ maven-plugin-testing-tools/src/main/java/org/apache/maven/shared/test/plugin/PluginTestTool.java (working copy) | |
@@ -20,6 +20,8 @@ | |
*/ | |
import org.apache.maven.project.MavenProject; | |
+import org.codehaus.plexus.component.annotations.Component; | |
+import org.codehaus.plexus.component.annotations.Requirement; | |
import org.codehaus.plexus.util.FileUtils; | |
import java.io.File; | |
@@ -39,23 +41,19 @@ | |
* plugin's ancestor POMs cannot be resolved. | |
* </p> | |
* | |
- * @plexus.component role="org.apache.maven.shared.test.plugin.PluginTestTool" role-hint="default" | |
* @author jdcasey | |
* @version $Id$ | |
*/ | |
+@Component( role = PluginTestTool.class ) | |
public class PluginTestTool | |
{ | |
/** Plexus role */ | |
public static final String ROLE = PluginTestTool.class.getName(); | |
- /** | |
- * @plexus.requirement role-hint="default" | |
- */ | |
+ @Requirement | |
private ProjectTool projectTool; | |
- /** | |
- * @plexus.requirement role-hint="default" | |
- */ | |
+ @Requirement | |
private RepositoryTool repositoryTool; | |
/** | |
Index: maven-plugin-testing-tools/src/main/java/org/apache/maven/shared/test/plugin/BuildTool.java | |
=================================================================== | |
--- maven-plugin-testing-tools/src/main/java/org/apache/maven/shared/test/plugin/BuildTool.java (revision 1179654) | |
+++ maven-plugin-testing-tools/src/main/java/org/apache/maven/shared/test/plugin/BuildTool.java (working copy) | |
@@ -32,6 +32,7 @@ | |
import org.apache.maven.shared.invoker.InvocationResult; | |
import org.apache.maven.shared.invoker.Invoker; | |
import org.apache.maven.shared.invoker.MavenInvocationException; | |
+import org.codehaus.plexus.component.annotations.Component; | |
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Disposable; | |
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; | |
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException; | |
@@ -41,10 +42,10 @@ | |
/** | |
* Test-tool used to execute Maven builds in order to test plugin functionality. | |
* | |
- * @plexus.component role="org.apache.maven.shared.test.plugin.BuildTool" role-hint="default" | |
* @author jdcasey | |
* @version $Id$ | |
*/ | |
+@Component(role=BuildTool.class) | |
public class BuildTool | |
implements Initializable, Disposable | |
{ | |
Index: maven-plugin-testing-tools/src/main/java/org/apache/maven/shared/test/plugin/RepositoryTool.java | |
=================================================================== | |
--- maven-plugin-testing-tools/src/main/java/org/apache/maven/shared/test/plugin/RepositoryTool.java (revision 1179654) | |
+++ maven-plugin-testing-tools/src/main/java/org/apache/maven/shared/test/plugin/RepositoryTool.java (working copy) | |
@@ -32,15 +32,20 @@ | |
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; | |
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; | |
import org.apache.maven.execution.DefaultMavenExecutionRequest; | |
+import org.apache.maven.execution.DefaultMavenExecutionResult; | |
+import org.apache.maven.execution.MavenSession; | |
import org.apache.maven.model.Model; | |
import org.apache.maven.model.Parent; | |
import org.apache.maven.model.io.xpp3.MavenXpp3Reader; | |
+import org.apache.maven.plugin.LegacySupport; | |
import org.apache.maven.project.MavenProject; | |
import org.apache.maven.project.artifact.ProjectArtifactMetadata; | |
import org.apache.maven.settings.MavenSettingsBuilder; | |
import org.apache.maven.settings.Settings; | |
import org.codehaus.plexus.PlexusConstants; | |
import org.codehaus.plexus.PlexusContainer; | |
+import org.codehaus.plexus.component.annotations.Component; | |
+import org.codehaus.plexus.component.annotations.Requirement; | |
import org.codehaus.plexus.component.repository.exception.ComponentLookupException; | |
import org.codehaus.plexus.context.Context; | |
import org.codehaus.plexus.context.ContextException; | |
@@ -49,6 +54,7 @@ | |
import org.codehaus.plexus.util.ReaderFactory; | |
import org.codehaus.plexus.util.StringUtils; | |
import org.codehaus.plexus.util.xml.pull.XmlPullParserException; | |
+import org.sonatype.aether.util.DefaultRepositorySystemSession; | |
/** | |
* Tools to access and manage Maven repositories for test builds, including construction of a local | |
@@ -61,36 +67,31 @@ | |
* plugin's ancestor POMs cannot be resolved. | |
* </p> | |
* | |
- * @plexus.component role="org.apache.maven.shared.test.plugin.RepositoryTool" role-hint="default" | |
* @author jdcasey | |
* @version $Id$ | |
*/ | |
+@Component( role = RepositoryTool.class ) | |
public class RepositoryTool | |
implements Contextualizable | |
{ | |
/** Plexus role */ | |
public static final String ROLE = RepositoryTool.class.getName(); | |
- /** | |
- * @plexus.requirement | |
- */ | |
+ @Requirement | |
private ArtifactRepositoryFactory repositoryFactory; | |
- /** | |
- * @plexus.requirement | |
- */ | |
+ @Requirement | |
private MavenSettingsBuilder settingsBuilder; | |
- /** | |
- * @plexus.requirement | |
- */ | |
+ @Requirement | |
private ArtifactFactory artifactFactory; | |
- /** | |
- * @plexus.requirement | |
- */ | |
+ @Requirement | |
private ArtifactInstaller artifactInstaller; | |
+ @Requirement | |
+ private LegacySupport legacySupport; | |
+ | |
// contextualized. | |
private PlexusContainer container; | |
@@ -217,6 +218,9 @@ | |
destination.getParentFile().mkdirs(); | |
} | |
+ legacySupport.setSession( new MavenSession( container, new DefaultRepositorySystemSession(), | |
+ new DefaultMavenExecutionRequest(), | |
+ new DefaultMavenExecutionResult() ) ); | |
try | |
{ | |
artifactInstaller.install( artifact.getFile(), artifact, localRepository ); | |
@@ -226,6 +230,10 @@ | |
throw new TestToolsException( "Error installing plugin artifact to target local repository: " | |
+ targetLocalRepoBasedir, e ); | |
} | |
+ finally | |
+ { | |
+ legacySupport.setSession( null ); | |
+ } | |
installLocallyReachableAncestorPoms( realPomFile, localRepository ); | |
} | |
Index: maven-plugin-testing-tools/pom.xml | |
=================================================================== | |
--- maven-plugin-testing-tools/pom.xml (revision 1179654) | |
+++ maven-plugin-testing-tools/pom.xml (working copy) | |
@@ -40,10 +40,6 @@ | |
<dependencies> | |
<dependency> | |
<groupId>org.codehaus.plexus</groupId> | |
- <artifactId>plexus-container-default</artifactId> | |
- </dependency> | |
- <dependency> | |
- <groupId>org.codehaus.plexus</groupId> | |
<artifactId>plexus-utils</artifactId> | |
</dependency> | |
<dependency> | |
@@ -66,7 +62,7 @@ | |
<dependency> | |
<groupId>org.apache.maven.plugin-testing</groupId> | |
<artifactId>maven-test-tools</artifactId> | |
- <version>2.0-SNAPSHOT</version> | |
+ <version>${project.version}</version> | |
<scope>test</scope> | |
</dependency> | |
<dependency> | |
Index: maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/StubArtifactRepository.java | |
=================================================================== | |
--- maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/StubArtifactRepository.java (revision 1179654) | |
+++ maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/StubArtifactRepository.java (working copy) | |
@@ -232,4 +232,9 @@ | |
return Collections.emptyList(); | |
} | |
+ public boolean isProjectAware() | |
+ { | |
+ return false; | |
+ } | |
+ | |
} | |
Index: maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/AbstractMojoTestCase.java | |
=================================================================== | |
--- maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/AbstractMojoTestCase.java (revision 1179654) | |
+++ maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/AbstractMojoTestCase.java (working copy) | |
@@ -26,14 +26,27 @@ | |
import java.io.Reader; | |
import java.lang.reflect.AccessibleObject; | |
import java.lang.reflect.Field; | |
+import java.util.Arrays; | |
import java.util.HashMap; | |
import java.util.Map; | |
+import org.apache.maven.execution.DefaultMavenExecutionRequest; | |
+import org.apache.maven.execution.DefaultMavenExecutionResult; | |
+import org.apache.maven.execution.MavenExecutionRequest; | |
+import org.apache.maven.execution.MavenExecutionResult; | |
+import org.apache.maven.execution.MavenSession; | |
+import org.apache.maven.lifecycle.internal.MojoDescriptorCreator; | |
+import org.apache.maven.model.Plugin; | |
import org.apache.maven.monitor.logging.DefaultLog; | |
import org.apache.maven.plugin.Mojo; | |
+import org.apache.maven.plugin.MojoExecution; | |
+import org.apache.maven.plugin.PluginParameterExpressionEvaluator; | |
+import org.apache.maven.plugin.descriptor.MojoDescriptor; | |
+import org.apache.maven.plugin.descriptor.Parameter; | |
import org.apache.maven.plugin.descriptor.PluginDescriptor; | |
import org.apache.maven.plugin.descriptor.PluginDescriptorBuilder; | |
import org.apache.maven.plugin.logging.Log; | |
+import org.apache.maven.project.MavenProject; | |
import org.codehaus.plexus.ContainerConfiguration; | |
import org.codehaus.plexus.DefaultContainerConfiguration; | |
import org.codehaus.plexus.DefaultPlexusContainer; | |
@@ -41,6 +54,7 @@ | |
import org.codehaus.plexus.PlexusContainerException; | |
import org.codehaus.plexus.PlexusTestCase; | |
import org.codehaus.plexus.classworlds.ClassWorld; | |
+import org.codehaus.plexus.component.configurator.ComponentConfigurationException; | |
import org.codehaus.plexus.component.configurator.ComponentConfigurator; | |
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; | |
import org.codehaus.plexus.component.repository.ComponentDescriptor; | |
@@ -50,9 +64,11 @@ | |
import org.codehaus.plexus.util.InterpolationFilterReader; | |
import org.codehaus.plexus.util.ReaderFactory; | |
import org.codehaus.plexus.util.ReflectionUtils; | |
+import org.codehaus.plexus.util.StringUtils; | |
import org.codehaus.plexus.util.xml.XmlStreamReader; | |
import org.codehaus.plexus.util.xml.Xpp3Dom; | |
import org.codehaus.plexus.util.xml.Xpp3DomBuilder; | |
+import org.sonatype.aether.util.DefaultRepositorySystemSession; | |
/** | |
* TODO: add a way to use the plugin POM for the lookup so that the user doesn't have to provide the a:g:v:goal | |
@@ -73,6 +89,8 @@ | |
private ComponentConfigurator configurator; | |
private PlexusContainer container; | |
+ | |
+ private Map<String, MojoDescriptor> mojoDescriptors; | |
/* | |
* for the harness I think we have decided against going the route of using the maven project builder. | |
@@ -94,11 +112,17 @@ | |
new InterpolationFilterReader( new BufferedReader( reader ), container.getContext().getContextData() ); | |
PluginDescriptor pluginDescriptor = new PluginDescriptorBuilder().build( interpolationFilterReader ); | |
- | |
+ | |
for ( ComponentDescriptor<?> desc : pluginDescriptor.getComponents() ) | |
{ | |
getContainer().addComponentDescriptor( desc ); | |
} | |
+ | |
+ mojoDescriptors = new HashMap<String, MojoDescriptor>(); | |
+ for ( MojoDescriptor mojoDescriptor : pluginDescriptor.getMojos() ) | |
+ { | |
+ mojoDescriptors.put( mojoDescriptor.getGoal(), mojoDescriptor ); | |
+ } | |
} | |
protected InputStream getPublicDescriptorStream() | |
@@ -272,6 +296,95 @@ | |
return mojo; | |
} | |
+ protected Mojo lookupConfiguredMojo( MavenProject project, String goal ) | |
+ throws Exception | |
+ { | |
+ MojoDescriptor mojoDescriptor = mojoDescriptors.get( goal ); | |
+ PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor(); | |
+ | |
+ String pluginKey = pluginDescriptor.getGroupId() + ":" + pluginDescriptor.getArtifactId(); | |
+ String mojoHint = pluginKey + ":" + pluginDescriptor.getVersion() + ":" + goal; | |
+ Mojo mojo = (Mojo) lookup( Mojo.ROLE, mojoHint ); | |
+ | |
+ MojoExecution execution = new MojoExecution( mojoDescriptor ); | |
+ finalizeMojoConfiguration( execution ); | |
+ | |
+ MavenExecutionRequest request = new DefaultMavenExecutionRequest(); | |
+ MavenExecutionResult result = new DefaultMavenExecutionResult(); | |
+ | |
+ MavenSession session = new MavenSession( container, new DefaultRepositorySystemSession(), request, result ); | |
+ session.setCurrentProject( project ); | |
+ session.setProjects( Arrays.asList( project ) ); | |
+ | |
+ ExpressionEvaluator evaluator = new PluginParameterExpressionEvaluator( session, execution ); | |
+ | |
+ Xpp3Dom configuration = null; | |
+ Plugin plugin = project.getPlugin( pluginKey ); | |
+ if ( plugin != null ) | |
+ { | |
+ configuration = (Xpp3Dom) plugin.getConfiguration(); | |
+ } | |
+ if ( configuration == null ) | |
+ { | |
+ configuration = new Xpp3Dom( "configuration" ); | |
+ } | |
+ configuration = Xpp3Dom.mergeXpp3Dom( execution.getConfiguration(), configuration ); | |
+ | |
+ PlexusConfiguration pluginConfiguration = new XmlPlexusConfiguration( configuration ); | |
+ | |
+ configurator.configureComponent( mojo, pluginConfiguration, evaluator, getContainer().getContainerRealm() ); | |
+ | |
+ return mojo; | |
+ } | |
+ | |
+ // copy&paste from org.apache.maven.lifecycle.internal.DefaultLifecycleExecutionPlanCalculator.finalizeMojoConfiguration(MojoExecution) | |
+ private void finalizeMojoConfiguration( MojoExecution mojoExecution ) | |
+ { | |
+ MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor(); | |
+ | |
+ Xpp3Dom executionConfiguration = mojoExecution.getConfiguration(); | |
+ if ( executionConfiguration == null ) | |
+ { | |
+ executionConfiguration = new Xpp3Dom( "configuration" ); | |
+ } | |
+ | |
+ Xpp3Dom defaultConfiguration = MojoDescriptorCreator.convert( mojoDescriptor );; | |
+ | |
+ Xpp3Dom finalConfiguration = new Xpp3Dom( "configuration" ); | |
+ | |
+ if ( mojoDescriptor.getParameters() != null ) | |
+ { | |
+ for ( Parameter parameter : mojoDescriptor.getParameters() ) | |
+ { | |
+ Xpp3Dom parameterConfiguration = executionConfiguration.getChild( parameter.getName() ); | |
+ | |
+ if ( parameterConfiguration == null ) | |
+ { | |
+ parameterConfiguration = executionConfiguration.getChild( parameter.getAlias() ); | |
+ } | |
+ | |
+ Xpp3Dom parameterDefaults = defaultConfiguration.getChild( parameter.getName() ); | |
+ | |
+ parameterConfiguration = Xpp3Dom.mergeXpp3Dom( parameterConfiguration, parameterDefaults, Boolean.TRUE ); | |
+ | |
+ if ( parameterConfiguration != null ) | |
+ { | |
+ parameterConfiguration = new Xpp3Dom( parameterConfiguration, parameter.getName() ); | |
+ | |
+ if ( StringUtils.isEmpty( parameterConfiguration.getAttribute( "implementation" ) ) | |
+ && StringUtils.isNotEmpty( parameter.getImplementation() ) ) | |
+ { | |
+ parameterConfiguration.setAttribute( "implementation", parameter.getImplementation() ); | |
+ } | |
+ | |
+ finalConfiguration.addChild( parameterConfiguration ); | |
+ } | |
+ } | |
+ } | |
+ | |
+ mojoExecution.setConfiguration( finalConfiguration ); | |
+ } | |
+ | |
/** | |
* @param artifactId | |
* @param pom |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment