private static boolean searchTree ( DependencyNode node , int level , ArtifactMatcher excludes , StringBuilder message ) throws InvalidVersionSpecificationException { List < DependencyNode > children = node . getChildren ( ) ; /* * if the node is deeper than direct dependency and is empty, it is transitive. */ boolean hasTransitiveDependencies = level > 1 ; boolean excluded = false ; /* * holds recursive message from children, will be appended to current message if this node has any transitive * descendants if message is null, don't generate recursive message. */ StringBuilder messageFromChildren = message == null ? null : new StringBuilder ( ) ; if ( excludes . match ( node . getArtifact ( ) ) ) { // is excluded, we don't care about descendants excluded = true ; hasTransitiveDependencies = false ; } else { for ( DependencyNode childNode : children ) { /* * if any of the children has transitive d. so does the parent */ hasTransitiveDependencies = ( searchTree ( childNode , level + 1 , excludes , messageFromChildren ) || hasTransitiveDependencies ) ; } } if ( ( excluded || hasTransitiveDependencies ) && message != null ) // then generate message { for ( int i = 0 ; i < level ; i ++ ) { message . append ( " " ) ; } message . append ( node . getArtifact ( ) ) ; if ( excluded ) { message . append ( " [excluded]\n" ) ; } if ( hasTransitiveDependencies ) { if ( level == 1 ) { message . append ( " has transitive dependencies:" ) ; } message . append ( "\n" ) . append ( messageFromChildren ) ; } } return hasTransitiveDependencies ; }
Searches dependency tree recursively for transitive dependencies that are not excluded while generating nice info message along the way .