1 package org.apache.maven.plugins.shade.filter;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
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 {
42 this.jar = jar;
43 this.includes = includes;
44 this.excludes = excludes;
45 }
46
47 public boolean canFilter( File jar )
48 {
49 return this.jar.equals( jar );
50 }
51
52 public boolean isFiltered( String classFile )
53 {
54
55 return !( isIncluded( classFile ) && !isExcluded( classFile ) );
56 }
57
58 private boolean isIncluded( String classFile )
59 {
60 if ( includes == null || includes.size() == 0 )
61 {
62 return true;
63 }
64
65 return matchPaths( includes, classFile );
66 }
67
68 private boolean isExcluded( String classFile )
69 {
70 if ( excludes == null || excludes.size() == 0 )
71 {
72 return false;
73 }
74
75 return matchPaths( excludes, classFile );
76 }
77
78 private boolean matchPaths( Set patterns, String classFile )
79 {
80 for ( Iterator iterator = patterns.iterator(); iterator.hasNext(); )
81 {
82 String pattern = (String) iterator.next();
83
84 if ( SelectorUtils.matchPath( pattern, classFile ) )
85 {
86 return true;
87 }
88 }
89
90 return false;
91 }
92 }