m-dependency-tree 3.0 cleanup
git-svn-id: https://svn.apache.org/repos/asf/maven/shared/branches/m-dependency-tree@1678815 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/pom.xml b/pom.xml
index 7eb3a6a..789609d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -28,7 +28,7 @@
</parent>
<artifactId>maven-dependency-tree</artifactId>
- <version>2.3-SNAPSHOT</version>
+ <version>3.0-SNAPSHOT</version>
<name>Apache Maven Dependency Tree</name>
<description>A tree-based API for resolution of Maven project dependencies</description>
@@ -50,7 +50,7 @@
</distributionManagement>
<properties>
- <mavenVersion>2.2.1</mavenVersion>
+ <mavenVersion>3.0</mavenVersion>
</properties>
<contributors>
@@ -62,12 +62,6 @@
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
- <artifactId>maven-project</artifactId>
- <version>${mavenVersion}</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>3.0.4</version>
<scope>provided</scope>
diff --git a/src/main/java/org/apache/maven/shared/dependency/graph/DependencyGraphBuilder.java b/src/main/java/org/apache/maven/shared/dependency/graph/DependencyGraphBuilder.java
index c5100ce..bfec7c2 100644
--- a/src/main/java/org/apache/maven/shared/dependency/graph/DependencyGraphBuilder.java
+++ b/src/main/java/org/apache/maven/shared/dependency/graph/DependencyGraphBuilder.java
@@ -21,6 +21,7 @@
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.ProjectBuildingRequest;
import java.util.Collection;
@@ -39,10 +40,24 @@
* @param filter artifact filter (can be <code>null</code>)
* @return the dependency graph
* @throws DependencyGraphBuilderException if some of the dependencies could not be resolved.
+ * @deprecated instead use {@link #buildDependencyGraph(ProjectBuildingRequest, ArtifactFilter)}
*/
+ @Deprecated
DependencyNode buildDependencyGraph( MavenProject project, ArtifactFilter filter )
throws DependencyGraphBuilderException;
+
+ /**
+ * Build the dependency graph.
+ *
+ * @param project the project
+ * @param filter artifact filter (can be <code>null</code>)
+ * @return the dependency graph
+ * @throws DependencyGraphBuilderException if some of the dependencies could not be resolved.
+ */
+ DependencyNode buildDependencyGraph( ProjectBuildingRequest buildingRequest, ArtifactFilter filter )
+ throws DependencyGraphBuilderException;
+
/**
* Build the dependency graph, with a hack to include dependencies contained in the reactor projects
* but that are not yet compiled, which is the minimum prerequisite for Maven core's
@@ -56,8 +71,28 @@
* @param reactorProjects Collection of those projects contained in the reactor (can be <code>null</code>).
* @return the dependency graph
* @throws DependencyGraphBuilderException if some of the dependencies could not be resolved.
+ * @deprecated instead use {@link #buildDependencyGraph(ProjectBuildingRequest, ArtifactFilter, Collection)}
*/
+ @Deprecated
DependencyNode buildDependencyGraph( MavenProject project, ArtifactFilter filter,
Collection<MavenProject> reactorProjects )
throws DependencyGraphBuilderException;
+
+ /**
+ * Build the dependency graph, with a hack to include dependencies contained in the reactor projects
+ * but that are not yet compiled, which is the minimum prerequisite for Maven core's
+ * ReactorReader to find them. Notice that this hack hasn't been done for Maven 2.
+ * <p>Notice: If Maven core did collect instead of resolving dependencies (ie did not try to get the
+ * artifacts but only the poms), probably this hack wouldn't be necessary even for people requiring
+ * the dependency graph before compiling. TODO: for Maven 3, use Aether to collect dependencies.</p>
+ *
+ * @param project the project
+ * @param filter artifact filter (can be <code>null</code>)
+ * @param reactorProjects Collection of those projects contained in the reactor (can be <code>null</code>).
+ * @return the dependency graph
+ * @throws DependencyGraphBuilderException if some of the dependencies could not be resolved.
+ */
+ DependencyNode buildDependencyGraph( ProjectBuildingRequest buildingRequest, ArtifactFilter filter,
+ Collection<MavenProject> reactorProjects )
+ throws DependencyGraphBuilderException;
}
diff --git a/src/main/java/org/apache/maven/shared/dependency/graph/internal/DefaultDependencyGraphBuilder.java b/src/main/java/org/apache/maven/shared/dependency/graph/internal/DefaultDependencyGraphBuilder.java
index 379bc89..0398ff8 100644
--- a/src/main/java/org/apache/maven/shared/dependency/graph/internal/DefaultDependencyGraphBuilder.java
+++ b/src/main/java/org/apache/maven/shared/dependency/graph/internal/DefaultDependencyGraphBuilder.java
@@ -21,6 +21,7 @@
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.shared.dependency.graph.DependencyGraphBuilder;
import org.apache.maven.shared.dependency.graph.DependencyGraphBuilderException;
import org.apache.maven.shared.dependency.graph.DependencyNode;
@@ -62,7 +63,13 @@
public DependencyNode buildDependencyGraph( MavenProject project, ArtifactFilter filter )
throws DependencyGraphBuilderException
{
- return buildDependencyGraph( project, filter, null );
+ return buildDependencyGraph( project.getProjectBuildingRequest(), filter, null );
+ }
+
+ public DependencyNode buildDependencyGraph( ProjectBuildingRequest buildingRequest, ArtifactFilter filter )
+ throws DependencyGraphBuilderException
+ {
+ return buildDependencyGraph( buildingRequest, filter, null );
}
/**
@@ -78,16 +85,24 @@
Collection<MavenProject> reactorProjects )
throws DependencyGraphBuilderException
{
+ return buildDependencyGraph( project.getProjectBuildingRequest(), filter, reactorProjects );
+ }
+
+ public DependencyNode buildDependencyGraph( ProjectBuildingRequest buildingRequest, ArtifactFilter filter,
+ Collection<MavenProject> reactorProjects )
+ throws DependencyGraphBuilderException
+ {
try
{
- String hint = isMaven31() ? "maven31" : isMaven2x() ? "maven2" : "maven3";
+ String hint = isMaven31() ? "maven31" : "maven3";
DependencyGraphBuilder effectiveGraphBuilder =
(DependencyGraphBuilder) container.lookup( DependencyGraphBuilder.class.getCanonicalName(), hint );
- getLogger().debug( "building " + hint + " dependency graph for " + project.getId() + " with "
- + effectiveGraphBuilder.getClass().getSimpleName() );
+
+ getLogger().debug( "building " + hint + " dependency graph for " + buildingRequest.getProject().getId()
+ + " with " + effectiveGraphBuilder.getClass().getSimpleName() );
- return effectiveGraphBuilder.buildDependencyGraph( project, filter, reactorProjects );
+ return effectiveGraphBuilder.buildDependencyGraph( buildingRequest, filter, reactorProjects );
}
catch ( ComponentLookupException e )
{
@@ -96,14 +111,6 @@
}
/**
- * @return true if the current Maven is Maven 2.x.
- */
- protected static boolean isMaven2x()
- {
- return !canFindCoreClass( "org.apache.maven.project.DependencyResolutionRequest" ); // Maven 3 specific
- }
-
- /**
* @return true if the current Maven version is Maven 3.1.
*/
protected static boolean isMaven31()
diff --git a/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven2DependencyGraphBuilder.java b/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven2DependencyGraphBuilder.java
deleted file mode 100644
index bb0fbca..0000000
--- a/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven2DependencyGraphBuilder.java
+++ /dev/null
@@ -1,131 +0,0 @@
-package org.apache.maven.shared.dependency.graph.internal;
-
-/*
- * 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.resolver.filter.ArtifactFilter;
-import org.apache.maven.project.MavenProject;
-import org.apache.maven.shared.dependency.graph.DependencyGraphBuilder;
-import org.apache.maven.shared.dependency.graph.DependencyGraphBuilderException;
-import org.apache.maven.shared.dependency.graph.DependencyNode;
-import org.apache.maven.shared.dependency.tree.DependencyTreeBuilder;
-import org.apache.maven.shared.dependency.tree.DependencyTreeBuilderException;
-import org.codehaus.plexus.component.annotations.Component;
-import org.codehaus.plexus.component.annotations.Requirement;
-import org.codehaus.plexus.logging.AbstractLogEnabled;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-
-/**
- * Wrapper around Maven 2 dependency tree builder.
- *
- * @see DependencyTreeBuilder
- * @author Hervé Boutemy
- * @since 2.0
- */
-@Component( role = DependencyGraphBuilder.class, hint = "maven2" )
-public class Maven2DependencyGraphBuilder
- extends AbstractLogEnabled
- implements DependencyGraphBuilder
-{
- @Requirement
- private DependencyTreeBuilder treeBuilder;
-
- /**
- * Builds the dependency graph for Maven 2.
- *
- * @param project the project
- * @param filter artifact filter (can be <code>null</code>)
- * @return DependencyNode containing the dependency graph.
- * @throws DependencyGraphBuilderException if some of the dependencies could not be resolved.
- */
- public DependencyNode buildDependencyGraph( MavenProject project, ArtifactFilter filter )
- throws DependencyGraphBuilderException
- {
- try
- {
- return buildDependencyNode( null, treeBuilder.buildDependencyTree( project ), filter );
- }
- catch ( DependencyTreeBuilderException e )
- {
- throw new DependencyGraphBuilderException( e.getMessage(), e );
- }
- }
-
- /**
- * Builds the dependency graph for Maven 2.
- * <p>
- * notice: the reactor projects are ignored as no work has been done to try to do the same hack as with Maven 3.
- * </p>
- *
- * @param project the project
- * @param filter artifact filter (can be <code>null</code>)
- * @param reactorProjects Ignored.
- * @return DependencyNode containing the dependency graph.
- * @throws DependencyGraphBuilderException if some of the dependencies could not be resolved.
- */
- public DependencyNode buildDependencyGraph( MavenProject project, ArtifactFilter filter,
- Collection<MavenProject> reactorProjects )
- throws DependencyGraphBuilderException
- {
- if ( reactorProjects != null )
- {
- getLogger().warn( "Reactor projects ignored - reactor project collection not implemented" );
- }
-
- return buildDependencyGraph( project, filter );
- }
-
- private DependencyNode buildDependencyNode( DependencyNode parent,
- org.apache.maven.shared.dependency.tree.DependencyNode node,
- ArtifactFilter filter )
- {
- String versionSelectedFromRange = null;
- if ( node.getVersionSelectedFromRange() != null )
- {
- versionSelectedFromRange = node.getVersionSelectedFromRange().toString();
- }
-
- DefaultDependencyNode current =
- new DefaultDependencyNode( parent, node.getArtifact(), node.getPremanagedVersion(),
- node.getPremanagedScope(), versionSelectedFromRange );
-
- List<DependencyNode> nodes = new ArrayList<DependencyNode>( node.getChildren().size() );
- for ( org.apache.maven.shared.dependency.tree.DependencyNode child : node.getChildren() )
- {
- if ( child.getState() != org.apache.maven.shared.dependency.tree.DependencyNode.INCLUDED )
- {
- // only included nodes are supported in the graph API
- continue;
- }
-
- if ( ( filter == null ) || filter.include( child.getArtifact() ) )
- {
- nodes.add( buildDependencyNode( current, child, filter ) );
- }
- }
-
- current.setChildren( Collections.unmodifiableList( nodes ) );
-
- return current;
- }
-}
diff --git a/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven31DependencyGraphBuilder.java b/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven31DependencyGraphBuilder.java
index 4256816..8c77b00 100644
--- a/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven31DependencyGraphBuilder.java
+++ b/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven31DependencyGraphBuilder.java
@@ -78,6 +78,12 @@
{
return buildDependencyGraph( project, filter, null );
}
+
+ public DependencyNode buildDependencyGraph( ProjectBuildingRequest buildingRequest, ArtifactFilter filter )
+ throws DependencyGraphBuilderException
+ {
+ return buildDependencyGraph( buildingRequest, filter, null );
+ }
/**
* Builds the dependency graph for Maven 3.1+, eventually hacking for collecting projects from
@@ -96,6 +102,15 @@
ProjectBuildingRequest projectBuildingRequest =
(ProjectBuildingRequest) Invoker.invoke( project, "getProjectBuildingRequest" );
+ return buildDependencyGraph( projectBuildingRequest, filter, reactorProjects );
+ }
+
+ public DependencyNode buildDependencyGraph( ProjectBuildingRequest projectBuildingRequest, ArtifactFilter filter,
+ Collection<MavenProject> reactorProjects )
+ throws DependencyGraphBuilderException
+ {
+ MavenProject project = projectBuildingRequest.getProject();
+
RepositorySystemSession session =
(RepositorySystemSession) Invoker.invoke( projectBuildingRequest, "getRepositorySession" );
diff --git a/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven3DependencyGraphBuilder.java b/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven3DependencyGraphBuilder.java
index f47363a..72d7df3 100644
--- a/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven3DependencyGraphBuilder.java
+++ b/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven3DependencyGraphBuilder.java
@@ -19,6 +19,13 @@
* under the License.
*/
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
@@ -36,16 +43,10 @@
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.AbstractLogEnabled;
+import org.sonatype.aether.RepositorySystemSession;
import org.sonatype.aether.graph.Dependency;
import org.sonatype.aether.version.VersionConstraint;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
/**
* Wrapper around Maven 3 dependency resolver.
*
@@ -77,6 +78,12 @@
{
return buildDependencyGraph( project, filter, null );
}
+
+ public DependencyNode buildDependencyGraph( ProjectBuildingRequest buildingRequest, ArtifactFilter filter )
+ throws DependencyGraphBuilderException
+ {
+ return buildDependencyGraph( buildingRequest, filter, null );
+ }
/**
* Builds the dependency graph for Maven 3, eventually hacking for collecting projects from
@@ -92,17 +99,31 @@
Collection<MavenProject> reactorProjects )
throws DependencyGraphBuilderException
{
+ // this method doesn't exist on all MavenProject versions and also has been deprecated.
ProjectBuildingRequest projectBuildingRequest =
(ProjectBuildingRequest) Invoker.invoke( project, "getProjectBuildingRequest" );
+ return buildDependencyGraph( projectBuildingRequest, filter, reactorProjects );
+ }
+
+ public DependencyNode buildDependencyGraph( ProjectBuildingRequest buildingRequest, ArtifactFilter filter,
+ Collection<MavenProject> reactorProjects )
+ throws DependencyGraphBuilderException
+ {
+ MavenProject project = buildingRequest.getProject();
+
+ RepositorySystemSession session =
+ (RepositorySystemSession) Invoker.invoke( buildingRequest, "getRepositorySession" );
+
DependencyResolutionRequest request =
- new DefaultDependencyResolutionRequest( project, projectBuildingRequest.getRepositorySession() );
+ new DefaultDependencyResolutionRequest( project, session );
DependencyResolutionResult result = resolveDependencies( request, reactorProjects );
return buildDependencyNode( null, result.getDependencyGraph(), project.getArtifact(), filter );
}
+
private DependencyResolutionResult resolveDependencies( DependencyResolutionRequest request,
Collection<MavenProject> reactorProjects )
throws DependencyGraphBuilderException
diff --git a/src/main/java/org/apache/maven/shared/dependency/tree/DefaultDependencyTreeBuilder.java b/src/main/java/org/apache/maven/shared/dependency/tree/DefaultDependencyTreeBuilder.java
deleted file mode 100644
index 491f8db..0000000
--- a/src/main/java/org/apache/maven/shared/dependency/tree/DefaultDependencyTreeBuilder.java
+++ /dev/null
@@ -1,172 +0,0 @@
-package 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.Artifact;
-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.ResolutionListener;
-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.component.annotations.Component;
-import org.codehaus.plexus.component.annotations.Requirement;
-import org.codehaus.plexus.logging.AbstractLogEnabled;
-
-/**
- * Default implementation of <code>DependencyTreeBuilder</code>.
- *
- * @author Edwin Punzalan
- * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
- * @version $Id$
- * @see DependencyTreeBuilder
- */
-@Component( role = DependencyTreeBuilder.class )
-public class DefaultDependencyTreeBuilder
- extends AbstractLogEnabled
- implements DependencyTreeBuilder
-{
- @Requirement
- private ArtifactFactory factory;
-
- @Requirement
- private ArtifactMetadataSource metadataSource;
-
- /**
- * Artifact collector component.
- */
- @Requirement
- private ArtifactCollector collector;
-
- // 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
- {
- @SuppressWarnings( "unchecked" )
- Map<String, Artifact> managedVersions = project.getManagedVersionMap();
-
- @SuppressWarnings( "unchecked" )
- Set<Artifact> 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( (ResolutionListener) 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() );
- }
- }
-
- /**
- * Builds a dependency tree.
- *
- * @param project MavenProject for which ot build the dependency tree.
- * @return DependencyNode containing the dependency tree for the project.
- * @throws DependencyTreeBuilderException if the dependency tree could not be built.
- */
- public DependencyNode buildDependencyTree( MavenProject project )
- throws DependencyTreeBuilderException
- {
- return buildDependencyTree( project, project.getProjectBuilderConfiguration().getLocalRepository(), factory,
- metadataSource, null, collector );
- }
-
- /**
- * Builds a dependency tree.
- *
- * @param project MavenProject for which ot build the dependency tree.
- * @param repository ArtifactRepository to search fro dependencies.
- * @param filter Filter to apply when searching for dependencies.
- * @return DependencyNode containing the dependency tree for the project.
- * @throws DependencyTreeBuilderException if the dependency tree could not be built.
- */
- public DependencyNode buildDependencyTree( MavenProject project, ArtifactRepository repository,
- ArtifactFilter filter )
- throws DependencyTreeBuilderException
- {
- return buildDependencyTree( project, repository, factory, metadataSource, filter, collector );
- }
-
- // protected methods ------------------------------------------------------
-
- protected ArtifactResolutionResult getArtifactResolutionResult()
- {
- return result;
- }
-}
diff --git a/src/main/java/org/apache/maven/shared/dependency/tree/DependencyNode.java b/src/main/java/org/apache/maven/shared/dependency/tree/DependencyNode.java
deleted file mode 100644
index dc4b7fa..0000000
--- a/src/main/java/org/apache/maven/shared/dependency/tree/DependencyNode.java
+++ /dev/null
@@ -1,878 +0,0 @@
-package 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.ArtifactVersion;
-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 <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
- * @version $Id$
- */
-public class DependencyNode
-{
- // constants --------------------------------------------------------------
-
- private static final int HASH_PRIME = 31;
-
- /**
- * 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<DependencyNode> children;
-
- /**
- * The parent dependency node of this dependency node.
- */
- private DependencyNode parent;
-
- /**
- * The state of this dependency node. This can be either <code>INCLUDED</code>, <code>OMITTED_FOR_DUPLICATE</code>,
- * <code>OMITTED_FOR_CONFLICT</code> or <code>OMITTED_FOR_CYCLE</code>.
- *
- * @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
- * <code>OMITTED_FOR_DUPLICATE</code> or <code>OMITTED_FOR_CONFLICT</code>, this represents the artifact that was
- * conflicted with. For dependency nodes of other states, this is always <code>null</code>.
- */
- private Artifact relatedArtifact;
-
- /**
- * The scope of this node's artifact before it was updated due to conflicts, or <code>null</code> 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 <code>null</code> 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 <code>null</code> 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 <code>null</code> if the
- * artifact scope has not been managed.
- */
- private String premanagedScope;
-
- private VersionRange versionSelectedFromRange;
-
- private List<ArtifactVersion> 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 <code>INCLUDED</code> or
- * <code>OMITTED_FOR_CYCLE</code>.
- * @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 <code>INCLUDED</code>,
- * <code>OMITTED_FOR_DUPLICATE</code>, <code>OMITTED_FOR_CONFLICT</code> or
- * <code>OMITTED_FOR_CYCLE</code>.
- * @param relatedArtifact the artifact related to the state of this dependency node. For dependency nodes with a
- * state of <code>OMITTED_FOR_DUPLICATE</code> or <code>OMITTED_FOR_CONFLICT</code>, this represents the
- * artifact that was conflicted with. For dependency nodes of other states, this should always be
- * <code>null</code>.
- * @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<DependencyNode>();
- }
-
- /**
- * Creates a new dependency node.
- *
- * @deprecated As of 1.1, replaced by {@link #DependencyNode(Artifact, int, Artifact)}
- */
- DependencyNode()
- {
- artifact = null;
- children = new ArrayList<DependencyNode>();
- }
-
- // 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 ) )
- {
- for ( DependencyNode child : getChildren() )
- {
- if ( !child.accept( visitor ) )
- {
- break;
- }
- }
- }
-
- 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 serializing 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<DependencyNode> getChildren()
- {
- return Collections.unmodifiableList( children );
- }
-
- public boolean hasChildren()
- {
- return children.size() > 0;
- }
-
- /**
- * Gets the state of this dependency node.
- *
- * @return the state: either <code>INCLUDED</code>, <code>OMITTED_FOR_DUPLICATE</code>,
- * <code>OMITTED_FOR_CONFLICT</code> or <code>OMITTED_FOR_CYCLE</code>.
- * @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
- * <code>OMITTED_FOR_CONFLICT</code>, this represents the artifact that was conflicted with. For dependency nodes of
- * other states, this is always <code>null</code>.
- *
- * @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 <code>null</code> 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 <code>null</code> 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 <code>null</code> 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 <code>null</code> 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 <code>null</code> 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 <code>null</code> 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 <code>null</code> 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 <code>null</code> 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 <code>null</code> 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
- * <code>null</code> if the artifact had a explicit version.
- * @since 1.2
- */
- public List<ArtifactVersion> getAvailableVersions()
- {
- return availableVersions;
- }
-
- public void setAvailableVersions( List<ArtifactVersion> availableVersions )
- {
- this.availableVersions = availableVersions;
- }
-
- /**
- * Changes the state of this dependency node to be omitted for conflict or duplication, depending on the specified
- * related artifact.
- * <p>
- * If the related artifact has a version equal to this dependency node's artifact, then this dependency node's state
- * is changed to <code>OMITTED_FOR_DUPLICATE</code>, otherwise it is changed to <code>OMITTED_FOR_CONFLICT</code>.
- * Omitting this dependency node also removes all of its children.
- * </p>
- *
- * @param relatedArtifact the artifact that this dependency node conflicted with
- * @throws IllegalStateException if this dependency node's state is not <code>INCLUDED</code>
- * @throws IllegalArgumentException if the related artifact was <code>null</code> 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.
- * <p>
- * Omitting this node sets its state to <code>OMITTED_FOR_CYCLE</code> and removes all of its children.
- * </p>
- *
- * @throws IllegalStateException if this dependency node's state is not <code>INCLUDED</code>
- * @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<DependencyNode> 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<DependencyNode> 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<DependencyNode> 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;
-
- default:
- 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.
- * <p>
- * As of 1.1, this method ignores the indentation depth and simply delegates to <code>toString()</code>.
- * </p>
- *
- * @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 * HASH_PRIME + getArtifact().hashCode();
- // DefaultArtifact.hashCode does not consider scope
- hashCode = hashCode * HASH_PRIME + nullHashCode( getArtifact().getScope() );
-
- // TODO: use parent's artifact to prevent recursion - how can we improve this?
- hashCode = hashCode * HASH_PRIME + nullHashCode( nullGetArtifact( getParent() ) );
-
- hashCode = hashCode * HASH_PRIME + getChildren().hashCode();
- hashCode = hashCode * HASH_PRIME + getState();
- hashCode = hashCode * HASH_PRIME + nullHashCode( getRelatedArtifact() );
- hashCode = hashCode * HASH_PRIME + nullHashCode( getPremanagedVersion() );
- hashCode = hashCode * HASH_PRIME + nullHashCode( getPremanagedScope() );
- hashCode = hashCode * HASH_PRIME + nullHashCode( getOriginalScope() );
- hashCode = hashCode * HASH_PRIME + nullHashCode( getFailedUpdateScope() );
- hashCode = hashCode * HASH_PRIME + nullHashCode( getVersionSelectedFromRange() );
- hashCode = hashCode * HASH_PRIME + nullHashCode( getAvailableVersions() );
-
- return hashCode;
- }
-
- @Override
- 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 ( DependencyNode child : children )
- {
- child.parent = null;
- }
-
- children.clear();
- }
-
- /**
- * Computes a hash-code for the specified object.
- *
- * @param a the object to compute a hash-code for, possibly <code>null</code>
- * @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 <code>null</code>
- * @param b the second object to compare, possibly <code>null</code>
- * @return <code>true</code> 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 <code>null</code>
- * @return the node's artifact, or <code>null</code> if the specified node was <code>null</code>
- */
- private static Artifact nullGetArtifact( DependencyNode node )
- {
- return ( node != null ) ? node.getArtifact() : null;
- }
-}
diff --git a/src/main/java/org/apache/maven/shared/dependency/tree/DependencyTree.java b/src/main/java/org/apache/maven/shared/dependency/tree/DependencyTree.java
deleted file mode 100644
index c8437b9..0000000
--- a/src/main/java/org/apache/maven/shared/dependency/tree/DependencyTree.java
+++ /dev/null
@@ -1,110 +0,0 @@
-package 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;
-
-import org.apache.maven.artifact.Artifact;
-
-/**
- * Represents a Maven project's dependency tree.
- *
- * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
- * @version $Id$
- * @deprecated As of 1.1, replaced by the dependency tree root {@link DependencyNode}
- */
-public class DependencyTree
-{
- // fields -----------------------------------------------------------------
-
- private final DependencyNode rootNode;
-
- private final Collection<DependencyNode> nodes;
-
- // constructors -----------------------------------------------------------
-
- /**
- * Create a tree initialized to the arguments
- *
- * @param rootNode
- * @param nodes
- */
- public DependencyTree( DependencyNode rootNode, Collection<DependencyNode> nodes )
- {
- this.rootNode = rootNode;
- this.nodes = nodes;
- }
-
- // public methods ---------------------------------------------------------
-
- public DependencyNode getRootNode()
- {
- return rootNode;
- }
-
- public Collection<DependencyNode> getNodes()
- {
- return nodes;
- }
-
- public List<Artifact> getArtifacts()
- {
- List<Artifact> artifacts = new ArrayList<Artifact>();
-
- for ( DependencyNode node : getNodes() )
- {
- artifacts.add( node.getArtifact() );
- }
-
- return artifacts;
- }
-
- public String toString()
- {
- return getRootNode().toString();
- }
-
- /**
- * @see DependencyNode#iterator()
- */
- public Iterator<DependencyNode> iterator()
- {
- return getRootNode().iterator();
- }
-
- /**
- * @see DependencyNode#preorderIterator()
- */
- public Iterator<DependencyNode> preorderIterator()
- {
- return getRootNode().preorderIterator();
- }
-
- /**
- * @see DependencyNode#inverseIterator()
- */
- public Iterator<DependencyNode> inverseIterator()
- {
- return getRootNode().inverseIterator();
- }
-}
diff --git a/src/main/java/org/apache/maven/shared/dependency/tree/DependencyTreeBuilder.java b/src/main/java/org/apache/maven/shared/dependency/tree/DependencyTreeBuilder.java
deleted file mode 100644
index b11caa4..0000000
--- a/src/main/java/org/apache/maven/shared/dependency/tree/DependencyTreeBuilder.java
+++ /dev/null
@@ -1,96 +0,0 @@
-package 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 2 project. Notice that it doesn't fail with Maven 3, but when Maven 2
- * and Maven 3 don't calculate the same transitive dependency result, the tree calculated with this component is
- * consistent with Maven 2 even if run with Maven 3 (see <a
- * href="http://jira.codehaus.org/browse/MSHARED-167">MSHARED-167</a>.
- *
- * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
- * @version $Id$
- */
-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;
-
- /**
- * @deprecated doesn't work with Maven 3
- */
- DependencyNode buildDependencyTree( MavenProject project )
- throws DependencyTreeBuilderException;
-
- /**
- * @since 2.1
- */
- DependencyNode buildDependencyTree( MavenProject project, ArtifactRepository repository, ArtifactFilter filter )
- throws DependencyTreeBuilderException;
-}
diff --git a/src/main/java/org/apache/maven/shared/dependency/tree/DependencyTreeBuilderException.java b/src/main/java/org/apache/maven/shared/dependency/tree/DependencyTreeBuilderException.java
deleted file mode 100644
index b4b2836..0000000
--- a/src/main/java/org/apache/maven/shared/dependency/tree/DependencyTreeBuilderException.java
+++ /dev/null
@@ -1,49 +0,0 @@
-package 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 <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
- * @version $Id$
- */
-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 );
- }
-}
diff --git a/src/main/java/org/apache/maven/shared/dependency/tree/DependencyTreeInverseIterator.java b/src/main/java/org/apache/maven/shared/dependency/tree/DependencyTreeInverseIterator.java
deleted file mode 100644
index bb93c6a..0000000
--- a/src/main/java/org/apache/maven/shared/dependency/tree/DependencyTreeInverseIterator.java
+++ /dev/null
@@ -1,69 +0,0 @@
-package 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 <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
- * @version $Id$
- */
-public class DependencyTreeInverseIterator
- implements Iterator<DependencyNode>
-{
- private Stack<DependencyNode> nodesToProcess = new Stack<DependencyNode>();
-
- public DependencyTreeInverseIterator( DependencyNode rootNode )
- {
- DependencyTreePreorderIterator it = new DependencyTreePreorderIterator( rootNode );
- while ( it.hasNext() )
- {
- nodesToProcess.push( it.next() );
- }
- }
-
- public boolean hasNext()
- {
- return !nodesToProcess.isEmpty();
- }
-
- public DependencyNode next()
- {
- if ( !hasNext() )
- {
- throw new NoSuchElementException();
- }
- return nodesToProcess.pop();
- }
-
- /**
- * @throws UnsupportedOperationException
- */
- public void remove()
- {
- throw new UnsupportedOperationException();
- }
-}
diff --git a/src/main/java/org/apache/maven/shared/dependency/tree/DependencyTreePreorderIterator.java b/src/main/java/org/apache/maven/shared/dependency/tree/DependencyTreePreorderIterator.java
deleted file mode 100644
index 958ce55..0000000
--- a/src/main/java/org/apache/maven/shared/dependency/tree/DependencyTreePreorderIterator.java
+++ /dev/null
@@ -1,73 +0,0 @@
-package 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 <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
- * @version $Id$
- */
-public class DependencyTreePreorderIterator
- implements Iterator<DependencyNode>
-{
- private Stack<DependencyNode> nodesToProcess = new Stack<DependencyNode>();
-
- public DependencyTreePreorderIterator( DependencyNode rootNode )
- {
- nodesToProcess.push( rootNode );
- }
-
- public boolean hasNext()
- {
- return !nodesToProcess.isEmpty();
- }
-
- public DependencyNode next()
- {
- if ( !hasNext() )
- {
- throw new NoSuchElementException();
- }
- DependencyNode currentNode = nodesToProcess.pop();
- List<DependencyNode> 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();
- }
-}
diff --git a/src/main/java/org/apache/maven/shared/dependency/tree/DependencyTreeResolutionListener.java b/src/main/java/org/apache/maven/shared/dependency/tree/DependencyTreeResolutionListener.java
deleted file mode 100644
index b8da755..0000000
--- a/src/main/java/org/apache/maven/shared/dependency/tree/DependencyTreeResolutionListener.java
+++ /dev/null
@@ -1,537 +0,0 @@
-package 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.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.codehaus.plexus.logging.Logger;
-
-/**
- * An artifact resolution listener that constructs a dependency tree.
- *
- * @author Edwin Punzalan
- * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
- * @version $Id$
- */
-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<DependencyNode> parentNodes;
-
- /**
- * A map of dependency nodes by their attached artifact.
- */
- private final Map<Artifact, DependencyNode> 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<String, String> managedVersions = new HashMap<String, String>();
-
- /**
- * Map < String replacementId, String premanaged scope >
- */
- private Map<String, String> managedScopes = new HashMap<String, String>();
-
- // 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<DependencyNode>();
- nodesByArtifact = new IdentityHashMap<Artifact, DependencyNode>();
- 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 = 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 org.apache.maven.shared.dependency.tree.traversal.CollectingDependencyNodeVisitor}
- * on the root dependency node
- */
- public Collection<DependencyNode> 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 = 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 = 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 <code>null</code> if the specified artifact has no corresponding dependency node
- */
- private DependencyNode getNode( Artifact artifact )
- {
- return 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 = 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 <code>true</code> if all the ancestors of the current dependency node have a state of
- * <code>INCLUDED</code>
- */
- private boolean isCurrentNodeIncluded()
- {
- for ( DependencyNode node : parentNodes )
- {
- if ( node.getState() != DependencyNode.INCLUDED )
- {
- return false;
- }
- }
-
- return true;
- }
-
- /**
- * Updates the specified node with any dependency management information cached in prior <code>manageArtifact</code>
- * calls.
- *
- * @param node the node to update
- */
- private void flushDependencyManagement( DependencyNode node )
- {
- Artifact artifact = node.getArtifact();
- String premanagedVersion = managedVersions.get( artifact.getId() );
- String premanagedScope = 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;
- }
- }
-}
diff --git a/src/main/java/org/apache/maven/shared/dependency/tree/filter/AncestorOrSelfDependencyNodeFilter.java b/src/main/java/org/apache/maven/shared/dependency/tree/filter/AncestorOrSelfDependencyNodeFilter.java
deleted file mode 100644
index c72d9aa..0000000
--- a/src/main/java/org/apache/maven/shared/dependency/tree/filter/AncestorOrSelfDependencyNodeFilter.java
+++ /dev/null
@@ -1,102 +0,0 @@
-package 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.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 <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
- * @version $Id$
- * @since 1.1
- */
-public class AncestorOrSelfDependencyNodeFilter
- implements DependencyNodeFilter
-{
- // fields -----------------------------------------------------------------
-
- /**
- * The list of nodes that this filter accepts ancestors-or-self of.
- */
- private final List<DependencyNode> 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<DependencyNode> descendantNodes )
- {
- this.descendantNodes = descendantNodes;
- }
-
- // DependencyNodeFilter methods -------------------------------------------
-
- /**
- * {@inheritDoc}
- */
- public boolean accept( DependencyNode node )
- {
- for ( DependencyNode descendantNode : descendantNodes )
- {
- if ( isAncestorOrSelf( node, descendantNode ) )
- {
- return true;
- }
- }
-
- return false;
- }
-
- // 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 <code>true</code> if <code>ancestorNode</code> is an ancestor, or equal to, <code>descendantNode</code>
- */
- private boolean isAncestorOrSelf( DependencyNode ancestorNode, DependencyNode descendantNode )
- {
- boolean ancestor = false;
-
- while ( !ancestor && descendantNode != null )
- {
- ancestor = ancestorNode.equals( descendantNode );
-
- descendantNode = descendantNode.getParent();
- }
-
- return ancestor;
- }
-}
diff --git a/src/main/java/org/apache/maven/shared/dependency/tree/filter/AndDependencyNodeFilter.java b/src/main/java/org/apache/maven/shared/dependency/tree/filter/AndDependencyNodeFilter.java
deleted file mode 100644
index 1202c23..0000000
--- a/src/main/java/org/apache/maven/shared/dependency/tree/filter/AndDependencyNodeFilter.java
+++ /dev/null
@@ -1,97 +0,0 @@
-package 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.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 <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
- * @version $Id$
- * @since 1.1
- */
-public class AndDependencyNodeFilter
- implements DependencyNodeFilter
-{
- // fields -----------------------------------------------------------------
-
- /**
- * The dependency node filters that this filter ANDs together.
- */
- private final List<DependencyNodeFilter> 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<DependencyNodeFilter> filters )
- {
- this.filters = Collections.unmodifiableList( filters );
- }
-
- // DependencyNodeFilter methods -------------------------------------------
-
- /**
- * {@inheritDoc}
- */
- public boolean accept( DependencyNode node )
- {
- for ( DependencyNodeFilter filter : filters )
- {
- if ( !filter.accept( node ) )
- {
- return false;
- }
- }
-
- return true;
- }
-
- // 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<DependencyNodeFilter> getDependencyNodeFilters()
- {
- return filters;
- }
-}
diff --git a/src/main/java/org/apache/maven/shared/dependency/tree/filter/ArtifactDependencyNodeFilter.java b/src/main/java/org/apache/maven/shared/dependency/tree/filter/ArtifactDependencyNodeFilter.java
deleted file mode 100644
index cac1f43..0000000
--- a/src/main/java/org/apache/maven/shared/dependency/tree/filter/ArtifactDependencyNodeFilter.java
+++ /dev/null
@@ -1,78 +0,0 @@
-package 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 <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
- * @version $Id$
- * @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;
- }
-}
diff --git a/src/main/java/org/apache/maven/shared/dependency/tree/filter/DependencyNodeFilter.java b/src/main/java/org/apache/maven/shared/dependency/tree/filter/DependencyNodeFilter.java
deleted file mode 100644
index 5fbe554..0000000
--- a/src/main/java/org/apache/maven/shared/dependency/tree/filter/DependencyNodeFilter.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package 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 <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
- * @version $Id$
- * @since 1.1
- */
-public interface DependencyNodeFilter
-{
- /**
- * Gets whether this filter accepts the specified dependency node.
- *
- * @param node the dependency node to check
- * @return <code>true</code> if this filter accepts the specified dependency node
- */
- boolean accept( DependencyNode node );
-}
diff --git a/src/main/java/org/apache/maven/shared/dependency/tree/filter/StateDependencyNodeFilter.java b/src/main/java/org/apache/maven/shared/dependency/tree/filter/StateDependencyNodeFilter.java
deleted file mode 100644
index 21756d4..0000000
--- a/src/main/java/org/apache/maven/shared/dependency/tree/filter/StateDependencyNodeFilter.java
+++ /dev/null
@@ -1,89 +0,0 @@
-package 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 <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
- * @version $Id$
- * @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;
- }
-}
diff --git a/src/main/java/org/apache/maven/shared/dependency/tree/traversal/BuildingDependencyNodeVisitor.java b/src/main/java/org/apache/maven/shared/dependency/tree/traversal/BuildingDependencyNodeVisitor.java
deleted file mode 100644
index 756405e..0000000
--- a/src/main/java/org/apache/maven/shared/dependency/tree/traversal/BuildingDependencyNodeVisitor.java
+++ /dev/null
@@ -1,144 +0,0 @@
-package 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 <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
- * @version $Id$
- * @since 1.1
- */
-public class BuildingDependencyNodeVisitor
- implements DependencyNodeVisitor
-{
- // fields -----------------------------------------------------------------
-
- /**
- * The dependency node visitor to apply on the resultant dependency tree, or <code>null</code> for none.
- */
- private final DependencyNodeVisitor visitor;
-
- /**
- * The resultant tree parent nodes for the currently visited node.
- */
- private final Stack<DependencyNode> 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 <code>null</code> for
- * none
- */
- public BuildingDependencyNodeVisitor( DependencyNodeVisitor visitor )
- {
- this.visitor = visitor;
-
- parentNodes = new Stack<DependencyNode>();
- }
-
- // 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 = 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 <code>null</code> 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 <code>null</code> if the source tree has not yet been visited
- */
- public DependencyNode getDependencyTree()
- {
- return rootNode;
- }
-}
diff --git a/src/main/java/org/apache/maven/shared/dependency/tree/traversal/CollectingDependencyNodeVisitor.java b/src/main/java/org/apache/maven/shared/dependency/tree/traversal/CollectingDependencyNodeVisitor.java
deleted file mode 100644
index 396c1e5..0000000
--- a/src/main/java/org/apache/maven/shared/dependency/tree/traversal/CollectingDependencyNodeVisitor.java
+++ /dev/null
@@ -1,87 +0,0 @@
-package 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 <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
- * @version $Id$
- * @since 1.1
- */
-public class CollectingDependencyNodeVisitor
- implements DependencyNodeVisitor
-{
- // fields -----------------------------------------------------------------
-
- /**
- * The collected list of nodes.
- */
- private final List<DependencyNode> nodes;
-
- // constructors -----------------------------------------------------------
-
- /**
- * Creates a dependency node visitor that collects visited nodes for further processing.
- */
- public CollectingDependencyNodeVisitor()
- {
- nodes = new ArrayList<DependencyNode>();
- }
-
- // 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<DependencyNode> getNodes()
- {
- return Collections.unmodifiableList( nodes );
- }
-}
diff --git a/src/main/java/org/apache/maven/shared/dependency/tree/traversal/DependencyNodeVisitor.java b/src/main/java/org/apache/maven/shared/dependency/tree/traversal/DependencyNodeVisitor.java
deleted file mode 100644
index 8ec30dc..0000000
--- a/src/main/java/org/apache/maven/shared/dependency/tree/traversal/DependencyNodeVisitor.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package 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 <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
- * @version $Id$
- * @since 1.1
- */
-public interface DependencyNodeVisitor
-{
- /**
- * Starts the visit to the specified dependency node.
- *
- * @param node the dependency node to visit
- * @return <code>true</code> to visit the specified dependency node's children, <code>false</code> 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 <code>true</code> to visit the specified dependency node's next sibling, <code>false</code> to skip the
- * specified dependency node's next siblings and proceed to its parent
- */
- boolean endVisit( DependencyNode node );
-}
diff --git a/src/main/java/org/apache/maven/shared/dependency/tree/traversal/FilteringDependencyNodeVisitor.java b/src/main/java/org/apache/maven/shared/dependency/tree/traversal/FilteringDependencyNodeVisitor.java
deleted file mode 100644
index 1eac512..0000000
--- a/src/main/java/org/apache/maven/shared/dependency/tree/traversal/FilteringDependencyNodeVisitor.java
+++ /dev/null
@@ -1,123 +0,0 @@
-package 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 <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
- * @version $Id$
- * @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;
- }
-}
diff --git a/src/main/java/org/apache/maven/shared/dependency/tree/traversal/SerializingDependencyNodeVisitor.java b/src/main/java/org/apache/maven/shared/dependency/tree/traversal/SerializingDependencyNodeVisitor.java
deleted file mode 100644
index 9e0d7a0..0000000
--- a/src/main/java/org/apache/maven/shared/dependency/tree/traversal/SerializingDependencyNodeVisitor.java
+++ /dev/null
@@ -1,236 +0,0 @@
-package 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 <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
- * @version $Id$
- * @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 <code>true</code> 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<DependencyNode> 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 <code>true</code> 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 );
- }
-}
diff --git a/src/test/java/org/apache/maven/shared/dependency/tree/AbstractDependencyNodeTest.java b/src/test/java/org/apache/maven/shared/dependency/tree/AbstractDependencyNodeTest.java
deleted file mode 100644
index 82ab94f..0000000
--- a/src/test/java/org/apache/maven/shared/dependency/tree/AbstractDependencyNodeTest.java
+++ /dev/null
@@ -1,93 +0,0 @@
-package 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 <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
- * @version $Id$
- */
-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;
- }
-}
diff --git a/src/test/java/org/apache/maven/shared/dependency/tree/ArtifactMetadataSourceStub.java b/src/test/java/org/apache/maven/shared/dependency/tree/ArtifactMetadataSourceStub.java
deleted file mode 100644
index 5e18f27..0000000
--- a/src/test/java/org/apache/maven/shared/dependency/tree/ArtifactMetadataSourceStub.java
+++ /dev/null
@@ -1,132 +0,0 @@
-package 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;
-import org.apache.maven.artifact.versioning.ArtifactVersion;
-
-/**
- * Provides a stub to simulate an artifact metadata source.
- *
- * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
- * @version $Id$
- */
-public class ArtifactMetadataSourceStub
- implements ArtifactMetadataSource
-{
- // TODO: move to maven-plugin-testing-harness?
-
- // fields -----------------------------------------------------------------
-
- /**
- * Map of resolution groups by artifact.
- */
- private final Map<Artifact, ResolutionGroup> resolutionGroupsByArtifact;
-
- /**
- * Map of available versions by artifact.
- */
- private final Map<Artifact, List<ArtifactVersion>> availableVersionsByArtifact;
-
- // constructors -----------------------------------------------------------
-
- /**
- * Creates a new artifact metadata source stub.
- */
- public ArtifactMetadataSourceStub()
- {
- resolutionGroupsByArtifact = new HashMap<Artifact, ResolutionGroup>();
- availableVersionsByArtifact = new HashMap<Artifact, List<ArtifactVersion>>();
- }
-
- // ArtifactMetadataSource methods -----------------------------------------
-
- /**
- * {@inheritDoc}
- */
- public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories )
- throws ArtifactMetadataRetrievalException
- {
- ResolutionGroup resolution = 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<ArtifactVersion> availableVersions = 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<Artifact> 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<ArtifactVersion> versions )
- {
- availableVersionsByArtifact.put( artifact, versions );
- }
-
- public Artifact retrieveRelocatedArtifact( Artifact artifact, ArtifactRepository localRepository,
- List remoteRepositories )
- throws ArtifactMetadataRetrievalException
- {
- return artifact;
- }
-}
diff --git a/src/test/java/org/apache/maven/shared/dependency/tree/DefaultDependencyTreeBuilderTest.java b/src/test/java/org/apache/maven/shared/dependency/tree/DefaultDependencyTreeBuilderTest.java
deleted file mode 100644
index 62bdf75..0000000
--- a/src/test/java/org/apache/maven/shared/dependency/tree/DefaultDependencyTreeBuilderTest.java
+++ /dev/null
@@ -1,812 +0,0 @@
-package 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 <code>DefaultDependencyTreeBuilder</code>.
- *
- * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
- * @version $Id$
- * @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:
- *
- * <pre>
- * g:p:t:1
- * \- g:a:t:1
- * </pre>
- *
- * @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:
- *
- * <pre>
- * g:p:t:1
- * \- g:a:t:1
- * \- g:b:t:1
- * </pre>
- *
- * @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:
- *
- * <pre>
- * g:p:t:1
- * +- g:a:t:1
- * | \- g:c:t:1
- * \- g:b:t:1
- * \- (g:c:t:1 - omitted for duplicate)
- * </pre>
- *
- * @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:
- *
- * <pre>
- * g:p:t:1
- * +- g:a:t:1
- * \- g:b:t:1
- * \- (g:a:t:2 - omitted for conflict with 1)
- * </pre>
- *
- * @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:
- *
- * <pre>
- * g:p:t:1
- * +- g:a:t:1
- * | \- (g:b:t:2 - omitted for conflict with 1)
- * \- g:b:t:1
- * </pre>
- *
- * @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:
- *
- * <pre>
- * 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)
- * </pre>
- *
- * @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:
- *
- * <pre>
- * 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)
- * </pre>
- *
- * @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: <pre> 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) </pre>
- * @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:
- *
- * <pre>
- * 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
- * </pre>
- *
- * @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: <pre> 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)
- * </pre>
- * @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:
- *
- * <pre>
- * g:p:t:1
- * \- g:a:t:1
- * \- g:b:t:2 (version managed from 1)
- * </pre>
- *
- * @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:
- *
- * <pre>
- * 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)
- * </pre>
- *
- * @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:
- *
- * <pre>
- * g:p:t:1
- * \- g:a:t:1
- * \- g:b:t:1:test (scope managed from compile)
- * </pre>
- *
- * @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:
- *
- * <pre>
- * g:p:t:1
- * \- g:a:t:1
- * \- g:b:t:2:test (version managed from 1; scope managed from compile)
- * </pre>
- *
- * @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:
- *
- * <pre>
- * 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)
- * </pre>
- *
- * @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
- *
- * <pre>
- * g:p:t:1
- * \- g:a:t:1
- * </pre>
- *
- * @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<ArtifactVersion> availableVersions = new ArrayList<ArtifactVersion>();
- 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<Artifact>( Arrays.asList( dependencyArtifacts ) ) );
- project.setManagedVersionMap( new HashMap<String, Artifact>() );
- 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<Artifact>( Arrays.asList( dependencyArtifacts ) ) );
- }
-
- private void addArtifactMetadata( Artifact artifact, Set<Artifact> dependencyArtifacts )
- {
- artifactMetadataSource.addArtifactMetadata( artifact, dependencyArtifacts );
- }
-
- private void setManagedVersionMap( MavenProject project, Set<Artifact> managedArtifacts )
- {
- Map<String, Artifact> managedVersionMap = new HashMap<String, Artifact>();
-
- for ( Artifact artifact : managedArtifacts )
- {
- 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<ResolutionNode> 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<DependencyNode> dependencyNodes, List<ResolutionNode> resolutionNodes )
- {
- assertNodesEquals( dependencyNodes.iterator(), resolutionNodes.iterator() );
- }
-
- private void assertNodesEquals( Iterator<DependencyNode> dependencyNodesIterator,
- Iterator<ResolutionNode> resolutionNodesIterator )
- {
- while ( dependencyNodesIterator.hasNext() && resolutionNodesIterator.hasNext() )
- {
- DependencyNode dependencyNode = dependencyNodesIterator.next();
- 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;
- }
-}
diff --git a/src/test/java/org/apache/maven/shared/dependency/tree/DependencyNodeTest.java b/src/test/java/org/apache/maven/shared/dependency/tree/DependencyNodeTest.java
deleted file mode 100644
index 5769d12..0000000
--- a/src/test/java/org/apache/maven/shared/dependency/tree/DependencyNodeTest.java
+++ /dev/null
@@ -1,275 +0,0 @@
-package 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 <code>DependencyNode</code>.
- *
- * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
- * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
- * @version $Id$
- * @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<DependencyNode> it, DependencyNode node )
- {
- assertTrue( it.hasNext() );
- assertSame( node, it.next() );
- }
-
- public void testPreorderIterator()
- {
- Iterator<DependencyNode> 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<DependencyNode> 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";
- }
-}
diff --git a/src/test/java/org/apache/maven/shared/dependency/tree/DependencyTreeResolutionListenerTest.java b/src/test/java/org/apache/maven/shared/dependency/tree/DependencyTreeResolutionListenerTest.java
deleted file mode 100644
index 9ad306a..0000000
--- a/src/test/java/org/apache/maven/shared/dependency/tree/DependencyTreeResolutionListenerTest.java
+++ /dev/null
@@ -1,414 +0,0 @@
-package 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 <code>DependencyTreeResolutionListener</code>.
- *
- * @author Edwin Punzalan
- * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
- * @version $Id$
- * @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 );
- }
-}
diff --git a/src/test/java/org/apache/maven/shared/dependency/tree/ResolutionNodeUtils.java b/src/test/java/org/apache/maven/shared/dependency/tree/ResolutionNodeUtils.java
deleted file mode 100644
index c3d412a..0000000
--- a/src/test/java/org/apache/maven/shared/dependency/tree/ResolutionNodeUtils.java
+++ /dev/null
@@ -1,136 +0,0 @@
-package 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 <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
- * @version $Id$
- * @see ResolutionNode
- */
-public final class ResolutionNodeUtils
-{
- // constructors -----------------------------------------------------------
-
- private ResolutionNodeUtils()
- {
- // private constructor for utility class
- }
-
- // public methods ---------------------------------------------------------
-
- public static List<ResolutionNode> getRootChildrenResolutionNodes( MavenProject project,
- ArtifactResolutionResult resolutionResult )
- {
- Set<ResolutionNode> resolutionNodes = resolutionResult.getArtifactResolutionNodes();
-
- // obtain root children nodes
-
- Map<Artifact, ResolutionNode> rootChildrenResolutionNodesByArtifact = new HashMap<Artifact, ResolutionNode>();
-
- for ( ResolutionNode resolutionNode : resolutionNodes )
- {
- if ( resolutionNode.isChildOfRootNode() )
- {
- rootChildrenResolutionNodesByArtifact.put( resolutionNode.getArtifact(), resolutionNode );
- }
- }
-
- // order root children by project dependencies
-
- List<ResolutionNode> rootChildrenResolutionNodes = new ArrayList<ResolutionNode>();
-
- for ( Iterator<Artifact> iterator = project.getDependencyArtifacts().iterator(); iterator.hasNext(); )
- {
- Artifact artifact = iterator.next();
- 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<ResolutionNode> rootChildrenNodes = getRootChildrenResolutionNodes( project, result );
- append( buffer, rootChildrenNodes.iterator(), 1 );
-
- return buffer;
- }
-
- // private methods --------------------------------------------------------
-
- private static StringBuffer append( StringBuffer buffer, Iterator<ResolutionNode> nodesIterator, int depth )
- {
- while ( nodesIterator.hasNext() )
- {
- ResolutionNode node = 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;
- }
-}
diff --git a/src/test/java/org/apache/maven/shared/dependency/tree/filter/AbstractDependencyNodeFilterTest.java b/src/test/java/org/apache/maven/shared/dependency/tree/filter/AbstractDependencyNodeFilterTest.java
deleted file mode 100644
index dead78d..0000000
--- a/src/test/java/org/apache/maven/shared/dependency/tree/filter/AbstractDependencyNodeFilterTest.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package 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 <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
- * @version $Id$
- */
-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();
- }
-}
diff --git a/src/test/java/org/apache/maven/shared/dependency/tree/filter/AncestorOrSelfDependencyNodeFilterTest.java b/src/test/java/org/apache/maven/shared/dependency/tree/filter/AncestorOrSelfDependencyNodeFilterTest.java
deleted file mode 100644
index 4e22340..0000000
--- a/src/test/java/org/apache/maven/shared/dependency/tree/filter/AncestorOrSelfDependencyNodeFilterTest.java
+++ /dev/null
@@ -1,114 +0,0 @@
-package 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 <code>AncestorOrSelfDependencyNodeFilter</code>.
- *
- * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
- * @version $Id$
- * @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 ) );
- }
-}
diff --git a/src/test/java/org/apache/maven/shared/dependency/tree/filter/AndDependencyNodeFilterTest.java b/src/test/java/org/apache/maven/shared/dependency/tree/filter/AndDependencyNodeFilterTest.java
deleted file mode 100644
index 34cafe7..0000000
--- a/src/test/java/org/apache/maven/shared/dependency/tree/filter/AndDependencyNodeFilterTest.java
+++ /dev/null
@@ -1,92 +0,0 @@
-package 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 <code>AndDependencyNodeFilter</code>.
- *
- * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
- * @version $Id$
- * @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 ) );
- }
-}
diff --git a/src/test/java/org/apache/maven/shared/dependency/tree/filter/ArtifactDependencyNodeFilterTest.java b/src/test/java/org/apache/maven/shared/dependency/tree/filter/ArtifactDependencyNodeFilterTest.java
deleted file mode 100644
index dad9055..0000000
--- a/src/test/java/org/apache/maven/shared/dependency/tree/filter/ArtifactDependencyNodeFilterTest.java
+++ /dev/null
@@ -1,89 +0,0 @@
-package 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 <code>ArtifactDependencyNodeFilter</code>.
- *
- * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
- * @version $Id$
- * @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();
- }
-}
diff --git a/src/test/java/org/apache/maven/shared/dependency/tree/filter/StateDependencyNodeFilterTest.java b/src/test/java/org/apache/maven/shared/dependency/tree/filter/StateDependencyNodeFilterTest.java
deleted file mode 100644
index 9b2f34a..0000000
--- a/src/test/java/org/apache/maven/shared/dependency/tree/filter/StateDependencyNodeFilterTest.java
+++ /dev/null
@@ -1,108 +0,0 @@
-package 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 <code>StateDependencyNodeFilter</code>.
- *
- * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
- * @version $Id$
- * @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 ) );
- }
-}
diff --git a/src/test/java/org/apache/maven/shared/dependency/tree/traversal/BuildingDependencyNodeVisitorTest.java b/src/test/java/org/apache/maven/shared/dependency/tree/traversal/BuildingDependencyNodeVisitorTest.java
deleted file mode 100644
index 8bad217..0000000
--- a/src/test/java/org/apache/maven/shared/dependency/tree/traversal/BuildingDependencyNodeVisitorTest.java
+++ /dev/null
@@ -1,195 +0,0 @@
-package 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 <code>BuildingDependencyNodeVisitor</code>.
- *
- * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
- * @version $Id$
- * @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 );
- }
-}
diff --git a/src/test/java/org/apache/maven/shared/dependency/tree/traversal/CollectingDependencyNodeVisitorTest.java b/src/test/java/org/apache/maven/shared/dependency/tree/traversal/CollectingDependencyNodeVisitorTest.java
deleted file mode 100644
index 50269fa..0000000
--- a/src/test/java/org/apache/maven/shared/dependency/tree/traversal/CollectingDependencyNodeVisitorTest.java
+++ /dev/null
@@ -1,104 +0,0 @@
-package 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 <code>CollectingDependencyNodeVisitor</code>.
- *
- * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
- * @version $Id$
- * @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 DependencyNode[] { node1, node2, node3 } ) );
- }
-
- public void testEndVisit()
- {
- assertEmptyNodes();
- assertTrue( visitor.endVisit( node1 ) );
- assertEmptyNodes();
- }
-
- // private methods --------------------------------------------------------
-
- private void assertEmptyNodes()
- {
- assertNodes( Collections.<DependencyNode> emptyList() );
- }
-
- private void assertNodes( DependencyNode node )
- {
- assertNodes( Collections.singletonList( node ) );
- }
-
- private void assertNodes( List<DependencyNode> expectedNodes )
- {
- assertEquals( "Collected nodes", expectedNodes, visitor.getNodes() );
- }
-}
diff --git a/src/test/java/org/apache/maven/shared/dependency/tree/traversal/FilteringDependencyNodeVisitorTest.java b/src/test/java/org/apache/maven/shared/dependency/tree/traversal/FilteringDependencyNodeVisitorTest.java
deleted file mode 100644
index f7898e9..0000000
--- a/src/test/java/org/apache/maven/shared/dependency/tree/traversal/FilteringDependencyNodeVisitorTest.java
+++ /dev/null
@@ -1,119 +0,0 @@
-package 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 <code>FilteringDependencyNodeVisitor</code>.
- *
- * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
- * @version $Id$
- * @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 ) );
- }
-}
diff --git a/src/test/java/org/apache/maven/shared/dependency/tree/traversal/SerializingDependencyNodeVisitorTest.java b/src/test/java/org/apache/maven/shared/dependency/tree/traversal/SerializingDependencyNodeVisitorTest.java
deleted file mode 100644
index 4ad1173..0000000
--- a/src/test/java/org/apache/maven/shared/dependency/tree/traversal/SerializingDependencyNodeVisitorTest.java
+++ /dev/null
@@ -1,120 +0,0 @@
-package 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 <code>SerializingDependencyNodeVisitor</code>.
- *
- * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
- * @version $Id$
- * @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() );
- }
-}