/** * Gets the depth of this dependency node within its hierarchy. * * @return the depth * @deprecated As of 1.1, depth is computed by node hierarchy. With the introduction of node visitors and filters * this method can give misleading results. For example, consider serializing a tree with a filter using * a visitor: this method would return the unfiltered depth of a node, whereas the correct depth would * be calculated by the visitor. */ public int getDepth() { int depth = 0; DependencyNode node = getParent(); while ( node != null ) { depth++; node = node.getParent(); } return depth; }
/** * Gets whether the specified dependency node ancestor is the last of its siblings. * * @param node the dependency node whose ancestor to check * @param ancestorDepth the depth of the ancestor of the specified dependency node to check * @return <code>true</code> if the specified dependency node ancestor is the last of its siblings */ private boolean isLast( DependencyNode node, int ancestorDepth ) { // TODO: remove node argument and calculate from visitor calls only int distance = depth - ancestorDepth; while ( distance-- > 0 ) { node = node.getParent(); } return isLast( node ); } }
/** * Gets whether the first dependency node is an ancestor-or-self of the second. * * @param ancestorNode the ancestor-or-self dependency node * @param descendantNode the dependency node to test * @return <code>true</code> if <code>ancestorNode</code> is an ancestor, or equal to, <code>descendantNode</code> */ private boolean isAncestorOrSelf( DependencyNode ancestorNode, DependencyNode descendantNode ) { boolean ancestor = false; while ( !ancestor && descendantNode != null ) { ancestor = ancestorNode.equals( descendantNode ); descendantNode = descendantNode.getParent(); } return ancestor; } }
/** * Gets whether the specified dependency node ancestor is the last of its siblings. * * @param node the dependency node whose ancestor to check * @param ancestorDepth the depth of the ancestor of the specified dependency node to check * @return <code>true</code> if the specified dependency node ancestor is the last of its siblings */ private boolean isLast( DependencyNode node, int ancestorDepth ) { // TODO: remove node argument and calculate from visitor calls only int distance = depth - ancestorDepth; while ( distance-- > 0 ) { node = node.getParent(); } return isLast( node ); } }
/** * 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; }
/** * 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; }
private StringBuilder buildTreeString( DependencyNode node ) { List<String> loc = new ArrayList<String>(); DependencyNode currentNode = node; while ( currentNode != null ) { loc.add( getFullArtifactName( currentNode.getArtifact() ) ); currentNode = currentNode.getParent(); } Collections.reverse( loc ); StringBuilder builder = new StringBuilder(); for ( int i = 0; i < loc.size(); i++ ) { for ( int j = 0; j < i; j++ ) { builder.append( " " ); } builder.append( "+-" + loc.get( i ) ); builder.append( "\n" ); } return builder; }
private StringBuilder buildTreeString( DependencyNode node ) { List<String> loc = new ArrayList<String>(); DependencyNode currentNode = node; while ( currentNode != null ) { loc.add( getFullArtifactName( currentNode.getArtifact() ) ); currentNode = currentNode.getParent(); } Collections.reverse( loc ); StringBuilder builder = new StringBuilder(); for ( int i = 0; i < loc.size(); i++ ) { for ( int j = 0; j < i; j++ ) { builder.append( " " ); } builder.append( "+-" + loc.get( i ) ); builder.append( System.lineSeparator() ); } return builder; }
private StringBuilder buildTreeString( DependencyNode node ) { List<String> loc = new ArrayList<String>(); DependencyNode currentNode = node; while ( currentNode != null ) { StringBuilder line = new StringBuilder( getFullArtifactName( currentNode, false ) ); if ( currentNode.getPremanagedVersion() != null ) { line.append( " (managed) <-- " ); line.append( getFullArtifactName( currentNode, true ) ); } loc.add( line.toString() ); currentNode = currentNode.getParent(); } Collections.reverse( loc ); StringBuilder builder = new StringBuilder(); for ( int i = 0; i < loc.size(); i++ ) { for ( int j = 0; j < i; j++ ) { builder.append( " " ); } builder.append( "+-" ).append( loc.get( i ) ); builder.append( "\n" ); } return builder; }
private StringBuilder buildTreeString( DependencyNode node ) { List<String> loc = new ArrayList<String>(); DependencyNode currentNode = node; while ( currentNode != null ) { StringBuilder line = new StringBuilder( getFullArtifactName( currentNode, false ) ); if ( currentNode.getPremanagedVersion() != null ) { line.append( " (managed) <-- " ); line.append( getFullArtifactName( currentNode, true ) ); } loc.add( line.toString() ); currentNode = currentNode.getParent(); } Collections.reverse( loc ); StringBuilder builder = new StringBuilder(); for ( int i = 0; i < loc.size(); i++ ) { for ( int j = 0; j < i; j++ ) { builder.append( " " ); } builder.append( "+-" ).append( loc.get( i ) ); builder.append( System.lineSeparator() ); } return builder; }
public boolean visit(DependencyNode node) { //TODO - Do we care about provided scope? Artifact artifact = node.getArtifact(); _log.debug("checking ["+artifact+"] for scala version"); //TODO - Handle version ranges???? does that make sense given scala's binary incompatability! if(isScalaDistroArtifact(artifact) && artifact.getVersion() != null) { VersionNumber originalVersion = new VersionNumber(artifact.getVersion()); if(originalVersion.compareTo(_version) != 0) { _failed = true; } //If this dependency is transitive, we want to track which artifact requires this... if(node.getParent() != null) { //TODO - Go all the way up the parent chain till we hit the bottom.... final Artifact parentArtifact = node.getParent().getArtifact(); scalaDependentArtifactStrings.add(" " + StringUtil.makeArtifactNameString(parentArtifact) + " requires scala version: " + originalVersion); } } else { //TODO - What now? } return !_failed; }
protected void saveDependency(final Project project, DependencyNode node, SensorContext context) { Resource from = (node.getParent().getParent() == null) ? index.getProject() : toResource(project, node.getParent().getArtifact(), context); Resource to = toResource(project, node.getArtifact(), context); Dependency dependency = new Dependency(from, to); dependency.setUsage(node.getArtifact().getScope()); dependency.setWeight(1); context.saveDependency(dependency); }
/** * {@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; }