1 | |
package org.apache.maven.plugins.shade.mojo; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import java.util.Collection; |
23 | |
import java.util.HashSet; |
24 | |
import java.util.Iterator; |
25 | |
|
26 | |
import org.apache.maven.artifact.Artifact; |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
class ArtifactSelector |
32 | |
{ |
33 | |
|
34 | |
private Collection includes; |
35 | |
|
36 | |
private Collection excludes; |
37 | |
|
38 | |
public ArtifactSelector( ArtifactSet artifactSet, String groupPrefix ) |
39 | |
{ |
40 | 0 | this( ( artifactSet != null ) ? artifactSet.getIncludes() : null, |
41 | |
( artifactSet != null ) ? artifactSet.getExcludes() : null, groupPrefix ); |
42 | 0 | } |
43 | |
|
44 | |
public ArtifactSelector( Collection includes, Collection excludes, String groupPrefix ) |
45 | 7 | { |
46 | 7 | this.includes = toIds( includes ); |
47 | 7 | this.excludes = toIds( excludes ); |
48 | |
|
49 | 7 | if ( groupPrefix != null && groupPrefix.length() > 0 ) |
50 | |
{ |
51 | 1 | this.includes.add( new ArtifactId( groupPrefix + "*", "*", "*", "*" ) ); |
52 | |
} |
53 | 7 | } |
54 | |
|
55 | |
private static Collection toIds( Collection patterns ) |
56 | |
{ |
57 | 14 | Collection result = new HashSet(); |
58 | |
|
59 | 14 | if ( patterns != null ) |
60 | |
{ |
61 | 8 | for ( Iterator it = patterns.iterator(); it.hasNext(); ) |
62 | |
{ |
63 | 4 | String pattern = (String) it.next(); |
64 | 4 | result.add( new ArtifactId( pattern ) ); |
65 | 4 | } |
66 | |
} |
67 | |
|
68 | 14 | return result; |
69 | |
} |
70 | |
|
71 | |
public boolean isSelected( Artifact artifact ) |
72 | |
{ |
73 | 0 | return ( artifact != null ) ? isSelected( new ArtifactId( artifact ) ) : false; |
74 | |
} |
75 | |
|
76 | |
boolean isSelected( ArtifactId id ) |
77 | |
{ |
78 | 13 | return ( includes.isEmpty() || matches( includes, id ) ) && !matches( excludes, id ); |
79 | |
} |
80 | |
|
81 | |
private boolean matches( Collection patterns, ArtifactId id ) |
82 | |
{ |
83 | 18 | for ( Iterator it = patterns.iterator(); it.hasNext(); ) |
84 | |
{ |
85 | 12 | ArtifactId pattern = (ArtifactId) it.next(); |
86 | 12 | if ( id.matches( pattern ) ) |
87 | |
{ |
88 | 7 | return true; |
89 | |
} |
90 | 5 | } |
91 | 11 | return false; |
92 | |
} |
93 | |
|
94 | |
} |