Coverage Report - org.apache.maven.shared.dependency.graph.internal.DefaultDependencyNode
 
Classes in this File Line Coverage Branch Coverage Complexity
DefaultDependencyNode
0 %
0/31
0 %
0/12
1,571
DefaultDependencyNode$ItemAppender
0 %
0/17
0 %
0/4
1,571
 
 1  
 package org.apache.maven.shared.dependency.graph.internal;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *  http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import java.util.List;
 23  
 
 24  
 import org.apache.maven.artifact.Artifact;
 25  
 import org.apache.maven.shared.dependency.graph.DependencyNode;
 26  
 import org.apache.maven.shared.dependency.graph.traversal.DependencyNodeVisitor;
 27  
 
 28  
 public class DefaultDependencyNode
 29  
     implements DependencyNode
 30  
 {
 31  
     private final Artifact artifact;
 32  
 
 33  
     private final DependencyNode parent;
 34  
 
 35  
     private final String premanagedVersion;
 36  
 
 37  
     private final String premanagedScope;
 38  
 
 39  
     private final String versionConstraint;
 40  
 
 41  
     private List<DependencyNode> children;
 42  
 
 43  
     public DefaultDependencyNode( DependencyNode parent, Artifact artifact, String premanagedVersion,
 44  
                                   String premanagedScope, String versionConstraint )
 45  0
     {
 46  0
         this.parent = parent;
 47  0
         this.artifact = artifact;
 48  0
         this.premanagedVersion = premanagedVersion;
 49  0
         this.premanagedScope = premanagedScope;
 50  0
         this.versionConstraint = versionConstraint;
 51  0
     }
 52  
 
 53  
     /**
 54  
      * Applies the specified dependency node visitor to this dependency node and its children.
 55  
      * 
 56  
      * @param visitor
 57  
      *            the dependency node visitor to use
 58  
      * @return the visitor result of ending the visit to this node
 59  
      * @since 1.1
 60  
      */
 61  
     public boolean accept( DependencyNodeVisitor visitor )
 62  
     {
 63  0
         if ( visitor.visit( this ) )
 64  
         {
 65  0
             for ( DependencyNode child : getChildren() )
 66  
             {
 67  0
                 if ( !child.accept( visitor ) )
 68  
                 {
 69  0
                     break;
 70  
                 }
 71  
             }
 72  
         }
 73  
 
 74  0
         return visitor.endVisit( this );
 75  
     }
 76  
 
 77  
     public Artifact getArtifact()
 78  
     {
 79  0
         return artifact;
 80  
     }
 81  
 
 82  
     public void setChildren( List<DependencyNode> children )
 83  
     {
 84  0
         this.children = children;
 85  0
     }
 86  
 
 87  
     public List<DependencyNode> getChildren()
 88  
     {
 89  0
         return children;
 90  
     }
 91  
 
 92  
     public DependencyNode getParent()
 93  
     {
 94  0
         return parent;
 95  
     }
 96  
 
 97  
     public String getPremanagedVersion()
 98  
     {
 99  0
         return premanagedVersion;
 100  
     }
 101  
 
 102  
     public String getPremanagedScope()
 103  
     {
 104  0
         return premanagedScope;
 105  
     }
 106  
 
 107  
     public String getVersionConstraint()
 108  
     {
 109  0
         return versionConstraint;
 110  
     }
 111  
 
 112  
     public String toNodeString()
 113  
     {
 114  0
         StringBuffer buffer = new StringBuffer();
 115  
 
 116  0
         buffer.append( artifact );
 117  
         
 118  0
         ItemAppender appender = new ItemAppender( buffer, " (", "; ", ")" );
 119  
 
 120  0
         if ( getPremanagedVersion() != null )
 121  
         {
 122  0
             appender.append( "version managed from ", getPremanagedVersion() );
 123  
         }
 124  
             
 125  0
         if ( getPremanagedScope() != null )
 126  
         {
 127  0
             appender.append( "scope managed from ", getPremanagedScope() );
 128  
         }
 129  
         
 130  0
         if ( getVersionConstraint() != null )
 131  
         {
 132  0
             appender.append( "version selected from constraint ", getVersionConstraint() );
 133  
         }
 134  
         
 135  0
         appender.flush();
 136  
 
 137  0
         return buffer.toString();
 138  
     }
 139  
 
 140  
     /**
 141  
      * Utility class to concatenate a number of parameters with separator tokens.   
 142  
      */
 143  
     private static class ItemAppender
 144  
     {
 145  
         private StringBuffer buffer;
 146  
         
 147  
         private String startToken;
 148  
         
 149  
         private String separatorToken;
 150  
         
 151  
         private String endToken;
 152  
         
 153  
         private boolean appended;
 154  
         
 155  
         public ItemAppender( StringBuffer buffer, String startToken, String separatorToken, String endToken )
 156  0
         {
 157  0
             this.buffer = buffer;
 158  0
             this.startToken = startToken;
 159  0
             this.separatorToken = separatorToken;
 160  0
             this.endToken = endToken;
 161  
             
 162  0
             appended = false;
 163  0
         }
 164  
 
 165  
         public ItemAppender append( String item1, String item2 )
 166  
         {
 167  0
             appendToken();
 168  
             
 169  0
             buffer.append( item1 ).append( item2 );
 170  
             
 171  0
             return this;
 172  
         }
 173  
         
 174  
         public void flush()
 175  
         {
 176  0
             if ( appended )
 177  
             {
 178  0
                 buffer.append( endToken );
 179  
                 
 180  0
                 appended = false;
 181  
             }
 182  0
         }
 183  
         
 184  
         private void appendToken()
 185  
         {
 186  0
             buffer.append( appended ? separatorToken : startToken );
 187  
             
 188  0
             appended = true;
 189  0
         }
 190  
     }
 191  
 }