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 public void testProject07()
88 throws Exception
89 {
90
91 testProject( "project-07" );
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 public void testProject16()
175 throws Exception
176 {
177
178 testProject( "project-16" );
179 }
180
181
182
183
184
185
186 public void testProject17()
187 throws Exception
188 {
189
190 testProject( "project-17" );
191 }
192
193
194
195
196
197
198 public void testProject18()
199 throws Exception
200 {
201 testProject( "project-18" );
202 }
203
204
205
206
207
208
209 public void testProject19()
210 throws Exception
211 {
212 testProject( "project-19" );
213 }
214
215
216
217
218
219
220 public void testProject20()
221 throws Exception
222 {
223 testProject( "project-20" );
224 }
225
226
227
228
229
230
231 public void testProject21()
232 throws Exception
233 {
234 testProject( "project-21" );
235 }
236
237
238
239
240
241
242 public void testProject22()
243 throws Exception
244 {
245 testProject( "project-22" );
246 }
247
248
249
250
251
252
253 public void testProject23()
254 throws Exception
255 {
256 testProject( "project-23" );
257 }
258
259
260
261
262
263
264 public void testProject24()
265 throws Exception
266 {
267 testProject( "project-24" );
268 }
269
270
271
272
273
274
275 public void testProject25()
276 throws Exception
277 {
278 testProject( "project-25" );
279 }
280
281
282
283
284
285
286 public void testProject26()
287 throws Exception
288 {
289 testProject( "project-26" );
290 }
291
292
293
294
295
296
297 public void testProject27()
298 throws Exception
299 {
300 testProject( "project-27" );
301 }
302
303
304
305
306
307
308 public void testProject28()
309 throws Exception
310 {
311 testProject( "project-28/module-1" );
312 }
313
314
315
316
317
318
319 public void testProject29()
320 throws Exception
321 {
322 testProject( "project-29" );
323 }
324
325
326
327
328
329
330 public void testProject30()
331 throws Exception
332 {
333 testProject( "project-30" );
334 }
335
336
337
338
339
340
341 public void testProject31()
342 throws Exception
343 {
344 try
345 {
346 testProject( "project-31" );
347
348
349
350 }
351 catch ( MojoExecutionException e )
352 {
353
354 }
355 }
356
357
358
359
360
361
362 public void testProject32()
363 throws Exception
364 {
365 testProject( "project-32" );
366 }
367
368
369
370
371
372
373
374 public void testProject33()
375 throws Exception
376 {
377 testProject( "project-33" );
378 }
379
380 public void testProject34()
381 throws Exception
382 {
383 testProject( "project-34" );
384 }
385
386 public void testProject35()
387 throws Exception
388 {
389 testProject( "project-35" );
390
391 File basedir = getTestFile( "target/test-classes/projects/project-35" );
392
393 checkContextRoot( basedir, "multymodule-war", "multymodule-ear", "/somethingVeryDifferent" );
394
395 FileReader reader =
396 new FileReader( new File( basedir, "multymodule-war/.settings/org.eclipse.wst.common.component" ) );
397 Xpp3Dom warComponent = Xpp3DomBuilder.build( reader );
398 Xpp3Dom[] dependentModules = warComponent.getChild( "wb-module" ).getChildren( "dependent-module" );
399 assertEquals( 2, dependentModules.length );
400 for ( int index = 0; index < dependentModules.length; index++ )
401 {
402 assertEquals( "/WEB-INF/lib", dependentModules[index].getAttribute( "deploy-path" ) );
403 }
404
405 reader = new FileReader( new File( basedir, "multymodule-ear/.settings/org.eclipse.wst.common.component" ) );
406 Xpp3Dom earComponent = Xpp3DomBuilder.build( reader );
407 dependentModules = earComponent.getChild( "wb-module" ).getChildren( "dependent-module" );
408 assertEquals( 2, dependentModules.length );
409 for ( int index = 0; index < dependentModules.length; index++ )
410 {
411 if ( dependentModules[index].getAttribute( "archiveName" ).endsWith( "war" ) )
412 {
413 assertEquals( "/", dependentModules[index].getAttribute( "deploy-path" ) );
414 assertTrue( !dependentModules[index].getAttribute( "archiveName" ).startsWith( ".." ) );
415 }
416 else
417 {
418 assertEquals( "lib", dependentModules[index].getAttribute( "deploy-path" ) );
419 assertTrue( dependentModules[index].getAttribute( "archiveName" ).startsWith( ".." ) );
420 }
421 }
422 }
423
424 public void testProject36()
425 throws Exception
426 {
427
428 File basedir = getTestFile( "target/test-classes/projects/project-36" );
429 File pom = new File( basedir, "pom.xml" );
430 List goals = new ArrayList();
431 goals.add( "install" );
432 executeMaven( pom, new Properties(), goals );
433
434 testProject( "project-36" );
435 }
436
437 public void testProject37()
438 throws Exception
439 {
440 testProject( "project-37" );
441 }
442
443
444
445
446 public void testMECLIPSE_56_encoding()
447 throws Exception
448 {
449 testProject( "MECLIPSE-56_encoding" );
450 }
451
452 public void testProject38()
453 throws Exception
454 {
455 testProject( "project-38" );
456 }
457
458 public void testProject39()
459 throws Exception
460 {
461 checkJRESettingsWithEclipseWorkspace( "project-39", new TempEclipseWorkspace( "eclipseWithDefault13", true ),
462 "", null );
463 checkJRESettingsWithEclipseWorkspace( "project-39", new TempEclipseWorkspace( "eclipseWithDefault15", false ),
464 "J2SE-1.3", null );
465 checkJRESettingsWithEclipseWorkspace( "project-39", new TempEclipseWorkspace( "rad7WithDefault14", false ),
466 "J2SE-1.3", null );
467 }
468
469 public void testProject40()
470 throws Exception
471 {
472 String jre131 = new java.io.File( "target/test-classes/eclipse/dummyJDK/1.3.1/bin/javac" ).getCanonicalPath();
473 checkJRESettingsWithEclipseWorkspace( "project-40", new TempEclipseWorkspace( "eclipseWithDefault13", true ),
474 "JVM 1.3.1", jre131 );
475 checkJRESettingsWithEclipseWorkspace( "project-40", new TempEclipseWorkspace( "eclipseWithDefault15", false ),
476 "JVM 1.3.1", jre131 );
477 checkJRESettingsWithEclipseWorkspace( "project-40", new TempEclipseWorkspace( "rad7WithDefault14", false ), "",
478 jre131 );
479 }
480
481 public void testProject41()
482 throws Exception
483 {
484 TempEclipseWorkspace rad7 = new TempEclipseWorkspace( "rad7WithDefault14", false );
485 Properties properties = new Properties();
486 properties.setProperty( "eclipse.workspace", rad7.workspaceLocation.getCanonicalPath() );
487 testProject( "project-41", properties, "clean", "eclipse" );
488
489 }
490
491 public void testProject42()
492 throws Exception
493 {
494 TempEclipseWorkspace rad7 = new TempEclipseWorkspace( "rad7WithDefault14", false );
495 Properties properties = new Properties();
496 properties.setProperty( "eclipse.workspace", rad7.workspaceLocation.getCanonicalPath() );
497 testProject( "project-42", properties, "clean", "eclipse" );
498
499 }
500
501
502
503
504
505
506
507 public void testProject43()
508 throws Exception
509 {
510 testProject( "project-43" );
511 }
512
513
514
515
516
517
518
519 public void testProject44()
520 throws Exception
521 {
522 testProject( "project-44" );
523 }
524
525
526
527
528
529
530
531 public void testProject45()
532 throws Exception
533 {
534 testProject( "project-45" );
535 }
536
537 public void testJeeSimple()
538 throws Exception
539 {
540
541 File basedir = getTestFile( "target/test-classes/projects/j2ee-simple" );
542 File pom = new File( basedir, "pom.xml" );
543 List goals = new ArrayList();
544 goals.add( "install" );
545 executeMaven( pom, new Properties(), goals );
546
547 testProject( "j2ee-simple" );
548 checkContextRoot( basedir, "servlets/servlet", "ear", "servlet" );
549
550 }
551
552 private void checkContextRoot( File basedir, String warModule, String earModule, String expectedContextRoot )
553 throws FileNotFoundException, XmlPullParserException, IOException
554 {
555 FileReader reader =
556 new FileReader( new File( basedir, warModule + "/.settings/org.eclipse.wst.common.component" ) );
557 Xpp3Dom warComponent = Xpp3DomBuilder.build( reader );
558 Xpp3Dom[] properties = warComponent.getChild( "wb-module" ).getChildren( "property" );
559 boolean contextRootAvaliable = false;
560 for ( int index = 0; index < properties.length; index++ )
561 {
562 if ( properties[index].getAttribute( "name" ).equals( "context-root" ) )
563 {
564 assertEquals( "Context root detection in org.eclipse.wst.common.component", expectedContextRoot,
565 properties[index].getAttribute( "value" ) );
566 contextRootAvaliable = true;
567 }
568 }
569 assertTrue( "there must be a context root here", contextRootAvaliable );
570
571 reader = new FileReader( new File( basedir, earModule + "/target/eclipseEar/META-INF/application.xml" ) );
572 Xpp3Dom generatedApplicationXML = Xpp3DomBuilder.build( reader );
573
574 Xpp3Dom[] modules = generatedApplicationXML.getChildren( "module" );
575 for ( int index = 0; index < modules.length; index++ )
576 {
577 if ( modules[index].getChild( "web" ) != null )
578 {
579 assertEquals( "Context root detection in target/eclipseEar/META-INF/application.xml",
580 expectedContextRoot,
581 modules[index].getChild( "web" ).getChild( "context-root" ).getValue() );
582 }
583 }
584 }
585
586 private void checkJRESettingsWithEclipseWorkspace( String project, TempEclipseWorkspace workspace,
587 String expectedJRE, String jreExec )
588 throws Exception
589 {
590 Properties properties = new Properties();
591 properties.setProperty( "eclipse.workspace", workspace.workspaceLocation.getCanonicalPath() );
592 if ( jreExec != null )
593 {
594 properties.setProperty( "maven.compiler.executable", jreExec );
595 }
596 testProject( project, properties, "clean", "eclipse" );
597
598 Xpp3Dom classpath =
599 Xpp3DomBuilder.build( new FileReader( getTestFile( "target/test-classes/projects/" + project +
600 "/.classpath" ) ) );
601
602 boolean foundDirectCompileAsProject = false;
603 String foundJRE = "";
604
605 Xpp3Dom[] classpathentries = classpath.getChildren( "classpathentry" );
606 for ( int index = 0; index < classpathentries.length; index++ )
607 {
608 if ( "/direct-compile".equals( classpathentries[index].getAttribute( "path" ) ) )
609 {
610 foundDirectCompileAsProject = true;
611 }
612 String path = classpathentries[index].getAttribute( "path" );
613 if ( "con".equals( classpathentries[index].getAttribute( "kind" ) ) && path.lastIndexOf( '/' ) > 0 )
614 {
615 foundJRE = path.substring( path.lastIndexOf( '/' ) + 1 );
616 }
617 }
618 assertTrue( foundDirectCompileAsProject );
619 assertEquals( expectedJRE, foundJRE );
620 }
621
622
623
624
625
626
627 }