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 | |
import org.apache.maven.model.Dependency; |
24 | |
import org.codehaus.plexus.util.SelectorUtils; |
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
class ArtifactId |
30 | |
{ |
31 | |
|
32 | |
private final String groupId; |
33 | |
|
34 | |
private final String artifactId; |
35 | |
|
36 | |
private final String type; |
37 | |
|
38 | |
private final String classifier; |
39 | |
|
40 | |
public ArtifactId( Dependency dependency ) |
41 | |
{ |
42 | 0 | this( dependency.getGroupId(), dependency.getArtifactId(), dependency.getType(), dependency.getClassifier() ); |
43 | 0 | } |
44 | |
|
45 | |
public ArtifactId( Artifact artifact ) |
46 | |
{ |
47 | 1 | this( artifact.getGroupId(), artifact.getArtifactId(), artifact.getType(), artifact.getClassifier() ); |
48 | 1 | } |
49 | |
|
50 | |
public ArtifactId( String groupId, String artifactId, String type, String classifier ) |
51 | 51 | { |
52 | 51 | this.groupId = ( groupId != null ) ? groupId : ""; |
53 | 51 | this.artifactId = ( artifactId != null ) ? artifactId : ""; |
54 | 51 | this.type = ( type != null ) ? type : ""; |
55 | 51 | this.classifier = ( classifier != null ) ? classifier : ""; |
56 | 51 | } |
57 | |
|
58 | |
public ArtifactId( String id ) |
59 | 56 | { |
60 | 56 | String[] tokens = new String[0]; |
61 | 56 | if ( id != null && id.length() > 0 ) |
62 | |
{ |
63 | 54 | tokens = id.split( ":", -1 ); |
64 | |
} |
65 | 56 | groupId = ( tokens.length > 0 ) ? tokens[0] : ""; |
66 | 56 | artifactId = ( tokens.length > 1 ) ? tokens[1] : "*"; |
67 | 56 | type = ( tokens.length > 3 ) ? tokens[2] : "*"; |
68 | 56 | classifier = ( tokens.length > 3 ) ? tokens[3] : ( ( tokens.length > 2 ) ? tokens[2] : "*" ); |
69 | 56 | } |
70 | |
|
71 | |
public String getGroupId() |
72 | |
{ |
73 | 113 | return groupId; |
74 | |
} |
75 | |
|
76 | |
public String getArtifactId() |
77 | |
{ |
78 | 93 | return artifactId; |
79 | |
} |
80 | |
|
81 | |
public String getType() |
82 | |
{ |
83 | 73 | return type; |
84 | |
} |
85 | |
|
86 | |
public String getClassifier() |
87 | |
{ |
88 | 71 | return classifier; |
89 | |
} |
90 | |
|
91 | |
public boolean matches( ArtifactId pattern ) |
92 | |
{ |
93 | 49 | if ( pattern == null ) |
94 | |
{ |
95 | 0 | return false; |
96 | |
} |
97 | 49 | if ( !match( getGroupId(), pattern.getGroupId() ) ) |
98 | |
{ |
99 | 9 | return false; |
100 | |
} |
101 | 40 | if ( !match( getArtifactId(), pattern.getArtifactId() ) ) |
102 | |
{ |
103 | 10 | return false; |
104 | |
} |
105 | 30 | if ( !match( getType(), pattern.getType() ) ) |
106 | |
{ |
107 | 1 | return false; |
108 | |
} |
109 | 29 | if ( !match( getClassifier(), pattern.getClassifier() ) ) |
110 | |
{ |
111 | 1 | return false; |
112 | |
} |
113 | |
|
114 | 28 | return true; |
115 | |
} |
116 | |
|
117 | |
private boolean match( String str, String pattern ) |
118 | |
{ |
119 | 148 | return SelectorUtils.match( pattern, str ); |
120 | |
} |
121 | |
|
122 | |
} |