elharo commented on a change in pull request #92: URL: https://github.com/apache/maven-dependency-plugin/pull/92#discussion_r467868212
########## File path: src/main/java/org/apache/maven/plugins/dependency/tree/verbose/VerboseDependencyGraphBuilder.java ########## @@ -0,0 +1,332 @@ +package org.apache.maven.plugins.dependency.tree.verbose; + +/* + * 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.model.DependencyManagement; +import org.apache.maven.model.Model; +import org.apache.maven.model.Repository; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.project.MavenProject; +import org.eclipse.aether.DefaultRepositorySystemSession; +import org.eclipse.aether.RepositorySystem; +import org.eclipse.aether.artifact.Artifact; +import org.eclipse.aether.artifact.DefaultArtifact; +import org.eclipse.aether.collection.CollectRequest; +import org.eclipse.aether.graph.DefaultDependencyNode; +import org.eclipse.aether.graph.Dependency; +import org.eclipse.aether.graph.DependencyNode; +import org.eclipse.aether.repository.RemoteRepository; +import org.eclipse.aether.resolution.DependencyRequest; +import org.eclipse.aether.resolution.DependencyResult; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import static org.apache.maven.plugins.dependency.tree.verbose.RepositoryUtility.mavenRepositoryFromUrl; + +/** + * Builds the VerboseDependencyGraph + */ +public class VerboseDependencyGraphBuilder Review comment: Yes, I think we should drop the verbose package. It's better to keep things non-public where you can. ########## File path: src/main/java/org/apache/maven/plugins/dependency/tree/TreeMojo.java ########## @@ -309,6 +352,64 @@ public void setSkip( boolean skip ) // private methods -------------------------------------------------------- + + private DependencyNode convertToCustomDependencyNode( org.eclipse.aether.graph.DependencyNode node ) + { + DefaultDependencyNode rootNode = new DefaultDependencyNode( null, + convertAetherArtifactToMavenArtifact( node ), null, null, null ); + + rootNode.setChildren( new ArrayList<DependencyNode>() ); + + for ( org.eclipse.aether.graph.DependencyNode child : node.getChildren() ) + { + rootNode.getChildren().add( buildTreeDfs( rootNode, child ) ); + } + + return rootNode; + } + + private DependencyNode buildTreeDfs( DependencyNode parent, org.eclipse.aether.graph.DependencyNode child ) Review comment: buildTreeDepthFirst? why does it matter whether we build tree depth first or breadth first if it's the same tree? ########## File path: pom.xml ########## @@ -456,7 +446,7 @@ under the License. <mockRepo> <source>src/it/mrm/repository</source> </mockRepo> - <!-- + <!-- Review comment: why not just delete the commented element? ########## File path: src/main/java/org/apache/maven/plugins/dependency/tree/TreeMojo.java ########## @@ -267,6 +306,10 @@ public void execute() { throw new MojoExecutionException( "Cannot serialise project dependency graph", exception ); } + catch ( DependencyResolutionException e ) + { + e.printStackTrace(); Review comment: stack trace might not be very helpful since this is an external issue, not a code issue; is there a logger we can report to instead? ########## File path: src/main/java/org/apache/maven/plugins/dependency/tree/verbose/CycleBreakerGraphTransformer.java ########## @@ -0,0 +1,88 @@ +package org.apache.maven.plugins.dependency.tree.verbose; + +/* + * 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.eclipse.aether.artifact.Artifact; +import org.eclipse.aether.collection.DependencyGraphTransformationContext; +import org.eclipse.aether.collection.DependencyGraphTransformer; +import org.eclipse.aether.graph.DependencyNode; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.IdentityHashMap; +import java.util.Map; +import java.util.Set; + +/** + * Transforms a dependency graph so that it does not contain cycles. + * + * <p>A cycle in a dependency graph is a situation where a path to a node from the root contains the + * same node. For example, jaxen 1.1-beta-6 is known to have cycle with dom4j 1.6.1. + */ +public final class CycleBreakerGraphTransformer implements DependencyGraphTransformer +{ + + private final Set<DependencyNode> visitedNodes = Collections.newSetFromMap( Review comment: why are we starting with an empty IdentityHashmap map here? I would think a simple HashSet would suffice. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
