This commit is contained in:
Jason van Zyl 2014-02-03 17:37:52 -05:00
commit 3bf568eda6
5 changed files with 100 additions and 4 deletions

View File

@ -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;
}
}

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -504,7 +504,7 @@ public class MavenCli
Console cons;
char[] password;
if ( ( cons = System.console() ) != null
&& ( password = cons.readPassword( "Master password:") ) != null )
&& ( password = cons.readPassword( "Master password: " ) ) != null )
{
// Cipher uses Strings
passwd = String.copyValueOf( password );
@ -529,7 +529,7 @@ public class MavenCli
Console cons;
char[] password;
if ( ( cons = System.console() ) != null
&& ( password = cons.readPassword( "Password:" ) ) != null )
&& ( password = cons.readPassword( "Password: " ) ) != null )
{
// Cipher uses Strings
passwd = String.copyValueOf( password );