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 | 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 | |
} |