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.io.File;
22 import java.io.FileNotFoundException;
23 import java.io.FileReader;
24 import java.io.IOException;
25 import java.util.ArrayList;
26 import java.util.List;
27 import java.util.Properties;
28
29 import org.apache.maven.plugin.MojoExecutionException;
30 import org.codehaus.plexus.util.xml.Xpp3Dom;
31 import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
32 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
33
34
35
36
37
38
39 public class EclipsePluginTest
40 extends AbstractEclipsePluginTestCase
41 {
42 protected void setUp()
43 throws Exception
44 {
45 super.setUp();
46 }
47
48 public void testProject01()
49 throws Exception
50 {
51 testProject( "project-01" );
52 }
53
54 public void testProject02()
55 throws Exception
56 {
57 testProject( "project-02" );
58 }
59
60 public void testProject03()
61 throws Exception
62 {
63 testProject( "project-03" );
64 }
65
66 public void testProject04()
67 throws Exception
68 {
69 testProject( "project-04" );
70 }
71
72 public void testProject05()
73 throws Exception
74 {
75 testProject( "project-05" );
76 }
77
78 public void testProject06()
79 throws Exception
80 {
81 testProject( "project-06" );
82 }
83
84
85
86
87
88
89
90
91
92
93
94 public void testProject08()
95 throws Exception
96 {
97 testProject( "project-08" );
98 }
99
100
101
102
103
104
105 public void testProject09()
106 throws Exception
107 {
108 testProject( "project-09" );
109 }
110
111 public void testProject10()
112 throws Exception
113 {
114 testProject( "project-10" );
115 }
116
117 public void testProject11()
118 throws Exception
119 {
120 testProject( "project-11" );
121 }
122
123
124
125
126
127
128 public void testProject12()
129 throws Exception
130 {
131 testProject( "project-12" );
132 }
133
134
135
136
137
138
139 public void testProject13()
140 throws Exception
141 {
142 testProject( "project-13" );
143 }
144
145
146
147
148
149
150 public void testProject14()
151 throws Exception
152 {
153 testProject( "project-14" );
154 }
155
156
157
158
159
160
161 public void testProject15()
162 throws Exception
163 {
164 Properties props = new Properties();
165 props.put( "outputDirectory", "bin" );
166 testProject( "project-15", props, "clean", "eclipse" );
167 }
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196 public void testProject18()
197 throws Exception
198 {
199 testProject( "project-18" );
200 }
201
202
203
204
205
206
207 public void testProject19()
208 throws Exception
209 {
210 testProject( "project-19" );
211 }
212
213
214
215
216
217
218 public void testProject20()
219 throws Exception
220 {
221 testProject( "project-20" );
222 }
223
224
225
226
227
228
229 public void testProject21()
230 throws Exception
231 {
232 testProject( "project-21" );
233 }
234
235
236
237
238
239
240 public void testProject22()
241 throws Exception
242 {
243 testProject( "project-22" );
244 }
245
246
247
248
249
250
251 public void testProject23()
252 throws Exception
253 {
254 testProject( "project-23" );
255 }
256
257
258
259
260
261
262 public void testProject24()
263 throws Exception
264 {
265 testProject( "project-24" );
266 }
267
268
269
270
271
272
273 public void testProject25()
274 throws Exception
275 {
276 testProject( "project-25" );
277 }
278
279
280
281
282
283
284 public void testProject26()
285 throws Exception
286 {
287 testProject( "project-26" );
288 }
289
290
291
292
293
294
295 public void testProject27()
296 throws Exception
297 {
298 testProject( "project-27" );
299 }
300
301
302
303
304
305
306 public void testProject28()
307 throws Exception
308 {
309 testProject( "project-28/module-1" );
310 }
311
312
313
314
315
316
317 public void testProject29()
318 throws Exception
319 {
320 testProject( "project-29" );
321 }
322
323
324
325
326
327
328 public void testProject30()
329 throws Exception
330 {
331 testProject( "project-30" );
332 }
333
334
335
336
337
338
339 public void testProject31()
340 throws Exception
341 {
342 try
343 {
344 testProject( "project-31" );
345
346
347
348 }
349 catch ( MojoExecutionException e )
350 {
351
352 }
353 }
354
355
356
357
358
359
360 public void testProject32()
361 throws Exception
362 {
363 testProject( "project-32" );
364 }
365
366 public void testProject34()
367 throws Exception
368 {
369 testProject( "project-34" );
370 }
371
372 public void testProject35()
373 throws Exception
374 {
375 testProject( "project-35" );
376
377 File basedir = getTestFile( "target/test-classes/projects/project-35" );
378
379 checkContextRoot( basedir, "multymodule-war", "multymodule-ear", "/somethingVeryDifferent" );
380
381 FileReader reader =
382 new FileReader( new File( basedir, "multymodule-war/.settings/org.eclipse.wst.common.component" ) );
383 Xpp3Dom warComponent = Xpp3DomBuilder.build( reader );
384 Xpp3Dom[] dependentModules = warComponent.getChild( "wb-module" ).getChildren( "dependent-module" );
385 assertEquals( 2, dependentModules.length );
386 for ( int index = 0; index < dependentModules.length; index++ )
387 {
388 assertEquals( "/WEB-INF/lib", dependentModules[index].getAttribute( "deploy-path" ) );
389 }
390
391 reader = new FileReader( new File( basedir, "multymodule-ear/.settings/org.eclipse.wst.common.component" ) );
392 Xpp3Dom earComponent = Xpp3DomBuilder.build( reader );
393 dependentModules = earComponent.getChild( "wb-module" ).getChildren( "dependent-module" );
394 assertEquals( 2, dependentModules.length );
395 for ( int index = 0; index < dependentModules.length; index++ )
396 {
397 if ( dependentModules[index].getAttribute( "archiveName" ).endsWith( "war" ) )
398 {
399 assertEquals( "/", dependentModules[index].getAttribute( "deploy-path" ) );
400 assertTrue( !dependentModules[index].getAttribute( "archiveName" ).startsWith( ".." ) );
401 }
402 else
403 {
404 assertEquals( "lib", dependentModules[index].getAttribute( "deploy-path" ) );
405 assertTrue( dependentModules[index].getAttribute( "archiveName" ).startsWith( ".." ) );
406 }
407 }
408 }
409
410 public void testProject36()
411 throws Exception
412 {
413
414 File basedir = getTestFile( "target/test-classes/projects/project-36" );
415 File pom = new File( basedir, "pom.xml" );
416 List goals = new ArrayList();
417 goals.add( "install" );
418 executeMaven( pom, new Properties(), goals );
419
420 testProject( "project-36" );
421 }
422
423 public void testProject37()
424 throws Exception
425 {
426 testProject( "project-37" );
427 }
428
429 public void testProject38()
430 throws Exception
431 {
432 testProject( "project-38" );
433 }
434
435 public void testJeeSimple()
436 throws Exception
437 {
438
439 File basedir = getTestFile( "target/test-classes/projects/j2ee-simple" );
440 File pom = new File( basedir, "pom.xml" );
441 List goals = new ArrayList();
442 goals.add( "install" );
443 executeMaven( pom, new Properties(), goals );
444
445 testProject( "j2ee-simple" );
446 checkContextRoot( basedir, "servlets/servlet", "ear", "servlet" );
447
448 }
449
450 private void checkContextRoot( File basedir, String warModule, String earModule, String expectedContextRoot )
451 throws FileNotFoundException, XmlPullParserException, IOException
452 {
453 FileReader reader =
454 new FileReader( new File( basedir, warModule + "/.settings/org.eclipse.wst.common.component" ) );
455 Xpp3Dom warComponent = Xpp3DomBuilder.build( reader );
456 Xpp3Dom[] properties = warComponent.getChild( "wb-module" ).getChildren( "property" );
457 boolean contextRootAvaliable = false;
458 for ( int index = 0; index < properties.length; index++ )
459 {
460 if ( properties[index].getAttribute( "name" ).equals( "context-root" ) )
461 {
462 assertEquals( "Context root detection in org.eclipse.wst.common.component", expectedContextRoot,
463 properties[index].getAttribute( "value" ) );
464 contextRootAvaliable = true;
465 }
466 }
467 assertTrue( "there must be a context root here", contextRootAvaliable );
468
469 reader = new FileReader( new File( basedir, earModule + "/target/eclipseEar/META-INF/application.xml" ) );
470 Xpp3Dom generatedApplicationXML = Xpp3DomBuilder.build( reader );
471
472 Xpp3Dom[] modules = generatedApplicationXML.getChildren( "module" );
473 for ( int index = 0; index < modules.length; index++ )
474 {
475 if ( modules[index].getChild( "web" ) != null )
476 {
477 assertEquals( "Context root detection in target/eclipseEar/META-INF/application.xml",
478 expectedContextRoot,
479 modules[index].getChild( "web" ).getChild( "context-root" ).getValue() );
480 }
481 }
482 }
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500 }