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