View Javadoc

1   package org.apache.maven.shared.dependency.tree;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.ArrayList;
23  import java.util.Collection;
24  import java.util.Iterator;
25  import java.util.List;
26  
27  /**
28   * Represents a Maven project's dependency tree.
29   * 
30   * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
31   * @version $Id: DependencyTree.java 661727 2008-05-30 14:21:49Z bentmann $
32   * @deprecated As of 1.1, replaced by the dependency tree root {@link DependencyNode}
33   */
34  public class DependencyTree
35  {
36      // fields -----------------------------------------------------------------
37  
38      private final DependencyNode rootNode;
39  
40      private final Collection nodes;
41  
42      // constructors -----------------------------------------------------------
43  
44      /**
45       * Create a tree initialized to the arguments
46       * 
47       * @param rootNode
48       * @param nodes
49       */
50      public DependencyTree( DependencyNode rootNode, Collection nodes )
51      {
52          this.rootNode = rootNode;
53          this.nodes = nodes;
54      }
55  
56      // public methods ---------------------------------------------------------
57  
58      public DependencyNode getRootNode()
59      {
60          return rootNode;
61      }
62  
63      public Collection getNodes()
64      {
65          return nodes;
66      }
67  
68      public List getArtifacts()
69      {
70          List artifacts = new ArrayList();
71  
72          Iterator it = getNodes().iterator();
73          while ( it.hasNext() )
74          {
75              DependencyNode node = (DependencyNode) it.next();
76              artifacts.add( node.getArtifact() );
77          }
78  
79          return artifacts;
80      }
81  
82      public String toString()
83      {
84          return getRootNode().toString();
85      }
86  
87      /**
88       * @see DependencyNode#iterator()
89       */
90      public Iterator iterator()
91      {
92          return getRootNode().iterator();
93      }
94  
95      /**
96       * @see DependencyNode#preorderIterator()
97       */
98      public Iterator preorderIterator()
99      {
100         return getRootNode().preorderIterator();
101     }
102 
103     /**
104      * @see DependencyNode#inverseIterator()
105      */
106     public Iterator inverseIterator()
107     {
108         return getRootNode().inverseIterator();
109     }
110 }