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  270
     Set<Artifact> resolvedDependencies = null;
 39  
 
 40  270
     Set<Artifact> unResolvedDependencies = null;
 41  
 
 42  270
     Set<Artifact> skippedDependencies = null;
 43  
 
 44  
     public DependencyStatusSets()
 45  22
     {
 46  
 
 47  22
     }
 48  
 
 49  
     public DependencyStatusSets( Set<Artifact> resolved, Set<Artifact> unResolved, Set<Artifact> skipped )
 50  248
     {
 51  248
         if ( resolved != null )
 52  
         {
 53  230
             this.resolvedDependencies = new LinkedHashSet<Artifact>( resolved );
 54  
         }
 55  248
         if ( unResolved != null )
 56  
         {
 57  24
             this.unResolvedDependencies = new LinkedHashSet<Artifact>( unResolved );
 58  
         }
 59  248
         if ( skipped != null )
 60  
         {
 61  230
             this.skippedDependencies = new LinkedHashSet<Artifact>( skipped );
 62  
         }
 63  248
     }
 64  
 
 65  
     /**
 66  
      * @return Returns the resolvedDependencies.
 67  
      */
 68  
     public Set<Artifact> getResolvedDependencies()
 69  
     {
 70  214
         return this.resolvedDependencies;
 71  
     }
 72  
 
 73  
     /**
 74  
      * @param resolvedDependencies
 75  
      *            The resolvedDependencies to set.
 76  
      */
 77  
     public void setResolvedDependencies( Set<Artifact> resolvedDependencies )
 78  
     {
 79  8
         if ( resolvedDependencies != null )
 80  
         {
 81  8
             this.resolvedDependencies = new LinkedHashSet<Artifact>( resolvedDependencies );
 82  
         }
 83  
         else
 84  
         {
 85  0
             this.resolvedDependencies = null;
 86  
         }
 87  8
     }
 88  
 
 89  
     /**
 90  
      * @return Returns the skippedDependencies.
 91  
      */
 92  
     public Set<Artifact> getSkippedDependencies()
 93  
     {
 94  184
         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  8
         if ( unResolvedDependencies != null )
 128  
         {
 129  8
             this.unResolvedDependencies = new LinkedHashSet<Artifact>( unResolvedDependencies );
 130  
         }
 131  
         else
 132  
         {
 133  0
             this.unResolvedDependencies = null;
 134  
         }
 135  8
     }
 136  
 
 137  
     public String getOutput( boolean outputAbsoluteArtifactFilename )
 138  
     {
 139  96
         return getOutput( outputAbsoluteArtifactFilename, true );
 140  
     }
 141  
 
 142  
     public String getOutput( boolean outputAbsoluteArtifactFilename, boolean outputScope )
 143  
     {
 144  124
         StringBuilder sb = new StringBuilder();
 145  124
         sb.append( "\n" );
 146  124
         sb.append( "The following files have been resolved:\n" );
 147  124
         if ( this.resolvedDependencies == null || this.resolvedDependencies.isEmpty() )
 148  
         {
 149  72
             sb.append( "   none\n" );
 150  
         }
 151  
         else
 152  
         {
 153  52
             for ( Artifact artifact : resolvedDependencies )
 154  
             {
 155  594
                 String artifactFilename = null;
 156  594
                 if ( outputAbsoluteArtifactFilename )
 157  
                 {
 158  
                     try
 159  
                     {
 160  
                         // we want to print the absolute file name here
 161  288
                         artifactFilename = artifact.getFile().getAbsoluteFile().getPath();
 162  
                     }
 163  144
                     catch ( NullPointerException e )
 164  
                     {
 165  
                         // ignore the null pointer, we'll output a null string
 166  144
                         artifactFilename = null;
 167  144
                     }
 168  
                 }
 169  
 
 170  594
                 String id = outputScope ? artifact.toString() : artifact.getId();
 171  
 
 172  594
                 sb.append( "   " + id + ( outputAbsoluteArtifactFilename ? ":" + artifactFilename : "" ) + "\n" );
 173  594
             }
 174  
         }
 175  
 
 176  124
         if ( this.skippedDependencies != null && !this.skippedDependencies.isEmpty() )
 177  
         {
 178  48
             sb.append( "\n" );
 179  48
             sb.append( "The following files were skipped:\n" );
 180  48
             Set<Artifact> skippedDependencies = new LinkedHashSet<Artifact>();
 181  48
             skippedDependencies.addAll( this.skippedDependencies );
 182  48
             for ( Artifact artifact : skippedDependencies )
 183  
             {
 184  576
                 sb.append( "   " + artifact.getId() + "\n" );
 185  
             }
 186  
         }
 187  
 
 188  124
         if ( this.unResolvedDependencies != null && !this.unResolvedDependencies.isEmpty() )
 189  
         {
 190  48
             sb.append( "\n" );
 191  48
             sb.append( "The following files have NOT been resolved:\n" );
 192  48
             Set<Artifact> unResolvedDependencies = new LinkedHashSet<Artifact>();
 193  48
             unResolvedDependencies.addAll( this.unResolvedDependencies );
 194  48
             for ( Artifact artifact : unResolvedDependencies )
 195  
             {
 196  576
                 sb.append( "   " + artifact.getId() + "\n" );
 197  
             }
 198  
         }
 199  124
         sb.append( "\n" );
 200  
 
 201  124
         return sb.toString();
 202  
     }
 203  
 }