1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugins.shade.mojo;
20
21 import org.apache.maven.artifact.Artifact;
22 import org.apache.maven.model.Dependency;
23 import org.codehaus.plexus.util.SelectorUtils;
24
25
26
27
28 class ArtifactId {
29
30 private final String groupId;
31
32 private final String artifactId;
33
34 private final String type;
35
36 private final String classifier;
37
38 ArtifactId(Dependency dependency) {
39 this(dependency.getGroupId(), dependency.getArtifactId(), dependency.getType(), dependency.getClassifier());
40 }
41
42 ArtifactId(Artifact artifact) {
43 this(artifact.getGroupId(), artifact.getArtifactId(), artifact.getType(), artifact.getClassifier());
44 }
45
46 ArtifactId(String groupId, String artifactId, String type, String classifier) {
47 this.groupId = (groupId != null) ? groupId : "";
48 this.artifactId = (artifactId != null) ? artifactId : "";
49 this.type = (type != null) ? type : "";
50 this.classifier = (classifier != null) ? classifier : "";
51 }
52
53 ArtifactId(String id) {
54 String[] tokens = new String[0];
55 if (id != null && id.length() > 0) {
56 tokens = id.split(":", -1);
57 }
58 groupId = (tokens.length > 0) ? tokens[0] : "";
59 artifactId = (tokens.length > 1) ? tokens[1] : "*";
60 type = (tokens.length > 3) ? tokens[2] : "*";
61 classifier = (tokens.length > 3) ? tokens[3] : ((tokens.length > 2) ? tokens[2] : "*");
62 }
63
64 public String getGroupId() {
65 return groupId;
66 }
67
68 public String getArtifactId() {
69 return artifactId;
70 }
71
72 public String getType() {
73 return type;
74 }
75
76 public String getClassifier() {
77 return classifier;
78 }
79
80 public boolean matches(ArtifactId pattern) {
81 if (pattern == null) {
82 return false;
83 }
84 if (!match(getGroupId(), pattern.getGroupId())) {
85 return false;
86 }
87 if (!match(getArtifactId(), pattern.getArtifactId())) {
88 return false;
89 }
90 if (!match(getType(), pattern.getType())) {
91 return false;
92 }
93 return match(getClassifier(), pattern.getClassifier());
94 }
95
96 private boolean match(String str, String pattern) {
97 return SelectorUtils.match(pattern, str);
98 }
99 }