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