@Override protected boolean createKeys(List<DependencyNode> toPopulate) { toPopulate.addAll(dn.getChildren()); return true; } }, false);
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; }
private String traverseNode(DependencyNode node) { Artifact artifact = node.getArtifact(); if ((protobufGroupId.equals(artifact.getGroupId()) && (protobufArtifactId.equals(artifact.getArtifactId())))){ return artifact.getVersion(); } for (Object o: node.getChildren()){ DependencyNode child = (DependencyNode)o; String result = traverseNode(child); if (result!=null) return result; } return null; } }
/** * 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; }
/** * Get all descendants nodes for a given dependency node. * * @param node * @return set of descendants artifacts. */ private Set<Artifact> getAllDescendants( DependencyNode node ) { Set<Artifact> children = null; if ( node.getChildren() != null ) { children = new HashSet<>(); for ( DependencyNode depNode : node.getChildren() ) { children.add( depNode.getArtifact() ); Set<Artifact> subNodes = getAllDescendants( depNode ); if ( subNodes != null ) { children.addAll( subNodes ); } } } return children; }
/** * 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; }
@Override public boolean visit(DependencyNode node) { if (root == null) { root = node; lst = new ArrayList<DependencyNode>(); } for (DependencyNode ch : node.getChildren()) { if (ch.getState() == DependencyNode.INCLUDED && scopes.contains(ch.getArtifact().getScope())) { lst.add(ch); } } return true; }
private void collect(final DependencyNode root, final Set<Artifact> artifacts) { Stack<DependencyNode> stack = new Stack<DependencyNode>(); stack.push(root); while (!stack.isEmpty()) { DependencyNode node = stack.pop(); if (node.getState() == DependencyNode.INCLUDED) { final Artifact artifact = node.getArtifact(); if (includedScope(artifact.getScope())) { getLog().info("Adding Artefact: " + artifact.toString()); artifacts.add(artifact); // check children if (!node.getChildren().isEmpty()) { stack.addAll(node.getChildren()); } } } } }
private Set<Artifact> getDependenciesToCheck( MavenProject project, ArtifactRepository localRepository ) { Set<Artifact> dependencies = null; try { DependencyNode node = treeBuilder.buildDependencyTree( project, localRepository, null ); if( isSearchTransitive() ) { dependencies = getAllDescendants( node ); } else if ( node.getChildren() != null ) { dependencies = new HashSet<Artifact>(); for( DependencyNode depNode : node.getChildren() ) { dependencies.add( depNode.getArtifact() ); } } } catch ( DependencyTreeBuilderException e ) { // otherwise we need to change the signature of this protected method throw new RuntimeException( e ); } return dependencies; }
artifactCollector); boolean modified = false; Iterator it = node.getChildren().listIterator(); while ( it.hasNext() ) Iterator it2 = n2.getChildren().listIterator(); while ( it2.hasNext() )
/** * 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 ); }
private Set<Artifact> getAllDescendants( DependencyNode node ) if( node.getChildren() != null ) for( DependencyNode depNode : node.getChildren() )
final DependencyNode rootNode = dependencyTreeBuilder.buildDependencyTree(coreProject, localRepository, artifactFactory, artifactMetadataSource, artifactFilter, artifactCollector); for (final Iterator<?> iterator = rootNode.getChildren().iterator(); iterator.hasNext();) { final DependencyNode child = (DependencyNode) iterator.next(); collect(child, artifacts);
node.getPremanagedScope(), versionSelectedFromRange ); List<DependencyNode> nodes = new ArrayList<DependencyNode>( node.getChildren().size() ); for ( org.apache.maven.shared.dependency.tree.DependencyNode child : node.getChildren() )
/** * {@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; }