maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ifedore...@apache.org
Subject git commit: MNG-5570 unit test lifecycle participant influence reactor order
Date Wed, 29 Jan 2014 12:43:09 GMT
Updated Branches:
  refs/heads/master 0f265210d -> 43d67de04


MNG-5570 unit test lifecycle participant influence reactor order

Signed-off-by: Igor Fedorenko <ifedorenko@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/maven/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven/commit/43d67de0
Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/43d67de0
Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/43d67de0

Branch: refs/heads/master
Commit: 43d67de0451d15f504490ed5adfde032249bd649
Parents: 0f26521
Author: Igor Fedorenko <ifedorenko@apache.org>
Authored: Wed Jan 29 07:40:06 2014 -0500
Committer: Igor Fedorenko <ifedorenko@apache.org>
Committed: Wed Jan 29 07:40:19 2014 -0500

----------------------------------------------------------------------
 .../maven/MavenLifecycleParticipantTest.java    | 63 +++++++++++++++++++-
 .../module-a/pom.xml                            | 12 ++++
 .../module-b/pom.xml                            | 12 ++++
 .../pom.xml                                     | 13 ++++
 4 files changed, 98 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven/blob/43d67de0/maven-core/src/test/java/org/apache/maven/MavenLifecycleParticipantTest.java
----------------------------------------------------------------------
diff --git a/maven-core/src/test/java/org/apache/maven/MavenLifecycleParticipantTest.java
b/maven-core/src/test/java/org/apache/maven/MavenLifecycleParticipantTest.java
index 558d917..7df09f6 100644
--- a/maven-core/src/test/java/org/apache/maven/MavenLifecycleParticipantTest.java
+++ b/maven-core/src/test/java/org/apache/maven/MavenLifecycleParticipantTest.java
@@ -15,11 +15,11 @@ package org.apache.maven;
  * the License.
  */
 
-
 import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.List;
 
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.execution.MavenExecutionRequest;
@@ -71,6 +71,32 @@ public class MavenLifecycleParticipantTest
 
     }
 
+    public static class InjectReactorDependency
+        extends AbstractMavenLifecycleParticipant
+    {
+        @Override
+        public void afterProjectsRead( MavenSession session )
+        {
+            injectReactorDependency( session.getProjects(), "module-a", "module-b" );
+        }
+
+        private void injectReactorDependency( List<MavenProject> projects, String moduleFrom,
String moduleTo )
+        {
+            for ( MavenProject project : projects )
+            {
+                if ( moduleFrom.equals( project.getArtifactId() ) )
+                {
+                    Dependency dependency = new Dependency();
+                    dependency.setArtifactId( moduleTo );
+                    dependency.setGroupId( project.getGroupId() );
+                    dependency.setVersion( project.getVersion() );
+
+                    project.getModel().addDependency( dependency );
+                }
+            }
+        }
+    }
+
     @Override
     protected void setupContainer()
     {
@@ -103,7 +129,7 @@ public class MavenLifecycleParticipantTest
         assertFalse( result.getExceptions().toString(), result.hasExceptions() );
 
         MavenProject project = result.getProject();
-        
+
         assertEquals( "bar", project.getProperties().getProperty( "foo" ) );
 
         ArrayList<Artifact> artifacts = new ArrayList<Artifact>( project.getArtifacts()
);
@@ -111,4 +137,37 @@ public class MavenLifecycleParticipantTest
         assertEquals( 1, artifacts.size() );
         assertEquals( INJECTED_ARTIFACT_ID, artifacts.get( 0 ).getArtifactId() );
     }
+
+    public void testReactorDependencyInjection()
+        throws Exception
+    {
+        List<String> reactorOrder =
+            getReactorOrder( "lifecycle-participant-reactor-dependency-injection", InjectReactorDependency.class
);
+        assertEquals( Arrays.asList( "parent", "module-b", "module-a" ), reactorOrder );
+    }
+
+    private <T> List<String> getReactorOrder( String testProject, Class<T>
participant )
+        throws Exception
+    {
+        PlexusContainer container = getContainer();
+
+        ComponentDescriptor<T> cd = new ComponentDescriptor<T>( participant,
container.getContainerRealm() );
+        cd.setRoleClass( AbstractMavenLifecycleParticipant.class );
+        container.addComponentDescriptor( cd );
+
+        Maven maven = container.lookup( Maven.class );
+        File pom = getProject( testProject );
+        MavenExecutionRequest request = createMavenExecutionRequest( pom );
+        request.setGoals( Arrays.asList( "validate" ) );
+        MavenExecutionResult result = maven.execute( request );
+
+        assertFalse( result.getExceptions().toString(), result.hasExceptions() );
+
+        List<String> order = new ArrayList<String>();
+        for ( MavenProject project : result.getTopologicallySortedProjects() )
+        {
+            order.add( project.getArtifactId() );
+        }
+        return order;
+    }
 }

http://git-wip-us.apache.org/repos/asf/maven/blob/43d67de0/maven-core/src/test/projects/lifecycle-listener/lifecycle-participant-reactor-dependency-injection/module-a/pom.xml
----------------------------------------------------------------------
diff --git a/maven-core/src/test/projects/lifecycle-listener/lifecycle-participant-reactor-dependency-injection/module-a/pom.xml
b/maven-core/src/test/projects/lifecycle-listener/lifecycle-participant-reactor-dependency-injection/module-a/pom.xml
new file mode 100644
index 0000000..6a173f6
--- /dev/null
+++ b/maven-core/src/test/projects/lifecycle-listener/lifecycle-participant-reactor-dependency-injection/module-a/pom.xml
@@ -0,0 +1,12 @@
+<project>
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>lifecycle-participant-reactor-dependency-injection</groupId>
+    <artifactId>parent</artifactId>
+    <version>1.0</version>
+  </parent>
+
+  <artifactId>module-a</artifactId>
+
+</project>

http://git-wip-us.apache.org/repos/asf/maven/blob/43d67de0/maven-core/src/test/projects/lifecycle-listener/lifecycle-participant-reactor-dependency-injection/module-b/pom.xml
----------------------------------------------------------------------
diff --git a/maven-core/src/test/projects/lifecycle-listener/lifecycle-participant-reactor-dependency-injection/module-b/pom.xml
b/maven-core/src/test/projects/lifecycle-listener/lifecycle-participant-reactor-dependency-injection/module-b/pom.xml
new file mode 100644
index 0000000..795111a
--- /dev/null
+++ b/maven-core/src/test/projects/lifecycle-listener/lifecycle-participant-reactor-dependency-injection/module-b/pom.xml
@@ -0,0 +1,12 @@
+<project>
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>lifecycle-participant-reactor-dependency-injection</groupId>
+    <artifactId>parent</artifactId>
+    <version>1.0</version>
+  </parent>
+
+  <artifactId>module-b</artifactId>
+
+</project>

http://git-wip-us.apache.org/repos/asf/maven/blob/43d67de0/maven-core/src/test/projects/lifecycle-listener/lifecycle-participant-reactor-dependency-injection/pom.xml
----------------------------------------------------------------------
diff --git a/maven-core/src/test/projects/lifecycle-listener/lifecycle-participant-reactor-dependency-injection/pom.xml
b/maven-core/src/test/projects/lifecycle-listener/lifecycle-participant-reactor-dependency-injection/pom.xml
new file mode 100644
index 0000000..2830b32
--- /dev/null
+++ b/maven-core/src/test/projects/lifecycle-listener/lifecycle-participant-reactor-dependency-injection/pom.xml
@@ -0,0 +1,13 @@
+<project>
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>lifecycle-participant-reactor-dependency-injection</groupId>
+  <artifactId>parent</artifactId>
+  <version>1.0</version>
+  <packaging>pom</packaging>
+
+  <modules>
+    <module>module-a</module>
+    <module>module-b</module>
+  </modules>
+</project>


Mime
View raw message