1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugin.eclipse;
20
21 import java.util.ArrayList;
22 import java.util.LinkedHashSet;
23 import java.util.List;
24
25 import org.apache.maven.plugin.MojoExecutionException;
26 import org.apache.maven.plugin.ide.IdeUtils;
27 import org.codehaus.plexus.util.StringUtils;
28
29
30
31
32
33
34
35
36
37
38 public class EclipseSourceDir
39 implements Comparable
40 {
41 private static final String PATTERN_SEPARATOR = "|";
42
43 private String path;
44
45
46
47
48 private String output;
49
50
51
52
53 private List include;
54
55
56
57
58 private List exclude;
59
60 private boolean isResource;
61
62 private boolean test;
63
64 private boolean filtering;
65
66
67
68
69
70
71
72
73
74
75
76 public EclipseSourceDir( String path, String output, boolean isResource, boolean test, List include, List exclude,
77 boolean filtering )
78 {
79 setPath( path );
80 this.output = output;
81 this.isResource = isResource;
82 this.test = test;
83 setInclude( include );
84 setExclude( exclude );
85 this.filtering = filtering;
86 }
87
88
89
90
91
92
93 public List getExclude()
94 {
95 return this.exclude;
96 }
97
98
99
100
101
102
103 public void setExclude( List exclude )
104 {
105 this.exclude = new ArrayList();
106 if ( exclude != null )
107 {
108 this.exclude.addAll( exclude );
109 }
110 }
111
112
113
114
115
116
117 public List getInclude()
118 {
119 return this.include;
120 }
121
122
123
124
125
126
127 public void setInclude( List include )
128 {
129 this.include = new ArrayList();
130 if ( include != null )
131 {
132 this.include.addAll( include );
133 }
134 }
135
136
137
138
139 public String getExcludeAsString()
140 {
141 return StringUtils.join( exclude.iterator(), PATTERN_SEPARATOR );
142 }
143
144
145
146
147 public String getIncludeAsString()
148 {
149 return StringUtils.join( include.iterator(), PATTERN_SEPARATOR );
150 }
151
152
153
154
155
156
157
158
159 public String getOutput()
160 {
161 return this.output;
162 }
163
164
165
166
167
168
169 public void setOutput( String output )
170 {
171 this.output = output;
172 }
173
174
175
176
177
178
179 public String getPath()
180 {
181 return this.path;
182 }
183
184
185
186
187
188
189
190 public void setPath( String path )
191 {
192 this.path = IdeUtils.fixSeparator( path );
193 }
194
195
196
197
198
199
200 public boolean isTest()
201 {
202 return this.test;
203 }
204
205
206
207
208
209
210 public void setTest( boolean test )
211 {
212 this.test = test;
213 }
214
215
216
217
218
219
220 public boolean isResource()
221 {
222 return this.isResource;
223 }
224
225
226
227
228 public boolean isFiltering()
229 {
230 return filtering;
231 }
232
233
234
235
236 public boolean equals( Object obj )
237 {
238 return ( obj != null ) && ( obj instanceof EclipseSourceDir )
239 && this.path.equals( ( (EclipseSourceDir) obj ).path );
240 }
241
242
243
244
245 public int hashCode()
246 {
247 return this.path.hashCode();
248 }
249
250
251
252
253 public int compareTo( Object obj )
254 {
255 return this.path.compareTo( ( (EclipseSourceDir) obj ).path );
256 }
257
258
259
260
261 public String toString()
262 {
263 StringBuffer buffer = new StringBuffer();
264 buffer.append( ( isResource ? "re" : "" ) + "source " );
265 buffer.append( path );
266 buffer.append( ": " );
267 buffer.append( "output=" ).append( output ).append( ", " );
268 buffer.append( "include=[" ).append( getIncludeAsString() ).append( "], " );
269 buffer.append( "exclude=[" ).append( getExcludeAsString() ).append( "], " );
270 buffer.append( "test=" ).append( test ).append( ", " );
271 buffer.append( "filtering=" ).append( filtering );
272 return buffer.toString();
273 }
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292 public void merge( EclipseSourceDir mergeWith )
293 throws MojoExecutionException
294 {
295 if ( test != mergeWith.test )
296 {
297 throw new MojoExecutionException( "Request to merge when 'test' is not identical. Original=" + toString()
298 + ", merging with=" + mergeWith.toString() );
299 }
300 if ( filtering != mergeWith.filtering )
301 {
302 throw new MojoExecutionException( "Request to merge when 'filtering' is not identical. Original="
303 + toString() + ", merging with=" + mergeWith.toString() );
304 }
305
306 if ( isResource != mergeWith.isResource )
307 {
308 if ( isResource )
309 {
310
311 output = mergeWith.output;
312 }
313 isResource = false;
314 setInclude( null );
315 setExclude( null );
316
317 }
318 else
319 {
320 if ( !StringUtils.equals( output, mergeWith.output ) )
321 {
322 throw new MojoExecutionException( "Request to merge when 'output' is not identical. Original="
323 + toString() + ", merging with=" + mergeWith.toString() );
324 }
325
326 LinkedHashSet includesAsSet = new LinkedHashSet();
327 includesAsSet.addAll( include );
328 includesAsSet.addAll( mergeWith.include );
329 include = new ArrayList( includesAsSet );
330
331 LinkedHashSet excludesAsSet = new LinkedHashSet();
332 excludesAsSet.addAll( exclude );
333 excludesAsSet.addAll( mergeWith.exclude );
334 exclude = new ArrayList( excludesAsSet );
335 }
336 }
337 }