Coverage Report - org.apache.maven.plugin.dependency.utils.DependencyStatusSets
 
Classes in this File Line Coverage Branch Coverage Complexity
DependencyStatusSets
89%
54/61
89%
32/36
2.4
 
 1  
 package org.apache.maven.plugin.dependency.utils;
 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  
 /**
 23  
  * 
 24  
  */
 25  
 
 26  
 import java.util.Iterator;
 27  
 import java.util.Set;
 28  
 import java.util.SortedSet;
 29  
 import java.util.TreeSet;
 30  
 
 31  
 import org.apache.maven.artifact.Artifact;
 32  
 
 33  
 /**
 34  
  * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
 35  
  * @version $Id: DependencyStatusSets.java 728546 2008-12-21 22:56:51Z bentmann $
 36  
  */
 37  
 public class DependencyStatusSets
 38  
 {
 39  
 
 40  132
     TreeSet resolvedDependencies = null;
 41  
 
 42  132
     TreeSet unResolvedDependencies = null;
 43  
 
 44  132
     TreeSet skippedDependencies = null;
 45  
 
 46  
     public DependencyStatusSets()
 47  11
     {
 48  
 
 49  11
     }
 50  
 
 51  
     public DependencyStatusSets( Set resolved, Set unResolved, Set skipped )
 52  121
     {
 53  121
         if ( resolved != null )
 54  
         {
 55  112
             this.resolvedDependencies = new TreeSet( resolved );
 56  
         }
 57  121
         if ( unResolved != null )
 58  
         {
 59  12
             this.unResolvedDependencies = new TreeSet( unResolved );
 60  
         }
 61  121
         if ( skipped != null )
 62  
         {
 63  112
             this.skippedDependencies = new TreeSet( skipped );
 64  
         }
 65  121
     }
 66  
 
 67  
     /**
 68  
      * @return Returns the resolvedDependencies.
 69  
      */
 70  
     public Set getResolvedDependencies()
 71  
     {
 72  104
         return this.resolvedDependencies;
 73  
     }
 74  
 
 75  
     /**
 76  
      * @param resolvedDependencies
 77  
      *            The resolvedDependencies to set.
 78  
      */
 79  
     public void setResolvedDependencies( Set resolvedDependencies )
 80  
     {
 81  4
         if ( resolvedDependencies != null )
 82  
         {
 83  4
             this.resolvedDependencies = new TreeSet( resolvedDependencies );
 84  
         }
 85  
         else
 86  
         {
 87  0
             this.resolvedDependencies = null;
 88  
         }
 89  4
     }
 90  
 
 91  
     /**
 92  
      * @return Returns the skippedDependencies.
 93  
      */
 94  
     public Set getSkippedDependencies()
 95  
     {
 96  89
         return this.skippedDependencies;
 97  
     }
 98  
 
 99  
     /**
 100  
      * @param skippedDependencies
 101  
      *            The skippedDependencies to set.
 102  
      */
 103  
     public void setSkippedDependencies( Set skippedDependencies )
 104  
     {
 105  0
         if ( skippedDependencies != null )
 106  
         {
 107  0
             this.skippedDependencies = new TreeSet( skippedDependencies );
 108  
         }
 109  
         else
 110  
         {
 111  0
             this.skippedDependencies = null;
 112  
         }
 113  0
     }
 114  
 
 115  
     /**
 116  
      * @return Returns the unResolvedDependencies.
 117  
      */
 118  
     public Set getUnResolvedDependencies()
 119  
     {
 120  0
         return this.unResolvedDependencies;
 121  
     }
 122  
 
 123  
     /**
 124  
      * @param unResolvedDependencies
 125  
      *            The unResolvedDependencies to set.
 126  
      */
 127  
     public void setUnResolvedDependencies( Set unResolvedDependencies )
 128  
     {
 129  4
         if ( unResolvedDependencies != null )
 130  
         {
 131  4
             this.unResolvedDependencies = new TreeSet( unResolvedDependencies );
 132  
         }
 133  
         else
 134  
         {
 135  0
             this.unResolvedDependencies = null;
 136  
         }
 137  4
     }
 138  
 
 139  
     public String getOutput(boolean outputAbsoluteArtifactFilename )
 140  
     {
 141  48
         return getOutput(outputAbsoluteArtifactFilename, true );
 142  
     }
 143  
 
 144  
     public String getOutput(boolean outputAbsoluteArtifactFilename, boolean outputScope )
 145  
     {
 146  62
         StringBuffer sb = new StringBuffer();
 147  62
         sb.append( "\n" );
 148  62
         sb.append( "The following files have been resolved:\n" );
 149  62
         if ( this.resolvedDependencies == null || this.resolvedDependencies.isEmpty() )
 150  
         {
 151  36
             sb.append( "   none\n" );
 152  
         }
 153  
         else
 154  
         {
 155  26
             for ( Iterator i = resolvedDependencies.iterator(); i.hasNext(); )
 156  
             {
 157  297
                 Artifact artifact = (Artifact) i.next();
 158  297
                 String artifactFilename = null;
 159  297
                 if ( outputAbsoluteArtifactFilename )
 160  
                 {
 161  
                     try
 162  
                     {
 163  
                         // we want to print the absolute file name here
 164  144
                         artifactFilename = artifact.getFile().getAbsoluteFile().getPath();
 165  
                     }
 166  72
                     catch ( NullPointerException e )
 167  
                     {
 168  
                         // ignore the null pointer, we'll output a null string
 169  72
                         artifactFilename = null;
 170  72
                     }
 171  
                 }
 172  
                 
 173  297
                 String id = outputScope ? artifact.toString() : artifact.getId();
 174  
                 
 175  297
                 sb.append( "   " + id + ( outputAbsoluteArtifactFilename ? ":" + artifactFilename : "" ) +"\n");
 176  297
             }
 177  
         }
 178  
 
 179  62
         if ( this.skippedDependencies != null && !this.skippedDependencies.isEmpty() )
 180  
         {
 181  24
             sb.append( "\n" );
 182  24
             sb.append( "The following files were skipped:\n" );
 183  24
             SortedSet sortedSkippedDependencies = new TreeSet();
 184  24
             sortedSkippedDependencies.addAll( this.skippedDependencies );
 185  24
             for ( Iterator i = sortedSkippedDependencies.iterator(); i.hasNext(); )
 186  
             {
 187  288
                 sb.append( "   " + ( (Artifact) i.next() ).getId()+"\n" );
 188  
             }
 189  
         }
 190  
 
 191  62
         if ( this.unResolvedDependencies != null && !this.unResolvedDependencies.isEmpty() )
 192  
         {
 193  24
             sb.append( "\n" );
 194  24
             sb.append( "The following files have NOT been resolved:\n" );
 195  24
             SortedSet sortedUnResolvedDependencies = new TreeSet();
 196  24
             sortedUnResolvedDependencies.addAll( this.unResolvedDependencies );
 197  24
             for ( Iterator i = sortedUnResolvedDependencies.iterator(); i.hasNext(); )
 198  
             {
 199  288
                 sb.append( "   " + ( (Artifact) i.next() ).getId()+"\n" );
 200  
             }
 201  
         }
 202  62
         sb.append("\n");
 203  
 
 204  62
         return sb.toString();
 205  
     }
 206  
 }