1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.resolver.internal.ant.types;
20
21 import java.util.regex.Matcher;
22 import java.util.regex.Pattern;
23
24 import org.apache.tools.ant.BuildException;
25 import org.apache.tools.ant.Task;
26 import org.apache.tools.ant.types.DataType;
27 import org.apache.tools.ant.types.Reference;
28
29
30
31 public class Exclusion extends DataType {
32
33 private static final String WILDCARD = "*";
34
35 private String groupId;
36
37 private String artifactId;
38
39 private String classifier;
40
41 private String extension;
42
43 protected Exclusion getRef() {
44 return (Exclusion) getCheckedRef();
45 }
46
47 public void validate(Task task) {
48 if (isReference()) {
49 getRef().validate(task);
50 } else {
51 if (groupId == null && artifactId == null && classifier == null && extension == null) {
52 throw new BuildException(
53 "You must specify at least one of " + "'groupId', 'artifactId', 'classifier' or 'extension'");
54 }
55 }
56 }
57
58 public void setRefid(Reference ref) {
59 if (groupId != null || artifactId != null || extension != null || classifier != null) {
60 throw tooManyAttributes();
61 }
62 super.setRefid(ref);
63 }
64
65 public String getGroupId() {
66 if (isReference()) {
67 return getRef().getGroupId();
68 }
69 return (groupId != null) ? groupId : WILDCARD;
70 }
71
72 public void setGroupId(String groupId) {
73 checkAttributesAllowed();
74 if (this.groupId != null) {
75 throw ambiguousCoords();
76 }
77 this.groupId = groupId;
78 }
79
80 public String getArtifactId() {
81 if (isReference()) {
82 return getRef().getArtifactId();
83 }
84 return (artifactId != null) ? artifactId : WILDCARD;
85 }
86
87 public void setArtifactId(String artifactId) {
88 checkAttributesAllowed();
89 if (this.artifactId != null) {
90 throw ambiguousCoords();
91 }
92 this.artifactId = artifactId;
93 }
94
95 public String getClassifier() {
96 if (isReference()) {
97 return getRef().getClassifier();
98 }
99 return (classifier != null) ? classifier : WILDCARD;
100 }
101
102 public void setClassifier(String classifier) {
103 checkAttributesAllowed();
104 if (this.classifier != null) {
105 throw ambiguousCoords();
106 }
107 this.classifier = classifier;
108 }
109
110 public String getExtension() {
111 if (isReference()) {
112 return getRef().getExtension();
113 }
114 return (extension != null) ? extension : WILDCARD;
115 }
116
117 public void setExtension(String extension) {
118 checkAttributesAllowed();
119 if (this.extension != null) {
120 throw ambiguousCoords();
121 }
122 this.extension = extension;
123 }
124
125 public void setCoords(String coords) {
126 checkAttributesAllowed();
127 if (groupId != null || artifactId != null || extension != null || classifier != null) {
128 throw ambiguousCoords();
129 }
130 Pattern p = Pattern.compile("([^: ]+)(:([^: ]+)(:([^: ]+)(:([^: ]*))?)?)?");
131 Matcher m = p.matcher(coords);
132 if (!m.matches()) {
133 throw new BuildException("Bad exclusion coordinates '" + coords
134 + "', expected format is <groupId>[:<artifactId>[:<extension>[:<classifier>]]]");
135 }
136 groupId = m.group(1);
137 artifactId = m.group(3);
138 if (artifactId == null) {
139 artifactId = "*";
140 }
141 extension = m.group(5);
142 if (extension == null) {
143 extension = "*";
144 }
145 classifier = m.group(7);
146 if (classifier == null) {
147 classifier = "*";
148 }
149 }
150
151 private BuildException ambiguousCoords() {
152 return new BuildException(
153 "You must not specify both 'coords' and " + "('groupId', 'artifactId', 'extension', 'classifier')");
154 }
155 }