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