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