Author: ogusakov Date: Mon Oct 6 13:59:59 2008 New Revision: 702260 URL: http://svn.apache.org/viewvc?rev=702260&view=rev Log: added DependencyTreeBuilder inc/exc ut's
Modified: maven/sandbox/trunk/mercury/mercury-md/mercury-md-sat/src/main/java/org/apache/maven/mercury/metadata/DependencyTreeBuilder.java maven/sandbox/trunk/mercury/mercury-md/mercury-md-sat/src/test/java/org/apache/maven/mercury/metadata/DependencyTreeBuilderTest.java Modified: maven/sandbox/trunk/mercury/mercury-md/mercury-md-sat/src/main/java/org/apache/maven/mercury/metadata/DependencyTreeBuilder.java URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/mercury/mercury-md/mercury-md-sat/src/main/java/org/apache/maven/mercury/metadata/DependencyTreeBuilder.java?rev=702260&r1=702259&r2=702260&view=diff ============================================================================== --- maven/sandbox/trunk/mercury/mercury-md/mercury-md-sat/src/main/java/org/apache/maven/mercury/metadata/DependencyTreeBuilder.java (original) +++ maven/sandbox/trunk/mercury/mercury-md/mercury-md-sat/src/main/java/org/apache/maven/mercury/metadata/DependencyTreeBuilder.java Mon Oct 6 13:59:59 2008 @@ -139,7 +139,7 @@ for( ArtifactBasicMetadata md : dependencies ) { - List<ArtifactBasicMetadata> versions = expandedDeps.get( md ); + List<ArtifactBasicMetadata> versions = expandedDeps.get( md ); if( versions == null || versions.size() < 1 ) { if( md.isOptional() ) @@ -148,28 +148,38 @@ } boolean noGoodVersions = true; + boolean noVersions = true; for( ArtifactBasicMetadata ver : versions ) { - if( veto( ver, _filters) ) - continue; - - if( vetoInclusionsExclusions(node, ver) ) + if( veto( ver, _filters) || vetoInclusionsExclusions(node, ver) ) + { + // there were good versions, but this one is filtered out filtered out + noGoodVersions = false; continue; + } MetadataTreeNode kid = createNode( ver, node, md ); node.addChild( kid ); + noVersions = false; + noGoodVersions = false; } - if( noGoodVersions ) + + if( noVersions && !noGoodVersions ) + { + // there were good versions, but they were all filtered out + continue; + } + else if( noGoodVersions ) { if( md.isOptional() ) continue; throw new MetadataTreeException( "did not find non-optional artifact for " + md ); } - - node.addQuery(md); + else + node.addQuery(md); } return node; @@ -228,7 +238,7 @@ { for( MetadataTreeNode n = node; n != null; n = n.getParent() ) { - ArtifactMetadata md = n.getMd(); + ArtifactBasicMetadata md = n.getQuery(); if( md.allowDependency( ver ) ) return false; Modified: maven/sandbox/trunk/mercury/mercury-md/mercury-md-sat/src/test/java/org/apache/maven/mercury/metadata/DependencyTreeBuilderTest.java URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/mercury/mercury-md/mercury-md-sat/src/test/java/org/apache/maven/mercury/metadata/DependencyTreeBuilderTest.java?rev=702260&r1=702259&r2=702260&view=diff ============================================================================== --- maven/sandbox/trunk/mercury/mercury-md/mercury-md-sat/src/test/java/org/apache/maven/mercury/metadata/DependencyTreeBuilderTest.java (original) +++ maven/sandbox/trunk/mercury/mercury-md/mercury-md-sat/src/test/java/org/apache/maven/mercury/metadata/DependencyTreeBuilderTest.java Mon Oct 6 13:59:59 2008 @@ -6,6 +6,7 @@ import junit.framework.TestCase; +import org.apache.maven.mercury.artifact.ArtifactBasicMetadata; import org.apache.maven.mercury.artifact.ArtifactMetadata; import org.apache.maven.mercury.artifact.ArtifactScopeEnum; import org.apache.maven.mercury.builder.api.DependencyProcessor; @@ -122,6 +123,114 @@ } //---------------------------------------------------------------------------------------------- + public void testResolveScopedConflictsWithFiltering() + throws MetadataTreeException + { + String title = "testResolveScopedConflictsWithFiltering"; + ArtifactMetadata md = new ArtifactMetadata( "a:a:4" ); + + List<ArtifactBasicMetadata> exclusions = new ArrayList<ArtifactBasicMetadata>(); + exclusions.add( new ArtifactBasicMetadata("c:c:3") ); + md.setExclusions( exclusions ); + + MetadataTreeNode root = mt.buildTree( md ); + assertNotNull( "null tree built", root ); + assertEquals( "wrong tree size", 3, root.countNodes() ); + + List<ArtifactMetadata> res = mt.resolveConflicts( ArtifactScopeEnum.compile ); + assertNotNull( "null resolution", res ); + assertEquals( "wrong tree size", 2, res.size() ); + + System.out.println( title+": " + res ); + + assertTrue( assertHasArtifact( res, "a:a:4" ) ); + assertFalse( assertHasArtifact( res, "c:c:3" ) ); + + } + //---------------------------------------------------------------------------------------------- + public void testResolveScopedConflictsWithFilteringOne() + throws MetadataTreeException + { + String title = "testResolveScopedConflictsWithFilteringOne"; + ArtifactMetadata md = new ArtifactMetadata( "a:a:2" ); + + List<ArtifactBasicMetadata> exclusions = new ArrayList<ArtifactBasicMetadata>(); + exclusions.add( new ArtifactBasicMetadata("c:c:2") ); + md.setExclusions( exclusions ); + + MetadataTreeNode root = mt.buildTree( md ); + assertNotNull( "null tree built", root ); + assertEquals( "wrong tree size", 3, root.countNodes() ); + + List<ArtifactMetadata> res = mt.resolveConflicts( ArtifactScopeEnum.compile ); + assertNotNull( "null resolution", res ); + assertEquals( "wrong tree size", 2, res.size() ); + + assertTrue( "no a:a:2 in the result", assertHasArtifact( res, "a:a:2" ) ); + assertTrue( "no b:b:2 in the result", assertHasArtifact( res, "b:b:2" ) ); + assertFalse( "no c:c:2 in the result", assertHasArtifact( res, "c:c:2" ) ); + + System.out.println( title+": " + res ); + + } + //---------------------------------------------------------------------------------------------- + public void testResolveScopedConflictsWithFilteringTwo() + throws MetadataTreeException + { + String title = "testResolveScopedConflictsWithFilteringTwo"; + ArtifactMetadata md = new ArtifactMetadata( "a:a:2" ); + + List<ArtifactBasicMetadata> exclusions = new ArrayList<ArtifactBasicMetadata>(); + exclusions.add( new ArtifactBasicMetadata("b:b:2") ); + exclusions.add( new ArtifactBasicMetadata("c:c:2") ); + md.setExclusions( exclusions ); + + MetadataTreeNode root = mt.buildTree( md ); + assertNotNull( "null tree built", root ); + assertEquals( "wrong tree size", 2, root.countNodes() ); + + List<ArtifactMetadata> res = mt.resolveConflicts( ArtifactScopeEnum.compile ); + assertNotNull( "null resolution", res ); + assertEquals( "wrong tree size", 2, res.size() ); + + assertTrue( "no a:a:2 in the result", assertHasArtifact( res, "a:a:2" ) ); + assertTrue( "no b:b:2 in the result", assertHasArtifact( res, "b:b:1" ) ); + assertFalse( "no b:b:2 in the result", assertHasArtifact( res, "b:b:2" ) ); + assertFalse( "no c:c:2 in the result", assertHasArtifact( res, "c:c:2" ) ); + + System.out.println( title+": " + res ); + + } + //---------------------------------------------------------------------------------------------- + public void testResolveScopedConflictsWithFilteringAll() + throws MetadataTreeException + { + String title = "testResolveScopedConflictsWithFilteringTwo"; + ArtifactMetadata md = new ArtifactMetadata( "a:a:2" ); + + List<ArtifactBasicMetadata> exclusions = new ArrayList<ArtifactBasicMetadata>(); + exclusions.add( new ArtifactBasicMetadata("b:b:1") ); + exclusions.add( new ArtifactBasicMetadata("b:b:2") ); + exclusions.add( new ArtifactBasicMetadata("c:c:2") ); + md.setExclusions( exclusions ); + + MetadataTreeNode root = mt.buildTree( md ); + assertNotNull( "null tree built", root ); + assertEquals( "wrong tree size", 1, root.countNodes() ); + + List<ArtifactMetadata> res = mt.resolveConflicts( ArtifactScopeEnum.compile ); + assertNotNull( "null resolution", res ); + assertEquals( "wrong tree size", 1, res.size() ); + + assertTrue( "no a:a:2 in the result", assertHasArtifact( res, "a:a:2" ) ); + assertFalse( "no b:b:1 in the result", assertHasArtifact( res, "b:b:1" ) ); + assertFalse( "no b:b:2 in the result", assertHasArtifact( res, "b:b:2" ) ); + assertFalse( "no c:c:2 in the result", assertHasArtifact( res, "c:c:2" ) ); + + System.out.println( title+": " + res ); + + } + //---------------------------------------------------------------------------------------------- public void testResolveBigConflicts() throws MetadataTreeException {