001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019
020 package org.apache.geronimo.genesis.plugins.tools;
021
022 import java.util.Iterator;
023
024 import org.apache.maven.artifact.Artifact;
025 import org.apache.maven.artifact.repository.ArtifactRepository;
026 import org.apache.maven.project.MavenProject;
027 import org.apache.maven.plugin.MojoExecutionException;
028 import org.apache.maven.plugin.MojoFailureException;
029
030 import org.apache.geronimo.genesis.dependency.DependencyHelper;
031 import org.apache.geronimo.genesis.dependency.DependencyTree;
032 import org.apache.geronimo.genesis.dependency.DependencyTree.Node;
033 import org.apache.geronimo.genesis.MojoSupport;
034
035 /**
036 * Helper to show a projects dependencies.
037 *
038 * @goal show-dependencies
039 *
040 * @version $Rev: 454267 $ $Date: 2006-10-08 20:20:28 -0700 (Sun, 08 Oct 2006) $
041 */
042 public class ShowDependenciesMojo
043 extends MojoSupport
044 {
045 /**
046 * Enable verbose details (version and scope).
047 *
048 * @parameter expression="${verbose}"
049 */
050 private boolean verbose = false;
051
052 /**
053 * @component
054 */
055 private DependencyHelper helper = null;
056
057 /**
058 * @parameter expression="${project}"
059 * @required
060 * @readonly
061 */
062 protected MavenProject project;
063
064 /**
065 * @parameter expression="${localRepository}"
066 * @required
067 * @readonly
068 */
069 protected ArtifactRepository repository;
070
071 protected void init() throws MojoExecutionException, MojoFailureException {
072 super.init();
073
074 helper.setArtifactRepository(repository);
075 }
076
077 protected void doExecute() throws Exception {
078 DependencyTree dependencies = helper.getDependencies(project);
079 printDependencyListing(dependencies.getRootNode(), "");
080 }
081
082 private void printDependencyListing(final Node node, final String pad) {
083 Artifact artifact = node.getArtifact();
084 String id = artifact.getDependencyConflictId();
085
086 StringBuffer buff = new StringBuffer(id);
087 if (verbose) {
088 buff.append(" ");
089 buff.append("{ version=").append(artifact.getVersion());
090 buff.append(", scope=").append(artifact.getScope());
091 buff.append(" }");
092 }
093 log.info(pad + buff);
094
095 if (!node.getChildren().isEmpty()) {
096 Iterator children = node.getChildren().iterator();
097
098 while (children.hasNext()) {
099 Node child = (Node) children.next();
100 printDependencyListing(child, pad + " ");
101 }
102 }
103 }
104 }