You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by be...@apache.org on 2008/05/14 22:59:57 UTC
svn commit: r656430 -
/maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InstallMojo.java
Author: bentmann
Date: Wed May 14 13:59:56 2008
New Revision: 656430
URL: http://svn.apache.org/viewvc?rev=656430&view=rev
Log:
[MINVOKER-37] Stage Reactor Contents to IT Repo
Modified:
maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InstallMojo.java
Modified: maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InstallMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InstallMojo.java?rev=656430&r1=656429&r2=656430&view=diff
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InstallMojo.java (original)
+++ maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InstallMojo.java Wed May 14 13:59:56 2008
@@ -21,7 +21,9 @@
import java.io.File;
import java.util.Collection;
+import java.util.HashMap;
import java.util.Iterator;
+import java.util.Map;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
@@ -35,12 +37,14 @@
import org.apache.maven.project.MavenProject;
/**
- * Installs the project artifacts into the local repository as a preparation to run the integration tests.
+ * Installs the project artifacts into the local repository as a preparation to run the integration tests. More
+ * precisely, all artifacts of the project itself, all its locally reachable parent POMs and all its dependencies from
+ * the reactor will be installed to the local repository.
*
* @goal install
* @phase pre-integration-test
+ * @requiresDependencyResolution runtime
* @since 1.2
- *
* @author Paul Gier
* @author Benjamin Bentmann
* @version $Id$
@@ -79,7 +83,9 @@
/**
* The path to the local repository into which the project artifacts should be installed for the integration tests.
- * If not set, the regular local repository will be used.
+ * If not set, the regular local repository will be used. To prevent soiling of your regular local repository with
+ * possibly broken artifacts, it is strongly recommended to use an isolated repository for the integration tests
+ * (e.g. <code>${project.build.directory}/it-repo</code>).
*
* @parameter expression="${invoker.localRepositoryPath}"
*/
@@ -95,37 +101,79 @@
private MavenProject project;
/**
+ * The set of Maven projects in the reactor build.
+ *
+ * @parameter default-value="${reactorProjects}"
+ * @readonly
+ */
+ private Collection reactorProjects;
+
+ /**
* Performs this mojo's tasks.
*/
public void execute()
throws MojoExecutionException, MojoFailureException
{
ArtifactRepository testRepository = createTestRepository();
- installProjectArtifacts( testRepository );
+ installProjectArtifacts( project, testRepository );
+ installProjectParents( project, testRepository );
+ installProjectDependencies( project, reactorProjects, testRepository );
+ }
+
+ /**
+ * Creates the local repository for the integration tests.
+ *
+ * @return The local repository for the integration tests, never <code>null</code>.
+ * @throws MojoExecutionException If the repository could not be created.
+ */
+ private ArtifactRepository createTestRepository()
+ throws MojoExecutionException
+ {
+ ArtifactRepository testRepository = localRepository;
+
+ if ( localRepositoryPath != null )
+ {
+ try
+ {
+ if ( !localRepositoryPath.exists() )
+ {
+ localRepositoryPath.mkdirs();
+ }
+
+ testRepository =
+ repositoryFactory.createArtifactRepository( "it-repo", localRepositoryPath.toURL().toString(),
+ localRepository.getLayout(),
+ localRepository.getSnapshots(),
+ localRepository.getReleases() );
+ }
+ catch ( Exception e )
+ {
+ throw new MojoExecutionException( "Failed to create local repository: " + localRepositoryPath, e );
+ }
+ }
+
+ return testRepository;
}
/**
- * Installs the main project artifact and any attached artifacts to the local repository.
+ * Installs the main artifact and any attached artifacts of the specified project to the local repository.
*
- * @param testRepository The local repository to install the artifacts into, must not be <code>null</code>.
+ * @param mvnProject The project whose artifacts should be installed, must not be <code>null</code>.
+ * @param testRepository The local repository to install the artifacts to, must not be <code>null</code>.
* @throws MojoExecutionException If any artifact could not be installed.
*/
- private void installProjectArtifacts( ArtifactRepository testRepository )
+ private void installProjectArtifacts( MavenProject mvnProject, ArtifactRepository testRepository )
throws MojoExecutionException
{
try
{
- // Install the pom
- Artifact pomArtifact =
- artifactFactory.createArtifact( project.getGroupId(), project.getArtifactId(), project.getVersion(),
- null, "pom" );
- installer.install( project.getFile(), pomArtifact, testRepository );
+ installProjectPom( mvnProject, testRepository );
// Install the main project artifact
- installer.install( project.getArtifact().getFile(), project.getArtifact(), testRepository );
+ installer.install( mvnProject.getArtifact().getFile(), mvnProject.getArtifact(), testRepository );
// Install any attached project artifacts
- Collection attachedArtifacts = project.getAttachedArtifacts();
+ Collection attachedArtifacts = mvnProject.getAttachedArtifacts();
for ( Iterator artifactIter = attachedArtifacts.iterator(); artifactIter.hasNext(); )
{
Artifact theArtifact = (Artifact) artifactIter.next();
@@ -134,43 +182,86 @@
}
catch ( ArtifactInstallationException e )
{
- throw new MojoExecutionException( "Failed to install project artifacts", e );
+ throw new MojoExecutionException( "Failed to install project artifacts: " + mvnProject, e );
}
}
/**
- * Creates the local repository for the integration tests.
+ * Installs the (locally reachable) parent POMs of the specified project to the local repository. The parent POMs
+ * from the reactor must be installed or the forked IT builds will fail when using a clean repository.
*
- * @return The local repository for the integration tests, never <code>null</code>.
- * @throws MojoExecutionException If the repository could not be created.
+ * @param mvnProject The project whose parent POMs should be installed, must not be <code>null</code>.
+ * @param testRepository The local repository to install the POMs to, must not be <code>null</code>.
+ * @throws MojoExecutionException If any POM could not be installed.
*/
- private ArtifactRepository createTestRepository()
+ private void installProjectParents( MavenProject mvnProject, ArtifactRepository testRepository )
throws MojoExecutionException
{
- ArtifactRepository testRepository = localRepository;
-
- if ( localRepositoryPath != null )
+ for ( MavenProject parent = mvnProject.getParent(); parent != null; parent = parent.getParent() )
{
- try
+ if ( parent.getFile() == null )
{
- if ( !localRepositoryPath.exists() )
- {
- localRepositoryPath.mkdirs();
- }
-
- testRepository =
- repositoryFactory.createArtifactRepository( "it-repo", localRepositoryPath.toURL().toString(),
- localRepository.getLayout(),
- localRepository.getSnapshots(),
- localRepository.getReleases() );
+ break;
}
- catch ( Exception e )
+ installProjectPom( parent, testRepository );
+ }
+ }
+
+ /**
+ * Installs the POM of the specified project to the local repository.
+ *
+ * @param mvnProject The project whose POM should be installed, must not be <code>null</code>.
+ * @param testRepository The local repository to install the POM to, must not be <code>null</code>.
+ * @throws MojoExecutionException If the POM could not be installed.
+ */
+ private void installProjectPom( MavenProject mvnProject, ArtifactRepository testRepository )
+ throws MojoExecutionException
+ {
+ try
+ {
+ Artifact pomArtifact =
+ artifactFactory.createProjectArtifact( mvnProject.getGroupId(), mvnProject.getArtifactId(),
+ mvnProject.getVersion() );
+ installer.install( mvnProject.getFile(), pomArtifact, testRepository );
+ }
+ catch ( Exception e )
+ {
+ throw new MojoExecutionException( "Failed to install POM: " + mvnProject, e );
+ }
+ }
+
+ /**
+ * Installs the dependent projects from the reactor to the local repository. The dependencies on other modules from
+ * the reactor must be installed or the forked IT builds will fail when using a clean repository.
+ *
+ * @param mvnProject The project whose dependent projects should be installed, must not be <code>null</code>.
+ * @param reactorProjects The set of projects in the reactor build, must not be <code>null</code>.
+ * @param testRepository The local repository to install the POMs to, must not be <code>null</code>.
+ * @throws MojoExecutionException If any dependency could not be installed.
+ */
+ private void installProjectDependencies( MavenProject mvnProject, Collection reactorProjects,
+ ArtifactRepository testRepository )
+ throws MojoExecutionException
+ {
+ Map projects = new HashMap();
+ for ( Iterator it = reactorProjects.iterator(); it.hasNext(); )
+ {
+ MavenProject reactorProject = (MavenProject) it.next();
+ projects.put( reactorProject.getId(), reactorProject );
+ }
+
+ for ( Iterator it = mvnProject.getArtifacts().iterator(); it.hasNext(); )
+ {
+ Artifact artifact = (Artifact) it.next();
+ String id =
+ artifact.getGroupId() + ':' + artifact.getArtifactId() + ':' + artifact.getType() + ':'
+ + artifact.getVersion();
+ MavenProject requiredProject = (MavenProject) projects.remove( id );
+ if ( requiredProject != null )
{
- throw new MojoExecutionException( "Failed to create local repository", e );
+ installProjectArtifacts( requiredProject, testRepository );
}
}
-
- return testRepository;
}
}