o testing ThatExecutionsWithoutIdsAreMergedAndTheChildWins

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@727635 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2008-12-18 04:23:35 +00:00
parent 4dcf7797bb
commit 854a44adf0
3 changed files with 43 additions and 28 deletions

View File

@ -303,13 +303,15 @@ public final class DefaultProjectBuilder
logger.debug( "Parent pom ids do not match: Parent File = " + parentFile.getAbsolutePath() + ", Parent ID = " logger.debug( "Parent pom ids do not match: Parent File = " + parentFile.getAbsolutePath() + ", Parent ID = "
+ parentDomainModel.getId() + ", Child ID = " + domainModel.getId() + ", Expected Parent ID = " + parentDomainModel.getId() + ", Child ID = " + domainModel.getId() + ", Expected Parent ID = "
+ domainModel.getModel().getParent().getId() ); + domainModel.getModel().getParent().getId() );
List<DomainModel> parentDomainModels = getDomainModelParentsFromRepository( domainModel, artifactResolver ); List<DomainModel> parentDomainModels = getDomainModelParentsFromRepository( domainModel, artifactResolver );
if(parentDomainModels.size() == 0) if(parentDomainModels.size() == 0)
{ {
throw new IOException("Unable to find parent pom on local path or repo: " throw new IOException("Unable to find parent pom on local path or repo: "
+ domainModel.getModel().getParent().getId()); + domainModel.getModel().getParent().getId());
} }
//logger.info("Attempting to lookup from the repository: Found parents: " + parentDomainModels.size());
domainModels.addAll( parentDomainModels ); domainModels.addAll( parentDomainModels );
return domainModels; return domainModels;
} }

View File

@ -31,37 +31,47 @@ public class PomConstructionTest
protected void setUp() protected void setUp()
throws Exception throws Exception
{ {
testDirectory = new File( getBasedir(), BASE_POM_DIR ); testDirectory = new File( getBasedir(), BASE_POM_DIR );
projectBuilder = lookup( ProjectBuilder.class ); projectBuilder = lookup( ProjectBuilder.class );
mavenTools = lookup( MavenTools.class ); mavenTools = lookup( MavenTools.class );
} }
public void testNexusPoms() public void testThatAllPluginExecutionsWithIdsAreJoined()
throws Exception throws Exception
{ {
Map<String,File> artifacts = new HashMap<String,File>(); File nexusLauncher = new File( testDirectory, "nexus/nexus-test-harness-launcher/pom.xml" );
PomArtifactResolver resolver = artifactResolver( "nexus" );
File nexusLauncher = new File( testDirectory, "nexus/nexus-test-harness-launcher/pom.xml" ); PomClassicDomainModel model = projectBuilder.buildModel( nexusLauncher, null, resolver );
assertEquals( 3, model.getLineageCount() );
PomArtifactResolver resolver = new FileBasedPomArtifactResolver( new File( BASE_POM_DIR, "nexus" ) ); PomTestWrapper pom = new PomTestWrapper( model );
assertModelEquals( pom, "maven-dependency-plugin", "build/plugins[4]/artifactId" );
// make a version that doesn't require a null mixin set. for most pom construction tests we're List executions = (List) pom.getValue( "build/plugins[4]/executions" );
// not going to use mixins.
PomClassicDomainModel model = projectBuilder.buildModel( nexusLauncher, null, resolver );
// Make sure we actually processed our 3 POMs.
assertEquals( 3, model.getLineageCount() );
PomTestWrapper pom = new PomTestWrapper( model );
assertEquals( "maven-dependency-plugin", pom.getValue( "build/plugins[4]/artifactId" ) );
List executions = (List) pom.getValue( "build/plugins[4]/executions" );
assertEquals( 7, executions.size() ); assertEquals( 7, executions.size() );
} }
public void testThatExecutionsWithoutIdsAreMergedAndTheChildWins()
throws Exception
{
File pom = new File( testDirectory, "micromailer/micromailer-1.0.3.pom" );
System.out.println( pom.exists());
PomArtifactResolver resolver = artifactResolver( "micromailer" );
PomClassicDomainModel model = projectBuilder.buildModel( pom, null, resolver );
// This should be 2
//assertEquals( 2, model.getLineageCount() );
PomTestWrapper tester = new PomTestWrapper( model );
assertModelEquals( tester, "child-descriptor", "build/plugins[1]/executions[1]/goals[1]" );
}
private PomArtifactResolver artifactResolver( String basedir )
{
PomArtifactResolver resolver = new FileBasedPomArtifactResolver( new File( BASE_POM_DIR, basedir ) );
return resolver;
}
protected void assertModelEquals( PomTestWrapper pom, Object expected, String expression )
{
assertEquals( expected, pom.getValue( expression ) );
}
// Need to get this to walk around a directory and automatically build up the artifact set. If we // Need to get this to walk around a directory and automatically build up the artifact set. If we
// follow some standard conventions this can be simple. // follow some standard conventions this can be simple.
@ -82,7 +92,8 @@ public class PomConstructionTest
if ( file.getName().endsWith( ".pom" ) ) if ( file.getName().endsWith( ".pom" ) )
{ {
int i = fileName.indexOf( ".pom" ); int i = fileName.indexOf( ".pom" );
String id = fileName.substring( 0, i - 1 ); String id = fileName.substring( 0, i );
System.out.println( id );
artifacts.put( id, file ); artifacts.put( id, file );
} }
} }
@ -96,7 +107,9 @@ public class PomConstructionTest
public void resolve( Artifact artifact ) public void resolve( Artifact artifact )
throws IOException throws IOException
{ {
artifact.setFile( artifacts.get( artifact.getArtifactId() ) ); String id = artifact.getArtifactId() + "-" + artifact.getVersion();
System.out.println( id );
artifact.setFile( artifacts.get( id ) );
} }
} }
} }

View File

@ -112,7 +112,7 @@
<executions> <executions>
<execution> <execution>
<goals> <goals>
<goal>descriptor</goal> <goal>child-descriptor</goal>
</goals> </goals>
</execution> </execution>
</executions> </executions>
@ -120,4 +120,4 @@
</plugins> </plugins>
</build> </build>
</project> </project>