maven-dependency-tree-1.2/0000755000175000017500000000000011226720336015473 5ustar twernertwernermaven-dependency-tree-1.2/src/0000755000175000017500000000000011226720336016262 5ustar twernertwernermaven-dependency-tree-1.2/src/test/0000755000175000017500000000000011226720336017241 5ustar twernertwernermaven-dependency-tree-1.2/src/test/resources/0000755000175000017500000000000011226720336021253 5ustar twernertwernermaven-dependency-tree-1.2/src/test/resources/org/0000755000175000017500000000000011226720336022042 5ustar twernertwernermaven-dependency-tree-1.2/src/test/resources/org/apache/0000755000175000017500000000000011226720336023263 5ustar twernertwernermaven-dependency-tree-1.2/src/test/resources/org/apache/maven/0000755000175000017500000000000011226720336024371 5ustar twernertwernermaven-dependency-tree-1.2/src/test/resources/org/apache/maven/shared/0000755000175000017500000000000011226720336025637 5ustar twernertwernermaven-dependency-tree-1.2/src/test/resources/org/apache/maven/shared/dependency/0000755000175000017500000000000011226720336027755 5ustar twernertwernermaven-dependency-tree-1.2/src/test/resources/org/apache/maven/shared/dependency/tree/0000755000175000017500000000000011226720336030714 5ustar twernertwerner././@LongLink0000000000000000000000000000016300000000000011565 Lustar rootrootmaven-dependency-tree-1.2/src/test/resources/org/apache/maven/shared/dependency/tree/DependencyTreeBuilderTest.xmlmaven-dependency-tree-1.2/src/test/resources/org/apache/maven/shared/dependency/tree/DependencyTreeB0000644000175000017500000000267711020006575033645 0ustar twernertwerner org.apache.maven.artifact.factory.ArtifactFactory org.apache.maven.artifact.factory.DefaultArtifactFactory org.apache.maven.artifact.handler.manager.ArtifactHandlerManager org.apache.maven.artifact.resolver.ArtifactCollector org.apache.maven.artifact.resolver.DefaultArtifactCollector maven-dependency-tree-1.2/src/test/java/0000755000175000017500000000000011226720336020162 5ustar twernertwernermaven-dependency-tree-1.2/src/test/java/org/0000755000175000017500000000000011226720336020751 5ustar twernertwernermaven-dependency-tree-1.2/src/test/java/org/apache/0000755000175000017500000000000011226720336022172 5ustar twernertwernermaven-dependency-tree-1.2/src/test/java/org/apache/maven/0000755000175000017500000000000011226720336023300 5ustar twernertwernermaven-dependency-tree-1.2/src/test/java/org/apache/maven/shared/0000755000175000017500000000000011226720336024546 5ustar twernertwernermaven-dependency-tree-1.2/src/test/java/org/apache/maven/shared/dependency/0000755000175000017500000000000011226720336026664 5ustar twernertwernermaven-dependency-tree-1.2/src/test/java/org/apache/maven/shared/dependency/tree/0000755000175000017500000000000011226720336027623 5ustar twernertwerner././@LongLink0000000000000000000000000000016600000000000011570 Lustar rootrootmaven-dependency-tree-1.2/src/test/java/org/apache/maven/shared/dependency/tree/DefaultDependencyTreeBuilderTest.javamaven-dependency-tree-1.2/src/test/java/org/apache/maven/shared/dependency/tree/DefaultDependencyTre0000644000175000017500000010453011020006575033601 0ustar twernertwernerpackage org.apache.maven.shared.dependency.tree; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; import junit.framework.AssertionFailedError; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.DefaultArtifact; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.handler.DefaultArtifactHandler; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.DefaultArtifactRepository; import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; import org.apache.maven.artifact.resolver.ArtifactCollector; import org.apache.maven.artifact.resolver.ArtifactResolutionResult; import org.apache.maven.artifact.resolver.ResolutionNode; import org.apache.maven.artifact.resolver.filter.ArtifactFilter; import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.DefaultArtifactVersion; import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.PlexusTestCase; /** * Tests DefaultDependencyTreeBuilder. * * @author Mark Hobson * @version $Id: DefaultDependencyTreeBuilderTest.java 661727 2008-05-30 14:21:49Z bentmann $ * @see DefaultDependencyTreeBuilder */ public class DefaultDependencyTreeBuilderTest extends PlexusTestCase { // fields ----------------------------------------------------------------- private DefaultDependencyTreeBuilder builder; private ArtifactRepository artifactRepository; private ArtifactFactory artifactFactory; private ArtifactMetadataSourceStub artifactMetadataSource; private ArtifactCollector artifactCollector; // TestCase methods ------------------------------------------------------- /** * {@inheritDoc} */ protected void setUp() throws Exception { super.setUp(); builder = (DefaultDependencyTreeBuilder) lookup( DependencyTreeBuilder.ROLE ); String repositoryURL = getTestFile( "target/local-repo" ).toURI().toString(); artifactRepository = new DefaultArtifactRepository( "local", repositoryURL, new DefaultRepositoryLayout() ); artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); artifactMetadataSource = new ArtifactMetadataSourceStub(); artifactCollector = (ArtifactCollector) lookup( ArtifactCollector.class.getName() ); } /** * {@inheritDoc} */ protected void tearDown() throws Exception { super.tearDown(); builder = null; } // tests ------------------------------------------------------------------ /** * Tests building a tree for a project with one dependency: * *
     * g:p:t:1
     * \- g:a:t:1
     * 
* * @throws DependencyTreeBuilderException */ public void testProjectWithDependency() throws DependencyTreeBuilderException { Artifact projectArtifact = createArtifact( "g:p:t:1" ); Artifact childArtifact = createArtifact( "g:a:t:1" ); MavenProject project = createProject( projectArtifact, new Artifact[] { childArtifact } ); DependencyNode expectedRootNode = createNode( "g:p:t:1" ); expectedRootNode.addChild( createNode( "g:a:t:1" ) ); assertDependencyTree( expectedRootNode, project ); } /** * Tests building a tree for a project with one transitive dependency: * *
     * g:p:t:1
     * \- g:a:t:1
     *    \- g:b:t:1
     * 
* * @throws DependencyTreeBuilderException */ public void testProjectWithTransitiveDependency() throws DependencyTreeBuilderException { Artifact projectArtifact = createArtifact( "g:p:t:1" ); Artifact childArtifact = createArtifact( "g:a:t:1" ); Artifact transitiveArtifact = createArtifact( "g:b:t:1" ); addArtifactMetadata( childArtifact, transitiveArtifact ); MavenProject project = createProject( projectArtifact, new Artifact[] { childArtifact } ); DependencyNode expectedRootNode = createNode( "g:p:t:1" ); DependencyNode childArtifactNode = createNode( "g:a:t:1" ); expectedRootNode.addChild( childArtifactNode ); childArtifactNode.addChild( createNode( "g:b:t:1" ) ); assertDependencyTree( expectedRootNode, project ); } /** * Tests building a tree for a project with a duplicate transitive dependency: * *
     * g:p:t:1
     * +- g:a:t:1
     * |  \- g:c:t:1
     * \- g:b:t:1
     *    \- (g:c:t:1 - omitted for duplicate)
     * 
* * @throws DependencyTreeBuilderException */ public void testProjectWithDuplicateDependency() throws DependencyTreeBuilderException { Artifact projectArtifact = createArtifact( "g:p:t:1" ); Artifact child1Artifact = createArtifact( "g:a:t:1" ); Artifact transitiveArtifact = createArtifact( "g:c:t:1" ); Artifact child2Artifact = createArtifact( "g:b:t:1" ); Artifact duplicateTransitiveArtifact = createArtifact( "g:c:t:1" ); addArtifactMetadata( child1Artifact, transitiveArtifact ); addArtifactMetadata( child2Artifact, duplicateTransitiveArtifact ); MavenProject project = createProject( projectArtifact, new Artifact[] { child1Artifact, child2Artifact } ); DependencyNode expectedRootNode = createNode( "g:p:t:1" ); DependencyNode child1ArtifactNode = createNode( "g:a:t:1" ); expectedRootNode.addChild( child1ArtifactNode ); DependencyNode transitiveArtifactNode = createNode( "g:c:t:1" ); child1ArtifactNode.addChild( transitiveArtifactNode ); DependencyNode child2ArtifactNode = createNode( "g:b:t:1" ); expectedRootNode.addChild( child2ArtifactNode ); child2ArtifactNode.addChild( createNode( "g:c:t:1", DependencyNode.OMITTED_FOR_DUPLICATE, transitiveArtifactNode.getArtifact() ) ); assertDependencyTree( expectedRootNode, project ); } /** * Tests building a tree for a project with a dependency that has conflicting versions, where the nearest is * encountered first: * *
     * g:p:t:1
     * +- g:a:t:1
     * \- g:b:t:1
     *    \- (g:a:t:2 - omitted for conflict with 1)
     * 
* * @throws DependencyTreeBuilderException */ public void testProjectWithConflictDependencyVersionFirstWins() throws DependencyTreeBuilderException { Artifact projectArtifact = createArtifact( "g:p:t:1" ); Artifact nearestArtifact = createArtifact( "g:a:t:1" ); Artifact childArtifact = createArtifact( "g:b:t:1" ); Artifact farthestArtifact = createArtifact( "g:a:t:2" ); addArtifactMetadata( childArtifact, farthestArtifact ); MavenProject project = createProject( projectArtifact, new Artifact[] { nearestArtifact, childArtifact } ); DependencyNode expectedRootNode = createNode( "g:p:t:1" ); DependencyNode nearestArtifactNode = createNode( "g:a:t:1" ); expectedRootNode.addChild( nearestArtifactNode ); DependencyNode childArtifactNode = createNode( "g:b:t:1" ); expectedRootNode.addChild( childArtifactNode ); childArtifactNode.addChild( createNode( "g:a:t:2", DependencyNode.OMITTED_FOR_CONFLICT, nearestArtifactNode.getArtifact() ) ); assertDependencyTree( expectedRootNode, project ); } /** * Tests building a tree for a project with a dependency that has conflicting versions, where the nearest is * encountered last: * *
     * g:p:t:1
     * +- g:a:t:1
     * |  \- (g:b:t:2 - omitted for conflict with 1)
     * \- g:b:t:1
     * 
* * @throws DependencyTreeBuilderException */ public void testProjectWithConflictDependencyVersionLastWins() throws DependencyTreeBuilderException { Artifact projectArtifact = createArtifact( "g:p:t:1" ); Artifact childArtifact = createArtifact( "g:a:t:1" ); Artifact farthestArtifact = createArtifact( "g:b:t:2" ); Artifact nearestArtifact = createArtifact( "g:b:t:1" ); addArtifactMetadata( childArtifact, farthestArtifact ); MavenProject project = createProject( projectArtifact, new Artifact[] { childArtifact, nearestArtifact } ); DependencyNode expectedRootNode = createNode( "g:p:t:1" ); DependencyNode childArtifactNode = createNode( "g:a:t:1" ); expectedRootNode.addChild( childArtifactNode ); DependencyNode farthestArtifactNode = createNode( "g:b:t:1" ); expectedRootNode.addChild( farthestArtifactNode ); childArtifactNode.addChild( createNode( "g:b:t:2", DependencyNode.OMITTED_FOR_CONFLICT, farthestArtifactNode.getArtifact() ) ); assertDependencyTree( expectedRootNode, project ); } /** * Tests building a tree for a project with a dependency that has conflicting scopes, where the nearest is not * broadened since it is defined in the top-level POM: * *
     * g:p:t:1
     * +- g:b:t:1:test (scope not updated to compile)
     * \- g:a:t:1
     *    \- (g:b:t:1:compile - omitted for duplicate)
     * 
* * @throws DependencyTreeBuilderException */ public void testProjectWithConflictDependencyScopeCurrentPom() throws DependencyTreeBuilderException { Artifact projectArtifact = createArtifact( "g:p:t:1" ); Artifact nearestArtifact = createArtifact( "g:b:t:1:test" ); Artifact childArtifact = createArtifact( "g:a:t:1" ); Artifact farthestArtifact = createArtifact( "g:b:t:1:compile" ); addArtifactMetadata( childArtifact, farthestArtifact ); MavenProject project = createProject( projectArtifact, new Artifact[] { nearestArtifact, childArtifact } ); DependencyNode expectedRootNode = createNode( "g:p:t:1" ); DependencyNode nearestArtifactNode = createNode( "g:b:t:1:test" ); nearestArtifactNode.setFailedUpdateScope( "compile" ); expectedRootNode.addChild( nearestArtifactNode ); DependencyNode childArtifactNode = createNode( "g:a:t:1" ); expectedRootNode.addChild( childArtifactNode ); childArtifactNode.addChild( createNode( "g:b:t:1:compile", DependencyNode.OMITTED_FOR_DUPLICATE, nearestArtifactNode.getArtifact() ) ); assertDependencyTree( expectedRootNode, project ); } /** * Tests building a tree for a project with a dependency that has conflicting scopes, where the winner is * encountered first: * *
     * g:p:t:1
     * \- g:a:t:1
     *    +- g:b:t:1
     *    |  \- g:c:t:1:compile
     *    \- (g:c:t:1:compile - scope updated from test; omitted for duplicate)
     * 
* * @throws DependencyTreeBuilderException */ public void testProjectWithConflictDependencyScopeFirstWins() throws DependencyTreeBuilderException { Artifact projectArtifact = createArtifact( "g:p:t:1" ); Artifact childArtifact = createArtifact( "g:a:t:1" ); Artifact grandchildArtifact = createArtifact( "g:b:t:1" ); Artifact farthestArtifact = createArtifact( "g:c:t:1:compile" ); Artifact nearestArtifact = createArtifact( "g:c:t:1:test" ); addArtifactMetadata( childArtifact, new Artifact[] { grandchildArtifact, nearestArtifact } ); addArtifactMetadata( grandchildArtifact, farthestArtifact ); MavenProject project = createProject( projectArtifact, new Artifact[] { childArtifact } ); /* * TODO: Not entirely convinced that the expected tree is correct - I would have expected: * *
         * g:p:t:1
         * \- g:a:t:1
         *    +- g:b:t:1
         *    |  \- (g:c:t:1:compile - omitted for duplicate)
         *    \- g:c:t:1:compile (scope updated from test)
         * 
* * @see http://www.mail-archive.com/dev@maven.apache.org/msg68011.html */ /* DependencyNode expectedRootNode = createNode( "g:p:t:1" ); DependencyNode childArtifactNode = createNode( "g:a:t:1" ); expectedRootNode.addChild( childArtifactNode ); DependencyNode grandchildArtifactNode = createNode( "g:b:t:1" ); childArtifactNode.addChild( grandchildArtifactNode ); DependencyNode nearestArtifactNode = createNode( "g:c:t:1:compile" ); DependencyNode farthestArtifactNode = createNode( "g:c:t:1:compile", DependencyNode.OMITTED_FOR_DUPLICATE, nearestArtifactNode.getArtifact() ); grandchildArtifactNode.addChild( farthestArtifactNode ); nearestArtifactNode.setOriginalScope( "test" ); childArtifactNode.addChild( nearestArtifactNode ); */ DependencyNode expectedRootNode = createNode( "g:p:t:1" ); DependencyNode childArtifactNode = createNode( "g:a:t:1" ); expectedRootNode.addChild( childArtifactNode ); DependencyNode grandchildArtifactNode = createNode( "g:b:t:1" ); childArtifactNode.addChild( grandchildArtifactNode ); DependencyNode farthestArtifactNode = createNode( "g:c:t:1:compile" ); grandchildArtifactNode.addChild( farthestArtifactNode ); DependencyNode nearestArtifactNode = createNode( "g:c:t:1:compile", DependencyNode.OMITTED_FOR_DUPLICATE, farthestArtifactNode.getArtifact() ); nearestArtifactNode.setOriginalScope( "test" ); childArtifactNode.addChild( nearestArtifactNode ); assertDependencyTree( expectedRootNode, project ); } /** * Tests building a tree for a project with a dependency that has conflicting scopes, where the winner is * encountered last: * *
     * g:p:t:1
     * \- g:a:t:1
     *    +- (g:c:t:1:compile - scope updated from test; omitted for duplicate)
     *    \- g:b:t:1
     *       \- g:c:t:1:compile
     * 
* * @throws DependencyTreeBuilderException */ public void testProjectWithConflictDependencyScopeLastWins() throws DependencyTreeBuilderException { Artifact projectArtifact = createArtifact( "g:p:t:1" ); Artifact childArtifact = createArtifact( "g:a:t:1" ); Artifact nearestArtifact = createArtifact( "g:c:t:1:test" ); Artifact grandchildArtifact = createArtifact( "g:b:t:1" ); Artifact farthestArtifact = createArtifact( "g:c:t:1:compile" ); addArtifactMetadata( childArtifact, new Artifact[] { nearestArtifact, grandchildArtifact } ); addArtifactMetadata( grandchildArtifact, farthestArtifact ); MavenProject project = createProject( projectArtifact, new Artifact[] { childArtifact } ); /* * TODO: Not entirely convinced that the expected tree is correct - I would have expected: * *
         * g:p:t:1
         * \- g:a:t:1
         *    +- g:c:t:1:compile (scope updated from test)
         *    \- g:b:t:1
         *       \- (g:c:t:1:compile - omitted for duplicate)
         * 
* * @see http://www.mail-archive.com/dev@maven.apache.org/msg68011.html */ /* DependencyNode expectedRootNode = createNode( "g:p:t:1" ); DependencyNode childArtifactNode = createNode( "g:a:t:1" ); expectedRootNode.addChild( childArtifactNode ); DependencyNode nearestArtifactNode = createNode( "g:c:t:1:compile" ); nearestArtifactNode.setOriginalScope( "test" ); childArtifactNode.addChild( nearestArtifactNode ); DependencyNode grandchildArtifactNode = createNode( "g:b:t:1" ); childArtifactNode.addChild( grandchildArtifactNode ); grandchildArtifactNode.addChild( createNode( "g:c:t:1:compile", DependencyNode.OMITTED_FOR_DUPLICATE, nearestArtifactNode.getArtifact() ) ); */ DependencyNode expectedRootNode = createNode( "g:p:t:1" ); DependencyNode childArtifactNode = createNode( "g:a:t:1" ); expectedRootNode.addChild( childArtifactNode ); DependencyNode farthestArtifactNode = createNode( "g:c:t:1:compile" ); DependencyNode nearestArtifactNode = createNode( "g:c:t:1:compile", DependencyNode.OMITTED_FOR_DUPLICATE, farthestArtifactNode.getArtifact() ); nearestArtifactNode.setOriginalScope( "test" ); childArtifactNode.addChild( nearestArtifactNode ); DependencyNode grandchildArtifactNode = createNode( "g:b:t:1" ); childArtifactNode.addChild( grandchildArtifactNode ); grandchildArtifactNode.addChild( farthestArtifactNode ); assertDependencyTree( expectedRootNode, project ); } /** * Tests building a tree for a project with one transitive dependency whose version is fixed in dependency * management: * *
     * g:p:t:1
     * \- g:a:t:1
     *    \- g:b:t:2 (version managed from 1)
     * 
* * @throws DependencyTreeBuilderException */ public void testProjectWithManagedTransitiveDependencyVersion() throws DependencyTreeBuilderException { Artifact projectArtifact = createArtifact( "g:p:t:1" ); Artifact childArtifact = createArtifact( "g:a:t:1" ); Artifact transitiveArtifact = createArtifact( "g:b:t:1" ); Artifact managedTransitiveArtifact = createArtifact( "g:b:t:2" ); addArtifactMetadata( childArtifact, transitiveArtifact ); MavenProject project = createProject( projectArtifact, new Artifact[] { childArtifact } ); setManagedVersionMap( project, Collections.singleton( managedTransitiveArtifact ) ); DependencyNode expectedRootNode = createNode( "g:p:t:1" ); DependencyNode childArtifactNode = createNode( "g:a:t:1" ); expectedRootNode.addChild( childArtifactNode ); DependencyNode managedTransitiveArtifactNode = createNode( "g:b:t:2" ); managedTransitiveArtifactNode.setPremanagedVersion( "1" ); childArtifactNode.addChild( managedTransitiveArtifactNode ); assertDependencyTree( expectedRootNode, project ); } // TODO: see MNG-3548 /** * Tests building a tree for a project with a dependency that is duplicated and the version is also fixed in * dependency management: * *
     * g:p:t:1
     * \- g:a:t:1
     *    +- g:b:t:1
     *    |  \- (g:c:t:2 - version managed from 1; omitted for duplicate)
     *    \- g:c:t:2 (version managed from 1)
     * 
* * @throws DependencyTreeBuilderException */ /* public void testProjectWithManagedTransitiveDependencyVersionAndDuplicate() throws DependencyTreeBuilderException { Artifact projectArtifact = createArtifact( "g:p:t:1" ); Artifact childArtifact = createArtifact( "g:a:t:1" ); Artifact grandchildArtifact = createArtifact( "g:b:t:1" ); Artifact farthestTransitiveArtifact = createArtifact( "g:c:t:1" ); Artifact nearestTransitiveArtifact = createArtifact( "g:c:t:1" ); Artifact managedTransitiveArtifact = createArtifact( "g:c:t:2" ); addArtifactMetadata( childArtifact, new Artifact[] { grandchildArtifact, nearestTransitiveArtifact } ); addArtifactMetadata( grandchildArtifact, farthestTransitiveArtifact ); MavenProject project = createProject( projectArtifact, new Artifact[] { childArtifact } ); setManagedVersionMap( project, Collections.singleton( managedTransitiveArtifact ) ); DependencyNode expectedRootNode = createNode( "g:p:t:1" ); DependencyNode childArtifactNode = createNode( "g:a:t:1" ); expectedRootNode.addChild( childArtifactNode ); DependencyNode grandchildArtifactNode = createNode( "g:b:t:2" ); childArtifactNode.addChild( grandchildArtifactNode ); DependencyNode managedTransitiveArtifactNode = createNode( "g:c:t:2" ); managedTransitiveArtifactNode.setPremanagedVersion( "1" ); childArtifactNode.addChild( managedTransitiveArtifactNode ); DependencyNode omittedManagedTransitiveArtifactNode = createNode( "g:c:t:2" ); omittedManagedTransitiveArtifactNode.setPremanagedVersion( "1" ); omittedManagedTransitiveArtifactNode.omitForConflict( managedTransitiveArtifact ); grandchildArtifactNode.addChild( omittedManagedTransitiveArtifactNode ); assertDependencyTree( expectedRootNode, project ); } */ /** * Tests building a tree for a project with one transitive dependency whose scope is fixed in dependency management: * *
     * g:p:t:1
     * \- g:a:t:1
     *    \- g:b:t:1:test (scope managed from compile)
     * 
* * @throws DependencyTreeBuilderException */ public void testProjectWithManagedTransitiveDependencyScope() throws DependencyTreeBuilderException { Artifact projectArtifact = createArtifact( "g:p:t:1" ); Artifact childArtifact = createArtifact( "g:a:t:1" ); Artifact transitiveArtifact = createArtifact( "g:b:t:1:compile" ); Artifact managedTransitiveArtifact = createArtifact( "g:b:t:1:test" ); addArtifactMetadata( childArtifact, transitiveArtifact ); MavenProject project = createProject( projectArtifact, new Artifact[] { childArtifact } ); setManagedVersionMap( project, Collections.singleton( managedTransitiveArtifact ) ); DependencyNode expectedRootNode = createNode( "g:p:t:1" ); DependencyNode childArtifactNode = createNode( "g:a:t:1" ); expectedRootNode.addChild( childArtifactNode ); DependencyNode managedTransitiveArtifactNode = createNode( "g:b:t:1:test" ); managedTransitiveArtifactNode.setPremanagedScope( "compile" ); childArtifactNode.addChild( managedTransitiveArtifactNode ); assertDependencyTree( expectedRootNode, project ); } /** * Tests building a tree for a project with one transitive dependency whose version and scope are fixed in * dependency management: * *
     * g:p:t:1
     * \- g:a:t:1
     *    \- g:b:t:2:test (version managed from 1; scope managed from compile)
     * 
* * @throws DependencyTreeBuilderException */ public void testProjectWithManagedTransitiveDependencyVersionAndScope() throws DependencyTreeBuilderException { Artifact projectArtifact = createArtifact( "g:p:t:1" ); Artifact childArtifact = createArtifact( "g:a:t:1" ); Artifact transitiveArtifact = createArtifact( "g:b:t:1:compile" ); Artifact managedTransitiveArtifact = createArtifact( "g:b:t:2:test" ); addArtifactMetadata( childArtifact, transitiveArtifact ); MavenProject project = createProject( projectArtifact, new Artifact[] { childArtifact } ); setManagedVersionMap( project, Collections.singleton( managedTransitiveArtifact ) ); DependencyNode expectedRootNode = createNode( "g:p:t:1" ); DependencyNode childArtifactNode = createNode( "g:a:t:1" ); expectedRootNode.addChild( childArtifactNode ); DependencyNode managedTransitiveArtifactNode = createNode( "g:b:t:2:test" ); managedTransitiveArtifactNode.setPremanagedVersion( "1" ); managedTransitiveArtifactNode.setPremanagedScope( "compile" ); childArtifactNode.addChild( managedTransitiveArtifactNode ); assertDependencyTree( expectedRootNode, project ); } /** * Tests building a tree for a project with a dependency that has conflicting versions and the version is also fixed * in dependency management: * *
     * g:p:t:1
     * +- g:a:t:1
     * \- g:b:t:1
     *    \- (g:a:t:3 - version managed from 2; omitted for conflict with 1)
     * 
* * @throws DependencyTreeBuilderException */ public void testProjectWithManagedTransitiveDependencyVersionAndConflictDependencyVersion() throws DependencyTreeBuilderException { Artifact projectArtifact = createArtifact( "g:p:t:1" ); Artifact nearestArtifact = createArtifact( "g:a:t:1" ); Artifact childArtifact = createArtifact( "g:b:t:1" ); Artifact farthestArtifact = createArtifact( "g:a:t:2" ); Artifact managedTransitiveArtifact = createArtifact( "g:a:t:3" ); addArtifactMetadata( childArtifact, farthestArtifact ); MavenProject project = createProject( projectArtifact, new Artifact[] { nearestArtifact, childArtifact } ); setManagedVersionMap( project, Collections.singleton( managedTransitiveArtifact ) ); DependencyNode expectedRootNode = createNode( "g:p:t:1" ); DependencyNode nearestArtifactNode = createNode( "g:a:t:1" ); expectedRootNode.addChild( nearestArtifactNode ); DependencyNode childArtifactNode = createNode( "g:b:t:1" ); expectedRootNode.addChild( childArtifactNode ); DependencyNode managedTransitiveArtifactNode = createNode( "g:a:t:3", DependencyNode.OMITTED_FOR_CONFLICT, nearestArtifactNode.getArtifact() ); managedTransitiveArtifactNode.setPremanagedVersion( "2" ); childArtifactNode.addChild( managedTransitiveArtifactNode ); assertDependencyTree( expectedRootNode, project ); } /** * Tests building a tree for a project with a dependency with version range * *
     * g:p:t:1
     * \- g:a:t:1
     * 
* * @throws InvalidVersionSpecificationException * @throws DependencyTreeBuilderException */ public void testProjectWithVersionRange() throws InvalidVersionSpecificationException, DependencyTreeBuilderException { String range = "[1,2)"; Artifact projectArtifact = createArtifact( "g:p:t:1" ); Artifact childArtifact = createArtifact( "g:a:t:" + range); MavenProject project = createProject( projectArtifact, new Artifact[] { childArtifact } ); ArtifactVersion version = new DefaultArtifactVersion( "1.0" ); List availableVersions = new ArrayList(); availableVersions.add( version ); DependencyNode expectedRootNode = createNode( "g:p:t:1" ); DependencyNode childNode = createNode( "g:a:t:1.0" ); childNode.setAvailableVersions( availableVersions ); childNode.setVersionSelectedFromRange( VersionRange.createFromVersionSpec( range ) ); expectedRootNode.addChild( childNode ); artifactMetadataSource.addAvailableVersions( childArtifact, availableVersions ); assertDependencyTree( expectedRootNode, project ); } // TODO: reinstate when MNG-3236 fixed /* public void testProjectWithFilter() throws DependencyTreeBuilderException, ArtifactResolutionException { Artifact projectArtifact = createArtifact( "g:p:t:1" ); Artifact child1Artifact = createArtifact( "g:a:t:1" ); Artifact child2Artifact = createArtifact( "g:b:t:1:test" ); MavenProject project = createProject( projectArtifact, new Artifact[] { child1Artifact, child2Artifact } ); DependencyNode expectedRootNode = createNode( "g:p:t:1" ); expectedRootNode.addChild( createNode( "g:a:t:1" ) ); ArtifactFilter artifactFilter = new ScopeArtifactFilter( Artifact.SCOPE_COMPILE ); assertDependencyTree( expectedRootNode, project, artifactFilter ); } */ // private methods -------------------------------------------------------- private DependencyNode createNode( String id ) { return createNode( id, DependencyNode.INCLUDED, null ); } private DependencyNode createNode( String id, int state, Artifact relatedArtifact ) { return new DependencyNode( createArtifact( id ), state, relatedArtifact ); } private Artifact createArtifact( String id ) { String[] tokens = id.split( ":" ); String groupId = get( tokens, 0 ); String artifactId = get( tokens, 1 ); String type = get( tokens, 2, "jar" ); String version = get( tokens, 3 ); String scope = get( tokens, 4 ); VersionRange versionRange; try { versionRange = VersionRange.createFromVersionSpec( version ); } catch ( InvalidVersionSpecificationException e ) { throw new RuntimeException(e); } return new DefaultArtifact( groupId, artifactId, versionRange, scope, type, null, new DefaultArtifactHandler() ); } private MavenProject createProject( Artifact projectArtifact, Artifact[] dependencyArtifacts ) { MavenProject project = new MavenProject(); project.setArtifact( projectArtifact ); // LinkedHashSet since order is significant when omitting conflicts project.setDependencyArtifacts( new LinkedHashSet( Arrays.asList( dependencyArtifacts ) ) ); project.setManagedVersionMap( new HashMap() ); project.setRemoteArtifactRepositories( Collections.EMPTY_LIST ); return project; } private void addArtifactMetadata( Artifact artifact, Artifact dependencyArtifact ) { addArtifactMetadata( artifact, new Artifact[] { dependencyArtifact } ); } private void addArtifactMetadata( Artifact artifact, Artifact[] dependencyArtifacts ) { addArtifactMetadata( artifact, new LinkedHashSet( Arrays.asList( dependencyArtifacts ) ) ); } private void addArtifactMetadata( Artifact artifact, Set dependencyArtifacts ) { artifactMetadataSource.addArtifactMetadata( artifact, dependencyArtifacts ); } private void setManagedVersionMap( MavenProject project, Set managedArtifacts ) { Map managedVersionMap = new HashMap(); for ( Iterator iterator = managedArtifacts.iterator(); iterator.hasNext(); ) { Artifact artifact = (Artifact) iterator.next(); String managementKey = getManagementKey( artifact ); managedVersionMap.put( managementKey, artifact ); } project.setManagedVersionMap( managedVersionMap ); } private String getManagementKey( Artifact artifact ) { return artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getType() + (artifact.getClassifier() != null ? ":" + artifact.getClassifier() : ""); } private void assertDependencyTree( DependencyNode expectedRootNode, MavenProject project ) throws DependencyTreeBuilderException { assertDependencyTree( expectedRootNode, project, null ); } private void assertDependencyTree( DependencyNode expectedRootNode, MavenProject project, ArtifactFilter artifactFilter ) throws DependencyTreeBuilderException { // assert built dependency tree is as expected DependencyNode actualRootNode = builder.buildDependencyTree( project, artifactRepository, artifactFactory, artifactMetadataSource, artifactFilter, artifactCollector ); assertEquals( "Dependency tree", expectedRootNode, actualRootNode ); // assert resolution tree is as expected ArtifactResolutionResult result = builder.getArtifactResolutionResult(); assertTreeEquals( expectedRootNode, project, result ); } private void assertTreeEquals( DependencyNode dependencyNode, MavenProject project, ArtifactResolutionResult resolutionResult ) { List rootChildrenResolutionNodes = ResolutionNodeUtils.getRootChildrenResolutionNodes( project, resolutionResult ); try { assertEquals( "Root node artifact", dependencyNode.getArtifact(), project.getArtifact() ); assertNodesEquals( dependencyNode.getChildren(), rootChildrenResolutionNodes ); } catch ( AssertionFailedError error ) { StringBuffer buffer = new StringBuffer(); buffer.append( error.getMessage() ).append( "; " ); buffer.append( "expected dependency tree <" ).append( dependencyNode ).append( "> " ); buffer.append( "actual resolution tree <" ); ResolutionNodeUtils.append( buffer, project, resolutionResult ); buffer.append( ">" ); throw new AssertionFailedError( buffer.toString() ); } } private void assertNodesEquals( List dependencyNodes, List resolutionNodes ) { assertNodesEquals( dependencyNodes.iterator(), resolutionNodes.iterator() ); } private void assertNodesEquals( Iterator dependencyNodesIterator, Iterator resolutionNodesIterator ) { while ( dependencyNodesIterator.hasNext() && resolutionNodesIterator.hasNext() ) { DependencyNode dependencyNode = (DependencyNode) dependencyNodesIterator.next(); ResolutionNode resolutionNode = (ResolutionNode) resolutionNodesIterator.next(); assertNodeEquals( dependencyNode, resolutionNode ); } if ( dependencyNodesIterator.hasNext() || resolutionNodesIterator.hasNext() ) { fail( "Node list size differs" ); } } private void assertNodeEquals( DependencyNode dependencyNode, ResolutionNode resolutionNode ) { assertEquals( "Node state", dependencyNode.getState() == DependencyNode.INCLUDED, resolutionNode.isActive() ); assertEquals( "Node artifact", dependencyNode.getArtifact(), resolutionNode.getArtifact() ); assertNodesEquals( dependencyNode.getChildren().iterator(), resolutionNode.getChildrenIterator() ); } private String get( String[] array, int index ) { return get( array, index, null ); } private String get( String[] array, int index, String defaultValue ) { return ( index < array.length ) ? array[index] : defaultValue; } } maven-dependency-tree-1.2/src/test/java/org/apache/maven/shared/dependency/tree/filter/0000755000175000017500000000000011226720336031110 5ustar twernertwerner././@LongLink0000000000000000000000000000017500000000000011570 Lustar rootrootmaven-dependency-tree-1.2/src/test/java/org/apache/maven/shared/dependency/tree/filter/ArtifactDependencyNodeFilterTest.javamaven-dependency-tree-1.2/src/test/java/org/apache/maven/shared/dependency/tree/filter/ArtifactDepen0000644000175000017500000000560311020006575033542 0ustar twernertwernerpackage org.apache.maven.shared.dependency.tree.filter; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.resolver.filter.ArtifactFilter; import org.apache.maven.plugin.testing.stubs.ArtifactStub; import org.apache.maven.shared.dependency.tree.DependencyNode; import org.jmock.Mock; import org.jmock.MockObjectTestCase; /** * Tests ArtifactDependencyNodeFilter. * * @author Mark Hobson * @version $Id: ArtifactDependencyNodeFilterTest.java 661727 2008-05-30 14:21:49Z bentmann $ * @see ArtifactDependencyNodeFilter */ public class ArtifactDependencyNodeFilterTest extends MockObjectTestCase { // fields ----------------------------------------------------------------- private Artifact artifact; private DependencyNode node; private ArtifactDependencyNodeFilter nodeFilter; private ArtifactFilter artifactFilter; // TestCase methods ------------------------------------------------------- /** * {@inheritDoc} */ protected void setUp() throws Exception { artifact = new ArtifactStub(); node = new DependencyNode( artifact ); } // tests ------------------------------------------------------------------ public void testArtifactFilterInclude() { artifactFilter = createArtifactFilter( artifact, true ); nodeFilter = new ArtifactDependencyNodeFilter( artifactFilter ); assertTrue( nodeFilter.accept( node ) ); } public void testArtifactFilterExclude() { artifactFilter = createArtifactFilter( artifact, false ); nodeFilter = new ArtifactDependencyNodeFilter( artifactFilter ); assertFalse( nodeFilter.accept( node ) ); } // private methods -------------------------------------------------------- private ArtifactFilter createArtifactFilter( Artifact artifact, boolean include ) { Mock mock = mock( ArtifactFilter.class ); mock.stubs().method( "include" ).with( same( artifact ) ).will( returnValue( include ) ); return (ArtifactFilter) mock.proxy(); } } ././@LongLink0000000000000000000000000000017200000000000011565 Lustar rootrootmaven-dependency-tree-1.2/src/test/java/org/apache/maven/shared/dependency/tree/filter/StateDependencyNodeFilterTest.javamaven-dependency-tree-1.2/src/test/java/org/apache/maven/shared/dependency/tree/filter/StateDependen0000644000175000017500000000763111020006575033557 0ustar twernertwernerpackage org.apache.maven.shared.dependency.tree.filter; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import junit.framework.TestCase; import org.apache.maven.artifact.Artifact; import org.apache.maven.plugin.testing.stubs.ArtifactStub; import org.apache.maven.shared.dependency.tree.DependencyNode; /** * Tests StateDependencyNodeFilter. * * @author Mark Hobson * @version $Id: StateDependencyNodeFilterTest.java 661727 2008-05-30 14:21:49Z bentmann $ * @see StateDependencyNodeFilter */ public class StateDependencyNodeFilterTest extends TestCase { // fields ----------------------------------------------------------------- private StateDependencyNodeFilter filter; private DependencyNode includedNode; private DependencyNode omittedForDuplicateNode; private DependencyNode omittedForConflictNode; private DependencyNode omittedForCycleNode; // TestCase methods ------------------------------------------------------- /** * {@inheritDoc} */ protected void setUp() throws Exception { Artifact artifact = new ArtifactStub(); Artifact relatedArtifact = new ArtifactStub(); includedNode = new DependencyNode( artifact, DependencyNode.INCLUDED ); omittedForDuplicateNode = new DependencyNode( artifact, DependencyNode.OMITTED_FOR_DUPLICATE, relatedArtifact ); omittedForConflictNode = new DependencyNode( artifact, DependencyNode.OMITTED_FOR_CONFLICT, relatedArtifact ); omittedForCycleNode = new DependencyNode( artifact, DependencyNode.OMITTED_FOR_CYCLE ); } // tests ------------------------------------------------------------------ public void testIncluded() { filter = new StateDependencyNodeFilter( DependencyNode.INCLUDED ); assertTrue( filter.accept( includedNode ) ); assertFalse( filter.accept( omittedForDuplicateNode ) ); assertFalse( filter.accept( omittedForConflictNode ) ); assertFalse( filter.accept( omittedForCycleNode ) ); } public void testOmittedForDuplicate() { filter = new StateDependencyNodeFilter( DependencyNode.OMITTED_FOR_DUPLICATE ); assertFalse( filter.accept( includedNode ) ); assertTrue( filter.accept( omittedForDuplicateNode ) ); assertFalse( filter.accept( omittedForConflictNode ) ); assertFalse( filter.accept( omittedForCycleNode ) ); } public void testOmittedForConflict() { filter = new StateDependencyNodeFilter( DependencyNode.OMITTED_FOR_CONFLICT ); assertFalse( filter.accept( includedNode ) ); assertFalse( filter.accept( omittedForDuplicateNode ) ); assertTrue( filter.accept( omittedForConflictNode ) ); assertFalse( filter.accept( omittedForCycleNode ) ); } public void testOmittedForCycle() { filter = new StateDependencyNodeFilter( DependencyNode.OMITTED_FOR_CYCLE ); assertFalse( filter.accept( includedNode ) ); assertFalse( filter.accept( omittedForDuplicateNode ) ); assertFalse( filter.accept( omittedForConflictNode ) ); assertTrue( filter.accept( omittedForCycleNode ) ); } } ././@LongLink0000000000000000000000000000017000000000000011563 Lustar rootrootmaven-dependency-tree-1.2/src/test/java/org/apache/maven/shared/dependency/tree/filter/AndDependencyNodeFilterTest.javamaven-dependency-tree-1.2/src/test/java/org/apache/maven/shared/dependency/tree/filter/AndDependency0000644000175000017500000000541211020006575033530 0ustar twernertwernerpackage org.apache.maven.shared.dependency.tree.filter; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import org.apache.maven.artifact.Artifact; import org.apache.maven.plugin.testing.stubs.ArtifactStub; import org.apache.maven.shared.dependency.tree.DependencyNode; /** * Tests AndDependencyNodeFilter. * * @author Mark Hobson * @version $Id: AndDependencyNodeFilterTest.java 661727 2008-05-30 14:21:49Z bentmann $ * @see AndDependencyNodeFilter */ public class AndDependencyNodeFilterTest extends AbstractDependencyNodeFilterTest { // fields ----------------------------------------------------------------- private Artifact artifact; private DependencyNode node; private DependencyNodeFilter includeFilter; private DependencyNodeFilter excludeFilter; private AndDependencyNodeFilter filter; // TestCase methods ------------------------------------------------------- /** * {@inheritDoc} */ protected void setUp() throws Exception { artifact = new ArtifactStub(); node = new DependencyNode( artifact ); includeFilter = createDependencyNodeFilter( node, true ); excludeFilter = createDependencyNodeFilter( node, false ); } // tests ------------------------------------------------------------------ public void testIncludeInclude() { filter = new AndDependencyNodeFilter( includeFilter, includeFilter ); assertTrue( filter.accept( node ) ); } public void testIncludeExclude() { filter = new AndDependencyNodeFilter( includeFilter, excludeFilter ); assertFalse( filter.accept( node ) ); } public void testExcludeInclude() { filter = new AndDependencyNodeFilter( excludeFilter, includeFilter ); assertFalse( filter.accept( node ) ); } public void testExcludeExclude() { filter = new AndDependencyNodeFilter( excludeFilter, excludeFilter ); assertFalse( filter.accept( node ) ); } } ././@LongLink0000000000000000000000000000020300000000000011560 Lustar rootrootmaven-dependency-tree-1.2/src/test/java/org/apache/maven/shared/dependency/tree/filter/AncestorOrSelfDependencyNodeFilterTest.javamaven-dependency-tree-1.2/src/test/java/org/apache/maven/shared/dependency/tree/filter/AncestorOrSel0000644000175000017500000000635111020006575033555 0ustar twernertwernerpackage org.apache.maven.shared.dependency.tree.filter; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import org.apache.maven.shared.dependency.tree.AbstractDependencyNodeTest; import org.apache.maven.shared.dependency.tree.DependencyNode; /** * Tests AncestorOrSelfDependencyNodeFilter. * * @author Mark Hobson * @version $Id: AncestorOrSelfDependencyNodeFilterTest.java 661727 2008-05-30 14:21:49Z bentmann $ * @see AncestorOrSelfDependencyNodeFilter */ public class AncestorOrSelfDependencyNodeFilterTest extends AbstractDependencyNodeTest { // constants -------------------------------------------------------------- private DependencyNode rootNode; private DependencyNode childNode1; private DependencyNode childNode2; private DependencyNode grandChildNode; private AncestorOrSelfDependencyNodeFilter filter; // TestCase methods ------------------------------------------------------- /** * {@inheritDoc} */ protected void setUp() throws Exception { /* * p -> a -> c * -> b */ rootNode = createNode( "g:p:t:1" ); childNode1 = createNode( "g:a:t:1" ); rootNode.addChild( childNode1 ); childNode2 = createNode( "g:b:t:1" ); rootNode.addChild( childNode2 ); grandChildNode = createNode( "g:c:t:1" ); childNode1.addChild( grandChildNode ); } // tests ------------------------------------------------------------------ public void testSelf() { filter = new AncestorOrSelfDependencyNodeFilter( rootNode ); assertTrue( filter.accept( rootNode ) ); } public void testParent() { filter = new AncestorOrSelfDependencyNodeFilter( childNode1 ); assertTrue( filter.accept( rootNode ) ); } public void testGrandParent() { filter = new AncestorOrSelfDependencyNodeFilter( grandChildNode ); assertTrue( filter.accept( rootNode ) ); } public void testCousin() { filter = new AncestorOrSelfDependencyNodeFilter( childNode2 ); assertFalse( filter.accept( childNode1 ) ); } public void testChild() { filter = new AncestorOrSelfDependencyNodeFilter( rootNode ); assertFalse( filter.accept( childNode1 ) ); } public void testGrandChild() { filter = new AncestorOrSelfDependencyNodeFilter( rootNode ); assertFalse( filter.accept( grandChildNode ) ); } } ././@LongLink0000000000000000000000000000017500000000000011570 Lustar rootrootmaven-dependency-tree-1.2/src/test/java/org/apache/maven/shared/dependency/tree/filter/AbstractDependencyNodeFilterTest.javamaven-dependency-tree-1.2/src/test/java/org/apache/maven/shared/dependency/tree/filter/AbstractDepen0000644000175000017500000000325611020006575033552 0ustar twernertwernerpackage org.apache.maven.shared.dependency.tree.filter; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import org.apache.maven.shared.dependency.tree.DependencyNode; import org.jmock.Mock; import org.jmock.MockObjectTestCase; /** * Provides utility methods for testing dependency node filters. * * @author Mark Hobson * @version $Id: AbstractDependencyNodeFilterTest.java 661727 2008-05-30 14:21:49Z bentmann $ */ public abstract class AbstractDependencyNodeFilterTest extends MockObjectTestCase { // protected methods --------------------------------------------------------- protected DependencyNodeFilter createDependencyNodeFilter( DependencyNode node, boolean accept ) { Mock mock = mock( DependencyNodeFilter.class ); mock.stubs().method( "accept" ).with( same( node ) ).will( returnValue( accept ) ); return (DependencyNodeFilter) mock.proxy(); } } ././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootmaven-dependency-tree-1.2/src/test/java/org/apache/maven/shared/dependency/tree/DependencyNodeTest.javamaven-dependency-tree-1.2/src/test/java/org/apache/maven/shared/dependency/tree/DependencyNodeTest.j0000644000175000017500000002141511020006575033517 0ustar twernertwernerpackage org.apache.maven.shared.dependency.tree; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.io.BufferedReader; import java.io.IOException; import java.io.StringReader; import java.util.Iterator; import org.apache.maven.artifact.Artifact; /** * Tests DependencyNode. * * @author Carlos Sanchez * @author Mark Hobson * @version $Id: DependencyNodeTest.java 661727 2008-05-30 14:21:49Z bentmann $ * @see DependencyNode */ public class DependencyNodeTest extends AbstractDependencyNodeTest { private DependencyNode rootNode, node1, node2, node3, node4, node5, node6, node7; protected void setUp() throws Exception { super.setUp(); /* * ------1------ * ----2---- 3 * 4 5 7 * 6 */ node1 = createNode( 1 ); node2 = createNode( node1, 2 ); node3 = createNode( node1, 3 ); node4 = createNode( node2, 4 ); node5 = createNode( node2, 5 ); node6 = createNode( node5, 6 ); node7 = createNode( node3, 7 ); rootNode = node1; } private void assertNode( Iterator it, DependencyNode node ) { assertTrue( it.hasNext() ); assertSame( node, it.next() ); } public void testPreorderIterator() { Iterator it = rootNode.iterator(); assertNode( it, node1 ); assertNode( it, node2 ); assertNode( it, node4 ); assertNode( it, node5 ); assertNode( it, node6 ); assertNode( it, node3 ); assertNode( it, node7 ); assertFalse( it.hasNext() ); } public void testInverseIterator() { Iterator it = rootNode.inverseIterator(); assertNode( it, node7 ); assertNode( it, node3 ); assertNode( it, node6 ); assertNode( it, node5 ); assertNode( it, node4 ); assertNode( it, node2 ); assertNode( it, node1 ); assertFalse( it.hasNext() ); } public void testToNodeStringIncluded() { Artifact artifact = createArtifact( "g:a:t:1:s" ); DependencyNode node = new DependencyNode( artifact ); assertEquals( "g:a:t:1:s", node.toNodeString() ); } public void testToNodeStringIncludedWithManagedVersion() { Artifact artifact = createArtifact( "g:a:t:1:s" ); DependencyNode node = new DependencyNode( artifact ); node.setPremanagedVersion( "2" ); assertEquals( "g:a:t:1:s (version managed from 2)", node.toNodeString() ); } public void testToNodeStringIncludedWithManagedScope() { Artifact artifact = createArtifact( "g:a:t:1:s" ); DependencyNode node = new DependencyNode( artifact ); node.setPremanagedScope( "x" ); assertEquals( "g:a:t:1:s (scope managed from x)", node.toNodeString() ); } public void testToNodeStringIncludedWithUpdatedScope() { Artifact artifact = createArtifact( "g:a:t:1:s" ); DependencyNode node = new DependencyNode( artifact ); node.setOriginalScope( "x" ); assertEquals( "g:a:t:1:s (scope updated from x)", node.toNodeString() ); } public void testToNodeStringOmittedForDuplicate() { Artifact artifact = createArtifact( "g:a:t:1:s" ); Artifact duplicateArtifact = createArtifact( "g:a:t:1:s" ); DependencyNode node = new DependencyNode( artifact, DependencyNode.OMITTED_FOR_DUPLICATE, duplicateArtifact ); assertEquals( "(g:a:t:1:s - omitted for duplicate)", node.toNodeString() ); } public void testToNodeStringOmittedForDuplicateWithUpdatedScope() { Artifact artifact = createArtifact( "g:a:t:1:s" ); Artifact duplicateArtifact = createArtifact( "g:a:t:1:s" ); DependencyNode node = new DependencyNode( artifact, DependencyNode.OMITTED_FOR_DUPLICATE, duplicateArtifact ); node.setOriginalScope( "x" ); assertEquals( "(g:a:t:1:s - scope updated from x; omitted for duplicate)", node.toNodeString() ); } public void testToNodeStringOmittedForConflict() { Artifact artifact = createArtifact( "g:a:t:1:s" ); Artifact conflictArtifact = createArtifact( "g:a:t:2:s" ); DependencyNode node = new DependencyNode(artifact, DependencyNode.OMITTED_FOR_CONFLICT, conflictArtifact); assertEquals( "(g:a:t:1:s - omitted for conflict with 2)", node.toNodeString() ); } public void testToNodeStringOmittedForCycle() { Artifact artifact = createArtifact( "g:a:t:1:s" ); DependencyNode node = new DependencyNode(artifact, DependencyNode.OMITTED_FOR_CYCLE); assertEquals( "(g:a:t:1:s - omitted for cycle)", node.toNodeString() ); } public void testToString() throws Exception { BufferedReader reader = new BufferedReader( new StringReader( node1.toString() ) ); assertLine( reader, 1, 0 ); assertLine( reader, 2, 1 ); assertLine( reader, 4, 2 ); assertLine( reader, 5, 2 ); assertLine( reader, 6, 3 ); assertLine( reader, 3, 1 ); assertLine( reader, 7, 2 ); } public void testOmitForConflict() { Artifact relatedArtifact = createArtifact( createArtifactId( 2, "3" ) ); node2.omitForConflict( relatedArtifact ); assertEquals( DependencyNode.OMITTED_FOR_CONFLICT, node2.getState() ); assertEquals( relatedArtifact, node2.getRelatedArtifact() ); assertTrue( node2.getChildren().isEmpty() ); assertNull( node4.getParent() ); assertNull( node5.getParent() ); } public void testOmitForConflictWithDuplicate() { Artifact relatedArtifact = createArtifact( createArtifactId( 2 ) ); node2.omitForConflict( relatedArtifact ); assertEquals( DependencyNode.OMITTED_FOR_DUPLICATE, node2.getState() ); assertEquals( relatedArtifact, node2.getRelatedArtifact() ); assertTrue( node2.getChildren().isEmpty() ); assertNull( node4.getParent() ); assertNull( node5.getParent() ); } public void testOmitForCycle() { node2.omitForCycle(); assertEquals( DependencyNode.OMITTED_FOR_CYCLE, node2.getState() ); assertTrue( node2.getChildren().isEmpty() ); assertNull( node4.getParent() ); assertNull( node5.getParent() ); } /** * @deprecated */ public void testGetDepth() { assertEquals( 0, rootNode.getDepth() ); assertEquals( 0, node1.getDepth() ); assertEquals( 1, node2.getDepth() ); assertEquals( 1, node3.getDepth() ); assertEquals( 2, node4.getDepth() ); assertEquals( 2, node5.getDepth() ); assertEquals( 3, node6.getDepth() ); assertEquals( 2, node7.getDepth() ); } private void assertLine( BufferedReader reader, int i, int depth ) throws IOException { String line = reader.readLine(); StringBuffer sb = new StringBuffer(); for ( int j = 0; j < depth; j++ ) { sb.append( " " ); } sb.append( "groupId" ); sb.append( i ); sb.append( ":artifactId" ); sb.append( i ); sb.append( ":jar:" ); sb.append( i ); sb.append( ":compile" ); assertEquals( sb.toString(), line ); } private DependencyNode createNode( DependencyNode parent, int i ) { DependencyNode node = createNode( i ); parent.addChild( node ); return node; } private DependencyNode createNode( int i ) { return createNode( createArtifactId( i ) ); } private String createArtifactId( int i ) { return createArtifactId( i, Integer.toString( i ) ); } private String createArtifactId( int i, String version ) { return "groupId" + i + ":artifactId" + i + ":jar:" + version + ":compile"; } } ././@LongLink0000000000000000000000000000016000000000000011562 Lustar rootrootmaven-dependency-tree-1.2/src/test/java/org/apache/maven/shared/dependency/tree/AbstractDependencyNodeTest.javamaven-dependency-tree-1.2/src/test/java/org/apache/maven/shared/dependency/tree/AbstractDependencyNo0000644000175000017500000000604611020006575033605 0ustar twernertwernerpackage org.apache.maven.shared.dependency.tree; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import org.apache.maven.artifact.Artifact; import org.apache.maven.plugin.testing.stubs.ArtifactStub; import org.jmock.MockObjectTestCase; /** * Provides utility methods for testing dependency nodes. * * @author Mark Hobson * @version $Id: AbstractDependencyNodeTest.java 661727 2008-05-30 14:21:49Z bentmann $ */ public abstract class AbstractDependencyNodeTest extends MockObjectTestCase { // protected methods ------------------------------------------------------ protected DependencyNode createNode( String id ) { return createNode( id, DependencyNode.INCLUDED ); } protected DependencyNode createNode( String id, int state ) { return createNode( id, state, null ); } protected DependencyNode createNode( String id, int state, String relatedId ) { return new DependencyNode( createArtifact( id ), state, createArtifact( relatedId ) ); } protected Artifact createArtifact( String id ) { if ( id == null ) { return null; } String[] tokens = id.split( ":" ); return createArtifact( get( tokens, 0 ), get( tokens, 1 ), get( tokens, 2 ), get( tokens, 3 ), get( tokens, 4 ) ); } protected Artifact createArtifact( String groupId, String artifactId, String version ) { return createArtifact( groupId, artifactId, "jar", version ); } protected Artifact createArtifact( String groupId, String artifactId, String type, String version ) { return createArtifact( groupId, artifactId, type, version, null ); } protected Artifact createArtifact( String groupId, String artifactId, String type, String version, String scope ) { ArtifactStub artifact = new ArtifactStub(); artifact.setGroupId( groupId ); artifact.setArtifactId( artifactId ); artifact.setType( type ); artifact.setVersion( version ); artifact.setScope( scope ); return artifact; } // private methods -------------------------------------------------------- private String get( String[] array, int index ) { return ( index < array.length ) ? array[index] : null; } } ././@LongLink0000000000000000000000000000015100000000000011562 Lustar rootrootmaven-dependency-tree-1.2/src/test/java/org/apache/maven/shared/dependency/tree/ResolutionNodeUtils.javamaven-dependency-tree-1.2/src/test/java/org/apache/maven/shared/dependency/tree/ResolutionNodeUtils.0000644000175000017500000001111311020006575033605 0ustar twernertwernerpackage org.apache.maven.shared.dependency.tree; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.resolver.ArtifactResolutionResult; import org.apache.maven.artifact.resolver.ResolutionNode; import org.apache.maven.project.MavenProject; /** * Utilities for working with resolution nodes. * * @author Mark Hobson * @version $Id: ResolutionNodeUtils.java 661727 2008-05-30 14:21:49Z bentmann $ * @see ResolutionNode */ public final class ResolutionNodeUtils { // constructors ----------------------------------------------------------- private ResolutionNodeUtils() { // private constructor for utility class } // public methods --------------------------------------------------------- public static List getRootChildrenResolutionNodes( MavenProject project, ArtifactResolutionResult resolutionResult ) { Set resolutionNodes = resolutionResult.getArtifactResolutionNodes(); // obtain root children nodes Map rootChildrenResolutionNodesByArtifact = new HashMap(); for ( Iterator iterator = resolutionNodes.iterator(); iterator.hasNext(); ) { ResolutionNode resolutionNode = (ResolutionNode) iterator.next(); if ( resolutionNode.isChildOfRootNode() ) { rootChildrenResolutionNodesByArtifact.put( resolutionNode.getArtifact(), resolutionNode ); } } // order root children by project dependencies List rootChildrenResolutionNodes = new ArrayList(); for ( Iterator iterator = project.getDependencyArtifacts().iterator(); iterator.hasNext(); ) { Artifact artifact = (Artifact) iterator.next(); ResolutionNode resolutionNode = (ResolutionNode) rootChildrenResolutionNodesByArtifact.get( artifact ); rootChildrenResolutionNodes.add( resolutionNode ); } return rootChildrenResolutionNodes; } public static String toString( MavenProject project, ArtifactResolutionResult result ) { StringBuffer buffer = new StringBuffer(); append( buffer, project, result ); return buffer.toString(); } public static StringBuffer append( StringBuffer buffer, MavenProject project, ArtifactResolutionResult result ) { ResolutionNode rootNode = new ResolutionNode( project.getArtifact(), Collections.EMPTY_LIST ); append( buffer, rootNode, 0 ); List rootChildrenNodes = getRootChildrenResolutionNodes( project, result ); append( buffer, rootChildrenNodes.iterator(), 1 ); return buffer; } // private methods -------------------------------------------------------- private static StringBuffer append( StringBuffer buffer, Iterator nodesIterator, int depth ) { while ( nodesIterator.hasNext() ) { ResolutionNode node = (ResolutionNode) nodesIterator.next(); append( buffer, node, depth ); } return buffer; } private static StringBuffer append( StringBuffer buffer, ResolutionNode node, int depth ) { for ( int i = 0; i < depth; i++ ) { buffer.append( " " ); } buffer.append( node ); buffer.append( System.getProperty( "line.separator" ) ); if ( node != null && node.isResolved() ) { append( buffer, node.getChildrenIterator(), depth + 1 ); } return buffer; } } ././@LongLink0000000000000000000000000000017200000000000011565 Lustar rootrootmaven-dependency-tree-1.2/src/test/java/org/apache/maven/shared/dependency/tree/DependencyTreeResolutionListenerTest.javamaven-dependency-tree-1.2/src/test/java/org/apache/maven/shared/dependency/tree/DependencyTreeResolu0000644000175000017500000004171511020006575033640 0ustar twernertwernerpackage org.apache.maven.shared.dependency.tree; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.DefaultArtifact; import org.apache.maven.artifact.handler.DefaultArtifactHandler; import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.plugin.testing.SilentLog; /** * Tests DependencyTreeResolutionListener. * * @author Edwin Punzalan * @author Mark Hobson * @version $Id: DependencyTreeResolutionListenerTest.java 661727 2008-05-30 14:21:49Z bentmann $ * @see DependencyTreeResolutionListener */ public class DependencyTreeResolutionListenerTest extends AbstractDependencyNodeTest { // fields ----------------------------------------------------------------- private DependencyTreeResolutionListener listener; // TestCase methods ------------------------------------------------------- /** * {@inheritDoc} */ protected void setUp() throws Exception { super.setUp(); listener = new DependencyTreeResolutionListener( new SilentLog() ); } // tests ------------------------------------------------------------------ public void testSimpleDependencyTree() { Artifact projectArtifact = createArtifact( "test-project", "project-artifact", "1.0" ); listener.includeArtifact( projectArtifact ); listener.startProcessChildren( projectArtifact ); Artifact depArtifact01 = createArtifact( "test-dep", "dependency-one", "1.0" ); listener.includeArtifact( depArtifact01 ); Artifact depArtifact02 = createArtifact( "test-dep", "dependency-two", "1.0" ); listener.includeArtifact( depArtifact02 ); Artifact depArtifact03 = createArtifact( "test-dep", "dependency-three", "1.0" ); listener.includeArtifact( depArtifact03 ); listener.endProcessChildren( projectArtifact ); DependencyNode projectArtifactNode = new DependencyNode( projectArtifact ); projectArtifactNode.addChild( new DependencyNode( depArtifact01 ) ); projectArtifactNode.addChild( new DependencyNode( depArtifact02 ) ); projectArtifactNode.addChild( new DependencyNode( depArtifact03 ) ); assertEquals( projectArtifactNode, listener.getRootNode() ); } public void testSimpleDepTreeWithTransitiveDeps() { Artifact projectArtifact = createArtifact( "test-project", "project-artifact", "1.0" ); listener.includeArtifact( projectArtifact ); listener.startProcessChildren( projectArtifact ); Artifact depArtifact1 = createArtifact( "test-dep", "dependency-one", "1.0" ); listener.includeArtifact( depArtifact1 ); listener.startProcessChildren( depArtifact1 ); Artifact depArtifact01 = createArtifact( "test-dep", "dependency-zero-one", "1.0" ); listener.includeArtifact( depArtifact01 ); Artifact depArtifact02 = createArtifact( "test-dep", "dependency-zero-two", "1.0" ); listener.includeArtifact( depArtifact02 ); listener.endProcessChildren( depArtifact1 ); Artifact depArtifact2 = createArtifact( "test-dep", "dependency-two", "1.0" ); listener.includeArtifact( depArtifact2 ); Artifact depArtifact3 = createArtifact( "test-dep", "dependency-three", "1.0" ); listener.includeArtifact( depArtifact3 ); listener.endProcessChildren( projectArtifact ); DependencyNode projectArtifactNode = new DependencyNode( projectArtifact ); DependencyNode depArtifact1Node = new DependencyNode( depArtifact1 ); projectArtifactNode.addChild( depArtifact1Node ); depArtifact1Node.addChild( new DependencyNode( depArtifact01 ) ); depArtifact1Node.addChild( new DependencyNode( depArtifact02 ) ); projectArtifactNode.addChild( new DependencyNode( depArtifact2 ) ); projectArtifactNode.addChild( new DependencyNode( depArtifact3 ) ); assertEquals( projectArtifactNode, listener.getRootNode() ); } public void testComplexDependencyTree() { Artifact projectArtifact = createArtifact( "test-project", "project-artifact", "1.0" ); listener.includeArtifact( projectArtifact ); listener.startProcessChildren( projectArtifact ); Artifact depArtifact1 = createArtifact( "test-dep", "dependency-one", "jar", "1.0", Artifact.SCOPE_COMPILE ); listener.includeArtifact( depArtifact1 ); listener.startProcessChildren( depArtifact1 ); Artifact depArtifact11 = createArtifact( "test-dep", "dependency-zero-one", "1.0" ); listener.includeArtifact( depArtifact11 ); Artifact depArtifact12 = createArtifact( "test-dep", "dependency-zero-two", "1.0" ); listener.includeArtifact( depArtifact12 ); listener.startProcessChildren( depArtifact12 ); Artifact depArtifact121 = createArtifact( "test-dep", "dep-zero-two-1", "1.0" ); listener.includeArtifact( depArtifact121 ); listener.endProcessChildren( depArtifact12 ); listener.endProcessChildren( depArtifact1 ); Artifact depArtifact2 = createArtifact( "test-dep", "dependency-two", "jar", "1.0", Artifact.SCOPE_TEST ); listener.includeArtifact( depArtifact2 ); listener.startProcessChildren( depArtifact2 ); Artifact depArtifact21 = createArtifact( "test-dep", "dep-zero-two-1", "1.0" ); listener.omitForNearer( depArtifact121, depArtifact21 ); listener.includeArtifact( depArtifact21 ); listener.endProcessChildren( depArtifact2 ); Artifact depArtifact3 = createArtifact( "test-dep", "dependency-three", "jar", "1.0", Artifact.SCOPE_COMPILE ); listener.includeArtifact( depArtifact3 ); listener.endProcessChildren( projectArtifact ); DependencyNode projectArtifactNode = new DependencyNode( projectArtifact ); DependencyNode depArtifact1Node = new DependencyNode( depArtifact1 ); projectArtifactNode.addChild( depArtifact1Node ); depArtifact1Node.addChild( new DependencyNode( depArtifact11 ) ); DependencyNode depArtifact12Node = new DependencyNode( depArtifact12 ); depArtifact1Node.addChild( depArtifact12Node ); depArtifact12Node.addChild( new DependencyNode( depArtifact121, DependencyNode.OMITTED_FOR_DUPLICATE, depArtifact21 ) ); DependencyNode depArtifact2Node = new DependencyNode( depArtifact2 ); projectArtifactNode.addChild( depArtifact2Node ); depArtifact2Node.addChild( new DependencyNode( depArtifact21 ) ); projectArtifactNode.addChild( new DependencyNode( depArtifact3 ) ); assertEquals( projectArtifactNode, listener.getRootNode() ); } public void testIncludeArtifactDuplicate() { Artifact projectArtifact = createArtifact( "test-project", "project-artifact", "1.0" ); listener.includeArtifact( projectArtifact ); listener.startProcessChildren( projectArtifact ); Artifact depArtifact1 = createArtifact( "test-dep", "dependency", "1.0" ); listener.includeArtifact( depArtifact1 ); Artifact depArtifact2 = createArtifact( "test-dep", "dependency", "1.0" ); listener.omitForNearer( depArtifact1, depArtifact2 ); listener.includeArtifact( depArtifact2 ); listener.endProcessChildren( projectArtifact ); DependencyNode projectArtifactNode = new DependencyNode( projectArtifact ); projectArtifactNode.addChild( new DependencyNode( depArtifact1, DependencyNode.OMITTED_FOR_DUPLICATE, depArtifact2 ) ); projectArtifactNode.addChild( new DependencyNode( depArtifact2 ) ); assertEquals( projectArtifactNode, listener.getRootNode() ); } public void testIncludeArtifactDuplicateWithChildren() { Artifact projectArtifact = createArtifact( "test-project", "project-artifact", "1.0" ); listener.includeArtifact( projectArtifact ); listener.startProcessChildren( projectArtifact ); Artifact depArtifact1 = createArtifact( "test-dep", "dependency", "1.0" ); listener.includeArtifact( depArtifact1 ); listener.startProcessChildren( depArtifact1 ); Artifact depArtifact11 = createArtifact( "test-dep", "child", "1.0" ); listener.includeArtifact( depArtifact11 ); listener.endProcessChildren( depArtifact1 ); Artifact depArtifact2 = createArtifact( "test-dep", "dependency", "1.0" ); listener.omitForNearer( depArtifact1, depArtifact2 ); listener.includeArtifact( depArtifact2 ); listener.startProcessChildren( depArtifact2 ); Artifact depArtifact21 = createArtifact( "test-dep", "child", "1.0" ); listener.includeArtifact( depArtifact21 ); listener.endProcessChildren( depArtifact2 ); listener.endProcessChildren( projectArtifact ); DependencyNode projectArtifactNode = new DependencyNode( projectArtifact ); DependencyNode depArtifact1Node = new DependencyNode( depArtifact1, DependencyNode.OMITTED_FOR_DUPLICATE, depArtifact2 ); projectArtifactNode.addChild( depArtifact1Node ); DependencyNode depArtifact2Node = new DependencyNode( depArtifact2 ); projectArtifactNode.addChild( depArtifact2Node ); depArtifact2Node.addChild( new DependencyNode( depArtifact21 ) ); assertEquals( projectArtifactNode, listener.getRootNode() ); } public void testOmitForConflictKept() { Artifact projectArtifact = createArtifact( "test-project", "project-artifact", "1.0" ); listener.includeArtifact( projectArtifact ); listener.startProcessChildren( projectArtifact ); Artifact depArtifact1 = createArtifact( "test-dep", "dependency", "1.0" ); listener.includeArtifact( depArtifact1 ); Artifact depArtifact2 = createArtifact( "test-dep", "dependency", "2.0" ); listener.omitForNearer( depArtifact1, depArtifact2 ); listener.includeArtifact( depArtifact2 ); listener.endProcessChildren( projectArtifact ); DependencyNode projectArtifactNode = new DependencyNode( projectArtifact ); projectArtifactNode.addChild( new DependencyNode( depArtifact1, DependencyNode.OMITTED_FOR_CONFLICT, depArtifact2 ) ); projectArtifactNode.addChild( new DependencyNode( depArtifact2 ) ); assertEquals( projectArtifactNode, listener.getRootNode() ); } public void testOmitForConflictKeptWithChildren() { Artifact projectArtifact = createArtifact( "test-project", "project-artifact", "1.0" ); listener.includeArtifact( projectArtifact ); listener.startProcessChildren( projectArtifact ); Artifact depArtifact1 = createArtifact( "test-dep", "dependency", "1.0" ); listener.includeArtifact( depArtifact1 ); listener.startProcessChildren( depArtifact1 ); Artifact depArtifact11 = createArtifact( "test-dep", "child", "1.0" ); listener.includeArtifact( depArtifact11 ); listener.endProcessChildren( depArtifact1 ); Artifact depArtifact2 = createArtifact( "test-dep", "dependency", "2.0" ); listener.omitForNearer( depArtifact1, depArtifact2 ); listener.includeArtifact( depArtifact2 ); listener.startProcessChildren( depArtifact2 ); Artifact depArtifact21 = createArtifact( "test-dep", "child", "2.0" ); listener.includeArtifact( depArtifact21 ); listener.endProcessChildren( depArtifact2 ); listener.endProcessChildren( projectArtifact ); DependencyNode projectArtifactNode = new DependencyNode( projectArtifact ); projectArtifactNode.addChild( new DependencyNode( depArtifact1, DependencyNode.OMITTED_FOR_CONFLICT, depArtifact2 ) ); DependencyNode depArtifact2Node = new DependencyNode( depArtifact2 ); projectArtifactNode.addChild( depArtifact2Node ); depArtifact2Node.addChild( new DependencyNode( depArtifact21 ) ); assertEquals( projectArtifactNode, listener.getRootNode() ); } public void testOmitForConflictOmitted() { Artifact projectArtifact = createArtifact( "test-project", "project-artifact", "1.0" ); listener.includeArtifact( projectArtifact ); listener.startProcessChildren( projectArtifact ); Artifact depArtifact2 = createArtifact( "test-dep", "dependency", "2.0" ); listener.includeArtifact( depArtifact2 ); Artifact depArtifact1 = createArtifact( "test-dep", "dependency", "1.0" ); listener.omitForNearer( depArtifact1, depArtifact2 ); listener.endProcessChildren( projectArtifact ); DependencyNode projectArtifactNode = new DependencyNode( projectArtifact ); projectArtifactNode.addChild( new DependencyNode( depArtifact2 ) ); projectArtifactNode.addChild( new DependencyNode( depArtifact1, DependencyNode.OMITTED_FOR_CONFLICT, depArtifact2 ) ); assertEquals( projectArtifactNode, listener.getRootNode() ); } public void testOmitForConflictOmittedWithChildren() { Artifact projectArtifact = createArtifact( "test-project", "project-artifact", "1.0" ); listener.includeArtifact( projectArtifact ); listener.startProcessChildren( projectArtifact ); Artifact depArtifact2 = createArtifact( "test-dep", "dependency", "2.0" ); listener.includeArtifact( depArtifact2 ); listener.startProcessChildren( depArtifact2 ); Artifact depArtifact21 = createArtifact( "test-dep", "child", "2.0" ); listener.includeArtifact( depArtifact21 ); listener.endProcessChildren( depArtifact2 ); Artifact depArtifact1 = createArtifact( "test-dep", "dependency", "1.0" ); listener.omitForNearer( depArtifact1, depArtifact2 ); listener.startProcessChildren( depArtifact1 ); Artifact depArtifact11 = createArtifact( "test-dep", "child", "1.0" ); listener.includeArtifact( depArtifact11 ); listener.endProcessChildren( depArtifact1 ); listener.endProcessChildren( projectArtifact ); DependencyNode projectArtifactNode = new DependencyNode( projectArtifact ); DependencyNode depArtifact2Node = new DependencyNode( depArtifact2 ); projectArtifactNode.addChild( depArtifact2Node ); depArtifact2Node.addChild( new DependencyNode( depArtifact21 ) ); projectArtifactNode.addChild( new DependencyNode( depArtifact1, DependencyNode.OMITTED_FOR_CONFLICT, depArtifact2 ) ); assertEquals( projectArtifactNode, listener.getRootNode() ); } public void testOmitForCycle() { Artifact projectArtifact = createArtifact( "test-project", "project-artifact", "1.0" ); listener.includeArtifact( projectArtifact ); listener.startProcessChildren( projectArtifact ); listener.omitForCycle( projectArtifact ); listener.endProcessChildren( projectArtifact ); DependencyNode projectArtifactNode = new DependencyNode( projectArtifact ); projectArtifactNode.addChild( new DependencyNode( projectArtifact, DependencyNode.OMITTED_FOR_CYCLE ) ); assertEquals( projectArtifactNode, listener.getRootNode() ); } public void testAddNode() { Artifact a1 = createArtifact( "test-project", "project-artifact", "1.0" ); listener.addNode( a1 ); listener.startProcessChildren( a1 ); Artifact a2 = createArtifact( "test-project", "project-artifact", "1.1" ); listener.addNode( a2 ); assertEquals( 1, listener.getRootNode().getChildren().size() ); } // protected methods ------------------------------------------------------ /** * {@inheritDoc} */ protected Artifact createArtifact( String groupId, String artifactId, String type, String version, String scope ) { // TODO: use super.createArtifact when possible VersionRange versionRange = VersionRange.createFromVersion( version ); return new DefaultArtifact( groupId, artifactId, versionRange, scope, "jar", null, new DefaultArtifactHandler(), false ); } } ././@LongLink0000000000000000000000000000016000000000000011562 Lustar rootrootmaven-dependency-tree-1.2/src/test/java/org/apache/maven/shared/dependency/tree/ArtifactMetadataSourceStub.javamaven-dependency-tree-1.2/src/test/java/org/apache/maven/shared/dependency/tree/ArtifactMetadataSour0000644000175000017500000001067411020006575033617 0ustar twernertwernerpackage org.apache.maven.shared.dependency.tree; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.metadata.ResolutionGroup; import org.apache.maven.artifact.repository.ArtifactRepository; /** * Provides a stub to simulate an artifact metadata source. * * @author Mark Hobson * @version $Id: ArtifactMetadataSourceStub.java 661727 2008-05-30 14:21:49Z bentmann $ */ public class ArtifactMetadataSourceStub implements ArtifactMetadataSource { // TODO: move to maven-plugin-testing-harness? // fields ----------------------------------------------------------------- /** * Map of resolution groups by artifact. */ private final Map resolutionGroupsByArtifact; /** * Map of available versions by artifact. */ private final Map availableVersionsByArtifact; // constructors ----------------------------------------------------------- /** * Creates a new artifact metadata source stub. */ public ArtifactMetadataSourceStub() { resolutionGroupsByArtifact = new HashMap(); availableVersionsByArtifact = new HashMap(); } // ArtifactMetadataSource methods ----------------------------------------- /** * {@inheritDoc} */ public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories ) throws ArtifactMetadataRetrievalException { ResolutionGroup resolution = (ResolutionGroup) resolutionGroupsByArtifact.get( artifact ); // if we return null then the artifact gets excluded in DefaultArtifactCollector if ( resolution == null ) { resolution = new ResolutionGroup( artifact, Collections.EMPTY_SET, Collections.EMPTY_LIST ); } return resolution; } /** * {@inheritDoc} */ public List retrieveAvailableVersions( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories ) throws ArtifactMetadataRetrievalException { List availableVersions = (List) availableVersionsByArtifact.get( artifact ); return availableVersions != null ? availableVersions : Collections.EMPTY_LIST; } // public methods --------------------------------------------------------- /** * Adds the specified dependency artifacts for the specified artifact to this artifact metadata source stub. * * @param artifact * the artifact to add metadata to * @param dependencyArtifacts * the set of artifacts to register as dependencies of the specified artifact */ public void addArtifactMetadata( Artifact artifact, Set dependencyArtifacts ) { ResolutionGroup resolution = new ResolutionGroup( artifact, dependencyArtifacts, Collections.EMPTY_LIST ); resolutionGroupsByArtifact.put( artifact, resolution ); } /** * Adds versions for the specified artifact to this artifact metadata source stub. * * @param artifact * the artifact to add metadata to * @param versions * the list of versions to register as available for the specified artifact */ public void addAvailableVersions( Artifact artifact, List versions ) { availableVersionsByArtifact.put( artifact, versions ); } } maven-dependency-tree-1.2/src/test/java/org/apache/maven/shared/dependency/tree/traversal/0000755000175000017500000000000011226720336031626 5ustar twernertwerner././@LongLink0000000000000000000000000000020400000000000011561 Lustar rootrootmaven-dependency-tree-1.2/src/test/java/org/apache/maven/shared/dependency/tree/traversal/SerializingDependencyNodeVisitorTest.javamaven-dependency-tree-1.2/src/test/java/org/apache/maven/shared/dependency/tree/traversal/Serializin0000644000175000017500000001057711020006575033666 0ustar twernertwernerpackage org.apache.maven.shared.dependency.tree.traversal; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.io.StringWriter; import org.apache.maven.shared.dependency.tree.AbstractDependencyNodeTest; import org.apache.maven.shared.dependency.tree.DependencyNode; /** * Tests SerializingDependencyNodeVisitor. * * @author Mark Hobson * @version $Id: SerializingDependencyNodeVisitorTest.java 661727 2008-05-30 14:21:49Z bentmann $ * @see SerializingDependencyNodeVisitor */ public class SerializingDependencyNodeVisitorTest extends AbstractDependencyNodeTest { // constants -------------------------------------------------------------- private static final String NEWLINE = System.getProperty( "line.separator" ); // fields ----------------------------------------------------------------- private StringWriter writer; private SerializingDependencyNodeVisitor serializer; // TestCase methods ------------------------------------------------------- /** * {@inheritDoc} */ protected void setUp() throws Exception { writer = new StringWriter(); serializer = new SerializingDependencyNodeVisitor( writer, SerializingDependencyNodeVisitor.STANDARD_TOKENS ); } // tests ------------------------------------------------------------------ public void testSingleNode() { DependencyNode rootNode = createNode( "g:p:t:1" ); assertTree( "g:p:t:1" + NEWLINE, rootNode ); } public void testNodeWithChild() { DependencyNode rootNode = createNode( "g:p:t:1" ); rootNode.addChild( createNode( "g:a:t:1" ) ); assertTree( "g:p:t:1" + NEWLINE + "\\- g:a:t:1" + NEWLINE, rootNode ); } public void testNodeWithMultipleChildren() { DependencyNode rootNode = createNode( "g:p:t:1" ); rootNode.addChild( createNode( "g:a:t:1" ) ); rootNode.addChild( createNode( "g:b:t:1" ) ); rootNode.addChild( createNode( "g:c:t:1" ) ); assertTree( "g:p:t:1" + NEWLINE + "+- g:a:t:1" + NEWLINE + "+- g:b:t:1" + NEWLINE + "\\- g:c:t:1" + NEWLINE, rootNode ); } public void testNodeWithGrandchild() { DependencyNode rootNode = createNode( "g:p:t:1" ); DependencyNode childNode = createNode( "g:a:t:1" ); rootNode.addChild( childNode ); childNode.addChild( createNode( "g:b:t:1" ) ); assertTree( "g:p:t:1" + NEWLINE + "\\- g:a:t:1" + NEWLINE + " \\- g:b:t:1" + NEWLINE, rootNode ); } public void testNodeWithMultipleGrandchildren() { DependencyNode rootNode = createNode( "g:p:t:1" ); DependencyNode child1Node = createNode( "g:a:t:1" ); rootNode.addChild( child1Node ); child1Node.addChild( createNode( "g:b:t:1" ) ); DependencyNode child2Node = createNode( "g:c:t:1" ); rootNode.addChild( child2Node ); child2Node.addChild( createNode( "g:d:t:1" ) ); assertTree( "g:p:t:1" + NEWLINE + "+- g:a:t:1" + NEWLINE + "| \\- g:b:t:1" + NEWLINE + "\\- g:c:t:1" + NEWLINE + " \\- g:d:t:1" + NEWLINE, rootNode ); } // private methods -------------------------------------------------------- private void assertTree( String expectedTree, DependencyNode actualNode ) { actualNode.accept( serializer ); assertEquals( expectedTree, writer.toString() ); } } ././@LongLink0000000000000000000000000000020200000000000011557 Lustar rootrootmaven-dependency-tree-1.2/src/test/java/org/apache/maven/shared/dependency/tree/traversal/FilteringDependencyNodeVisitorTest.javamaven-dependency-tree-1.2/src/test/java/org/apache/maven/shared/dependency/tree/traversal/FilteringD0000644000175000017500000001124711020006575033577 0ustar twernertwernerpackage org.apache.maven.shared.dependency.tree.traversal; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import org.apache.maven.plugin.testing.stubs.ArtifactStub; import org.apache.maven.shared.dependency.tree.DependencyNode; import org.apache.maven.shared.dependency.tree.filter.AbstractDependencyNodeFilterTest; import org.apache.maven.shared.dependency.tree.filter.DependencyNodeFilter; import org.jmock.Mock; /** * Tests FilteringDependencyNodeVisitor. * * @author Mark Hobson * @version $Id: FilteringDependencyNodeVisitorTest.java 661727 2008-05-30 14:21:49Z bentmann $ * @see FilteringDependencyNodeVisitor */ public class FilteringDependencyNodeVisitorTest extends AbstractDependencyNodeFilterTest { // fields ----------------------------------------------------------------- private FilteringDependencyNodeVisitor visitor; private DependencyNode node; private DependencyNodeFilter acceptingFilter; private DependencyNodeFilter rejectingFilter; // TestCase methods ------------------------------------------------------- /** * {@inheritDoc} */ protected void setUp() throws Exception { node = new DependencyNode( new ArtifactStub() ); acceptingFilter = createDependencyNodeFilter( node, true ); rejectingFilter = createDependencyNodeFilter( node, false ); } // tests ------------------------------------------------------------------ public void testVisitAcceptTrue() { Mock filteredVisitorMock = mock( DependencyNodeVisitor.class ); filteredVisitorMock.expects( once() ).method( "visit" ).with( eq( node ) ).will( returnValue( true ) ); DependencyNodeVisitor filteredVisitor = (DependencyNodeVisitor) filteredVisitorMock.proxy(); visitor = new FilteringDependencyNodeVisitor( filteredVisitor, acceptingFilter ); assertTrue( visitor.visit( node ) ); } public void testVisitAcceptFalse() { Mock filteredVisitorMock = mock( DependencyNodeVisitor.class ); filteredVisitorMock.expects( once() ).method( "visit" ).with( eq( node ) ).will( returnValue( false ) ); DependencyNodeVisitor filteredVisitor = (DependencyNodeVisitor) filteredVisitorMock.proxy(); visitor = new FilteringDependencyNodeVisitor( filteredVisitor, acceptingFilter ); assertFalse( visitor.visit( node ) ); } public void testVisitReject() { DependencyNodeVisitor filteredVisitor = (DependencyNodeVisitor) mock( DependencyNodeVisitor.class ).proxy(); visitor = new FilteringDependencyNodeVisitor( filteredVisitor, rejectingFilter ); assertTrue( visitor.visit( node ) ); } public void testEndVisitAcceptTrue() { Mock filteredVisitorMock = mock( DependencyNodeVisitor.class ); filteredVisitorMock.expects( once() ).method( "endVisit" ).with( eq( node ) ).will( returnValue( true ) ); DependencyNodeVisitor filteredVisitor = (DependencyNodeVisitor) filteredVisitorMock.proxy(); visitor = new FilteringDependencyNodeVisitor( filteredVisitor, acceptingFilter ); assertTrue( visitor.endVisit( node ) ); } public void testEndVisitAcceptFalse() { Mock filteredVisitorMock = mock( DependencyNodeVisitor.class ); filteredVisitorMock.expects( once() ).method( "endVisit" ).with( eq( node ) ).will( returnValue( false ) ); DependencyNodeVisitor filteredVisitor = (DependencyNodeVisitor) filteredVisitorMock.proxy(); visitor = new FilteringDependencyNodeVisitor( filteredVisitor, acceptingFilter ); assertFalse( visitor.endVisit( node ) ); } public void testEndVisitReject() { DependencyNodeVisitor filteredVisitor = (DependencyNodeVisitor) mock( DependencyNodeVisitor.class ).proxy(); visitor = new FilteringDependencyNodeVisitor( filteredVisitor, rejectingFilter ); assertTrue( visitor.endVisit( node ) ); } } ././@LongLink0000000000000000000000000000020300000000000011560 Lustar rootrootmaven-dependency-tree-1.2/src/test/java/org/apache/maven/shared/dependency/tree/traversal/CollectingDependencyNodeVisitorTest.javamaven-dependency-tree-1.2/src/test/java/org/apache/maven/shared/dependency/tree/traversal/Collecting0000644000175000017500000000617111020006575033633 0ustar twernertwernerpackage org.apache.maven.shared.dependency.tree.traversal; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.util.Arrays; import java.util.Collections; import java.util.List; import org.apache.maven.shared.dependency.tree.AbstractDependencyNodeTest; import org.apache.maven.shared.dependency.tree.DependencyNode; /** * Tests CollectingDependencyNodeVisitor. * * @author Mark Hobson * @version $Id: CollectingDependencyNodeVisitorTest.java 661727 2008-05-30 14:21:49Z bentmann $ * @see CollectingDependencyNodeVisitor */ public class CollectingDependencyNodeVisitorTest extends AbstractDependencyNodeTest { // fields ----------------------------------------------------------------- private CollectingDependencyNodeVisitor visitor; private DependencyNode node1; private DependencyNode node2; private DependencyNode node3; // TestCase methods ------------------------------------------------------- /** * {@inheritDoc} */ protected void setUp() throws Exception { visitor = new CollectingDependencyNodeVisitor(); node1 = createNode( "g:a:t:1" ); node2 = createNode( "g:b:t:1" ); node3 = createNode( "g:c:t:1" ); } // tests ------------------------------------------------------------------ public void testVisitSingleNode() { assertEmptyNodes(); assertTrue( visitor.visit( node1 ) ); assertNodes( node1 ); } public void testVisitMultipleNodes() { assertEmptyNodes(); assertTrue( visitor.visit( node1 ) ); assertTrue( visitor.visit( node2 ) ); assertTrue( visitor.visit( node3 ) ); assertNodes( Arrays.asList( new Object[] { node1, node2, node3 } ) ); } public void testEndVisit() { assertEmptyNodes(); assertTrue( visitor.endVisit( node1 ) ); assertEmptyNodes(); } // private methods -------------------------------------------------------- private void assertEmptyNodes() { assertNodes( Collections.EMPTY_LIST ); } private void assertNodes( DependencyNode node ) { assertNodes( Collections.singletonList( node ) ); } private void assertNodes( List expectedNodes ) { assertEquals( "Collected nodes", expectedNodes, visitor.getNodes() ); } } ././@LongLink0000000000000000000000000000020100000000000011556 Lustar rootrootmaven-dependency-tree-1.2/src/test/java/org/apache/maven/shared/dependency/tree/traversal/BuildingDependencyNodeVisitorTest.javamaven-dependency-tree-1.2/src/test/java/org/apache/maven/shared/dependency/tree/traversal/BuildingDe0000644000175000017500000001662411020006575033562 0ustar twernertwernerpackage org.apache.maven.shared.dependency.tree.traversal; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import org.apache.maven.shared.dependency.tree.AbstractDependencyNodeTest; import org.apache.maven.shared.dependency.tree.DependencyNode; import org.jmock.Mock; /** * Tests BuildingDependencyNodeVisitor. * * @author Mark Hobson * @version $Id: BuildingDependencyNodeVisitorTest.java 661727 2008-05-30 14:21:49Z bentmann $ * @see BuildingDependencyNodeVisitor */ public class BuildingDependencyNodeVisitorTest extends AbstractDependencyNodeTest { // fields ----------------------------------------------------------------- private BuildingDependencyNodeVisitor visitor; // tests ------------------------------------------------------------------ public void testVisitNode() { DependencyNode sourceNode = createNode( "g:a:t:1" ); visitor = new BuildingDependencyNodeVisitor(); visitor.visit( sourceNode ); visitor.endVisit( sourceNode ); DependencyNode resultNode = visitor.getDependencyTree(); assertNotSame( sourceNode, resultNode ); assertEquals( sourceNode, resultNode ); } public void testVisitNodeWithState() { DependencyNode sourceNode = createNode( "g:a:t:1", DependencyNode.OMITTED_FOR_CYCLE ); visitor = new BuildingDependencyNodeVisitor(); visitor.visit( sourceNode ); visitor.endVisit( sourceNode ); DependencyNode resultNode = visitor.getDependencyTree(); assertNotSame( sourceNode, resultNode ); assertEquals( sourceNode, resultNode ); } public void testVisitNodeWithRelatedArtifact() { DependencyNode sourceNode = createNode( "g:a:t:1", DependencyNode.OMITTED_FOR_CONFLICT, "g:a:t:2" ); visitor = new BuildingDependencyNodeVisitor(); visitor.visit( sourceNode ); visitor.endVisit( sourceNode ); DependencyNode resultNode = visitor.getDependencyTree(); assertNotSame( sourceNode, resultNode ); assertEquals( sourceNode, resultNode ); } public void testVisitNodeWithOriginalScope() { DependencyNode sourceNode = createNode( "g:a:t:1" ); sourceNode.setOriginalScope( "x" ); visitor = new BuildingDependencyNodeVisitor(); visitor.visit( sourceNode ); visitor.endVisit( sourceNode ); DependencyNode resultNode = visitor.getDependencyTree(); assertNotSame( sourceNode, resultNode ); assertEquals( sourceNode, resultNode ); } public void testVisitNodeWithFailedUpdateScope() { DependencyNode sourceNode = createNode( "g:a:t:1" ); sourceNode.setFailedUpdateScope( "x" ); visitor = new BuildingDependencyNodeVisitor(); visitor.visit( sourceNode ); visitor.endVisit( sourceNode ); DependencyNode resultNode = visitor.getDependencyTree(); assertNotSame( sourceNode, resultNode ); assertEquals( sourceNode, resultNode ); } public void testVisitNodeWithPremanagedVersion() { DependencyNode sourceNode = createNode( "g:a:t:1" ); sourceNode.setPremanagedVersion( "2" ); visitor = new BuildingDependencyNodeVisitor(); visitor.visit( sourceNode ); visitor.endVisit( sourceNode ); DependencyNode resultNode = visitor.getDependencyTree(); assertNotSame( sourceNode, resultNode ); assertEquals( sourceNode, resultNode ); } public void testVisitNodeWithPremanagedScope() { DependencyNode sourceNode = createNode( "g:a:t:1" ); sourceNode.setPremanagedScope( "x" ); visitor = new BuildingDependencyNodeVisitor(); visitor.visit( sourceNode ); visitor.endVisit( sourceNode ); DependencyNode resultNode = visitor.getDependencyTree(); assertNotSame( sourceNode, resultNode ); assertEquals( sourceNode, resultNode ); } public void testVisitNodeWithChild() { DependencyNode sourceNode = createNode( "g:a:t:1" ); DependencyNode sourceChildNode = createNode( "g:b:t:1" ); sourceNode.addChild( sourceChildNode ); visitor = new BuildingDependencyNodeVisitor(); visitor.visit( sourceNode ); visitor.visit( sourceChildNode ); visitor.endVisit( sourceChildNode ); visitor.endVisit( sourceNode ); DependencyNode resultNode = visitor.getDependencyTree(); assertNotSame( sourceNode, resultNode ); assertEquals( sourceNode, resultNode ); } public void testVisitNodeWithVisitor() { DependencyNode sourceNode = createNode( "g:a:t:1" ); Mock nextVisitorMock = mock( DependencyNodeVisitor.class ); nextVisitorMock.expects( once() ).method( "visit" ).with( eq( sourceNode ) ).will( returnValue( true ) ).id( "1" ); nextVisitorMock.expects( once() ).method( "endVisit" ).with( eq( sourceNode ) ).after( "1" ).will( returnValue( true ) ); DependencyNodeVisitor nextVisitor = (DependencyNodeVisitor) nextVisitorMock.proxy(); visitor = new BuildingDependencyNodeVisitor( nextVisitor ); visitor.visit( sourceNode ); visitor.endVisit( sourceNode ); DependencyNode resultNode = visitor.getDependencyTree(); assertNotSame( sourceNode, resultNode ); assertEquals( sourceNode, resultNode ); } public void testVisitNodeWithChildAndVisitor() { DependencyNode sourceNode = createNode( "g:a:t:1" ); DependencyNode sourceChildNode = createNode( "g:b:t:1" ); sourceNode.addChild( sourceChildNode ); Mock nextVisitorMock = mock( DependencyNodeVisitor.class ); nextVisitorMock.expects( once() ).method( "visit" ).with( eq( sourceNode ) ).will( returnValue( true ) ).id( "1" ); nextVisitorMock.expects( once() ).method( "visit" ).with( eq( sourceChildNode ) ).after( "1" ).will( returnValue( true ) ).id( "2" ); nextVisitorMock.expects( once() ).method( "endVisit" ).with( eq( sourceChildNode ) ).after( "2" ).will( returnValue( true ) ).id( "3" ); nextVisitorMock.expects( once() ).method( "endVisit" ).with( eq( sourceNode ) ).after( "3" ).will( returnValue( true ) ); DependencyNodeVisitor nextVisitor = (DependencyNodeVisitor) nextVisitorMock.proxy(); visitor = new BuildingDependencyNodeVisitor( nextVisitor ); visitor.visit( sourceNode ); visitor.visit( sourceChildNode ); visitor.endVisit( sourceChildNode ); visitor.endVisit( sourceNode ); DependencyNode resultNode = visitor.getDependencyTree(); assertNotSame( sourceNode, resultNode ); assertEquals( sourceNode, resultNode ); } } maven-dependency-tree-1.2/src/main/0000755000175000017500000000000011226720336017206 5ustar twernertwernermaven-dependency-tree-1.2/src/main/java/0000755000175000017500000000000011226720336020127 5ustar twernertwernermaven-dependency-tree-1.2/src/main/java/org/0000755000175000017500000000000011226720336020716 5ustar twernertwernermaven-dependency-tree-1.2/src/main/java/org/apache/0000755000175000017500000000000011226720336022137 5ustar twernertwernermaven-dependency-tree-1.2/src/main/java/org/apache/maven/0000755000175000017500000000000011226720336023245 5ustar twernertwernermaven-dependency-tree-1.2/src/main/java/org/apache/maven/shared/0000755000175000017500000000000011226720336024513 5ustar twernertwernermaven-dependency-tree-1.2/src/main/java/org/apache/maven/shared/dependency/0000755000175000017500000000000011226720336026631 5ustar twernertwernermaven-dependency-tree-1.2/src/main/java/org/apache/maven/shared/dependency/tree/0000755000175000017500000000000011226720336027570 5ustar twernertwerner././@LongLink0000000000000000000000000000016400000000000011566 Lustar rootrootmaven-dependency-tree-1.2/src/main/java/org/apache/maven/shared/dependency/tree/DependencyTreeBuilderException.javamaven-dependency-tree-1.2/src/main/java/org/apache/maven/shared/dependency/tree/DependencyTreeBuilde0000644000175000017500000000321111020006575033525 0ustar twernertwernerpackage org.apache.maven.shared.dependency.tree; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ /** * Indicates that a Maven project's dependency tree cannot be resolved. * * @author Mark Hobson * @version $Id: DependencyTreeBuilderException.java 661727 2008-05-30 14:21:49Z bentmann $ */ public class DependencyTreeBuilderException extends Exception { // constants -------------------------------------------------------------- /** * The serialisation unique ID. */ private static final long serialVersionUID = -3525803081807951764L; // constructors ----------------------------------------------------------- public DependencyTreeBuilderException( String message ) { super( message ); } public DependencyTreeBuilderException( String message, Throwable cause ) { super( message, cause ); } } maven-dependency-tree-1.2/src/main/java/org/apache/maven/shared/dependency/tree/DependencyNode.java0000644000175000017500000007041311020006575033316 0ustar twernertwernerpackage org.apache.maven.shared.dependency.tree; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.io.StringWriter; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.shared.dependency.tree.traversal.DependencyNodeVisitor; import org.apache.maven.shared.dependency.tree.traversal.SerializingDependencyNodeVisitor; /** * Represents an artifact node within a Maven project's dependency tree. * * @author Edwin Punzalan * @author Mark Hobson * @version $Id: DependencyNode.java 661727 2008-05-30 14:21:49Z bentmann $ */ public class DependencyNode { // constants -------------------------------------------------------------- /** * State that represents an included dependency node. * * @since 1.1 */ public static final int INCLUDED = 0; /** * State that represents a dependency node that has been omitted for duplicating another dependency node. * * @since 1.1 */ public static final int OMITTED_FOR_DUPLICATE = 1; /** * State that represents a dependency node that has been omitted for conflicting with another dependency node. * * @since 1.1 */ public static final int OMITTED_FOR_CONFLICT = 2; /** * State that represents a dependency node that has been omitted for introducing a cycle into the dependency tree. * * @since 1.1 */ public static final int OMITTED_FOR_CYCLE = 3; // classes ---------------------------------------------------------------- /** * Utility class to concatenate a number of parameters with separator tokens. */ private static class ItemAppender { private StringBuffer buffer; private String startToken; private String separatorToken; private String endToken; private boolean appended; public ItemAppender( StringBuffer buffer, String startToken, String separatorToken, String endToken ) { this.buffer = buffer; this.startToken = startToken; this.separatorToken = separatorToken; this.endToken = endToken; appended = false; } public ItemAppender append( String item ) { appendToken(); buffer.append( item ); return this; } public ItemAppender append( String item1, String item2 ) { appendToken(); buffer.append( item1 ).append( item2 ); return this; } public void flush() { if ( appended ) { buffer.append( endToken ); appended = false; } } private void appendToken() { buffer.append( appended ? separatorToken : startToken ); appended = true; } } // fields ----------------------------------------------------------------- /** * The artifact that is attached to this dependency node. */ private final Artifact artifact; /** * The list of child dependency nodes of this dependency node. */ private final List children; /** * The parent dependency node of this dependency node. */ private DependencyNode parent; /** * The state of this dependency node. This can be either INCLUDED, * OMITTED_FOR_DUPLICATE, OMITTED_FOR_CONFLICT or OMITTED_FOR_CYCLE. * * @see #INCLUDED * @see #OMITTED_FOR_DUPLICATE * @see #OMITTED_FOR_CONFLICT * @see #OMITTED_FOR_CYCLE */ private int state; /** * The artifact related to the state of this dependency node. For dependency nodes with a state of * OMITTED_FOR_DUPLICATE or OMITTED_FOR_CONFLICT, this represents the artifact that * was conflicted with. For dependency nodes of other states, this is always null. */ private Artifact relatedArtifact; /** * The scope of this node's artifact before it was updated due to conflicts, or null if the artifact * scope has not been updated. */ private String originalScope; /** * The scope that this node's artifact was attempted to be updated to due to conflicts, or null if * the artifact scope has not failed being updated. */ private String failedUpdateScope; /** * The version of this node's artifact before it was updated by dependency management, or null if the * artifact version has not been managed. */ private String premanagedVersion; /** * The scope of this node's artifact before it was updated by dependency management, or null if the * artifact scope has not been managed. */ private String premanagedScope; private VersionRange versionSelectedFromRange; private List availableVersions; // constructors ----------------------------------------------------------- /** * Creates a new dependency node for the specified artifact with an included state. * * @param artifact * the artifact attached to the new dependency node * @throws IllegalArgumentException * if the parameter constraints were violated * @since 1.1 */ public DependencyNode( Artifact artifact ) { this( artifact, INCLUDED ); } /** * Creates a new dependency node for the specified artifact with the specified state. * * @param artifact * the artifact attached to the new dependency node * @param state * the state of the new dependency node. This can be either INCLUDED or * OMITTED_FOR_CYCLE. * @throws IllegalArgumentException * if the parameter constraints were violated * @since 1.1 */ public DependencyNode( Artifact artifact, int state ) { this( artifact, state, null ); } /** * Creates a new dependency node for the specified artifact with the specified state and related artifact. * * @param artifact * the artifact attached to the new dependency node * @param state * the state of the new dependency node. This can be either INCLUDED, * OMITTED_FOR_DUPLICATE, OMITTED_FOR_CONFLICT or * OMITTED_FOR_CYCLE. * @param relatedArtifact * the artifact related to the state of this dependency node. For dependency nodes with a state of * OMITTED_FOR_DUPLICATE or OMITTED_FOR_CONFLICT, this represents the * artifact that was conflicted with. For dependency nodes of other states, this should always be * null. * @throws IllegalArgumentException * if the parameter constraints were violated * @since 1.1 */ public DependencyNode( Artifact artifact, int state, Artifact relatedArtifact ) { if ( artifact == null ) { throw new IllegalArgumentException( "artifact cannot be null" ); } if ( state < INCLUDED || state > OMITTED_FOR_CYCLE ) { throw new IllegalArgumentException( "Unknown state: " + state ); } boolean requiresRelatedArtifact = ( state == OMITTED_FOR_DUPLICATE || state == OMITTED_FOR_CONFLICT ); if ( requiresRelatedArtifact && relatedArtifact == null ) { throw new IllegalArgumentException( "Related artifact is required for states " + "OMITTED_FOR_DUPLICATE and OMITTED_FOR_CONFLICT" ); } if ( !requiresRelatedArtifact && relatedArtifact != null ) { throw new IllegalArgumentException( "Related artifact is only required for states " + "OMITTED_FOR_DUPLICATE and OMITTED_FOR_CONFLICT" ); } this.artifact = artifact; this.state = state; this.relatedArtifact = relatedArtifact; children = new ArrayList(); } /** * Creates a new dependency node. * * @deprecated As of 1.1, replaced by {@link #DependencyNode(Artifact, int, Artifact)} */ DependencyNode() { artifact = null; children = new ArrayList(); } // public methods --------------------------------------------------------- /** * Applies the specified dependency node visitor to this dependency node and its children. * * @param visitor * the dependency node visitor to use * @return the visitor result of ending the visit to this node * @since 1.1 */ public boolean accept( DependencyNodeVisitor visitor ) { if ( visitor.visit( this ) ) { boolean visiting = true; for ( Iterator iterator = getChildren().iterator(); visiting && iterator.hasNext(); ) { DependencyNode child = (DependencyNode) iterator.next(); visiting = child.accept( visitor ); } } return visitor.endVisit( this ); } /** * Adds the specified dependency node to this dependency node's children. * * @param child * the child dependency node to add * @since 1.1 */ public void addChild( DependencyNode child ) { children.add( child ); child.parent = this; } /** * Removes the specified dependency node from this dependency node's children. * * @param child * the child dependency node to remove * @since 1.1 */ public void removeChild( DependencyNode child ) { children.remove( child ); child.parent = null; } /** * Gets the parent dependency node of this dependency node. * * @return the parent dependency node */ public DependencyNode getParent() { return parent; } /** * Gets the artifact attached to this dependency node. * * @return the artifact */ public Artifact getArtifact() { return artifact; } /** * Gets the depth of this dependency node within its hierarchy. * * @return the depth * @deprecated As of 1.1, depth is computed by node hierarchy. With the introduction of node * visitors and filters this method can give misleading results. For example, consider * serialising a tree with a filter using a visitor: this method would return the * unfiltered depth of a node, whereas the correct depth would be calculated by the * visitor. */ public int getDepth() { int depth = 0; DependencyNode node = getParent(); while ( node != null ) { depth++; node = node.getParent(); } return depth; } /** * Gets the list of child dependency nodes of this dependency node. * * @return the list of child dependency nodes */ public List getChildren() { return Collections.unmodifiableList( children ); } public boolean hasChildren() { return children.size() > 0; } /** * Gets the state of this dependency node. * * @return the state: either INCLUDED, OMITTED_FOR_DUPLICATE, * OMITTED_FOR_CONFLICT or OMITTED_FOR_CYCLE. * @since 1.1 */ public int getState() { return state; } /** * Gets the artifact related to the state of this dependency node. For dependency nodes with a state of * OMITTED_FOR_CONFLICT, this represents the artifact that was conflicted with. For dependency nodes * of other states, this is always null. * * @return the related artifact * @since 1.1 */ public Artifact getRelatedArtifact() { return relatedArtifact; } /** * Gets the scope of this node's artifact before it was updated due to conflicts. * * @return the original scope, or null if the artifact scope has not been updated * @since 1.1 */ public String getOriginalScope() { return originalScope; } /** * Sets the scope of this node's artifact before it was updated due to conflicts. * * @param originalScope * the original scope, or null if the artifact scope has not been updated * @since 1.1 */ public void setOriginalScope( String originalScope ) { this.originalScope = originalScope; } /** * Gets the scope that this node's artifact was attempted to be updated to due to conflicts. * * @return the failed update scope, or null if the artifact scope has not failed being updated * @since 1.1 */ public String getFailedUpdateScope() { return failedUpdateScope; } /** * Sets the scope that this node's artifact was attempted to be updated to due to conflicts. * * @param failedUpdateScope * the failed update scope, or null if the artifact scope has not failed being updated * @since 1.1 */ public void setFailedUpdateScope( String failedUpdateScope ) { this.failedUpdateScope = failedUpdateScope; } /** * Gets the version of this node's artifact before it was updated by dependency management. * * @return the premanaged version, or null if the artifact version has not been managed * @since 1.1 */ public String getPremanagedVersion() { return premanagedVersion; } /** * Sets the version of this node's artifact before it was updated by dependency management. * * @param premanagedVersion * the premanaged version, or null if the artifact version has not been managed * @since 1.1 */ public void setPremanagedVersion( String premanagedVersion ) { this.premanagedVersion = premanagedVersion; } /** * Gets the scope of this node's artifact before it was updated by dependency management. * * @return the premanaged scope, or null if the artifact scope has not been managed * @since 1.1 */ public String getPremanagedScope() { return premanagedScope; } /** * Sets the scope of this node's artifact before it was updated by dependency management. * * @param premanagedScope * the premanaged scope, or null if the artifact scope has not been managed * @since 1.1 */ public void setPremanagedScope( String premanagedScope ) { this.premanagedScope = premanagedScope; } /** * If the version was selected from a range this method will return the range. * * @return the version range before a version was selected, or null if the artifact had a explicit * version. * @since 1.2 */ public VersionRange getVersionSelectedFromRange() { return versionSelectedFromRange; } public void setVersionSelectedFromRange( VersionRange versionSelectedFromRange ) { this.versionSelectedFromRange = versionSelectedFromRange; } /** * If the version was selected from a range this method will return the available versions when making the decision. * * @return {@link List} < {@link String} > the versions available when a version was selected from a range, or * null if the artifact had a explicit version. * @since 1.2 */ public List getAvailableVersions() { return availableVersions; } public void setAvailableVersions( List availableVersions ) { this.availableVersions = availableVersions; } /** * Changes the state of this dependency node to be omitted for conflict or duplication, depending on the specified * related artifact. * *

* If the related artifact has a version equal to this dependency node's artifact, then this dependency node's state * is changed to OMITTED_FOR_DUPLICATE, otherwise it is changed to OMITTED_FOR_CONFLICT. * Omitting this dependency node also removes all of its children. *

* * @param relatedArtifact * the artifact that this dependency node conflicted with * @throws IllegalStateException * if this dependency node's state is not INCLUDED * @throws IllegalArgumentException * if the related artifact was null or had a different dependency conflict id to this * dependency node's artifact * @see #OMITTED_FOR_DUPLICATE * @see #OMITTED_FOR_CONFLICT * @since 1.1 */ public void omitForConflict( Artifact relatedArtifact ) { if ( getState() != INCLUDED ) { throw new IllegalStateException( "Only INCLUDED dependency nodes can be omitted for conflict" ); } if ( relatedArtifact == null ) { throw new IllegalArgumentException( "Related artifact cannot be null" ); } if ( !relatedArtifact.getDependencyConflictId().equals( getArtifact().getDependencyConflictId() ) ) { throw new IllegalArgumentException( "Related artifact has a different dependency conflict id" ); } this.relatedArtifact = relatedArtifact; boolean duplicate = false; if ( getArtifact().getVersion() != null ) { duplicate = getArtifact().getVersion().equals( relatedArtifact.getVersion() ); } else if ( getArtifact().getVersionRange() != null ) { duplicate = getArtifact().getVersionRange().equals( relatedArtifact.getVersionRange() ); } else { throw new RuntimeException( "Artifact version and version range is null: " + getArtifact() ); } state = duplicate ? OMITTED_FOR_DUPLICATE : OMITTED_FOR_CONFLICT; removeAllChildren(); } /** * Changes the state of this dependency node to be omitted for a cycle in the dependency tree. * *

* Omitting this node sets its state to OMITTED_FOR_CYCLE and removes all of its children. *

* * @throws IllegalStateException * if this dependency node's state is not INCLUDED * @see #OMITTED_FOR_CYCLE * @since 1.1 */ public void omitForCycle() { if ( getState() != INCLUDED ) { throw new IllegalStateException( "Only INCLUDED dependency nodes can be omitted for cycle" ); } state = OMITTED_FOR_CYCLE; removeAllChildren(); } /** * Gets an iterator that returns this dependency node and it's children in preorder traversal. * * @return the preorder traversal iterator * @see #preorderIterator() */ public Iterator iterator() { return preorderIterator(); } /** * Gets an iterator that returns this dependency node and it's children in preorder traversal. * * @return the preorder traversal iterator * @see DependencyTreePreorderIterator */ public Iterator preorderIterator() { return new DependencyTreePreorderIterator( this ); } /** * Gets an iterator that returns this dependency node and it's children in postorder traversal. * * @return the postorder traversal iterator * @see DependencyTreeInverseIterator */ public Iterator inverseIterator() { return new DependencyTreeInverseIterator( this ); } /** * Returns a string representation of this dependency node. * * @return the string representation * @see #toString() * @since 1.1 */ public String toNodeString() { StringBuffer buffer = new StringBuffer(); boolean included = ( getState() == INCLUDED ); if ( !included ) { buffer.append( '(' ); } buffer.append( artifact ); ItemAppender appender = new ItemAppender( buffer, included ? " (" : " - ", "; ", included ? ")" : "" ); if ( getPremanagedVersion() != null ) { appender.append( "version managed from ", getPremanagedVersion() ); } if ( getPremanagedScope() != null ) { appender.append( "scope managed from ", getPremanagedScope() ); } if ( getOriginalScope() != null ) { appender.append( "scope updated from ", getOriginalScope() ); } if ( getFailedUpdateScope() != null ) { appender.append( "scope not updated to ", getFailedUpdateScope() ); } if ( getVersionSelectedFromRange() != null ) { appender.append( "version selected from range ", getVersionSelectedFromRange().toString() ); appender.append( "available versions ", getAvailableVersions().toString() ); } switch ( state ) { case INCLUDED: break; case OMITTED_FOR_DUPLICATE: appender.append( "omitted for duplicate" ); break; case OMITTED_FOR_CONFLICT: appender.append( "omitted for conflict with ", relatedArtifact.getVersion() ); break; case OMITTED_FOR_CYCLE: appender.append( "omitted for cycle" ); break; } appender.flush(); if ( !included ) { buffer.append( ')' ); } return buffer.toString(); } /** * Returns a string representation of this dependency node and its children, indented to the specified depth. * *

* As of 1.1, this method ignores the indentation depth and simply delegates to toString(). *

* * @param indentDepth * the indentation depth * @return the string representation * @deprecated As of 1.1, replaced by {@link #toString()} */ public String toString( int indentDepth ) { return toString(); } // Object methods --------------------------------------------------------- /** * {@inheritDoc} */ public int hashCode() { // TODO: probably better using commons-lang HashCodeBuilder int hashCode = 1; hashCode = hashCode * 31 + getArtifact().hashCode(); // DefaultArtifact.hashCode does not consider scope hashCode = hashCode * 31 + nullHashCode( getArtifact().getScope() ); // TODO: use parent's artifact to prevent recursion - how can we improve this? hashCode = hashCode * 31 + nullHashCode( nullGetArtifact( getParent() ) ); hashCode = hashCode * 31 + getChildren().hashCode(); hashCode = hashCode * 31 + getState(); hashCode = hashCode * 31 + nullHashCode( getRelatedArtifact() ); hashCode = hashCode * 31 + nullHashCode( getPremanagedVersion() ); hashCode = hashCode * 31 + nullHashCode( getPremanagedScope() ); hashCode = hashCode * 31 + nullHashCode( getOriginalScope() ); hashCode = hashCode * 31 + nullHashCode( getFailedUpdateScope() ); hashCode = hashCode * 31 + nullHashCode( getVersionSelectedFromRange() ); hashCode = hashCode * 31 + nullHashCode( getAvailableVersions() ); return hashCode; } /** * {@inheritDoc} */ public boolean equals( Object object ) { // TODO: probably better using commons-lang EqualsBuilder boolean equal; if ( object instanceof DependencyNode ) { DependencyNode node = (DependencyNode) object; equal = getArtifact().equals( node.getArtifact() ); // DefaultArtifact.hashCode does not consider scope equal &= nullEquals( getArtifact().getScope(), node.getArtifact().getScope() ); // TODO: use parent's artifact to prevent recursion - how can we improve this? equal &= nullEquals( nullGetArtifact( getParent() ), nullGetArtifact( node.getParent() ) ); equal &= getChildren().equals( node.getChildren() ); equal &= getState() == node.getState(); equal &= nullEquals( getRelatedArtifact(), node.getRelatedArtifact() ); equal &= nullEquals( getPremanagedVersion(), node.getPremanagedVersion() ); equal &= nullEquals( getPremanagedScope(), node.getPremanagedScope() ); equal &= nullEquals( getOriginalScope(), node.getOriginalScope() ); equal &= nullEquals( getFailedUpdateScope(), node.getFailedUpdateScope() ); equal &= nullEquals( getVersionSelectedFromRange(), node.getVersionSelectedFromRange() ); equal &= nullEquals( getAvailableVersions(), node.getAvailableVersions() ); } else { equal = false; } return equal; } /** * Returns a string representation of this dependency node and its children. * * @return the string representation * @see #toNodeString() * @see java.lang.Object#toString() */ public String toString() { StringWriter writer = new StringWriter(); accept( new SerializingDependencyNodeVisitor( writer ) ); return writer.toString(); } // private methods -------------------------------------------------------- /** * Removes all of this dependency node's children. */ private void removeAllChildren() { for ( Iterator iterator = children.iterator(); iterator.hasNext(); ) { DependencyNode child = (DependencyNode) iterator.next(); child.parent = null; } children.clear(); } /** * Computes a hash-code for the specified object. * * @param a * the object to compute a hash-code for, possibly null * @return the computed hash-code */ private int nullHashCode( Object a ) { return ( a == null ) ? 0 : a.hashCode(); } /** * Gets whether the specified objects are equal. * * @param a * the first object to compare, possibly null * @param b * the second object to compare, possibly null * @return true if the specified objects are equal */ private boolean nullEquals( Object a, Object b ) { return ( a == null ? b == null : a.equals( b ) ); } /** * Gets the artifact for the specified node. * * @param node * the dependency node, possibly null * @return the node's artifact, or null if the specified node was null */ private static Artifact nullGetArtifact( DependencyNode node ) { return ( node != null ) ? node.getArtifact() : null; } } maven-dependency-tree-1.2/src/main/java/org/apache/maven/shared/dependency/tree/filter/0000755000175000017500000000000011226720336031055 5ustar twernertwerner././@LongLink0000000000000000000000000000016600000000000011570 Lustar rootrootmaven-dependency-tree-1.2/src/main/java/org/apache/maven/shared/dependency/tree/filter/StateDependencyNodeFilter.javamaven-dependency-tree-1.2/src/main/java/org/apache/maven/shared/dependency/tree/filter/StateDependen0000644000175000017500000000554711020006575033530 0ustar twernertwernerpackage org.apache.maven.shared.dependency.tree.filter; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import org.apache.maven.shared.dependency.tree.DependencyNode; /** * A dependency node filter that accepts nodes depending on their state. * * @author Mark Hobson * @version $Id: StateDependencyNodeFilter.java 661727 2008-05-30 14:21:49Z bentmann $ * @since 1.1 */ public class StateDependencyNodeFilter implements DependencyNodeFilter { // constants -------------------------------------------------------------- /** * A dependency node filter that only accepts included nodes. */ public static final StateDependencyNodeFilter INCLUDED = new StateDependencyNodeFilter( DependencyNode.INCLUDED ); // fields ----------------------------------------------------------------- /** * The state of dependency nodes to accept. * * @see DependencyNode */ private final int state; // constructors ----------------------------------------------------------- /** * Creates a dependency node filter that only accepts dependency nodes of the specified state. * * @param state * the state of dependency nodes to accept * @throws IllegalArgumentException * if the specified state is invalid */ public StateDependencyNodeFilter( int state ) { if ( state < DependencyNode.INCLUDED || state > DependencyNode.OMITTED_FOR_CYCLE ) { throw new IllegalArgumentException( "Unknown state: " + state ); } this.state = state; } // DependencyNodeFilter methods ------------------------------------------- /** * {@inheritDoc} */ public boolean accept( DependencyNode node ) { return node.getState() == state; } // public methods --------------------------------------------------------- /** * Gets the dependency node state that this filter accepts. * * @return the dependency node state that this filter accepts */ public int getState() { return state; } } ././@LongLink0000000000000000000000000000016100000000000011563 Lustar rootrootmaven-dependency-tree-1.2/src/main/java/org/apache/maven/shared/dependency/tree/filter/DependencyNodeFilter.javamaven-dependency-tree-1.2/src/main/java/org/apache/maven/shared/dependency/tree/filter/DependencyNod0000644000175000017500000000270411020006575033514 0ustar twernertwernerpackage org.apache.maven.shared.dependency.tree.filter; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import org.apache.maven.shared.dependency.tree.DependencyNode; /** * Defines a filter for dependency nodes. * * @author Mark Hobson * @version $Id: DependencyNodeFilter.java 661727 2008-05-30 14:21:49Z bentmann $ * @since 1.1 */ public interface DependencyNodeFilter { /** * Gets whether this filter accepts the specified dependency node. * * @param node * the dependency node to check * @return true if this filter accepts the specified dependency node */ boolean accept( DependencyNode node ); } ././@LongLink0000000000000000000000000000017100000000000011564 Lustar rootrootmaven-dependency-tree-1.2/src/main/java/org/apache/maven/shared/dependency/tree/filter/ArtifactDependencyNodeFilter.javamaven-dependency-tree-1.2/src/main/java/org/apache/maven/shared/dependency/tree/filter/ArtifactDepen0000644000175000017500000000477211020006575033515 0ustar twernertwernerpackage org.apache.maven.shared.dependency.tree.filter; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.resolver.filter.ArtifactFilter; import org.apache.maven.shared.dependency.tree.DependencyNode; /** * A dependency node filter that delegates to an artifact filter. * * @author Mark Hobson * @version $Id: ArtifactDependencyNodeFilter.java 661727 2008-05-30 14:21:49Z bentmann $ * @since 1.1 */ public class ArtifactDependencyNodeFilter implements DependencyNodeFilter { // fields ----------------------------------------------------------------- /** * The artifact filter this dependency node filter delegates to. */ private final ArtifactFilter filter; // constructors ----------------------------------------------------------- /** * Creates a dependency node filter that delegates to the specified artifact filter. * * @param filter * the artifact filter to delegate to */ public ArtifactDependencyNodeFilter( ArtifactFilter filter ) { this.filter = filter; } // DependencyNodeFilter methods ------------------------------------------- /** * {@inheritDoc} */ public boolean accept( DependencyNode node ) { Artifact artifact = node.getArtifact(); return filter.include( artifact ); } // public methods --------------------------------------------------------- /** * Gets the artifact filter this dependency node filter delegates to. * * @return the artifact filter this dependency node filter delegates to */ public ArtifactFilter getArtifactFilter() { return filter; } } ././@LongLink0000000000000000000000000000017700000000000011572 Lustar rootrootmaven-dependency-tree-1.2/src/main/java/org/apache/maven/shared/dependency/tree/filter/AncestorOrSelfDependencyNodeFilter.javamaven-dependency-tree-1.2/src/main/java/org/apache/maven/shared/dependency/tree/filter/AncestorOrSel0000644000175000017500000000704411020006575033522 0ustar twernertwernerpackage org.apache.maven.shared.dependency.tree.filter; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.util.Collections; import java.util.Iterator; import java.util.List; import org.apache.maven.shared.dependency.tree.DependencyNode; /** * A dependency node filter than only accepts nodes that are ancestors of, or equal to, a given list of nodes. * * @author Mark Hobson * @version $Id: AncestorOrSelfDependencyNodeFilter.java 661727 2008-05-30 14:21:49Z bentmann $ * @since 1.1 */ public class AncestorOrSelfDependencyNodeFilter implements DependencyNodeFilter { // fields ----------------------------------------------------------------- /** * The list of nodes that this filter accepts ancestors-or-self of. */ private final List descendantNodes; // constructors ----------------------------------------------------------- public AncestorOrSelfDependencyNodeFilter( DependencyNode descendantNode ) { this( Collections.singletonList( descendantNode ) ); } /** * Creates a dependency node filter that only accepts nodes that are ancestors of, or equal to, the specified list * of nodes. * * @param descendantNodes * the list of nodes to accept ancestors-or-self of */ public AncestorOrSelfDependencyNodeFilter( List descendantNodes ) { this.descendantNodes = descendantNodes; } // DependencyNodeFilter methods ------------------------------------------- /** * {@inheritDoc} */ public boolean accept( DependencyNode node ) { boolean accept = false; for ( Iterator iterator = descendantNodes.iterator(); !accept && iterator.hasNext(); ) { DependencyNode descendantNode = (DependencyNode) iterator.next(); if ( isAncestorOrSelf( node, descendantNode ) ) { accept = true; } } return accept; } // private methods -------------------------------------------------------- /** * Gets whether the first dependency node is an ancestor-or-self of the second. * * @param ancestorNode * the ancestor-or-self dependency node * @param descendantNode * the dependency node to test * @return true if ancestorNode is an ancestor, or equal to, * descendantNode */ private boolean isAncestorOrSelf( DependencyNode ancestorNode, DependencyNode descendantNode ) { boolean ancestor = false; while ( !ancestor && descendantNode != null ) { ancestor = ancestorNode.equals( descendantNode ); descendantNode = descendantNode.getParent(); } return ancestor; } } ././@LongLink0000000000000000000000000000016400000000000011566 Lustar rootrootmaven-dependency-tree-1.2/src/main/java/org/apache/maven/shared/dependency/tree/filter/AndDependencyNodeFilter.javamaven-dependency-tree-1.2/src/main/java/org/apache/maven/shared/dependency/tree/filter/AndDependency0000644000175000017500000000643611020006575033504 0ustar twernertwernerpackage org.apache.maven.shared.dependency.tree.filter; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.util.Arrays; import java.util.Collections; import java.util.Iterator; import java.util.List; import org.apache.maven.shared.dependency.tree.DependencyNode; /** * A dependency node filter that logically ANDs together a number of other dependency node filters. * * @author Mark Hobson * @version $Id: AndDependencyNodeFilter.java 661727 2008-05-30 14:21:49Z bentmann $ * @since 1.1 */ public class AndDependencyNodeFilter implements DependencyNodeFilter { // fields ----------------------------------------------------------------- /** * The dependency node filters that this filter ANDs together. */ private final List filters; // constructors ----------------------------------------------------------- /** * Creates a dependency node filter that logically ANDs together the two specified dependency node filters. * * @param filter1 * the first dependency node filter to logically AND together * @param filter2 * the second dependency node filter to logically AND together */ public AndDependencyNodeFilter( DependencyNodeFilter filter1, DependencyNodeFilter filter2 ) { this( Arrays.asList( new DependencyNodeFilter[] { filter1, filter2 } ) ); } /** * Creates a dependency node filter that logically ANDs together the specified dependency node filters. * * @param filters * the list of dependency node filters to logically AND together */ public AndDependencyNodeFilter( List filters ) { this.filters = Collections.unmodifiableList( filters ); } // DependencyNodeFilter methods ------------------------------------------- /** * {@inheritDoc} */ public boolean accept( DependencyNode node ) { boolean accept = true; for ( Iterator iterator = filters.iterator(); accept && iterator.hasNext(); ) { DependencyNodeFilter filter = (DependencyNodeFilter) iterator.next(); accept = filter.accept( node ); } return accept; } // public methods --------------------------------------------------------- /** * Gets the list of dependency node filters that this filter ANDs together. * * @return the dependency node filters that this filter ANDs together */ public List getDependencyNodeFilters() { return filters; } } ././@LongLink0000000000000000000000000000016200000000000011564 Lustar rootrootmaven-dependency-tree-1.2/src/main/java/org/apache/maven/shared/dependency/tree/DefaultDependencyTreeBuilder.javamaven-dependency-tree-1.2/src/main/java/org/apache/maven/shared/dependency/tree/DefaultDependencyTre0000644000175000017500000001171011020006575033543 0ustar twernertwernerpackage org.apache.maven.shared.dependency.tree; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.util.Collections; import java.util.Map; import java.util.Set; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.resolver.ArtifactCollector; import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.artifact.resolver.ArtifactResolutionResult; import org.apache.maven.artifact.resolver.filter.ArtifactFilter; import org.apache.maven.project.MavenProject; import org.apache.maven.project.artifact.InvalidDependencyVersionException; import org.apache.maven.shared.dependency.tree.traversal.CollectingDependencyNodeVisitor; import org.codehaus.plexus.logging.AbstractLogEnabled; /** * Default implementation of DependencyTreeBuilder. * * @author Edwin Punzalan * @author Mark Hobson * @version $Id: DefaultDependencyTreeBuilder.java 661727 2008-05-30 14:21:49Z bentmann $ * @plexus.component role="org.apache.maven.shared.dependency.tree.DependencyTreeBuilder" * @see DependencyTreeBuilder */ public class DefaultDependencyTreeBuilder extends AbstractLogEnabled implements DependencyTreeBuilder { // fields ----------------------------------------------------------------- private ArtifactResolutionResult result; // DependencyTreeBuilder methods ------------------------------------------ /** * {@inheritDoc} * * @deprecated */ public DependencyTree buildDependencyTree( MavenProject project, ArtifactRepository repository, ArtifactFactory factory, ArtifactMetadataSource metadataSource, ArtifactCollector collector ) throws DependencyTreeBuilderException { DependencyNode rootNode = buildDependencyTree( project, repository, factory, metadataSource, null, collector ); CollectingDependencyNodeVisitor collectingVisitor = new CollectingDependencyNodeVisitor(); rootNode.accept( collectingVisitor ); return new DependencyTree( rootNode, collectingVisitor.getNodes() ); } /** * {@inheritDoc} */ public DependencyNode buildDependencyTree( MavenProject project, ArtifactRepository repository, ArtifactFactory factory, ArtifactMetadataSource metadataSource, ArtifactFilter filter, ArtifactCollector collector ) throws DependencyTreeBuilderException { DependencyTreeResolutionListener listener = new DependencyTreeResolutionListener( getLogger() ); try { Map managedVersions = project.getManagedVersionMap(); Set dependencyArtifacts = project.getDependencyArtifacts(); if ( dependencyArtifacts == null ) { dependencyArtifacts = project.createArtifacts( factory, null, null ); } getLogger().debug( "Dependency tree resolution listener events:" ); // TODO: note that filter does not get applied due to MNG-3236 result = collector.collect( dependencyArtifacts, project.getArtifact(), managedVersions, repository, project.getRemoteArtifactRepositories(), metadataSource, filter, Collections.singletonList( listener ) ); return listener.getRootNode(); } catch ( ArtifactResolutionException exception ) { throw new DependencyTreeBuilderException( "Cannot build project dependency tree", exception ); } catch ( InvalidDependencyVersionException e ) { throw new DependencyTreeBuilderException( "Invalid dependency version for artifact " + project.getArtifact() ); } } // protected methods ------------------------------------------------------ protected ArtifactResolutionResult getArtifactResolutionResult() { return result; } } maven-dependency-tree-1.2/src/main/java/org/apache/maven/shared/dependency/tree/DependencyTree.java0000644000175000017500000000550411020006575033327 0ustar twernertwernerpackage org.apache.maven.shared.dependency.tree; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.List; /** * Represents a Maven project's dependency tree. * * @author Mark Hobson * @version $Id: DependencyTree.java 661727 2008-05-30 14:21:49Z bentmann $ * @deprecated As of 1.1, replaced by the dependency tree root {@link DependencyNode} */ public class DependencyTree { // fields ----------------------------------------------------------------- private final DependencyNode rootNode; private final Collection nodes; // constructors ----------------------------------------------------------- /** * Create a tree initialized to the arguments * * @param rootNode * @param nodes */ public DependencyTree( DependencyNode rootNode, Collection nodes ) { this.rootNode = rootNode; this.nodes = nodes; } // public methods --------------------------------------------------------- public DependencyNode getRootNode() { return rootNode; } public Collection getNodes() { return nodes; } public List getArtifacts() { List artifacts = new ArrayList(); Iterator it = getNodes().iterator(); while ( it.hasNext() ) { DependencyNode node = (DependencyNode) it.next(); artifacts.add( node.getArtifact() ); } return artifacts; } public String toString() { return getRootNode().toString(); } /** * @see DependencyNode#iterator() */ public Iterator iterator() { return getRootNode().iterator(); } /** * @see DependencyNode#preorderIterator() */ public Iterator preorderIterator() { return getRootNode().preorderIterator(); } /** * @see DependencyNode#inverseIterator() */ public Iterator inverseIterator() { return getRootNode().inverseIterator(); } } ././@LongLink0000000000000000000000000000016300000000000011565 Lustar rootrootmaven-dependency-tree-1.2/src/main/java/org/apache/maven/shared/dependency/tree/DependencyTreeInverseIterator.javamaven-dependency-tree-1.2/src/main/java/org/apache/maven/shared/dependency/tree/DependencyTreeInvers0000644000175000017500000000414511020006575033576 0ustar twernertwernerpackage org.apache.maven.shared.dependency.tree; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.util.Iterator; import java.util.NoSuchElementException; import java.util.Stack; /** * {@link Iterator} for {@link DependencyNode} implementing a traversal from leaves to root. * * TODO {@link #DependencyTreeInverseIterator(DependencyNode)} is costly, * a better implementation would move the cost to {@link #next()} * * @author Carlos Sanchez * @version $Id: DependencyTreeInverseIterator.java 661727 2008-05-30 14:21:49Z bentmann $ */ public class DependencyTreeInverseIterator implements Iterator { private Stack nodesToProcess = new Stack(); public DependencyTreeInverseIterator( DependencyNode rootNode ) { DependencyTreePreorderIterator it = new DependencyTreePreorderIterator( rootNode ); while ( it.hasNext() ) { nodesToProcess.push( it.next() ); } } public boolean hasNext() { return !nodesToProcess.isEmpty(); } public Object next() { if ( !hasNext() ) { throw new NoSuchElementException(); } return nodesToProcess.pop(); } /** * @throws UnsupportedOperationException */ public void remove() { throw new UnsupportedOperationException(); } } maven-dependency-tree-1.2/src/main/java/org/apache/maven/shared/dependency/tree/traversal/0000755000175000017500000000000011226720336031573 5ustar twernertwerner././@LongLink0000000000000000000000000000016500000000000011567 Lustar rootrootmaven-dependency-tree-1.2/src/main/java/org/apache/maven/shared/dependency/tree/traversal/DependencyNodeVisitor.javamaven-dependency-tree-1.2/src/main/java/org/apache/maven/shared/dependency/tree/traversal/Dependency0000644000175000017500000000372711020006575033577 0ustar twernertwernerpackage org.apache.maven.shared.dependency.tree.traversal; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import org.apache.maven.shared.dependency.tree.DependencyNode; /** * Defines a hierarchical visitor for processing dependency node trees. * * @author Mark Hobson * @version $Id: DependencyNodeVisitor.java 661727 2008-05-30 14:21:49Z bentmann $ * @since 1.1 */ public interface DependencyNodeVisitor { /** * Starts the visit to the specified dependency node. * * @param node * the dependency node to visit * @return true to visit the specified dependency node's children, false to skip the * specified dependency node's children and proceed to its next sibling */ boolean visit( DependencyNode node ); /** * Ends the visit to to the specified dependency node. * * @param node * the dependency node to visit * @return true to visit the specified dependency node's next sibling, false to skip * the specified dependency node's next siblings and proceed to its parent */ boolean endVisit( DependencyNode node ); } ././@LongLink0000000000000000000000000000017600000000000011571 Lustar rootrootmaven-dependency-tree-1.2/src/main/java/org/apache/maven/shared/dependency/tree/traversal/FilteringDependencyNodeVisitor.javamaven-dependency-tree-1.2/src/main/java/org/apache/maven/shared/dependency/tree/traversal/FilteringD0000644000175000017500000000671211020006575033545 0ustar twernertwernerpackage org.apache.maven.shared.dependency.tree.traversal; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import org.apache.maven.shared.dependency.tree.DependencyNode; import org.apache.maven.shared.dependency.tree.filter.DependencyNodeFilter; /** * A dependency node visitor that filters nodes and delegates to another visitor. * * @author Mark Hobson * @version $Id: FilteringDependencyNodeVisitor.java 661727 2008-05-30 14:21:49Z bentmann $ * @since 1.1 */ public class FilteringDependencyNodeVisitor implements DependencyNodeVisitor { // fields ----------------------------------------------------------------- /** * The dependency node visitor to delegate to. */ private final DependencyNodeVisitor visitor; /** * The dependency node filter to apply before delegation. */ private final DependencyNodeFilter filter; // constructors ----------------------------------------------------------- /** * Creates a dependency node visitor that delegates nodes that are accepted by the specified filter to the specified * visitor. * * @param visitor * the dependency node visitor to delegate to * @param filter * the dependency node filter to apply before delegation */ public FilteringDependencyNodeVisitor( DependencyNodeVisitor visitor, DependencyNodeFilter filter ) { this.visitor = visitor; this.filter = filter; } // DependencyNodeVisitor methods ------------------------------------------ /** * {@inheritDoc} */ public boolean visit( DependencyNode node ) { boolean visit; if ( filter.accept( node ) ) { visit = visitor.visit( node ); } else { visit = true; } return visit; } /** * {@inheritDoc} */ public boolean endVisit( DependencyNode node ) { boolean visit; if ( filter.accept( node ) ) { visit = visitor.endVisit( node ); } else { visit = true; } return visit; } // public methods --------------------------------------------------------- /** * Gets the dependency node visitor that this visitor delegates to. * * @return the dependency node visitor */ public DependencyNodeVisitor getDependencyNodeVisitor() { return visitor; } /** * Gets the dependency node filter that this visitor applies before delegation. * * @return the dependency node filter */ public DependencyNodeFilter getDependencyNodeFilter() { return filter; } } ././@LongLink0000000000000000000000000000020000000000000011555 Lustar rootrootmaven-dependency-tree-1.2/src/main/java/org/apache/maven/shared/dependency/tree/traversal/SerializingDependencyNodeVisitor.javamaven-dependency-tree-1.2/src/main/java/org/apache/maven/shared/dependency/tree/traversal/Serializin0000644000175000017500000001544611020006575033633 0ustar twernertwernerpackage org.apache.maven.shared.dependency.tree.traversal; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.io.PrintWriter; import java.io.Writer; import java.util.List; import org.apache.maven.shared.dependency.tree.DependencyNode; /** * A dependency node visitor that serializes visited nodes to a writer. * * @author Mark Hobson * @version $Id: SerializingDependencyNodeVisitor.java 661727 2008-05-30 14:21:49Z bentmann $ * @since 1.1 */ public class SerializingDependencyNodeVisitor implements DependencyNodeVisitor { // classes ---------------------------------------------------------------- /** * Provides tokens to use when serializing the dependency tree. */ public static class TreeTokens { private final String nodeIndent; private final String lastNodeIndent; private final String fillIndent; private final String lastFillIndent; public TreeTokens( String nodeIndent, String lastNodeIndent, String fillIndent, String lastFillIndent ) { this.nodeIndent = nodeIndent; this.lastNodeIndent = lastNodeIndent; this.fillIndent = fillIndent; this.lastFillIndent = lastFillIndent; } public String getNodeIndent( boolean last ) { return last ? lastNodeIndent : nodeIndent; } public String getFillIndent( boolean last ) { return last ? lastFillIndent : fillIndent; } } // constants -------------------------------------------------------------- /** * Whitespace tokens to use when outputing the dependency tree. */ public static final TreeTokens WHITESPACE_TOKENS = new TreeTokens( " ", " ", " ", " " ); /** * The standard ASCII tokens to use when outputing the dependency tree. */ public static final TreeTokens STANDARD_TOKENS = new TreeTokens( "+- ", "\\- ", "| ", " " ); /** * The extended ASCII tokens to use when outputing the dependency tree. */ public static final TreeTokens EXTENDED_TOKENS = new TreeTokens( "\u00c3\u00c4 ", "\u00c0\u00c4 ", "\u00b3 ", " " ); // fields ----------------------------------------------------------------- /** * The writer to serialize to. */ private final PrintWriter writer; /** * The tokens to use when serializing the dependency tree. */ private final TreeTokens tokens; /** * The depth of the currently visited dependency node. */ private int depth; // constructors ----------------------------------------------------------- /** * Creates a dependency node visitor that serializes visited nodes to the specified writer using whitespace tokens. * * @param writer * the writer to serialize to */ public SerializingDependencyNodeVisitor( Writer writer ) { this( writer, WHITESPACE_TOKENS ); } /** * Creates a dependency node visitor that serializes visited nodes to the specified writer using the specified * tokens. * * @param writer * the writer to serialize to * @param tokens * the tokens to use when serializing the dependency tree */ public SerializingDependencyNodeVisitor( Writer writer, TreeTokens tokens ) { if ( writer instanceof PrintWriter ) { this.writer = (PrintWriter) writer; } else { this.writer = new PrintWriter( writer, true ); } this.tokens = tokens; depth = 0; } // DependencyNodeVisitor methods ------------------------------------------ /** * {@inheritDoc} */ public boolean visit( DependencyNode node ) { indent( node ); writer.println( node.toNodeString() ); depth++; return true; } /** * {@inheritDoc} */ public boolean endVisit( DependencyNode node ) { depth--; return true; } // private methods -------------------------------------------------------- /** * Writes the necessary tokens to indent the specified dependency node to this visitor's writer. * * @param node * the dependency node to indent */ private void indent( DependencyNode node ) { for ( int i = 1; i < depth; i++ ) { writer.write( tokens.getFillIndent( isLast( node, i ) ) ); } if ( depth > 0 ) { writer.write( tokens.getNodeIndent( isLast( node ) ) ); } } /** * Gets whether the specified dependency node is the last of its siblings. * * @param node * the dependency node to check * @return true if the specified dependency node is the last of its last siblings */ private boolean isLast( DependencyNode node ) { // TODO: remove node argument and calculate from visitor calls only DependencyNode parent = node.getParent(); boolean last; if ( parent == null ) { last = true; } else { List siblings = parent.getChildren(); last = ( siblings.indexOf( node ) == siblings.size() - 1 ); } return last; } /** * Gets whether the specified dependency node ancestor is the last of its siblings. * * @param node * the dependency node whose ancestor to check * @param ancestorDepth * the depth of the ancestor of the specified dependency node to check * @return true if the specified dependency node ancestor is the last of its siblings */ private boolean isLast( DependencyNode node, int ancestorDepth ) { // TODO: remove node argument and calculate from visitor calls only int distance = depth - ancestorDepth; while ( distance-- > 0 ) { node = node.getParent(); } return isLast( node ); } } ././@LongLink0000000000000000000000000000017700000000000011572 Lustar rootrootmaven-dependency-tree-1.2/src/main/java/org/apache/maven/shared/dependency/tree/traversal/CollectingDependencyNodeVisitor.javamaven-dependency-tree-1.2/src/main/java/org/apache/maven/shared/dependency/tree/traversal/Collecting0000644000175000017500000000466411020006575033605 0ustar twernertwernerpackage org.apache.maven.shared.dependency.tree.traversal; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.apache.maven.shared.dependency.tree.DependencyNode; /** * A dependency node visitor that collects visited nodes for further processing. * * @author Mark Hobson * @version $Id: CollectingDependencyNodeVisitor.java 661727 2008-05-30 14:21:49Z bentmann $ * @since 1.1 */ public class CollectingDependencyNodeVisitor implements DependencyNodeVisitor { // fields ----------------------------------------------------------------- /** * The collected list of nodes. */ private final List nodes; // constructors ----------------------------------------------------------- /** * Creates a dependency node visitor that collects visited nodes for further processing. */ public CollectingDependencyNodeVisitor() { nodes = new ArrayList(); } // DependencyNodeVisitor methods ------------------------------------------ /** * {@inheritDoc} */ public boolean visit( DependencyNode node ) { // collect node nodes.add( node ); return true; } /** * {@inheritDoc} */ public boolean endVisit( DependencyNode node ) { return true; } // public methods --------------------------------------------------------- /** * Gets the list of collected dependency nodes. * * @return the list of collected dependency nodes */ public List getNodes() { return Collections.unmodifiableList( nodes ); } } ././@LongLink0000000000000000000000000000017500000000000011570 Lustar rootrootmaven-dependency-tree-1.2/src/main/java/org/apache/maven/shared/dependency/tree/traversal/BuildingDependencyNodeVisitor.javamaven-dependency-tree-1.2/src/main/java/org/apache/maven/shared/dependency/tree/traversal/BuildingDe0000644000175000017500000001067411020006575033526 0ustar twernertwernerpackage org.apache.maven.shared.dependency.tree.traversal; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.util.Stack; import org.apache.maven.shared.dependency.tree.DependencyNode; /** * A dependency node visitor that clones visited nodes into a new dependency tree. This can be used in conjunction with * a dependency node filter to construct subtrees. * * @author Mark Hobson * @version $Id: BuildingDependencyNodeVisitor.java 661727 2008-05-30 14:21:49Z bentmann $ * @since 1.1 */ public class BuildingDependencyNodeVisitor implements DependencyNodeVisitor { // fields ----------------------------------------------------------------- /** * The dependency node visitor to apply on the resultant dependency tree, or null for none. */ private final DependencyNodeVisitor visitor; /** * The resultant tree parent nodes for the currently visited node. */ private final Stack parentNodes; /** * The root node of the resultant tree. */ private DependencyNode rootNode; // constructors ----------------------------------------------------------- /** * Creates a dependency node visitor that clones visited nodes into a new dependency tree. */ public BuildingDependencyNodeVisitor() { this( null ); } /** * Creates a dependency node visitor that clones visited nodes into a new dependency tree, and then applies the * specified dependency node visitor on the resultant dependency tree. * * @param visitor * the dependency node visitor to apply on the resultant dependency tree, or null for none */ public BuildingDependencyNodeVisitor( DependencyNodeVisitor visitor ) { this.visitor = visitor; parentNodes = new Stack(); } // DependencyNodeVisitor methods ------------------------------------------ /** * {@inheritDoc} */ public boolean visit( DependencyNode node ) { // clone the node DependencyNode newNode = new DependencyNode( node.getArtifact(), node.getState(), node.getRelatedArtifact() ); newNode.setOriginalScope( node.getOriginalScope() ); newNode.setFailedUpdateScope( node.getFailedUpdateScope() ); newNode.setPremanagedVersion( node.getPremanagedVersion() ); newNode.setPremanagedScope( node.getPremanagedScope() ); if ( parentNodes.empty() ) { rootNode = newNode; } else { DependencyNode parentNode = (DependencyNode) parentNodes.peek(); parentNode.addChild( newNode ); } parentNodes.push( newNode ); return true; } /** * {@inheritDoc} */ public boolean endVisit( DependencyNode node ) { parentNodes.pop(); // apply the visitor to the resultant tree on the last visit if ( parentNodes.empty() && visitor != null ) { rootNode.accept( visitor ); } return true; } // public methods --------------------------------------------------------- /** * Gets the dependency node visitor that this visitor applies on the resultant dependency tree. * * @return the dependency node visitor, or null for none */ public DependencyNodeVisitor getDependencyNodeVisitor() { return visitor; } /** * Gets the root node of the resultant dependency tree constructed by this visitor. * * @return the root node, or null if the source tree has not yet been visited */ public DependencyNode getDependencyTree() { return rootNode; } } ././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootmaven-dependency-tree-1.2/src/main/java/org/apache/maven/shared/dependency/tree/DependencyTreeBuilder.javamaven-dependency-tree-1.2/src/main/java/org/apache/maven/shared/dependency/tree/DependencyTreeBuilde0000644000175000017500000000746711020006575033546 0ustar twernertwernerpackage org.apache.maven.shared.dependency.tree; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.resolver.ArtifactCollector; import org.apache.maven.artifact.resolver.filter.ArtifactFilter; import org.apache.maven.project.MavenProject; /** * Builds a tree of dependencies for a given Maven project. * * @author Mark Hobson * @version $Id: DependencyTreeBuilder.java 661727 2008-05-30 14:21:49Z bentmann $ */ public interface DependencyTreeBuilder { // fields ----------------------------------------------------------------- /** * The plexus role for this component. */ String ROLE = DependencyTreeBuilder.class.getName(); // public methods --------------------------------------------------------- /** * Builds a tree of dependencies for the specified Maven project. * * @param project * the Maven project * @param repository * the artifact repository to resolve against * @param factory * the artifact factory to use * @param metadataSource * the artifact metadata source to use * @param collector * the artifact collector to use * @return the dependency tree of the specified Maven project * @throws DependencyTreeBuilderException * if the dependency tree cannot be resolved * @deprecated As of 1.1, replaced by * {@link #buildDependencyTree(MavenProject, ArtifactRepository, ArtifactFactory, ArtifactMetadataSource, ArtifactFilter, ArtifactCollector)} */ DependencyTree buildDependencyTree( MavenProject project, ArtifactRepository repository, ArtifactFactory factory, ArtifactMetadataSource metadataSource, ArtifactCollector collector ) throws DependencyTreeBuilderException; /** * Builds a tree of dependencies for the specified Maven project. * * @param project * the Maven project * @param repository * the artifact repository to resolve against * @param factory * the artifact factory to use * @param metadataSource * the artifact metadata source to use * @param filter * the artifact filter to use * @param collector * the artifact collector to use * @return the dependency tree root node of the specified Maven project * @throws DependencyTreeBuilderException * if the dependency tree cannot be resolved * @since 1.1 */ DependencyNode buildDependencyTree( MavenProject project, ArtifactRepository repository, ArtifactFactory factory, ArtifactMetadataSource metadataSource, ArtifactFilter filter, ArtifactCollector collector ) throws DependencyTreeBuilderException; } ././@LongLink0000000000000000000000000000016400000000000011566 Lustar rootrootmaven-dependency-tree-1.2/src/main/java/org/apache/maven/shared/dependency/tree/DependencyTreePreorderIterator.javamaven-dependency-tree-1.2/src/main/java/org/apache/maven/shared/dependency/tree/DependencyTreePreord0000644000175000017500000000421411020006575033560 0ustar twernertwernerpackage org.apache.maven.shared.dependency.tree; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.util.Iterator; import java.util.List; import java.util.NoSuchElementException; import java.util.Stack; /** * {@link Iterator} for {@link DependencyNode} implementing a preoder traversal. * * @author Carlos Sanchez * @version $Id: DependencyTreePreorderIterator.java 661727 2008-05-30 14:21:49Z bentmann $ */ public class DependencyTreePreorderIterator implements Iterator { private Stack nodesToProcess = new Stack(); public DependencyTreePreorderIterator( DependencyNode rootNode ) { nodesToProcess.push( rootNode ); } public boolean hasNext() { return !nodesToProcess.isEmpty(); } public Object next() { if ( !hasNext() ) { throw new NoSuchElementException(); } DependencyNode currentNode = (DependencyNode) nodesToProcess.pop(); List children = currentNode.getChildren(); if ( children != null ) { for ( int i = children.size() - 1; i >= 0; i-- ) { nodesToProcess.push( children.get( i ) ); } } return currentNode; } /** * @throws UnsupportedOperationException */ public void remove() { throw new UnsupportedOperationException(); } } ././@LongLink0000000000000000000000000000016600000000000011570 Lustar rootrootmaven-dependency-tree-1.2/src/main/java/org/apache/maven/shared/dependency/tree/DependencyTreeResolutionListener.javamaven-dependency-tree-1.2/src/main/java/org/apache/maven/shared/dependency/tree/DependencyTreeResolu0000644000175000017500000004126111020006575033601 0ustar twernertwernerpackage org.apache.maven.shared.dependency.tree; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.IdentityHashMap; import java.util.Iterator; import java.util.Map; import java.util.Stack; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.resolver.ResolutionListener; import org.apache.maven.artifact.resolver.ResolutionListenerForDepMgmt; import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.shared.dependency.tree.traversal.CollectingDependencyNodeVisitor; import org.codehaus.plexus.logging.Logger; /** * An artifact resolution listener that constructs a dependency tree. * * @author Edwin Punzalan * @author Mark Hobson * @version $Id: DependencyTreeResolutionListener.java 661727 2008-05-30 14:21:49Z bentmann $ */ public class DependencyTreeResolutionListener implements ResolutionListener, ResolutionListenerForDepMgmt { // fields ----------------------------------------------------------------- /** * The log to write debug messages to. */ private final Logger logger; /** * The parent dependency nodes of the current dependency node. */ private final Stack parentNodes; /** * A map of dependency nodes by their attached artifact. */ private final Map nodesByArtifact; /** * The root dependency node of the computed dependency tree. */ private DependencyNode rootNode; /** * The dependency node currently being processed by this listener. */ private DependencyNode currentNode; /** * Map < String replacementId, String premanaged version > */ private Map managedVersions = new HashMap(); /** * Map < String replacementId, String premanaged scope > */ private Map managedScopes = new HashMap(); // constructors ----------------------------------------------------------- /** * Creates a new dependency tree resolution listener that writes to the specified log. * * @param logger * the log to write debug messages to */ public DependencyTreeResolutionListener( Logger logger ) { this.logger = logger; parentNodes = new Stack(); nodesByArtifact = new IdentityHashMap(); rootNode = null; currentNode = null; } // ResolutionListener methods --------------------------------------------- /** * {@inheritDoc} */ public void testArtifact( Artifact artifact ) { log( "testArtifact: artifact=" + artifact ); } /** * {@inheritDoc} */ public void startProcessChildren( Artifact artifact ) { log( "startProcessChildren: artifact=" + artifact ); if ( !currentNode.getArtifact().equals( artifact ) ) { throw new IllegalStateException( "Artifact was expected to be " + currentNode.getArtifact() + " but was " + artifact ); } parentNodes.push( currentNode ); } /** * {@inheritDoc} */ public void endProcessChildren( Artifact artifact ) { DependencyNode node = (DependencyNode) parentNodes.pop(); log( "endProcessChildren: artifact=" + artifact ); if ( node == null ) { throw new IllegalStateException( "Parent dependency node was null" ); } if ( !node.getArtifact().equals( artifact ) ) { throw new IllegalStateException( "Parent dependency node artifact was expected to be " + node.getArtifact() + " but was " + artifact ); } } /** * {@inheritDoc} */ public void includeArtifact( Artifact artifact ) { log( "includeArtifact: artifact=" + artifact ); DependencyNode existingNode = getNode( artifact ); /* * Ignore duplicate includeArtifact calls since omitForNearer can be called prior to includeArtifact on the same * artifact, and we don't wish to include it twice. */ if ( existingNode == null && isCurrentNodeIncluded() ) { DependencyNode node = addNode( artifact ); /* * Add the dependency management information cached in any prior manageArtifact calls, since includeArtifact * is always called after manageArtifact. */ flushDependencyManagement( node ); } } /** * {@inheritDoc} */ public void omitForNearer( Artifact omitted, Artifact kept ) { log( "omitForNearer: omitted=" + omitted + " kept=" + kept ); if ( !omitted.getDependencyConflictId().equals( kept.getDependencyConflictId() ) ) { throw new IllegalArgumentException( "Omitted artifact dependency conflict id " + omitted.getDependencyConflictId() + " differs from kept artifact dependency conflict id " + kept.getDependencyConflictId() ); } if ( isCurrentNodeIncluded() ) { DependencyNode omittedNode = getNode( omitted ); if ( omittedNode != null ) { removeNode( omitted ); } else { omittedNode = createNode( omitted ); currentNode = omittedNode; } omittedNode.omitForConflict( kept ); /* * Add the dependency management information cached in any prior manageArtifact calls, since omitForNearer * is always called after manageArtifact. */ flushDependencyManagement( omittedNode ); DependencyNode keptNode = getNode( kept ); if ( keptNode == null ) { addNode( kept ); } } } /** * {@inheritDoc} */ public void updateScope( Artifact artifact, String scope ) { log( "updateScope: artifact=" + artifact + ", scope=" + scope ); DependencyNode node = getNode( artifact ); if ( node == null ) { // updateScope events can be received prior to includeArtifact events node = addNode( artifact ); } node.setOriginalScope( artifact.getScope() ); } /** * {@inheritDoc} */ public void manageArtifact( Artifact artifact, Artifact replacement ) { // TODO: remove when ResolutionListenerForDepMgmt merged into ResolutionListener log( "manageArtifact: artifact=" + artifact + ", replacement=" + replacement ); if ( replacement.getVersion() != null ) { manageArtifactVersion( artifact, replacement ); } if ( replacement.getScope() != null ) { manageArtifactScope( artifact, replacement ); } } /** * {@inheritDoc} */ public void omitForCycle( Artifact artifact ) { log( "omitForCycle: artifact=" + artifact ); if ( isCurrentNodeIncluded() ) { DependencyNode node = createNode( artifact ); node.omitForCycle(); } } /** * {@inheritDoc} */ public void updateScopeCurrentPom( Artifact artifact, String scopeIgnored ) { log( "updateScopeCurrentPom: artifact=" + artifact + ", scopeIgnored=" + scopeIgnored ); DependencyNode node = getNode( artifact ); if ( node == null ) { // updateScopeCurrentPom events can be received prior to includeArtifact events node = addNode( artifact ); // TODO remove the node that tried to impose its scope and add some info } node.setFailedUpdateScope( scopeIgnored ); } /** * {@inheritDoc} */ public void selectVersionFromRange( Artifact artifact ) { log( "selectVersionFromRange: artifact=" + artifact ); DependencyNode node = getNode( artifact ); /* * selectVersionFromRange is called before includeArtifact */ if ( node == null && isCurrentNodeIncluded() ) { node = addNode( artifact ); } node.setVersionSelectedFromRange( artifact.getVersionRange() ); node.setAvailableVersions( artifact.getAvailableVersions() ); } /** * {@inheritDoc} */ public void restrictRange( Artifact artifact, Artifact replacement, VersionRange versionRange ) { log( "restrictRange: artifact=" + artifact + ", replacement=" + replacement + ", versionRange=" + versionRange ); // TODO: track range restriction in node (MNG-3093) } // ResolutionListenerForDepMgmt methods ----------------------------------- /** * {@inheritDoc} */ public void manageArtifactVersion( Artifact artifact, Artifact replacement ) { log( "manageArtifactVersion: artifact=" + artifact + ", replacement=" + replacement ); /* * DefaultArtifactCollector calls manageArtifact twice: first with the change; then subsequently with no change. * We ignore the second call when the versions are equal. */ if ( isCurrentNodeIncluded() && !replacement.getVersion().equals( artifact.getVersion() ) ) { /* * Cache management information and apply in includeArtifact, since DefaultArtifactCollector mutates the * artifact and then calls includeArtifact after manageArtifact. */ managedVersions.put( replacement.getId(), artifact.getVersion() ); } } /** * {@inheritDoc} */ public void manageArtifactScope( Artifact artifact, Artifact replacement ) { log( "manageArtifactScope: artifact=" + artifact + ", replacement=" + replacement ); /* * DefaultArtifactCollector calls manageArtifact twice: first with the change; then subsequently with no change. * We ignore the second call when the scopes are equal. */ if ( isCurrentNodeIncluded() && !replacement.getScope().equals( artifact.getScope() ) ) { /* * Cache management information and apply in includeArtifact, since DefaultArtifactCollector mutates the * artifact and then calls includeArtifact after manageArtifact. */ managedScopes.put( replacement.getId(), artifact.getScope() ); } } // public methods --------------------------------------------------------- /** * Gets a list of all dependency nodes in the computed dependency tree. * * @return a list of dependency nodes * @deprecated As of 1.1, use a {@link CollectingDependencyNodeVisitor} on the root dependency node */ public Collection getNodes() { return Collections.unmodifiableCollection( nodesByArtifact.values() ); } /** * Gets the root dependency node of the computed dependency tree. * * @return the root node */ public DependencyNode getRootNode() { return rootNode; } // private methods -------------------------------------------------------- /** * Writes the specified message to the log at debug level with indentation for the current node's depth. * * @param message * the message to write to the log */ private void log( String message ) { int depth = parentNodes.size(); StringBuffer buffer = new StringBuffer(); for ( int i = 0; i < depth; i++ ) { buffer.append( " " ); } buffer.append( message ); logger.debug( buffer.toString() ); } /** * Creates a new dependency node for the specified artifact and appends it to the current parent dependency node. * * @param artifact * the attached artifact for the new dependency node * @return the new dependency node */ private DependencyNode createNode( Artifact artifact ) { DependencyNode node = new DependencyNode( artifact ); if ( !parentNodes.isEmpty() ) { DependencyNode parent = (DependencyNode) parentNodes.peek(); parent.addChild( node ); } return node; } /** * Creates a new dependency node for the specified artifact, appends it to the current parent dependency node and * puts it into the dependency node cache. * * @param artifact * the attached artifact for the new dependency node * @return the new dependency node */ // package protected for unit test DependencyNode addNode( Artifact artifact ) { DependencyNode node = createNode( artifact ); DependencyNode previousNode = (DependencyNode) nodesByArtifact.put( node.getArtifact(), node ); if ( previousNode != null ) { throw new IllegalStateException( "Duplicate node registered for artifact: " + node.getArtifact() ); } if ( rootNode == null ) { rootNode = node; } currentNode = node; return node; } /** * Gets the dependency node for the specified artifact from the dependency node cache. * * @param artifact * the artifact to find the dependency node for * @return the dependency node, or null if the specified artifact has no corresponding dependency * node */ private DependencyNode getNode( Artifact artifact ) { return (DependencyNode) nodesByArtifact.get( artifact ); } /** * Removes the dependency node for the specified artifact from the dependency node cache. * * @param artifact * the artifact to remove the dependency node for */ private void removeNode( Artifact artifact ) { DependencyNode node = (DependencyNode) nodesByArtifact.remove( artifact ); if ( !artifact.equals( node.getArtifact() ) ) { throw new IllegalStateException( "Removed dependency node artifact was expected to be " + artifact + " but was " + node.getArtifact() ); } } /** * Gets whether the all the ancestors of the dependency node currently being processed by this listener have an * included state. * * @return true if all the ancestors of the current dependency node have a state of * INCLUDED */ private boolean isCurrentNodeIncluded() { boolean included = true; for ( Iterator iterator = parentNodes.iterator(); included && iterator.hasNext(); ) { DependencyNode node = (DependencyNode) iterator.next(); if ( node.getState() != DependencyNode.INCLUDED ) { included = false; } } return included; } /** * Updates the specified node with any dependency management information cached in prior manageArtifact * calls. * * @param node * the node to update */ private void flushDependencyManagement( DependencyNode node ) { Artifact artifact = node.getArtifact(); String premanagedVersion = (String) managedVersions.get( artifact.getId() ); String premanagedScope = (String) managedScopes.get( artifact.getId() ); if ( premanagedVersion != null || premanagedScope != null ) { if ( premanagedVersion != null ) { node.setPremanagedVersion( premanagedVersion ); } if ( premanagedScope != null ) { node.setPremanagedScope( premanagedScope ); } premanagedVersion = null; premanagedScope = null; } } } maven-dependency-tree-1.2/pom.xml0000644000175000017500000000666111053525237017022 0ustar twernertwerner org.apache.maven.shared maven-shared-components 9 4.0.0 org.apache.maven.shared maven-dependency-tree jar 1.2 Maven Dependency Tree scm:svn:http://svn.apache.org/repos/asf/maven/shared/tags/maven-dependency-tree-1.2 scm:svn:https://svn.apache.org/repos/asf/maven/shared/tags/maven-dependency-tree-1.2 http://svn.apache.org/viewcvs.cgi/maven/shared/tags/maven-dependency-tree-1.2 org.codehaus.plexus plexus-maven-plugin descriptor org.apache.maven.plugins maven-release-plugin 2.0-beta-7 maven-surefire-plugin 2.3 org.apache.maven maven-project 2.0.8 jmock jmock 1.2.0 test org.apache.maven.shared maven-plugin-testing-harness 1.1 test org.apache.maven maven-artifact 2.0.9 apache.snapshots Apache Snapshot Repository http://people.apache.org/repo/m2-snapshot-repository false