Coverage Report - org.apache.maven.plugins.shade.filter.SimpleFilter
 
Classes in this File Line Coverage Branch Coverage Complexity
SimpleFilter
0%
0/19
0%
0/16
2,667
 
 1  
 package org.apache.maven.plugins.shade.filter;
 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 org.codehaus.plexus.util.SelectorUtils;
 23  
 
 24  
 import java.io.File;
 25  
 import java.util.Iterator;
 26  
 import java.util.Set;
 27  
 
 28  
 /**
 29  
  * @author David Blevins
 30  
  */
 31  
 public class SimpleFilter
 32  
     implements Filter
 33  
 {
 34  
     private File jar;
 35  
 
 36  
     private Set includes;
 37  
 
 38  
     private Set excludes;
 39  
 
 40  
     public SimpleFilter( File jar, Set includes, Set excludes )
 41  0
     {
 42  0
         this.jar = jar;
 43  0
         this.includes = includes;
 44  0
         this.excludes = excludes;
 45  0
     }
 46  
 
 47  
     public boolean canFilter( File jar )
 48  
     {
 49  0
         return this.jar.equals( jar );
 50  
     }
 51  
 
 52  
     public boolean isFiltered( String classFile )
 53  
     {
 54  
 
 55  0
         return !( isIncluded( classFile ) && !isExcluded( classFile ) );
 56  
     }
 57  
 
 58  
     private boolean isIncluded( String classFile )
 59  
     {
 60  0
         if ( includes == null || includes.size() == 0 )
 61  
         {
 62  0
             return true;
 63  
         }
 64  
 
 65  0
         return matchPaths( includes, classFile );
 66  
     }
 67  
 
 68  
     private boolean isExcluded( String classFile )
 69  
     {
 70  0
         if ( excludes == null || excludes.size() == 0 )
 71  
         {
 72  0
             return false;
 73  
         }
 74  
 
 75  0
         return matchPaths( excludes, classFile );
 76  
     }
 77  
 
 78  
     private boolean matchPaths( Set patterns, String classFile )
 79  
     {
 80  0
         for ( Iterator iterator = patterns.iterator(); iterator.hasNext(); )
 81  
         {
 82  0
             String pattern = (String) iterator.next();
 83  
 
 84  0
             if ( SelectorUtils.matchPath( pattern, classFile ) )
 85  
             {
 86  0
                 return true;
 87  
             }
 88  0
         }
 89  
 
 90  0
         return false;
 91  
     }
 92  
 }