1 | |
package org.apache.maven.plugin.war; |
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.ArrayList; |
25 | |
import java.util.Arrays; |
26 | |
import java.util.List; |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
public class Overlay |
44 | |
{ |
45 | |
|
46 | 1 | public static final String[] DEFAULT_INCLUDES = new String[]{"**/**"}; |
47 | |
|
48 | 1 | public static final String[] DEFAULT_EXCLUDES = new String[]{"META-INF/MANIFEST.MF"}; |
49 | |
|
50 | |
private String id; |
51 | |
|
52 | |
private String groupId; |
53 | |
|
54 | |
private String artifactId; |
55 | |
|
56 | 110 | private String classifier = null; |
57 | |
|
58 | 110 | private String[] includes = DEFAULT_INCLUDES; |
59 | |
|
60 | 110 | private String[] excludes = DEFAULT_EXCLUDES; |
61 | |
|
62 | 110 | private boolean filtered = false; |
63 | |
|
64 | 110 | private boolean skip = false; |
65 | |
|
66 | |
private Artifact artifact; |
67 | |
|
68 | |
private String targetPath; |
69 | |
|
70 | |
|
71 | 110 | private String type = "war"; |
72 | |
|
73 | |
public Overlay() |
74 | |
{ |
75 | 110 | super(); |
76 | 110 | } |
77 | |
|
78 | |
|
79 | |
public Overlay( String groupId, String artifactId ) |
80 | |
{ |
81 | 1 | this(); |
82 | 1 | this.groupId = groupId; |
83 | 1 | this.artifactId = artifactId; |
84 | 1 | } |
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
public boolean isCurrentProject() |
92 | |
{ |
93 | 162 | return ( groupId == null && artifactId == null ); |
94 | |
} |
95 | |
|
96 | |
public static Overlay createInstance() |
97 | |
{ |
98 | 69 | Overlay overlay = new Overlay(); |
99 | 69 | overlay.setId( "currentBuild" ); |
100 | 69 | return overlay; |
101 | |
} |
102 | |
|
103 | |
|
104 | |
|
105 | |
public String getId() |
106 | |
{ |
107 | 389 | if ( id == null ) |
108 | |
{ |
109 | 37 | final StringBuilder sb = new StringBuilder(); |
110 | 37 | sb.append( getGroupId() ).append( ":" ).append( getArtifactId() ); |
111 | 37 | if ( getClassifier() != null ) |
112 | |
{ |
113 | 0 | sb.append( ":" ).append( getClassifier() ); |
114 | |
} |
115 | 37 | id = sb.toString(); |
116 | |
} |
117 | 389 | return id; |
118 | |
} |
119 | |
|
120 | |
public void setId( String id ) |
121 | |
{ |
122 | 69 | this.id = id; |
123 | 69 | } |
124 | |
|
125 | |
public String getGroupId() |
126 | |
{ |
127 | 119 | return groupId; |
128 | |
} |
129 | |
|
130 | |
public void setGroupId( String groupId ) |
131 | |
{ |
132 | 40 | this.groupId = groupId; |
133 | 40 | } |
134 | |
|
135 | |
public String getArtifactId() |
136 | |
{ |
137 | 119 | return artifactId; |
138 | |
} |
139 | |
|
140 | |
public void setArtifactId( String artifactId ) |
141 | |
{ |
142 | 40 | this.artifactId = artifactId; |
143 | 40 | } |
144 | |
|
145 | |
public String getClassifier() |
146 | |
{ |
147 | 99 | return classifier; |
148 | |
} |
149 | |
|
150 | |
public void setClassifier( String classifier ) |
151 | |
{ |
152 | 40 | this.classifier = classifier; |
153 | 40 | } |
154 | |
|
155 | |
public String[] getIncludes() |
156 | |
{ |
157 | 66 | return includes; |
158 | |
} |
159 | |
|
160 | |
public void setIncludes( String includes ) |
161 | |
{ |
162 | 42 | this.includes = parse( includes ); |
163 | 42 | } |
164 | |
|
165 | |
public void setIncludes( String[] includes ) |
166 | |
{ |
167 | 0 | this.includes = includes; |
168 | 0 | } |
169 | |
|
170 | |
public String[] getExcludes() |
171 | |
{ |
172 | 62 | return excludes; |
173 | |
} |
174 | |
|
175 | |
public void setExcludes( String excludes ) |
176 | |
{ |
177 | 43 | this.excludes = parse( excludes ); |
178 | 43 | } |
179 | |
|
180 | |
public void setExcludes( String[] excludes ) |
181 | |
{ |
182 | 0 | this.excludes = excludes; |
183 | 0 | } |
184 | |
|
185 | |
public boolean isFiltered() |
186 | |
{ |
187 | 33 | return filtered; |
188 | |
} |
189 | |
|
190 | |
public void setFiltered( boolean filtered ) |
191 | |
{ |
192 | 0 | this.filtered = filtered; |
193 | 0 | } |
194 | |
|
195 | |
public boolean shouldSkip() |
196 | |
{ |
197 | 34 | return skip; |
198 | |
} |
199 | |
|
200 | |
public void setSkip( boolean skip ) |
201 | |
{ |
202 | 2 | this.skip = skip; |
203 | 2 | } |
204 | |
|
205 | |
public Artifact getArtifact() |
206 | |
{ |
207 | 33 | return artifact; |
208 | |
} |
209 | |
|
210 | |
public void setArtifact( Artifact artifact ) |
211 | |
{ |
212 | 68 | this.artifact = artifact; |
213 | 68 | } |
214 | |
|
215 | |
public String getTargetPath() |
216 | |
{ |
217 | 68 | return targetPath; |
218 | |
} |
219 | |
|
220 | |
|
221 | |
public void setTargetPath( String targetPath ) |
222 | |
{ |
223 | 1 | this.targetPath = targetPath; |
224 | 1 | } |
225 | |
|
226 | |
public String getType() |
227 | |
{ |
228 | 29 | return type; |
229 | |
} |
230 | |
|
231 | |
|
232 | |
public void setType( String type ) |
233 | |
{ |
234 | 43 | this.type = type; |
235 | 43 | } |
236 | |
|
237 | |
public String toString() |
238 | |
{ |
239 | 68 | return " id " + getId(); |
240 | |
} |
241 | |
|
242 | |
|
243 | |
public boolean equals( Object o ) |
244 | |
{ |
245 | 80 | if ( this == o ) |
246 | |
{ |
247 | 11 | return true; |
248 | |
} |
249 | 69 | if ( o == null || getClass() != o.getClass() ) |
250 | |
{ |
251 | 67 | return false; |
252 | |
} |
253 | |
|
254 | 2 | Overlay overlay = (Overlay) o; |
255 | |
|
256 | 2 | if ( excludes != null ? !Arrays.equals( excludes, overlay.excludes ) : overlay.excludes != null ) |
257 | |
{ |
258 | 0 | return false; |
259 | |
} |
260 | 2 | if ( getId() != null ? !getId().equals( overlay.getId() ) : overlay.getId() != null ) |
261 | |
{ |
262 | 0 | return false; |
263 | |
} |
264 | 2 | if ( includes != null ? !Arrays.equals( includes, overlay.includes ) : overlay.includes != null ) |
265 | |
{ |
266 | 0 | return false; |
267 | |
} |
268 | |
|
269 | 2 | return true; |
270 | |
} |
271 | |
|
272 | |
public int hashCode() |
273 | |
{ |
274 | |
int result; |
275 | 0 | result = ( getId() != null ? getId().hashCode() : 0 ); |
276 | 0 | result = 31 * result + ( includes != null ? includes.hashCode() : 0 ); |
277 | 0 | result = 31 * result + ( excludes != null ? excludes.hashCode() : 0 ); |
278 | 0 | return result; |
279 | |
} |
280 | |
|
281 | |
private String[] parse( String s ) |
282 | |
{ |
283 | 85 | final List<String> result = new ArrayList<String>(); |
284 | 85 | if ( s == null ) |
285 | |
{ |
286 | 0 | return (String[]) result.toArray( new String[result.size()] ); |
287 | |
} |
288 | |
else |
289 | |
{ |
290 | 85 | String[] tokens = s.split( "," ); |
291 | 177 | for ( int i = 0; i < tokens.length; i++ ) |
292 | |
{ |
293 | 92 | String token = tokens[i]; |
294 | 92 | result.add( token.trim() ); |
295 | |
} |
296 | 85 | return (String[]) result.toArray( new String[result.size()] ); |
297 | |
} |
298 | |
} |
299 | |
|
300 | |
} |