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.handler.ArtifactHandler;
23 import org.apache.maven.plugin.testing.stubs.ArtifactStub;
24 import org.apache.maven.plugin.war.stub.AarArtifactStub;
25 import org.apache.maven.plugin.war.stub.EJBArtifactStub;
26 import org.apache.maven.plugin.war.stub.EJBArtifactStubWithClassifier;
27 import org.apache.maven.plugin.war.stub.EJBClientArtifactStub;
28 import org.apache.maven.plugin.war.stub.IncludeExcludeWarArtifactStub;
29 import org.apache.maven.plugin.war.stub.JarArtifactStub;
30 import org.apache.maven.plugin.war.stub.MarArtifactStub;
31 import org.apache.maven.plugin.war.stub.MavenProjectArtifactsStub;
32 import org.apache.maven.plugin.war.stub.MavenProjectBasicStub;
33 import org.apache.maven.plugin.war.stub.PARArtifactStub;
34 import org.apache.maven.plugin.war.stub.ResourceStub;
35 import org.apache.maven.plugin.war.stub.TLDArtifactStub;
36 import org.apache.maven.plugin.war.stub.WarArtifactStub;
37 import org.codehaus.plexus.util.FileUtils;
38
39 import java.io.File;
40 import java.text.SimpleDateFormat;
41 import java.util.LinkedList;
42 import java.util.Locale;
43
44 public class WarExplodedMojoTest
45 extends AbstractWarExplodedMojoTest
46 {
47
48 protected File getPomFile()
49 {
50 return new File( getBasedir(), "/target/test-classes/unit/warexplodedmojo/plugin-config.xml" );
51 }
52
53 protected File getTestDirectory()
54 {
55 return new File( getBasedir(), "target/test-classes/unit/warexplodedmojo/test-dir" );
56 }
57
58
59
60
61 public void testSimpleExplodedWar()
62 throws Exception
63 {
64
65 String testId = "SimpleExplodedWar";
66 MavenProjectBasicStub project = new MavenProjectBasicStub();
67 File webAppSource = createWebAppSource( testId );
68 File classesDir = createClassesDir( testId, false );
69 File webAppResource = new File( getTestDirectory(), testId + "-resources" );
70 File webAppDirectory = new File( getTestDirectory(), testId );
71 File sampleResource = new File( webAppResource, "pix/panis_na.jpg" );
72 ResourceStub[] resources = new ResourceStub[]{new ResourceStub()};
73
74 createFile( sampleResource );
75
76 assertTrue( "sampeResource not found", sampleResource.exists() );
77
78
79 resources[0].setDirectory( webAppResource.getAbsolutePath() );
80 this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project );
81 setVariableValueToObject( mojo, "webResources", resources );
82 mojo.execute();
83
84
85 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
86 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
87 File expectedWebResourceFile = new File( webAppDirectory, "pix/panis_na.jpg" );
88 File expectedWEBINFDir = new File( webAppDirectory, "WEB-INF" );
89 File expectedMETAINFDir = new File( webAppDirectory, "META-INF" );
90
91 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
92 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
93 assertTrue( "resources doesn't exist: " + expectedWebResourceFile, expectedWebResourceFile.exists() );
94 assertTrue( "WEB-INF not found", expectedWEBINFDir.exists() );
95 assertTrue( "META-INF not found", expectedMETAINFDir.exists() );
96
97
98 expectedWebSourceFile.delete();
99 expectedWebSource2File.delete();
100 expectedWebResourceFile.delete();
101 }
102
103
104
105
106 public void testSimpleExplodedWarWTargetPath()
107 throws Exception
108 {
109
110 String testId = "SimpleExplodedWar";
111 MavenProjectBasicStub project = new MavenProjectBasicStub();
112 File webAppSource = createWebAppSource( testId );
113 File classesDir = createClassesDir( testId, false );
114 File webAppResource = new File( getTestDirectory(), "resources" );
115 File webAppDirectory = new File( getTestDirectory(), testId );
116 File sampleResource = new File( webAppResource, "pix/panis_na.jpg" );
117 ResourceStub[] resources = new ResourceStub[]{new ResourceStub()};
118
119 createFile( sampleResource );
120
121
122 resources[0].setDirectory( webAppResource.getAbsolutePath() );
123 resources[0].setTargetPath( "targetPath" );
124 this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project );
125 setVariableValueToObject( mojo, "webResources", resources );
126 mojo.execute();
127
128
129 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
130 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
131 File expectedWebResourceFile = new File( webAppDirectory, "targetPath/pix/panis_na.jpg" );
132 File expectedWEBINFDir = new File( webAppDirectory, "WEB-INF" );
133 File expectedMETAINFDir = new File( webAppDirectory, "META-INF" );
134
135 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
136 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
137 assertTrue( "resources doesn't exist: " + expectedWebResourceFile, expectedWebResourceFile.exists() );
138 assertTrue( "WEB-INF not found", expectedWEBINFDir.exists() );
139 assertTrue( "META-INF not found", expectedMETAINFDir.exists() );
140
141
142 expectedWebSourceFile.delete();
143 expectedWebSource2File.delete();
144 expectedWebResourceFile.delete();
145 }
146
147
148
149
150 public void testExplodedWar_WithCustomWebXML()
151 throws Exception
152 {
153
154 String testId = "ExplodedWar_WithCustomWebXML";
155 MavenProjectBasicStub project = new MavenProjectBasicStub();
156 File webAppSource = createWebAppSource( testId );
157 File classesDir = createClassesDir( testId, true );
158 File xmlSource = createXMLConfigDir( testId, new String[]{"web.xml"} );
159 File webAppDirectory = new File( getTestDirectory(), testId );
160
161
162 this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project );
163 mojo.setWebXml( new File( xmlSource, "web.xml" ) );
164 mojo.execute();
165
166
167 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
168 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
169 File expectedWEBXMLFile = new File( webAppDirectory, "WEB-INF/web.xml" );
170 File expectedMETAINFDir = new File( webAppDirectory, "META-INF" );
171
172 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
173 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
174 assertTrue( "WEB XML not found: " + expectedWEBXMLFile.toString(), expectedWEBXMLFile.exists() );
175 assertTrue( "META-INF not found", expectedMETAINFDir.exists() );
176 assertEquals( "WEB XML not correct", mojo.getWebXml().toString(), FileUtils.fileRead( expectedWEBXMLFile ) );
177
178
179 expectedWebSourceFile.delete();
180 expectedWebSource2File.delete();
181 expectedWEBXMLFile.delete();
182 expectedMETAINFDir.delete();
183 }
184
185
186
187
188 public void testExplodedWar_WithContainerConfigXML()
189 throws Exception
190 {
191
192 String testId = "ExplodedWar_WithContainerConfigXML";
193 MavenProjectBasicStub project = new MavenProjectBasicStub();
194 File classesDir = createClassesDir( testId, true );
195 File webAppSource = createWebAppSource( testId );
196 File xmlSource = createXMLConfigDir( testId, new String[]{"config.xml"} );
197 File webAppDirectory = new File( getTestDirectory(), testId );
198
199
200 this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project );
201 mojo.setContainerConfigXML( new File( xmlSource, "config.xml" ) );
202 mojo.execute();
203
204
205 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
206 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
207 File expectedContainerConfigXMLFile = new File( webAppDirectory, "META-INF/config.xml" );
208 File expectedWEBINFDir = new File( webAppDirectory, "WEB-INF" );
209
210 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
211 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
212 assertTrue( "WEB-INF not found", expectedWEBINFDir.exists() );
213 assertTrue( "Container Config XML not found:" + expectedContainerConfigXMLFile.toString(),
214 expectedContainerConfigXMLFile.exists() );
215
216
217 expectedWebSourceFile.delete();
218 expectedWebSource2File.delete();
219 expectedContainerConfigXMLFile.delete();
220 expectedWEBINFDir.delete();
221 }
222
223
224
225
226 public void testExplodedWar_WithSimpleExternalWARFile()
227 throws Exception
228 {
229
230 MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
231 WarArtifactStub warArtifact = new WarArtifactStub( getBasedir() );
232
233 String testId = "ExplodedWar_WithSimpleExternalWARFile";
234 File webAppDirectory = new File( getTestDirectory(), testId );
235 File webAppSource = createWebAppSource( testId );
236 File classesDir = createClassesDir( testId, true );
237 File workDirectory = new File( getTestDirectory(), "/war/work-" + testId );
238 File simpleWarFile = warArtifact.getFile();
239
240 assertTrue( "simple war not found: " + simpleWarFile.toString(), simpleWarFile.exists() );
241
242 createDir( workDirectory );
243
244
245 project.addArtifact( warArtifact );
246 this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project );
247 setVariableValueToObject( mojo, "workDirectory", workDirectory );
248 mojo.execute();
249
250
251 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
252 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
253 File expectedWEBXMLFile = new File( webAppDirectory, "WEB-INF/web.xml" );
254 File expectedWARFile = new File( webAppDirectory, "/org/sample/company/test.jsp" );
255
256 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
257 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
258
259 assertTrue( "web xml not found: " + expectedWEBXMLFile.toString(), expectedWEBXMLFile.exists() );
260 assertTrue( "war file not found: " + expectedWARFile.toString(), expectedWARFile.exists() );
261
262
263 expectedWebSourceFile.delete();
264 expectedWebSource2File.delete();
265 expectedWEBXMLFile.delete();
266 expectedWARFile.delete();
267 }
268
269
270
271
272 public void testExplodedWarMergeWarLocalFileOverride()
273 throws Exception
274 {
275
276 MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
277 WarArtifactStub warArtifact = new WarArtifactStub( getBasedir() );
278
279 String testId = "testExplodedWarMergeWarLocalFileOverride";
280 File webAppDirectory = new File( getTestDirectory(), testId );
281 File webAppSource = getWebAppSource( testId );
282 File simpleJSP = new File( webAppSource, "org/sample/company/test.jsp" );
283 createFile( simpleJSP );
284
285 File workDirectory = new File( getTestDirectory(), "/war/work-" + testId );
286 createDir( workDirectory );
287
288 File classesDir = createClassesDir( testId, true );
289
290
291 project.addArtifact( warArtifact );
292 this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project );
293 setVariableValueToObject( mojo, "workDirectory", workDirectory );
294 mojo.execute();
295
296
297 File expectedFile = new File( webAppDirectory, "/org/sample/company/test.jsp" );
298
299 assertTrue( "file not found: " + expectedFile.toString(), expectedFile.exists() );
300 assertEquals( "file incorrect", simpleJSP.toString(), FileUtils.fileRead( expectedFile ) );
301
302
303 long time = new SimpleDateFormat( "yyyy-MM-dd", Locale.US ).parse( "2005-1-1" ).getTime();
304 simpleJSP.setLastModified( time );
305 expectedFile.setLastModified( time );
306
307 project.addArtifact( warArtifact );
308 this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project );
309 setVariableValueToObject( mojo, "workDirectory", workDirectory );
310 mojo.execute();
311
312 assertTrue( "file not found: " + expectedFile.toString(), expectedFile.exists() );
313 assertEquals( "file incorrect", simpleJSP.toString(), FileUtils.fileRead( expectedFile ) );
314
315
316 expectedFile.delete();
317 }
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377 public void testExplodedWar_WithEJB()
378 throws Exception
379 {
380
381 String testId = "ExplodedWar_WithEJB";
382 MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
383 File webAppDirectory = new File( getTestDirectory(), testId );
384 File webAppSource = createWebAppSource( testId );
385 File classesDir = createClassesDir( testId, true );
386 EJBArtifactStub ejbArtifact = new EJBArtifactStub( getBasedir() );
387 File ejbFile = ejbArtifact.getFile();
388
389 assertTrue( "ejb jar not found: " + ejbFile.toString(), ejbFile.exists() );
390
391
392 project.addArtifact( ejbArtifact );
393 this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project );
394 mojo.execute();
395
396
397 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
398 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
399
400 File expectedEJBArtifact = new File( webAppDirectory, "WEB-INF/lib/ejbartifact-0.0-Test.jar" );
401
402
403 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
404 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
405 assertTrue( "ejb artifact not found: " + expectedEJBArtifact.toString(), expectedEJBArtifact.exists() );
406
407
408 expectedWebSourceFile.delete();
409 expectedWebSource2File.delete();
410 expectedEJBArtifact.delete();
411 }
412
413 public void testExplodedWarWithJar()
414 throws Exception
415 {
416
417 String testId = "ExplodedWarWithJar";
418 MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
419 File webAppDirectory = new File( getTestDirectory(), testId );
420 File webAppSource = createWebAppSource( testId );
421 File classesDir = createClassesDir( testId, true );
422 ArtifactHandler artifactHandler = (ArtifactHandler) lookup( ArtifactHandler.ROLE, "jar" );
423 ArtifactStub jarArtifact = new JarArtifactStub( getBasedir(), artifactHandler );
424 File jarFile = jarArtifact.getFile();
425
426 assertTrue( "jar not found: " + jarFile.toString(), jarFile.exists() );
427
428
429 project.addArtifact( jarArtifact );
430 this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project );
431 mojo.execute();
432
433
434 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
435 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
436
437 File expectedJarArtifact = new File( webAppDirectory, "WEB-INF/lib/jarartifact-0.0-Test.jar" );
438
439 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
440 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
441 assertTrue( "jar artifact not found: " + expectedJarArtifact.toString(), expectedJarArtifact.exists() );
442
443
444 expectedWebSourceFile.delete();
445 expectedWebSource2File.delete();
446 expectedJarArtifact.delete();
447 }
448
449
450
451
452 public void testExplodedWar_WithEJBClient()
453 throws Exception
454 {
455
456 String testId = "ExplodedWar_WithEJB";
457 MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
458 File webAppDirectory = new File( getTestDirectory(), testId );
459 File webAppSource = createWebAppSource( testId );
460 File classesDir = createClassesDir( testId, true );
461 EJBClientArtifactStub ejbArtifact = new EJBClientArtifactStub( getBasedir() );
462 File ejbFile = ejbArtifact.getFile();
463
464 assertTrue( "ejb jar not found: " + ejbFile.toString(), ejbFile.exists() );
465
466
467 project.addArtifact( ejbArtifact );
468 this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project );
469 mojo.execute();
470
471
472 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
473 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
474
475 File expectedEJBArtifact = new File( webAppDirectory, "WEB-INF/lib/ejbclientartifact-0.0-Test-client.jar" );
476
477 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
478 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
479 assertTrue( "ejb artifact not found: " + expectedEJBArtifact.toString(), expectedEJBArtifact.exists() );
480
481
482 expectedWebSourceFile.delete();
483 expectedWebSource2File.delete();
484 expectedEJBArtifact.delete();
485 }
486
487
488
489
490 public void testExplodedWar_WithTLD()
491 throws Exception
492 {
493
494 String testId = "ExplodedWar_WithTLD";
495 MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
496 File webAppDirectory = new File( getTestDirectory(), testId );
497 File webAppSource = createWebAppSource( testId );
498 File classesDir = createClassesDir( testId, true );
499 TLDArtifactStub tldArtifact = new TLDArtifactStub( getBasedir() );
500 File tldFile = tldArtifact.getFile();
501
502 assertTrue( "tld jar not found: " + tldFile.getAbsolutePath(), tldFile.exists() );
503
504
505 project.addArtifact( tldArtifact );
506 this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project );
507 mojo.execute();
508
509
510 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
511 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
512
513 File expectedTLDArtifact = new File( webAppDirectory, "WEB-INF/tld/tldartifact-0.0-Test.tld" );
514
515 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
516 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
517 assertTrue( "tld artifact not found: " + expectedTLDArtifact.toString(), expectedTLDArtifact.exists() );
518
519
520 expectedWebSourceFile.delete();
521 expectedWebSource2File.delete();
522 expectedTLDArtifact.delete();
523 }
524
525
526
527
528 public void testExplodedWar_WithPAR()
529 throws Exception
530 {
531
532 String testId = "ExplodedWar_WithPAR";
533 MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
534 File webAppDirectory = new File( getTestDirectory(), testId );
535 File webAppSource = createWebAppSource( testId );
536 File classesDir = createClassesDir( testId, true );
537 PARArtifactStub parartifact = new PARArtifactStub( getBasedir() );
538 File parFile = parartifact.getFile();
539
540 assertTrue( "par not found: " + parFile.getAbsolutePath(), parFile.exists() );
541
542
543 project.addArtifact( parartifact );
544 this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project );
545 mojo.execute();
546
547
548 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
549 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
550
551 File expectedPARArtifact = new File( webAppDirectory, "WEB-INF/lib/parartifact-0.0-Test.jar" );
552
553 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
554 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
555 assertTrue( "par artifact not found: " + expectedPARArtifact.toString(), expectedPARArtifact.exists() );
556
557
558 expectedWebSourceFile.delete();
559 expectedWebSource2File.delete();
560 expectedPARArtifact.delete();
561 }
562
563 public void testExplodedWarWithAar()
564 throws Exception
565 {
566
567 String testId = "ExplodedWarWithAar";
568 MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
569 File webAppDirectory = new File( getTestDirectory(), testId );
570 File webAppSource = createWebAppSource( testId );
571 File classesDir = createClassesDir( testId, true );
572
573 ArtifactHandler artifactHandler = (ArtifactHandler) lookup( ArtifactHandler.ROLE, "jar" );
574 ArtifactStub aarArtifact = new AarArtifactStub( getBasedir(), artifactHandler );
575 File aarFile = aarArtifact.getFile();
576
577 assertTrue( "jar not found: " + aarFile.toString(), aarFile.exists() );
578
579
580 project.addArtifact( aarArtifact );
581 this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project );
582 mojo.execute();
583
584
585 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
586 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
587
588 File expectedJarArtifact = new File( webAppDirectory, "WEB-INF/services/aarartifact-0.0-Test.jar" );
589
590 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
591 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
592 assertTrue( "jar artifact not found: " + expectedJarArtifact.toString(), expectedJarArtifact.exists() );
593
594
595 expectedWebSourceFile.delete();
596 expectedWebSource2File.delete();
597 expectedJarArtifact.delete();
598 }
599
600 public void testExplodedWarWithMar()
601 throws Exception
602 {
603
604 String testId = "ExplodedWarWithMar";
605 MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
606 File webAppDirectory = new File( getTestDirectory(), testId );
607 File webAppSource = createWebAppSource( testId );
608 File classesDir = createClassesDir( testId, true );
609
610 ArtifactHandler artifactHandler = (ArtifactHandler) lookup( ArtifactHandler.ROLE, "jar" );
611 ArtifactStub marArtifact = new MarArtifactStub( getBasedir(), artifactHandler );
612 File marFile = marArtifact.getFile();
613
614 assertTrue( "jar not found: " + marFile.toString(), marFile.exists() );
615
616
617 project.addArtifact( marArtifact );
618 this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project );
619 mojo.execute();
620
621
622 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
623 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
624
625 File expectedJarArtifact = new File( webAppDirectory, "WEB-INF/modules/marartifact-0.0-Test.jar" );
626
627 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
628 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
629 assertTrue( "jar artifact not found: " + expectedJarArtifact.toString(), expectedJarArtifact.exists() );
630
631
632 expectedWebSourceFile.delete();
633 expectedWebSource2File.delete();
634 expectedJarArtifact.delete();
635 }
636
637
638
639
640 public void testExplodedWar_WithDuplicateDependencies()
641 throws Exception
642 {
643
644 String testId = "ExplodedWar_WithDuplicateDependencies";
645 MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
646 File webAppDirectory = new File( getTestDirectory(), testId );
647 File webAppSource = createWebAppSource( testId );
648 File classesDir = createClassesDir( testId, true );
649 EJBArtifactStub ejbArtifact = new EJBArtifactStub( getBasedir() );
650 EJBArtifactStub ejbArtifactDup = new EJBArtifactStub( getBasedir() );
651 File ejbFile = ejbArtifact.getFile();
652
653
654 assertTrue( "ejb not found: " + ejbFile.getAbsolutePath(), ejbFile.exists() );
655
656
657 ejbArtifact.setGroupId( "org.sample.ejb" );
658 ejbArtifactDup.setGroupId( "org.dup.ejb" );
659 project.addArtifact( ejbArtifact );
660 project.addArtifact( ejbArtifactDup );
661 this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project );
662 mojo.execute();
663
664
665 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
666 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
667
668 File expectedEJBArtifact = new File( webAppDirectory, "WEB-INF/lib/org.sample.ejb-ejbartifact-0.0-Test.jar" );
669 File expectedEJBDupArtifact = new File( webAppDirectory, "WEB-INF/lib/org.dup.ejb-ejbartifact-0.0-Test.jar" );
670
671 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
672 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
673 assertTrue( "ejb artifact not found: " + expectedEJBArtifact.toString(), expectedEJBArtifact.exists() );
674 assertTrue( "ejb dup artifact not found: " + expectedEJBDupArtifact.toString(),
675 expectedEJBDupArtifact.exists() );
676
677
678 expectedWebSourceFile.delete();
679 expectedWebSource2File.delete();
680 expectedEJBArtifact.delete();
681 expectedEJBDupArtifact.delete();
682 }
683
684
685
686
687 public void testExplodedWar_DuplicateWithClassifier()
688 throws Exception
689 {
690
691 String testId = "ExplodedWar_DuplicateWithClassifier";
692 MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
693 File webAppDirectory = new File( getTestDirectory(), testId );
694 File webAppSource = createWebAppSource( testId );
695 File classesDir = createClassesDir( testId, true );
696 EJBArtifactStub ejbArtifact = new EJBArtifactStub( getBasedir() );
697 EJBArtifactStubWithClassifier ejbArtifactDup = new EJBArtifactStubWithClassifier( getBasedir() );
698
699 File ejbFile = ejbArtifact.getFile();
700
701
702 assertTrue( "ejb not found: " + ejbFile.getAbsolutePath(), ejbFile.exists() );
703
704
705
706 ejbArtifact.setGroupId( "org.sample.ejb" );
707 ejbArtifactDup.setGroupId( "org.sample.ejb" );
708
709 ejbArtifactDup.setClassifier( "classifier" );
710
711 project.addArtifact( ejbArtifact );
712 project.addArtifact( ejbArtifactDup );
713
714 this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project );
715 mojo.execute();
716
717
718 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
719 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
720
721 File expectedEJBArtifact = new File( webAppDirectory, "WEB-INF/lib/ejbartifact-0.0-Test.jar" );
722 File expectedEJBDupArtifact = new File( webAppDirectory, "WEB-INF/lib/ejbartifact-0.0-Test-classifier.jar" );
723
724 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
725 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
726 assertTrue( "ejb artifact not found: " + expectedEJBArtifact.toString(), expectedEJBArtifact.exists() );
727 assertTrue( "ejb dup artifact not found: " + expectedEJBDupArtifact.toString(),
728 expectedEJBDupArtifact.exists() );
729
730
731 expectedWebSourceFile.delete();
732 expectedWebSource2File.delete();
733 expectedEJBArtifact.delete();
734 expectedEJBDupArtifact.delete();
735 }
736
737
738
739
740 public void testExplodedWar_WithClasses()
741 throws Exception
742 {
743
744 String testId = "ExplodedWar_WithClasses";
745 MavenProjectBasicStub project = new MavenProjectBasicStub();
746 File webAppDirectory = new File( getTestDirectory(), testId );
747 File webAppSource = createWebAppSource( testId );
748 File classesDir = createClassesDir( testId, false );
749
750
751 this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project );
752 mojo.execute();
753
754
755 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
756 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
757
758 File expectedClass = new File( webAppDirectory, "WEB-INF/classes/sample-servlet.class" );
759
760 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
761 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
762 assertTrue( "classes not found: " + expectedClass.toString(), expectedClass.exists() );
763
764
765 expectedWebSourceFile.delete();
766 expectedWebSource2File.delete();
767 expectedClass.delete();
768 }
769
770 public void testExplodedWar_WithSourceIncludeExclude()
771 throws Exception
772 {
773
774 String testId = "ExplodedWar_WithSourceIncludeExclude";
775 MavenProjectBasicStub project = new MavenProjectBasicStub();
776 File webAppSource = createWebAppSource( testId );
777 File classesDir = createClassesDir( testId, true );
778 File webAppDirectory = new File( getTestDirectory(), testId );
779
780
781 this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project );
782 setVariableValueToObject( mojo, "warSourceIncludes", "**/*sit.jsp" );
783 setVariableValueToObject( mojo, "warSourceExcludes", "**/last*.*" );
784 mojo.execute();
785
786
787 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
788 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
789 File expectedWEBXMLDir = new File( webAppDirectory, "WEB-INF" );
790 File expectedMETAINFDir = new File( webAppDirectory, "META-INF" );
791
792 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
793 assertFalse( "source files found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
794 assertTrue( "WEB XML not found: " + expectedWEBXMLDir.toString(), expectedWEBXMLDir.exists() );
795 assertTrue( "META-INF not found", expectedMETAINFDir.exists() );
796
797
798 expectedWebSourceFile.delete();
799 expectedWebSource2File.delete();
800 expectedWEBXMLDir.delete();
801 expectedMETAINFDir.delete();
802 }
803
804 public void testExplodedWar_WithWarDependencyIncludeExclude()
805 throws Exception
806 {
807
808 String testId = "ExplodedWar_WithWarDependencyIncludeExclude";
809 MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
810 IncludeExcludeWarArtifactStub includeexcludeWarArtifact = new IncludeExcludeWarArtifactStub( getBasedir() );
811 File webAppDirectory = new File( getTestDirectory(), testId );
812 File webAppSource = createWebAppSource( testId );
813 File classesDir = createClassesDir( testId, true );
814 File workDirectory = new File( getTestDirectory(), "/war/work-" + testId );
815 File includeExcludeWarFile = includeexcludeWarArtifact.getFile();
816
817 assertTrue( "war not found: " + includeExcludeWarFile.toString(), includeExcludeWarFile.exists() );
818
819 createDir( workDirectory );
820
821
822 project.addArtifact( includeexcludeWarArtifact );
823 this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project );
824 setVariableValueToObject( mojo, "dependentWarIncludes", "**/*Include.jsp,**/*.xml" );
825 setVariableValueToObject( mojo, "dependentWarExcludes", "**/*Exclude*,**/MANIFEST.MF" );
826 setVariableValueToObject( mojo, "workDirectory", workDirectory );
827 mojo.execute();
828
829
830 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
831 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
832 File expectedManifestFile = new File( webAppDirectory, "META-INF/MANIFEST.MF" );
833 File expectedWEBXMLFile = new File( webAppDirectory, "WEB-INF/web.xml" );
834 File expectedIncludedWARFile = new File( webAppDirectory, "/org/sample/company/testInclude.jsp" );
835 File expectedExcludedWarfile = new File( webAppDirectory, "/org/sample/companyExclude/test.jsp" );
836
837 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
838 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
839
840 assertTrue( "web xml not found: " + expectedWEBXMLFile.toString(), expectedWEBXMLFile.exists() );
841 assertFalse( "manifest file found: " + expectedManifestFile.toString(), expectedManifestFile.exists() );
842 assertTrue( "war file not found: " + expectedIncludedWARFile.toString(), expectedIncludedWARFile.exists() );
843 assertFalse( "war file not found: " + expectedExcludedWarfile.toString(), expectedExcludedWarfile.exists() );
844
845
846 expectedWebSourceFile.delete();
847 expectedWebSource2File.delete();
848 expectedManifestFile.delete();
849 expectedWEBXMLFile.delete();
850 expectedIncludedWARFile.delete();
851 expectedExcludedWarfile.delete();
852 }
853
854 public void testExplodedWarWithSourceModificationCheck()
855 throws Exception
856 {
857
858 String testId = "ExplodedWarWithSourceModificationCheck";
859 MavenProjectBasicStub project = new MavenProjectBasicStub();
860 File webAppSource = createWebAppSource( testId );
861 File classesDir = createClassesDir( testId, false );
862 File webAppDirectory = new File( getTestDirectory(), testId );
863
864
865 this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project );
866
867
868
869 mojo.execute();
870
871
872
873 File expectedWEBINFDir = new File( webAppDirectory, "WEB-INF" );
874 File expectedMETAINFDir = new File( webAppDirectory, "META-INF" );
875 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
876 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
877
878 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
879 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
880 assertTrue( "WEB-INF not found", expectedWEBINFDir.exists() );
881 assertTrue( "META-INF not found", expectedMETAINFDir.exists() );
882
883
884
885 assertFalse( "source files not updated with new copy: " + expectedWebSourceFile.toString(),
886 "error".equals( FileUtils.fileRead( expectedWebSourceFile ) ) );
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901 expectedWEBINFDir.delete();
902 expectedMETAINFDir.delete();
903 expectedWebSourceFile.delete();
904 expectedWebSource2File.delete();
905 }
906
907 public void testExplodedWarWithOutputFileNameMapping()
908 throws Exception
909 {
910
911 String testId = "ExplodedWarWithFileNameMapping";
912 MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
913 File webAppDirectory = new File( getTestDirectory(), testId );
914 File webAppSource = createWebAppSource( testId );
915 File classesDir = createClassesDir( testId, true );
916 ArtifactHandler artifactHandler = (ArtifactHandler) lookup( ArtifactHandler.ROLE, "jar" );
917 ArtifactStub jarArtifact = new JarArtifactStub( getBasedir(), artifactHandler );
918 File jarFile = jarArtifact.getFile();
919
920 assertTrue( "jar not found: " + jarFile.toString(), jarFile.exists() );
921
922
923 project.addArtifact( jarArtifact );
924 mojo.setOutputFileNameMapping( "@{artifactId}@.@{extension}@" );
925 this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project );
926 mojo.execute();
927
928
929 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
930 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
931
932 File expectedJarArtifact = new File( webAppDirectory, "WEB-INF/lib/jarartifact.jar" );
933
934 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
935 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
936 assertTrue( "jar artifact not found: " + expectedJarArtifact.toString(), expectedJarArtifact.exists() );
937
938
939 expectedWebSourceFile.delete();
940 expectedWebSource2File.delete();
941 expectedJarArtifact.delete();
942 }
943
944
945
946
947 public void testExplodedWarWithOutputFileNameMappingAndDuplicateDependencies()
948 throws Exception
949 {
950
951 String testId = "ExplodedWarWithFileNameMappingAndDuplicateDependencies";
952 MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
953 File webAppDirectory = new File( getTestDirectory(), testId );
954 File webAppSource = createWebAppSource( testId );
955 File classesDir = createClassesDir( testId, true );
956 EJBArtifactStub ejbArtifact = new EJBArtifactStub( getBasedir() );
957 EJBArtifactStub ejbArtifactDup = new EJBArtifactStub( getBasedir() );
958 File ejbFile = ejbArtifact.getFile();
959
960
961 assertTrue( "ejb not found: " + ejbFile.getAbsolutePath(), ejbFile.exists() );
962
963
964 ejbArtifact.setGroupId( "org.sample.ejb" );
965 ejbArtifactDup.setGroupId( "org.dup.ejb" );
966 project.addArtifact( ejbArtifact );
967 project.addArtifact( ejbArtifactDup );
968 mojo.setOutputFileNameMapping( "@{artifactId}@.@{extension}@" );
969 this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project );
970 mojo.execute();
971
972
973 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
974 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
975
976 File expectedEJBArtifact = new File( webAppDirectory, "WEB-INF/lib/org.sample.ejb-ejbartifact.jar" );
977 File expectedEJBDupArtifact = new File( webAppDirectory, "WEB-INF/lib/org.dup.ejb-ejbartifact.jar" );
978
979 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
980 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
981 assertTrue( "ejb artifact not found: " + expectedEJBArtifact.toString(), expectedEJBArtifact.exists() );
982 assertTrue( "ejb dup artifact not found: " + expectedEJBDupArtifact.toString(),
983 expectedEJBDupArtifact.exists() );
984
985
986 expectedWebSourceFile.delete();
987 expectedWebSource2File.delete();
988 expectedEJBArtifact.delete();
989 expectedEJBDupArtifact.delete();
990 }
991
992
993
994
995
996
997 }