1 package org.apache.maven.plugin.idea;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.codehaus.plexus.PlexusTestCase;
23 import org.dom4j.Document;
24 import org.dom4j.Element;
25
26 import java.io.File;
27 import java.util.ArrayList;
28 import java.util.Iterator;
29 import java.util.List;
30
31
32
33
34 public class IdeaModuleTest
35 extends AbstractIdeaTestCase
36 {
37 public void testJarMinConfig()
38 throws Exception
39 {
40 executeMojo( "src/test/module-plugin-configs/min-plugin-config.xml" );
41 }
42
43 public void testProvidedDependencies()
44 throws Exception
45 {
46 executeMojo( "src/test/module-plugin-configs/provided-dep-plugin-config.xml" );
47 }
48
49 public void testExcludeDirectoryConfig()
50 throws Exception
51 {
52 File projectBasedir = new File( getBasedir(), "target/test-harness/m-dir-excl" );
53
54 projectBasedir.mkdirs();
55
56 File excluded = new File( projectBasedir, "excluded" );
57 excluded.mkdirs();
58 File sub = new File( excluded, "sub" );
59 sub.mkdirs();
60 File sub2 = new File( excluded, "sub2" );
61 sub2.mkdirs();
62 File subsub1 = new File( sub, "sub1" );
63 subsub1.mkdirs();
64
65 Document imlDocument = executeMojo( "src/test/module-plugin-configs/dir-exclusion-plugin-config.xml" );
66
67 Element component = findComponent( imlDocument.getRootElement(), "NewModuleRootManager" );
68
69 boolean excludedDirFound = false;
70 Element content = findElement( component, "content" );
71 for ( Iterator excludes = content.elementIterator( "excludeFolder" ); excludes.hasNext(); )
72 {
73 Element exclude = (Element) excludes.next();
74
75 if ( "file://$MODULE_DIR$/excluded".equals( exclude.attributeValue( "url" ) ) )
76 {
77 excludedDirFound = true;
78 }
79 }
80 assertTrue( "Test excluded dir", excludedDirFound );
81 }
82
83 public void testWarMinConfig()
84 throws Exception
85 {
86 List expectedLibs = new ArrayList();
87 expectedLibs.add( "/WEB-INF/lib/maven-model-2.0.1.jar" );
88 expectedLibs.add( "/WEB-INF/lib/junit-3.8.1.jar" );
89
90 Document imlDocument = executeMojo( "src/test/module-plugin-configs/min-war-plugin-config.xml" );
91
92 Element root = imlDocument.getRootElement();
93
94 assertEquals( "Test Project type", "J2EE_WEB_MODULE", root.attributeValue( "type" ) );
95
96 Element component = findComponent( root, "WebModuleBuildComponent" );
97
98 Element setting = findElement( component, "setting" );
99 assertTrue( "Test exploded url setting", "EXPLODED_URL".equals( setting.attributeValue( "name" ) ) );
100 assertTrue( "Test exploded url value",
101 setting.attributeValue( "value" ).startsWith( "file://$MODULE_DIR$/target/" ) );
102
103 component = findComponent( root, "WebModuleProperties" );
104
105 Element deployDescriptor = component.element( "deploymentDescriptor" );
106 assertEquals( "Test deployment descriptor version", "2.3", deployDescriptor.attributeValue( "version" ) );
107 assertEquals( "Test deployment descriptor name", "web.xml", deployDescriptor.attributeValue( "name" ) );
108 assertEquals( "Test deployment descriptor optional", "false", deployDescriptor.attributeValue( "optional" ) );
109 assertEquals( "Test deployment descriptor file", "file://$MODULE_DIR$/src/main/webapp/WEB-INF/web.xml",
110 deployDescriptor.attributeValue( "url" ) );
111
112 Element webroots = component.element( "webroots" );
113 Element webroot = webroots.element( "root" );
114 assertEquals( "Test webroot relative location", "/", webroot.attributeValue( "relative" ) );
115 assertEquals( "Test webroot url", "file://$MODULE_DIR$/src/main/webapp", webroot.attributeValue( "url" ) );
116
117 List containerElementList = findElementsByName( component, "containerElement" );
118 for ( Iterator containerElements = containerElementList.iterator(); containerElements.hasNext(); )
119 {
120 Element containerElement = (Element) containerElements.next();
121
122 assertEquals( "Test container element type", "library", containerElement.attributeValue( "type" ) );
123 assertEquals( "Test container element level", "module", containerElement.attributeValue( "level" ) );
124 assertTrue( "Test library url", containerElement.element( "url" ).getText().startsWith( "jar://" ) );
125
126 Element attribute = findElementByNameAttribute( containerElement, "attribute", "method" );
127 assertEquals( "Test library method", "1", attribute.attributeValue( "value" ) );
128
129 attribute = findElementByNameAttribute( containerElement, "attribute", "URI" );
130 String attributeValue = attribute.attributeValue( "value" );
131 assertTrue( "Test library URI", expectedLibs.contains( attributeValue ) );
132 expectedLibs.remove( attributeValue );
133 }
134
135 assertTrue( "All libraries are present", expectedLibs.size() == 0 );
136 }
137
138 public void testWarConfigWithProvidedDependency()
139 throws Exception
140 {
141 List expectedLibs = new ArrayList();
142 expectedLibs.add( "/WEB-INF/lib/maven-model-2.0.1.jar" );
143 expectedLibs.add( "/WEB-INF/lib/jdbc-stdext-2.0.jar" );
144 expectedLibs.add( "/WEB-INF/lib/junit-3.8.1.jar" );
145
146 Document imlDocument = executeMojo( "src/test/module-plugin-configs/provided-dep-plugin-config.xml" );
147
148 Element root = imlDocument.getRootElement();
149
150 assertEquals( "Test Project type", "J2EE_WEB_MODULE", root.attributeValue( "type" ) );
151
152 Element component = findComponent( root, "WebModuleBuildComponent" );
153
154 Element setting = findElement( component, "setting" );
155 assertTrue( "Test exploded url setting", "EXPLODED_URL".equals( setting.attributeValue( "name" ) ) );
156 assertTrue( "Test exploded url value",
157 setting.attributeValue( "value" ).startsWith( "file://$MODULE_DIR$/target/" ) );
158
159 component = findComponent( root, "WebModuleProperties" );
160
161 Element deployDescriptor = component.element( "deploymentDescriptor" );
162 assertEquals( "Test deployment descriptor version", "2.3", deployDescriptor.attributeValue( "version" ) );
163 assertEquals( "Test deployment descriptor name", "web.xml", deployDescriptor.attributeValue( "name" ) );
164 assertEquals( "Test deployment descriptor optional", "false", deployDescriptor.attributeValue( "optional" ) );
165 assertEquals( "Test deployment descriptor file", "file://$MODULE_DIR$/src/main/webapp/WEB-INF/web.xml",
166 deployDescriptor.attributeValue( "url" ) );
167
168 Element webroots = component.element( "webroots" );
169 Element webroot = webroots.element( "root" );
170 assertEquals( "Test webroot relative location", "/", webroot.attributeValue( "relative" ) );
171 assertEquals( "Test webroot url", "file://$MODULE_DIR$/src/main/webapp", webroot.attributeValue( "url" ) );
172
173 List containerElementList = findElementsByName( component, "containerElement" );
174 for ( Iterator containerElements = containerElementList.iterator(); containerElements.hasNext(); )
175 {
176 Element containerElement = (Element) containerElements.next();
177
178 assertEquals( "Test container element type", "library", containerElement.attributeValue( "type" ) );
179 assertEquals( "Test container element level", "module", containerElement.attributeValue( "level" ) );
180 assertTrue( "Test library url", containerElement.element( "url" ).getText().startsWith( "jar://" ) );
181
182 Element attribute = findElementByNameAttribute( containerElement, "attribute", "URI" );
183 String attributeValue = attribute.attributeValue( "value" );
184
185 attribute = findElementByNameAttribute( containerElement, "attribute", "method" );
186
187 if ( "/WEB-INF/lib/maven-model-2.0.1.jar".equals( attributeValue ) )
188 {
189 assertEquals( "Test library method for provided dependency", "0", attribute.attributeValue( "value" ) );
190 }
191 else if ( "/WEB-INF/lib/jdbc-stdext-2.0.jar".equals( attributeValue ) )
192 {
193 assertEquals( "Test library method for system dependency", "0", attribute.attributeValue( "value" ) );
194 }
195 else if ( "/WEB-INF/lib/junit-3.8.1.jar".equals( attributeValue ) )
196 {
197 assertEquals( "Test library method for test dependency", "0", attribute.attributeValue( "value" ) );
198 }
199 else
200 {
201 assertEquals( "Test library method", "1", attribute.attributeValue( "value" ) );
202 }
203
204 assertTrue( "Test library URI", expectedLibs.contains( attributeValue ) );
205 expectedLibs.remove( attributeValue );
206 }
207
208 assertTrue( "All libraries are present", expectedLibs.size() == 0 );
209 }
210
211 public void testEjbMinConfig()
212 throws Exception
213 {
214 List expectedLibs = new ArrayList();
215 expectedLibs.add( "/lib/maven-model-2.0.1.jar" );
216 expectedLibs.add( "/lib/junit-3.8.1.jar" );
217
218 Document imlDocument = executeMojo( "src/test/module-plugin-configs/min-ejb-plugin-config.xml" );
219
220 Element root = imlDocument.getRootElement();
221
222 assertEquals( "Test Project type", "J2EE_EJB_MODULE", root.attributeValue( "type" ) );
223
224 Element component = findComponent( root, "EjbModuleBuildComponent" );
225
226 Element setting = findElement( component, "setting" );
227 assertTrue( "Test exploded url setting", "EXPLODED_URL".equals( setting.attributeValue( "name" ) ) );
228 assertTrue( "Test exploded url value",
229 setting.attributeValue( "value" ).startsWith( "file://$MODULE_DIR$/target/" ) );
230
231 component = findComponent( root, "EjbModuleProperties" );
232
233 Element deployDescriptor = component.element( "deploymentDescriptor" );
234 assertEquals( "Test deployment descriptor version", "2.x", deployDescriptor.attributeValue( "version" ) );
235 assertEquals( "Test deployment descriptor name", "ejb-jar.xml", deployDescriptor.attributeValue( "name" ) );
236 assertEquals( "Test deployment descriptor optional", "false", deployDescriptor.attributeValue( "optional" ) );
237 assertEquals( "Test deployment descriptor file", "file://$MODULE_DIR$/src/main/resources/META-INF/ejb-jar.xml",
238 deployDescriptor.attributeValue( "url" ) );
239
240 List containerElementList = findElementsByName( component, "containerElement" );
241 for ( Iterator containerElements = containerElementList.iterator(); containerElements.hasNext(); )
242 {
243 Element containerElement = (Element) containerElements.next();
244
245 assertEquals( "Test container element type", "library", containerElement.attributeValue( "type" ) );
246 assertEquals( "Test container element level", "module", containerElement.attributeValue( "level" ) );
247
248 Element attribute = findElementByNameAttribute( containerElement, "attribute", "method" );
249 assertEquals( "Test library method", "2", attribute.attributeValue( "value" ) );
250
251 attribute = findElementByNameAttribute( containerElement, "attribute", "URI" );
252 String attributeValue = attribute.attributeValue( "value" );
253 assertTrue( "Test library URI", expectedLibs.contains( attributeValue ) );
254 expectedLibs.remove( attributeValue );
255 }
256
257 assertTrue( "All libraries are present", expectedLibs.size() == 0 );
258 }
259
260 public void testEarMinConfig()
261 throws Exception
262 {
263 Document imlDocument = executeMojo( "src/test/module-plugin-configs/min-ear-plugin-config.xml" );
264
265 Element root = imlDocument.getRootElement();
266
267 assertEquals( "Test Project type", "J2EE_APPLICATION_MODULE", root.attributeValue( "type" ) );
268
269 Element component = findComponent( root, "ApplicationModuleProperties" );
270
271 Element deployDescriptor = component.element( "deploymentDescriptor" );
272 assertEquals( "Test deployment descriptor version", "1.3", deployDescriptor.attributeValue( "version" ) );
273 assertEquals( "Test deployment descriptor name", "application.xml", deployDescriptor.attributeValue( "name" ) );
274 assertEquals( "Test deployment descriptor optional", "false", deployDescriptor.attributeValue( "optional" ) );
275 assertEquals( "Test deployment descriptor file", "file://$MODULE_DIR$/target/application.xml",
276 deployDescriptor.attributeValue( "url" ) );
277 }
278
279 public void testGeneralConfigurations()
280 throws Exception
281 {
282 Document imlDocument = executeMojo( "src/test/module-plugin-configs/general-plugin-config.xml" );
283
284 Element component = findComponent( imlDocument.getRootElement(), "NewModuleRootManager" );
285
286 Element content = findElement( component, "content" );
287
288 List expectedExcludes = new ArrayList();
289 expectedExcludes.add( "file://$MODULE_DIR$/src/main/resources/excluded" );
290 expectedExcludes.add( "file://$MODULE_DIR$/src/main/resources/excluded-too" );
291
292 List excludeList = content.elements( "excludeFolder" );
293 for ( Iterator excludes = excludeList.iterator(); excludes.hasNext(); )
294 {
295 Element exclude = (Element) excludes.next();
296
297 String excluded = exclude.attributeValue( "url" );
298
299 if ( excluded.equals( "file://$MODULE_DIR$/src/main/resources/excluded/sub" ) )
300 {
301 fail( "A subdirectory of an already excluded directory must be removed" );
302 }
303
304 if ( expectedExcludes.contains( excluded ) )
305 {
306 expectedExcludes.remove( excluded );
307 }
308 }
309 assertEquals( "Test all excludes", 0, expectedExcludes.size() );
310
311 List orderEntryList = findElementsByName( component, "orderEntry" );
312 for ( Iterator orderEntries = orderEntryList.iterator(); orderEntries.hasNext(); )
313 {
314 Element orderEntry = (Element) orderEntries.next();
315
316 if ( "module-library".equals( orderEntry.attributeValue( "type" ) ) )
317 {
318 Element library = orderEntry.element( "library" );
319
320 String name = library.attributeValue( "name" );
321 assertTrue( "Test usage of fullnames", name.indexOf( ":" ) > 0 );
322 }
323 }
324
325 File srcFile = new File( PlexusTestCase.getBasedir(),
326 "target/local-repo/org/apache/maven/maven-model/2.0.1/maven-model-2.0.1-src.jar" );
327 assertTrue( "Test maven-model source is downloaded", srcFile.exists() );
328 srcFile = new File( PlexusTestCase.getBasedir(), "target/local-repo/junit/junit/3.8.1/junit-3.8.1-src.jar" );
329 assertTrue( "Test junit source is downloaded", srcFile.exists() );
330
331 File docFile = new File( PlexusTestCase.getBasedir(),
332 "target/local-repo/org/apache/maven/maven-model/2.0.1/maven-model-2.0.1-doc.jar" );
333 assertTrue( "Test maven-model javadoc is downloaded", docFile.exists() );
334 }
335
336 public void testWarConfig()
337 throws Exception
338 {
339 List expectedLibs = new ArrayList();
340 expectedLibs.add( "/WEB-INF/lib/maven-model-2.0.1.jar" );
341 expectedLibs.add( "/WEB-INF/lib/junit-3.8.1.jar" );
342
343 Document imlDocument = executeMojo( "src/test/module-plugin-configs/war-plugin-config.xml" );
344
345 Element root = imlDocument.getRootElement();
346
347 assertEquals( "Test Project type", "J2EE_WEB_MODULE", root.attributeValue( "type" ) );
348
349 Element component = findComponent( root, "WebModuleBuildComponent" );
350
351 Element setting = findElement( component, "setting" );
352 assertTrue( "Test exploded url setting", "EXPLODED_URL".equals( setting.attributeValue( "name" ) ) );
353 assertTrue( "Test exploded url value",
354 setting.attributeValue( "value" ).startsWith( "file://$MODULE_DIR$/target/" ) );
355
356 component = findComponent( root, "WebModuleProperties" );
357
358 Element deployDescriptor = component.element( "deploymentDescriptor" );
359 assertEquals( "Test deployment descriptor version", "2.3", deployDescriptor.attributeValue( "version" ) );
360 assertEquals( "Test deployment descriptor name", "web.xml", deployDescriptor.attributeValue( "name" ) );
361 assertEquals( "Test deployment descriptor optional", "false", deployDescriptor.attributeValue( "optional" ) );
362 assertEquals( "Test deployment descriptor file", "file://$MODULE_DIR$/src/main/web/WEB-INF/web.xml",
363 deployDescriptor.attributeValue( "url" ) );
364
365 Element webroots = component.element( "webroots" );
366 Element webroot = webroots.element( "root" );
367 assertEquals( "Test webroot relative location", "/", webroot.attributeValue( "relative" ) );
368 assertEquals( "Test webroot url", "file://$MODULE_DIR$/src/main/webapp", webroot.attributeValue( "url" ) );
369
370 List containerElementList = findElementsByName( component, "containerElement" );
371 for ( Iterator containerElements = containerElementList.iterator(); containerElements.hasNext(); )
372 {
373 Element containerElement = (Element) containerElements.next();
374
375 assertEquals( "Test container element type", "library", containerElement.attributeValue( "type" ) );
376 assertEquals( "Test container element level", "module", containerElement.attributeValue( "level" ) );
377 assertTrue( "Test library url", containerElement.element( "url" ).getText().startsWith( "jar://" ) );
378
379 Element attribute = findElementByNameAttribute( containerElement, "attribute", "method" );
380 assertEquals( "Test library method", "1", attribute.attributeValue( "value" ) );
381
382 attribute = findElementByNameAttribute( containerElement, "attribute", "URI" );
383 String attributeValue = attribute.attributeValue( "value" );
384 assertTrue( "Test library URI", expectedLibs.contains( attributeValue ) );
385 expectedLibs.remove( attributeValue );
386 }
387
388 assertTrue( "All libraries are present", expectedLibs.size() == 0 );
389 }
390
391 public void testProjectWithModulesConfigurations()
392 throws Exception
393 {
394 Document imlDocument = executeMojo( "src/test/module-plugin-configs/module-plugin-config.xml" );
395
396 Element component = findComponent( imlDocument.getRootElement(), "NewModuleRootManager" );
397
398 boolean moduleFound = false;
399 List orderEntryList = component.elements( "orderEntry" );
400 for ( Iterator orderEntries = orderEntryList.iterator(); orderEntries.hasNext(); )
401 {
402 Element orderEntry = (Element) orderEntries.next();
403 if ( "module".equals( orderEntry.attributeValue( "type" ) ) )
404 {
405 String moduleName = orderEntry.attributeValue( "module-name" );
406 assertTrue( "Test idea module name", moduleName.startsWith( "plugin-reactor-project-" ) );
407 moduleFound = true;
408 }
409 }
410 assertTrue( "Test presence of idea module", moduleFound );
411 }
412
413 public void testProjectWithLibrariesConfigurations()
414 throws Exception
415 {
416 Document imlDocument = executeMojo( "src/test/module-plugin-configs/library-plugin-config.xml" );
417
418 Element component = findComponent( imlDocument.getRootElement(), "NewModuleRootManager" );
419
420 boolean libraryFound = false;
421 for ( Iterator orderEntries = component.elementIterator( "orderEntry" ); orderEntries.hasNext(); )
422 {
423 Element orderEntry = (Element) orderEntries.next();
424 Element library = orderEntry.element( "library" );
425 if ( library != null )
426 {
427 String name = library.attributeValue( "name" );
428 if ( name != null && name.equals( "test-library" ) )
429 {
430 libraryFound = true;
431
432 String url = library.element( "CLASSES" ).element( "root" ).attributeValue( "url" );
433 assertEquals( "Test user provided class path", "file:///user/defined/classes", url );
434
435 url = library.element( "SOURCES" ).element( "root" ).attributeValue( "url" );
436 assertEquals( "Test user provided source path", "file:///user/defined/sources", url );
437 }
438 }
439 }
440 assertTrue( "Test if configured library was found", libraryFound );
441 }
442
443 public void testProjectWithLibraryExcludeConfigurations()
444 throws Exception
445 {
446 Document imlDocument = executeMojo( "src/test/module-plugin-configs/library-exclude-plugin-config.xml" );
447
448 Element component = findComponent( imlDocument.getRootElement(), "NewModuleRootManager" );
449
450 for ( Iterator orderEntries = component.elementIterator( "orderEntry" ); orderEntries.hasNext(); )
451 {
452 Element orderEntry = (Element) orderEntries.next();
453 Element library = orderEntry.element( "library" );
454 if ( library != null )
455 {
456 Element classes = library.element( "CLASSES" );
457 if ( classes != null )
458 {
459 Element root = classes.element( "root" );
460 String url = root.attributeValue( "url" );
461
462 if ( url.indexOf( "test-library" ) >= 0 )
463 {
464 fail( "test-library must be excluded" );
465 }
466 }
467 }
468 }
469 }
470
471 public void testWarProjectWithModulesConfigurations()
472 throws Exception
473 {
474 Document imlDocument = executeMojo( "src/test/module-plugin-configs/war-module-plugin-config.xml" );
475
476 Element component = findComponent( imlDocument.getRootElement(), "NewModuleRootManager" );
477
478 boolean moduleFound = false;
479 List orderEntryList = component.elements( "orderEntry" );
480 for ( Iterator orderEntries = orderEntryList.iterator(); orderEntries.hasNext(); )
481 {
482 Element orderEntry = (Element) orderEntries.next();
483 if ( "module".equals( orderEntry.attributeValue( "type" ) ) )
484 {
485 String moduleName = orderEntry.attributeValue( "module-name" );
486 assertTrue( "Test idea module name", moduleName.startsWith( "plugin-reactor-project-" ) );
487 moduleFound = true;
488 }
489 }
490 assertTrue( "Test presence of idea module", moduleFound );
491
492 component = findComponent( imlDocument.getRootElement(), "WebModuleProperties" );
493
494 boolean webModuleFound = false;
495 for ( Iterator elements = component.elementIterator( "containerElement" ); elements.hasNext(); )
496 {
497 Element containerElement = (Element) elements.next();
498
499 if ( "module".equals( containerElement.attributeValue( "type" ) ) )
500 {
501 String name = containerElement.attributeValue( "name" );
502
503 assertTrue( "Module must be from reactor", name.indexOf( "plugin-reactor-project-" ) >= 0 );
504
505 assertNull( "Library url for modules must not be present", containerElement.element( "url" ) );
506
507 Element method = findElementByNameAttribute( containerElement, "attribute", "method" );
508 assertEquals( "Test Library module method", "5", method.attributeValue( "value" ) );
509
510 Element uri = findElementByNameAttribute( containerElement, "attribute", "URI" );
511 assertEquals( "Test Library module method", "/WEB-INF/lib/" + name + "-1.0.jar",
512 uri.attributeValue( "value" ) );
513
514 webModuleFound = true;
515 }
516 }
517 assertTrue( "Test WebModuleProperties for module library", webModuleFound );
518 }
519
520 public void testEjbProjectWithModulesConfigurations()
521 throws Exception
522 {
523 Document imlDocument = executeMojo( "src/test/module-plugin-configs/ejb-module-plugin-config.xml" );
524
525 Element component = findComponent( imlDocument.getRootElement(), "NewModuleRootManager" );
526
527 boolean moduleFound = false;
528 List orderEntryList = component.elements( "orderEntry" );
529 for ( Iterator orderEntries = orderEntryList.iterator(); orderEntries.hasNext(); )
530 {
531 Element orderEntry = (Element) orderEntries.next();
532 if ( "module".equals( orderEntry.attributeValue( "type" ) ) )
533 {
534 String moduleName = orderEntry.attributeValue( "module-name" );
535 assertTrue( "Test idea module name", moduleName.startsWith( "plugin-reactor-project-" ) );
536 moduleFound = true;
537 }
538 }
539 assertTrue( "Test presence of idea module", moduleFound );
540
541 component = findComponent( imlDocument.getRootElement(), "EjbModuleProperties" );
542
543 boolean ejbModuleFound = false;
544 for ( Iterator elements = component.elementIterator( "containerElement" ); elements.hasNext(); )
545 {
546 Element containerElement = (Element) elements.next();
547
548 if ( "module".equals( containerElement.attributeValue( "type" ) ) )
549 {
550 String name = containerElement.attributeValue( "name" );
551
552 assertTrue( "Module must be from reactor", name.indexOf( "plugin-reactor-project-" ) >= 0 );
553
554 assertNull( "Library url for modules must not be present", containerElement.element( "url" ) );
555
556 Element method = findElementByNameAttribute( containerElement, "attribute", "method" );
557 assertEquals( "Test Library module method", "6", method.attributeValue( "value" ) );
558
559 Element uri = findElementByNameAttribute( containerElement, "attribute", "URI" );
560 assertEquals( "Test Library module method", "/lib/plugin-reactor-project-m-ejb-mod-1.jar", uri.attributeValue( "value" ) );
561
562 ejbModuleFound = true;
563 }
564 }
565 assertTrue( "Test EjbModuleProperties for module library", ejbModuleFound );
566 }
567
568 public void testProjectArtifactsWithVersionRange()
569 throws Exception
570 {
571 List expectedDeps = new ArrayList();
572 expectedDeps.add( "/junit/junit/4.0/junit-4.0.jar!/" );
573
574 Document imlDocument = super.executeMojo( "module", "src/test/module-plugin-configs/artifact-version-range-plugin-config.xml", "iml" );
575
576 Element component = findComponent( imlDocument.getRootElement(), "NewModuleRootManager" );
577
578 Element output = findElement( component, "output" );
579 assertEquals( "Module output url created.", "file://$MODULE_DIR$/target/classes",
580 output.attributeValue( "url" ) );
581
582 Element outputTest = findElement( component, "output-test" );
583 assertEquals( "Module test-output url created.", "file://$MODULE_DIR$/target/test-classes",
584 outputTest.attributeValue( "url" ) );
585
586 Element content = findElement( component, "content" );
587
588 List excludeList = content.elements( "excludeFolder" );
589 if ( excludeList.size() == 1 )
590 {
591 Element excl = content.element( "excludeFolder" );
592 assertEquals( "Test default exclude folder", "file://$MODULE_DIR$/target", excl.attributeValue( "url" ) );
593 }
594 else
595 {
596 boolean targetIsExcluded = false;
597 for ( Iterator excludes = excludeList.iterator(); excludes.hasNext(); )
598 {
599 Element excl = (Element) excludes.next();
600
601 if ( "file://$MODULE_DIR$/target".equals( excl.attributeValue( "url" ) ) )
602 {
603 targetIsExcluded = true;
604 break;
605 }
606 }
607
608 if ( !targetIsExcluded )
609 {
610 fail( "Default exclude folder 'target' not found" );
611 }
612 }
613
614 List elementList = findElementsByName( content, "sourceFolder" );
615 for ( Iterator sourceFolders = elementList.iterator(); sourceFolders.hasNext(); )
616 {
617 Element sourceFolder = (Element) sourceFolders.next();
618
619 String isTestSource = sourceFolder.attributeValue( "isTestSource" ).toLowerCase();
620 if ( "false".equals( isTestSource ) )
621 {
622 assertTrue( "Main source url",
623 sourceFolder.attributeValue( "url" ).startsWith( "file://$MODULE_DIR$/src/main" ) );
624 }
625 else if ( "true".equals( isTestSource ) )
626 {
627 assertTrue( "Test source url",
628 sourceFolder.attributeValue( "url" ).startsWith( "file://$MODULE_DIR$/src/test" ) );
629 }
630 else
631 {
632 fail( "Unknown sourceFolder 'isTestSource' attribute value: " + isTestSource );
633 }
634 }
635
636 List orderEntryList = findElementsByName( component, "orderEntry" );
637
638 for ( Iterator orderEntries = orderEntryList.iterator(); orderEntries.hasNext(); )
639 {
640 Element orderEntry = (Element) orderEntries.next();
641
642 if ( "module-library".equals( orderEntry.attributeValue( "type" ) ) )
643 {
644 Element library = (Element) orderEntry.elementIterator( "library" ).next();
645
646 Element classes = (Element) library.elementIterator( "CLASSES" ).next();
647
648 Element root = (Element) classes.elementIterator( "root" ).next();
649
650 String depUrl = root.attributeValue( "url" );
651
652 if ( depUrl.endsWith( "/junit/junit/4.0/junit-4.0.jar!/" ) )
653 {
654 expectedDeps.remove( "/junit/junit/4.0/junit-4.0.jar!/" );
655 }
656 }
657 }
658
659 assertTrue( "All dependencies are present", expectedDeps.size() == 0 );
660 }
661
662 protected Document executeMojo( String pluginXml )
663 throws Exception
664 {
665 List expectedDeps = new ArrayList();
666 expectedDeps.add( "/org/apache/maven/maven-model/2.0.1/maven-model-2.0.1.jar!/" );
667 expectedDeps.add( "/junit/junit/3.8.1/junit-3.8.1.jar!/" );
668
669 Document imlDocument = super.executeMojo( "module", pluginXml, "iml" );
670
671 Element component = findComponent( imlDocument.getRootElement(), "NewModuleRootManager" );
672
673 Element output = findElement( component, "output" );
674 assertEquals( "Module output url created.", "file://$MODULE_DIR$/target/classes",
675 output.attributeValue( "url" ) );
676
677 Element outputTest = findElement( component, "output-test" );
678 assertEquals( "Module test-output url created.", "file://$MODULE_DIR$/target/test-classes",
679 outputTest.attributeValue( "url" ) );
680
681 Element content = findElement( component, "content" );
682
683 List excludeList = content.elements( "excludeFolder" );
684 if ( excludeList.size() == 1 )
685 {
686 Element excl = content.element( "excludeFolder" );
687 assertEquals( "Test default exclude folder", "file://$MODULE_DIR$/target", excl.attributeValue( "url" ) );
688 }
689 else
690 {
691 boolean targetIsExcluded = false;
692 for ( Iterator excludes = excludeList.iterator(); excludes.hasNext(); )
693 {
694 Element excl = (Element) excludes.next();
695
696 if ( "file://$MODULE_DIR$/target".equals( excl.attributeValue( "url" ) ) )
697 {
698 targetIsExcluded = true;
699 break;
700 }
701 }
702
703 if ( !targetIsExcluded )
704 {
705 fail( "Default exclude folder 'target' not found" );
706 }
707 }
708
709 List elementList = findElementsByName( content, "sourceFolder" );
710 for ( Iterator sourceFolders = elementList.iterator(); sourceFolders.hasNext(); )
711 {
712 Element sourceFolder = (Element) sourceFolders.next();
713
714 String isTestSource = sourceFolder.attributeValue( "isTestSource" ).toLowerCase();
715 if ( "false".equals( isTestSource ) )
716 {
717 assertTrue( "Main source url",
718 sourceFolder.attributeValue( "url" ).startsWith( "file://$MODULE_DIR$/src/main" ) );
719 }
720 else if ( "true".equals( isTestSource ) )
721 {
722 assertTrue( "Test source url",
723 sourceFolder.attributeValue( "url" ).startsWith( "file://$MODULE_DIR$/src/test" ) );
724 }
725 else
726 {
727 fail( "Unknown sourceFolder 'isTestSource' attribute value: " + isTestSource );
728 }
729 }
730
731 List orderEntryList = findElementsByName( component, "orderEntry" );
732
733 for ( Iterator orderEntries = orderEntryList.iterator(); orderEntries.hasNext(); )
734 {
735 Element orderEntry = (Element) orderEntries.next();
736
737 if ( "module-library".equals( orderEntry.attributeValue( "type" ) ) )
738 {
739 Element library = (Element) orderEntry.elementIterator( "library" ).next();
740
741 Element classes = (Element) library.elementIterator( "CLASSES" ).next();
742
743 Element root = (Element) classes.elementIterator( "root" ).next();
744
745 String depUrl = root.attributeValue( "url" );
746
747 if ( depUrl.endsWith( "/org/apache/maven/maven-model/2.0.1/maven-model-2.0.1.jar!/" ) )
748 {
749 expectedDeps.remove( "/org/apache/maven/maven-model/2.0.1/maven-model-2.0.1.jar!/" );
750 }
751 else if ( depUrl.endsWith( "/junit/junit/3.8.1/junit-3.8.1.jar!/" ) )
752 {
753 expectedDeps.remove( "/junit/junit/3.8.1/junit-3.8.1.jar!/" );
754 }
755 }
756 }
757
758 assertTrue( "All dependencies are present", expectedDeps.size() == 0 );
759
760 return imlDocument;
761 }
762 }