View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *  http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.geronimo.genesis.plugins.tools;
21  
22  import java.util.Iterator;
23  
24  import org.apache.maven.artifact.Artifact;
25  import org.apache.maven.artifact.repository.ArtifactRepository;
26  import org.apache.maven.project.MavenProject;
27  import org.apache.maven.plugin.MojoExecutionException;
28  import org.apache.maven.plugin.MojoFailureException;
29  
30  import org.apache.geronimo.genesis.dependency.DependencyHelper;
31  import org.apache.geronimo.genesis.dependency.DependencyTree;
32  import org.apache.geronimo.genesis.dependency.DependencyTree.Node;
33  import org.apache.geronimo.genesis.MojoSupport;
34  
35  /**
36   * Helper to show a projects dependencies.
37   *
38   * @goal show-dependencies
39   * 
40   * @version $Rev: 454267 $ $Date: 2006-10-08 20:20:28 -0700 (Sun, 08 Oct 2006) $
41   */
42  public class ShowDependenciesMojo
43      extends MojoSupport
44  {
45      /**
46       * Enable verbose details (version and scope).
47       * 
48       * @parameter expression="${verbose}"
49       */
50      private boolean verbose = false;
51  
52      /**
53       * @component
54       */
55      private DependencyHelper helper = null;
56  
57      /**
58       * @parameter expression="${project}"
59       * @required
60       * @readonly
61       */
62      protected MavenProject project;
63  
64      /**
65       * @parameter expression="${localRepository}"
66       * @required
67       * @readonly
68       */
69      protected ArtifactRepository repository;
70  
71      protected void init() throws MojoExecutionException, MojoFailureException {
72          super.init();
73          
74          helper.setArtifactRepository(repository);
75      }
76  
77      protected void doExecute() throws Exception {
78          DependencyTree dependencies = helper.getDependencies(project);
79          printDependencyListing(dependencies.getRootNode(), "");
80      }
81  
82      private void printDependencyListing(final Node node, final String pad) {
83          Artifact artifact = node.getArtifact();
84          String id = artifact.getDependencyConflictId();
85  
86          StringBuffer buff = new StringBuffer(id);
87          if (verbose) {
88              buff.append(" ");
89              buff.append("{ version=").append(artifact.getVersion());
90              buff.append(", scope=").append(artifact.getScope());
91              buff.append(" }");
92          }
93          log.info(pad + buff);
94  
95          if (!node.getChildren().isEmpty()) {
96              Iterator children = node.getChildren().iterator();
97              
98              while (children.hasNext()) {
99                  Node child = (Node) children.next();
100                 printDependencyListing(child, pad + "    ");
101             }
102         }
103     }
104 }