Coverage Report - org.apache.maven.plugin.dependency.utils.filters.FilterArtifacts
 
Classes in this File Line Coverage Branch Coverage Complexity
FilterArtifacts
100% 
100% 
1.571
 
 1  
 package org.apache.maven.plugin.dependency.utils.filters;
 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.ArrayList;
 27  
 import java.util.Iterator;
 28  
 import java.util.Set;
 29  
 
 30  
 import org.apache.maven.plugin.MojoExecutionException;
 31  
 import org.apache.maven.plugin.logging.Log;
 32  
 
 33  
 /**
 34  
  * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
 35  
  * @version $Id: FilterArtifacts.java 552528 2007-07-02 16:12:47Z markh $
 36  
  */
 37  
 public class FilterArtifacts
 38  
 {
 39  202
     private ArrayList filters = new ArrayList();
 40  
 
 41  
     public FilterArtifacts()
 42  202
     {
 43  202
         filters = new ArrayList();
 44  202
     }
 45  
 
 46  
     /**
 47  
      * Removes all of the elements from this list. The list will be empty after
 48  
      * this call returns.
 49  
      */
 50  
     public void clearFilters()
 51  
     {
 52  100
         filters.clear();
 53  100
     }
 54  
 
 55  
     /**
 56  
      * Appends the specified element to the end of this list.
 57  
      * 
 58  
      * @param filter
 59  
      *            element to be appended to this list.
 60  
      */
 61  
     public void addFilter( ArtifactsFilter filter )
 62  
     {
 63  708
         if ( filter != null )
 64  
         {
 65  704
             filters.add( filter );
 66  
         }
 67  708
     }
 68  
 
 69  
     /**
 70  
      * Inserts the specified element at the specified position in this list.
 71  
      * Shifts the element currently at that position (if any) and any subsequent
 72  
      * elements to the right (adds one to their indices).
 73  
      * 
 74  
      * @param index
 75  
      *            index at which the specified element is to be inserted.
 76  
      * @param element
 77  
      *            element to be inserted.
 78  
      * @throws IndexOutOfBoundsException
 79  
      *             if index is out of range
 80  
      *             <tt>(index &lt; 0 || index &gt; size())</tt>.
 81  
      */
 82  
     public void addFilter( int index, ArtifactsFilter filter )
 83  
     {
 84  1
         if ( filter != null )
 85  
         {
 86  1
             filters.add( index, filter );
 87  
         }
 88  1
     }
 89  
 
 90  
     public Set filter( Set artifacts, Log log )
 91  
         throws MojoExecutionException
 92  
     {
 93  
         // apply filters
 94  203
         Iterator filterIterator = filters.iterator();
 95  897
         while ( filterIterator.hasNext() )
 96  
         {
 97  
             // log(artifacts,log);
 98  696
             ArtifactsFilter filter = (ArtifactsFilter) filterIterator.next();
 99  
             try
 100  
             {
 101  696
                 artifacts = filter.filter( artifacts, log );
 102  
             }
 103  2
             catch ( NullPointerException e )
 104  
             {
 105  
                 // don't do anything, just skip this.
 106  2
                 continue;
 107  692
             }
 108  692
         }
 109  
 
 110  201
         return artifacts;
 111  
     }
 112  
 
 113  
     /**
 114  
      * @return Returns the filters.
 115  
      */
 116  
     public ArrayList getFilters()
 117  
     {
 118  17
         return this.filters;
 119  
     }
 120  
 
 121  
     /**
 122  
      * @param filters
 123  
      *            The filters to set.
 124  
      */
 125  
     public void setFilters( ArrayList filters )
 126  
     {
 127  2
         this.filters = filters;
 128  2
     }
 129  
 }