1 package org.apache.maven.project;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.util.ArrayList;
24 import java.util.Arrays;
25 import java.util.List;
26 import java.util.Map;
27 import java.util.Properties;
28
29 import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
30 import org.apache.maven.model.Plugin;
31 import org.apache.maven.model.PluginExecution;
32 import org.apache.maven.model.building.ModelBuildingRequest;
33 import org.apache.maven.project.harness.PomTestWrapper;
34 import org.apache.maven.repository.RepositorySystem;
35 import org.apache.maven.repository.internal.MavenRepositorySystemSession;
36 import org.codehaus.plexus.PlexusTestCase;
37 import org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager;
38
39 public class PomConstructionTest
40 extends PlexusTestCase
41 {
42 private static String BASE_DIR = "src/test";
43
44 private static String BASE_POM_DIR = BASE_DIR + "/resources-project-builder";
45
46 private static String BASE_MIXIN_DIR = BASE_DIR + "/resources-mixins";
47
48 private DefaultProjectBuilder projectBuilder;
49
50 private RepositorySystem repositorySystem;
51
52 private File testDirectory;
53
54 protected void setUp()
55 throws Exception
56 {
57 testDirectory = new File( getBasedir(), BASE_POM_DIR );
58 new File( getBasedir(), BASE_MIXIN_DIR );
59 projectBuilder = (DefaultProjectBuilder) lookup( ProjectBuilder.class );
60 repositorySystem = lookup( RepositorySystem.class );
61 }
62
63 @Override
64 protected void tearDown()
65 throws Exception
66 {
67 projectBuilder = null;
68
69 super.tearDown();
70 }
71
72
73
74
75
76
77
78 public void testEmptyUrl()
79 throws Exception
80 {
81 buildPom( "empty-distMng-repo-url" );
82 }
83
84
85
86
87
88
89
90 public void testProfileModules()
91 throws Exception
92 {
93 PomTestWrapper pom = buildPom( "profile-module", "a" );
94 assertEquals( "test-prop", pom.getValue( "properties[1]/b" ) );
95 assertEquals( 4, ( (List<?>) pom.getValue( "modules" ) ).size() );
96 assertEquals( "module-2", pom.getValue( "modules[1]" ) );
97 assertEquals( "module-1", pom.getValue( "modules[2]" ) );
98 assertEquals( "module-3", pom.getValue( "modules[3]" ) );
99 assertEquals( "module-4", pom.getValue( "modules[4]" ) );
100 }
101
102
103
104
105
106
107 public void testParentInheritance()
108 throws Exception
109 {
110 buildPom( "parent-inheritance/sub" );
111 }
112
113
114 public void testExecutionConfigurationJoin()
115 throws Exception
116 {
117 PomTestWrapper pom = buildPom( "execution-configuration-join" );
118 assertEquals( 2, ( (List<?>) pom.getValue( "build/plugins[1]/executions[1]/configuration[1]/fileset[1]" ) ).size() );
119 }
120
121
122 public void testPluginConfigProperties()
123 throws Exception
124 {
125 PomTestWrapper pom = buildPom( "plugin-config-properties" );
126 assertEquals( "my.property", pom.getValue( "build/plugins[1]/configuration[1]/systemProperties[1]/property[1]/name" ) );
127 }
128
129
130 public void testProfilePropertiesInterpolation()
131 throws Exception
132 {
133 PomTestWrapper pom = buildPom( "profile-properties-interpolation", "interpolation-profile" );
134 assertEquals("PASSED", pom.getValue("properties[1]/test"));
135 assertEquals("PASSED", pom.getValue("properties[1]/property"));
136 }
137
138
139
140
141
142
143
144
145 public void testThatExecutionsWithoutIdsAreMergedAndTheChildWins()
146 throws Exception
147 {
148 PomTestWrapper tester = buildPom("micromailer");
149 assertModelEquals( tester, "child-descriptor", "build/plugins[1]/executions[1]/goals[1]" );
150 }
151
152
153
154
155
156
157
158
159
160
161 public void testDuplicateExclusionsDependency()
162 throws Exception
163 {
164 PomTestWrapper pom = buildPom( "duplicate-exclusions-dependency/sub" );
165 assertEquals( 1, ( (List<?>) pom.getValue( "dependencies[1]/exclusions" ) ).size() );
166
167 }
168
169
170 public void testMultipleFilters()
171 throws Exception
172 {
173 PomTestWrapper pom = buildPom( "multiple-filters" );
174 assertEquals( 4, ( (List<?>) pom.getValue( "build/filters" ) ).size() );
175
176 }
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236 public void testDuplicateDependenciesCauseLastDeclarationToBePickedInLenientMode()
237 throws Exception
238 {
239 PomTestWrapper pom = buildPom( "unique-dependency-key/deps", true, null );
240 assertEquals( 1, ( (List<?>) pom.getValue( "dependencies" ) ).size() );
241 assertEquals( "0.2", pom.getValue( "dependencies[1]/version" ) );
242 }
243
244
245 public void testParentInterpolation()
246 throws Exception
247 {
248 PomTestWrapper pom = buildPom( "parent-interpolation/sub" );
249 pom = new PomTestWrapper(pom.getMavenProject().getParent());
250 assertEquals( "1.3.0-SNAPSHOT", pom.getValue( "build/plugins[1]/version" ) );
251 }
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267 public void testPluginManagementInherited()
268 throws Exception
269 {
270 PomTestWrapper pom = buildPom( "pluginmanagement-inherited/sub" );
271 assertEquals( "1.0-alpha-21", pom.getValue( "build/plugins[1]/version" ) );
272 }
273
274
275 public void testPluginManagementDependencies()
276 throws Exception
277 {
278 PomTestWrapper pom = buildPom( "plugin-management-dependencies/sub", "test" );
279 assertEquals( "1.0-alpha-21", pom.getValue( "build/plugins[1]/version" ) );
280 assertEquals( "1.0", pom.getValue( "build/plugins[1]/dependencies[1]/version" ) );
281 }
282
283
284
285 public void testReportingInterpolation()
286 throws Exception
287 {
288 PomTestWrapper pom = buildPom( "reporting-interpolation" );
289 assertEquals( createPath(Arrays.asList(System.getProperty("user.dir"),
290 "src", "test", "resources-project-builder", "reporting-interpolation", "target", "site")),
291 pom.getValue( "reporting/outputDirectory" ) );
292 }
293
294
295 public void testPluginOrder()
296 throws Exception
297 {
298 PomTestWrapper pom = buildPom( "plugin-order" );
299 assertEquals( "plexus-component-metadata", pom.getValue( "build/plugins[1]/artifactId" ) );
300 assertEquals( "maven-surefire-plugin", pom.getValue( "build/plugins[2]/artifactId" ) );
301 }
302
303 public void testErroneousJoiningOfDifferentPluginsWithEqualDependencies()
304 throws Exception
305 {
306 PomTestWrapper pom = buildPom( "equal-plugin-deps" );
307 assertEquals( "maven-it-plugin-a", pom.getValue( "build/plugins[1]/artifactId" ) );
308 assertEquals( 1, ( (List<?>) pom.getValue( "build/plugins[1]/dependencies" ) ).size() );
309 assertEquals( "maven-it-plugin-b", pom.getValue( "build/plugins[2]/artifactId" ) );
310 assertEquals( 1, ( (List<?>) pom.getValue( "build/plugins[1]/dependencies" ) ).size() );
311 }
312
313
314 public void testErroneousJoiningOfDifferentPluginsWithEqualExecutionIds()
315 throws Exception
316 {
317 PomTestWrapper pom = buildPom( "equal-plugin-exec-ids" );
318 assertEquals( "maven-it-plugin-a", pom.getValue( "build/plugins[1]/artifactId" ) );
319 assertEquals( 1, ( (List<?>) pom.getValue( "build/plugins[1]/executions" ) ).size() );
320 assertEquals( "maven-it-plugin-b", pom.getValue( "build/plugins[2]/artifactId" ) );
321 assertEquals( 1, ( (List<?>) pom.getValue( "build/plugins[1]/executions" ) ).size() );
322 assertEquals( "maven-it-plugin-a", pom.getValue( "reporting/plugins[1]/artifactId" ) );
323 assertEquals( 1, ( (List<?>) pom.getValue( "reporting/plugins[1]/reportSets" ) ).size() );
324 assertEquals( "maven-it-plugin-b", pom.getValue( "reporting/plugins[2]/artifactId" ) );
325 assertEquals( 1, ( (List<?>) pom.getValue( "reporting/plugins[1]/reportSets" ) ).size() );
326 }
327
328
329 public void testExecutionConfiguration()
330 throws Exception
331 {
332 PomTestWrapper pom = buildPom( "execution-configuration" );
333 assertEquals( 2, ( (List<?>) pom.getValue( "build/plugins[1]/executions" ) ).size() );
334 assertEquals( "src/main/mdo/nexus.xml", ( pom.getValue( "build/plugins[1]/executions[1]/configuration[1]/model" ) ));
335 assertEquals( "src/main/mdo/security.xml", ( pom.getValue( "build/plugins[1]/executions[2]/configuration[1]/model" ) ));
336 }
337
338
339
340
341
342
343
344
345
346
347 public void testSingleConfigurationInheritance()
348 throws Exception
349 {
350 PomTestWrapper pom = buildPom( "single-configuration-inheritance" );
351
352 assertEquals( 2, ( (List<?>) pom.getValue( "build/plugins[1]/executions[1]/configuration[1]/rules" ) ).size() );
353 assertEquals("2.0.6", pom.getValue( "build/plugins[1]/executions[1]/configuration[1]/rules[1]/requireMavenVersion[1]/version" ) );
354 assertEquals("[1.4,)", pom.getValue( "build/plugins[1]/executions[1]/configuration[1]/rules[1]/requireJavaVersion[1]/version" ) );
355 }
356
357 public void testConfigWithPluginManagement()
358 throws Exception
359 {
360 PomTestWrapper pom = buildPom( "config-with-plugin-mng" );
361 assertEquals( 2, ( (List<?>) pom.getValue( "build/plugins[1]/executions" ) ).size() );
362 assertEquals( "src/main/mdo/security.xml", pom.getValue( "build/plugins[1]/executions[2]/configuration[1]/model" ) );
363 assertEquals( "1.0.8", pom.getValue( "build/plugins[1]/executions[1]/configuration[1]/version" ) );
364 }
365
366
367 public void testExecutionConfigurationSubcollections()
368 throws Exception
369 {
370 PomTestWrapper pom = buildPom( "execution-configuration-subcollections" );
371 assertEquals( 2, ( (List<?>) pom.getValue( "build/plugins[1]/executions[1]/configuration[1]/rules[1]/bannedDependencies" ) ).size() );
372 }
373
374
375 public void testMultipleRepositories()
376 throws Exception
377 {
378 PomTestWrapper pom = buildPom( "multiple-repos/sub" );
379 assertEquals( 3, ( (List<?>) pom.getValue( "repositories" ) ).size() );
380 }
381
382
383 public void testMultipleExecutionIds()
384 throws Exception
385 {
386 PomTestWrapper pom = buildPom( "dual-execution-ids/sub" );
387 assertEquals( 1, ( (List<?>) pom.getValue( "build/plugins[1]/executions" ) ).size() );
388 }
389
390
391 public void testConsecutiveEmptyElements()
392 throws Exception
393 {
394 PomTestWrapper pom = buildPom( "consecutive_empty_elements" );
395 }
396
397 public void testOrderOfGoalsFromPluginExecutionWithoutPluginManagement()
398 throws Exception
399 {
400 PomTestWrapper pom = buildPom( "plugin-exec-goals-order/wo-plugin-mngt" );
401 assertEquals( 5, ( (List<?>) pom.getValue( "build/plugins[1]/executions[1]/goals" ) ).size() );
402 assertEquals( "b", pom.getValue( "build/plugins[1]/executions[1]/goals[1]" ) );
403 assertEquals( "a", pom.getValue( "build/plugins[1]/executions[1]/goals[2]" ) );
404 assertEquals( "d", pom.getValue( "build/plugins[1]/executions[1]/goals[3]" ) );
405 assertEquals( "c", pom.getValue( "build/plugins[1]/executions[1]/goals[4]" ) );
406 assertEquals( "e", pom.getValue( "build/plugins[1]/executions[1]/goals[5]" ) );
407 }
408
409
410 public void testOrderOfGoalsFromPluginExecutionWithPluginManagement()
411 throws Exception
412 {
413 PomTestWrapper pom = buildPom( "plugin-exec-goals-order/w-plugin-mngt" );
414 assertEquals( 5, ( (List<?>) pom.getValue( "build/plugins[1]/executions[1]/goals" ) ).size() );
415 assertEquals( "b", pom.getValue( "build/plugins[1]/executions[1]/goals[1]" ) );
416 assertEquals( "a", pom.getValue( "build/plugins[1]/executions[1]/goals[2]" ) );
417 assertEquals( "d", pom.getValue( "build/plugins[1]/executions[1]/goals[3]" ) );
418 assertEquals( "c", pom.getValue( "build/plugins[1]/executions[1]/goals[4]" ) );
419 assertEquals( "e", pom.getValue( "build/plugins[1]/executions[1]/goals[5]" ) );
420 }
421
422 public void testOrderOfPluginExecutionsWithoutPluginManagement()
423 throws Exception
424 {
425 PomTestWrapper pom = buildPom( "plugin-exec-order/wo-plugin-mngt" );
426 assertEquals( 5, ( (List<?>) pom.getValue( "build/plugins[1]/executions" ) ).size() );
427 assertEquals( "b", pom.getValue( "build/plugins[1]/executions[1]/id" ) );
428 assertEquals( "a", pom.getValue( "build/plugins[1]/executions[2]/id" ) );
429 assertEquals( "d", pom.getValue( "build/plugins[1]/executions[3]/id" ) );
430 assertEquals( "c", pom.getValue( "build/plugins[1]/executions[4]/id" ) );
431 assertEquals( "e", pom.getValue( "build/plugins[1]/executions[5]/id" ) );
432 }
433
434
435 public void testOrderOfPluginExecutionsWithPluginManagement()
436 throws Exception
437 {
438 PomTestWrapper pom = buildPom( "plugin-exec-order/w-plugin-mngt" );
439 assertEquals( 5, ( (List<?>) pom.getValue( "build/plugins[1]/executions" ) ).size() );
440 assertEquals( "b", pom.getValue( "build/plugins[1]/executions[1]/id" ) );
441 assertEquals( "a", pom.getValue( "build/plugins[1]/executions[2]/id" ) );
442 assertEquals( "d", pom.getValue( "build/plugins[1]/executions[3]/id" ) );
443 assertEquals( "c", pom.getValue( "build/plugins[1]/executions[4]/id" ) );
444 assertEquals( "e", pom.getValue( "build/plugins[1]/executions[5]/id" ) );
445 }
446
447 public void testMergeOfPluginExecutionsWhenChildInheritsPluginVersion()
448 throws Exception
449 {
450 PomTestWrapper pom = buildPom( "plugin-exec-merging-wo-version/sub" );
451 assertEquals( 4, ( (List<?>) pom.getValue( "build/plugins[1]/executions" ) ).size() );
452 }
453
454
455 public void testMergeOfPluginExecutionsWhenChildAndParentUseDifferentPluginVersions()
456 throws Exception
457 {
458 PomTestWrapper pom = buildPom( "plugin-exec-merging-version-insensitive/sub" );
459 assertEquals( 4, ( (List<?>) pom.getValue( "build/plugins[1]/executions" ) ).size() );
460 }
461
462
463 public void testInterpolationWithXmlMarkup()
464 throws Exception
465 {
466 PomTestWrapper pom = buildPom( "xml-markup-interpolation" );
467 assertEquals( "<?xml version='1.0'?>Tom&Jerry", pom.getValue( "properties/xmlTest" ) );
468 }
469
470
471 public void testOrderOfMergedPluginExecutionsWithoutPluginManagement()
472 throws Exception
473 {
474 PomTestWrapper pom = buildPom( "merged-plugin-exec-order/wo-plugin-mngt/sub" );
475 assertEquals( 5, ( (List<?>) pom.getValue( "build/plugins[1]/executions" ) ).size() );
476 assertEquals( "parent-1", pom.getValue( "build/plugins[1]/executions[1]/goals[1]" ) );
477 assertEquals( "parent-2", pom.getValue( "build/plugins[1]/executions[2]/goals[1]" ) );
478 assertEquals( "child-default", pom.getValue( "build/plugins[1]/executions[3]/goals[1]" ) );
479 assertEquals( "child-1", pom.getValue( "build/plugins[1]/executions[4]/goals[1]" ) );
480 assertEquals( "child-2", pom.getValue( "build/plugins[1]/executions[5]/goals[1]" ) );
481 }
482
483 public void testOrderOfMergedPluginExecutionsWithPluginManagement()
484 throws Exception
485 {
486 PomTestWrapper pom = buildPom( "merged-plugin-exec-order/w-plugin-mngt/sub" );
487 assertEquals( 5, ( (List<?>) pom.getValue( "build/plugins[1]/executions" ) ).size() );
488 assertEquals( "parent-1", pom.getValue( "build/plugins[1]/executions[1]/goals[1]" ) );
489 assertEquals( "parent-2", pom.getValue( "build/plugins[1]/executions[2]/goals[1]" ) );
490 assertEquals( "child-default", pom.getValue( "build/plugins[1]/executions[3]/goals[1]" ) );
491 assertEquals( "child-1", pom.getValue( "build/plugins[1]/executions[4]/goals[1]" ) );
492 assertEquals( "child-2", pom.getValue( "build/plugins[1]/executions[5]/goals[1]" ) );
493 }
494
495
496 public void testDifferentContainersWithSameId()
497 throws Exception
498 {
499 PomTestWrapper pom = buildPom( "join-different-containers-same-id" );
500 assertEquals( 1, ( (List<?>) pom.getValue( "build/plugins[1]/executions[1]/goals" ) ).size() );
501 assertEquals( 1, ( (List<?>) pom.getValue( "build/pluginManagement/plugins[@artifactId='maven-it-plugin-b']/executions[1]/goals" ) ).size() );
502 }
503
504
505 public void testOrderOfMergedPluginExecutionGoalsWithoutPluginManagement()
506 throws Exception
507 {
508 PomTestWrapper pom = buildPom( "merged-plugin-exec-goals-order/wo-plugin-mngt/sub" );
509
510 assertEquals( 5, ( (List<?>) pom.getValue( "build/plugins[1]/executions[1]/goals" ) ).size() );
511 assertEquals( "child-a", pom.getValue( "build/plugins[1]/executions[1]/goals[1]" ) );
512 assertEquals( "merged", pom.getValue( "build/plugins[1]/executions[1]/goals[2]" ) );
513 assertEquals( "child-b", pom.getValue( "build/plugins[1]/executions[1]/goals[3]" ) );
514 assertEquals( "parent-b", pom.getValue( "build/plugins[1]/executions[1]/goals[4]" ) );
515 assertEquals( "parent-a", pom.getValue( "build/plugins[1]/executions[1]/goals[5]" ) );
516 }
517
518 public void testOrderOfMergedPluginExecutionGoalsWithPluginManagement()
519 throws Exception
520 {
521 PomTestWrapper pom = buildPom( "merged-plugin-exec-goals-order/w-plugin-mngt/sub" );
522 assertEquals( 5, ( (List<?>) pom.getValue( "build/plugins[1]/executions[1]/goals" ) ).size() );
523 assertEquals( "child-a", pom.getValue( "build/plugins[1]/executions[1]/goals[1]" ) );
524 assertEquals( "merged", pom.getValue( "build/plugins[1]/executions[1]/goals[2]" ) );
525 assertEquals( "child-b", pom.getValue( "build/plugins[1]/executions[1]/goals[3]" ) );
526 assertEquals( "parent-b", pom.getValue( "build/plugins[1]/executions[1]/goals[4]" ) );
527 assertEquals( "parent-a", pom.getValue( "build/plugins[1]/executions[1]/goals[5]" ) );
528 }
529
530
531 public void testOverridingOfInheritedPluginExecutionsWithoutPluginManagement()
532 throws Exception
533 {
534 PomTestWrapper pom = buildPom( "plugin-exec-merging/wo-plugin-mngt/sub" );
535 assertEquals( 2, ( (List<?>) pom.getValue( "build/plugins[1]/executions" ) ).size() );
536 assertEquals( "child-default", pom.getValue( "build/plugins[1]/executions[@id='default']/phase" ) );
537 assertEquals( "child-non-default", pom.getValue( "build/plugins[1]/executions[@id='non-default']/phase" ) );
538 }
539
540
541 public void testOverridingOfInheritedPluginExecutionsWithPluginManagement()
542 throws Exception
543 {
544 PomTestWrapper pom = buildPom( "plugin-exec-merging/w-plugin-mngt/sub" );
545 assertEquals( 2, ( (List<?>) pom.getValue( "build/plugins[1]/executions" ) ).size() );
546 assertEquals( "child-default", pom.getValue( "build/plugins[1]/executions[@id='default']/phase" ) );
547 assertEquals( "child-non-default", pom.getValue( "build/plugins[1]/executions[@id='non-default']/phase" ) );
548 }
549
550
551
552 public void testOrderOfMergedPluginDependenciesWithoutPluginManagement()
553 throws Exception
554 {
555 PomTestWrapper pom = buildPom( "merged-plugin-class-path-order/wo-plugin-mngt/sub" );
556
557 assertEquals( 5, ( (List<?>) pom.getValue( "build/plugins[1]/dependencies" ) ).size() );
558 assertNotNull( pom.getValue( "build/plugins[1]/dependencies[1]" ));
559 assertEquals( "c", pom.getValue( "build/plugins[1]/dependencies[1]/artifactId" ) );
560 assertEquals( "1", pom.getValue( "build/plugins[1]/dependencies[1]/version" ) );
561 assertEquals( "a", pom.getValue( "build/plugins[1]/dependencies[2]/artifactId" ) );
562 assertEquals( "2", pom.getValue( "build/plugins[1]/dependencies[2]/version" ) );
563 assertEquals( "b", pom.getValue( "build/plugins[1]/dependencies[3]/artifactId" ) );
564 assertEquals( "1", pom.getValue( "build/plugins[1]/dependencies[3]/version" ) );
565 assertEquals( "e", pom.getValue( "build/plugins[1]/dependencies[4]/artifactId" ) );
566 assertEquals( "1", pom.getValue( "build/plugins[1]/dependencies[4]/version" ) );
567 assertEquals( "d", pom.getValue( "build/plugins[1]/dependencies[5]/artifactId" ) );
568 assertEquals( "1", pom.getValue( "build/plugins[1]/dependencies[5]/version" ) );
569 }
570
571 public void testOrderOfMergedPluginDependenciesWithPluginManagement()
572 throws Exception
573 {
574 PomTestWrapper pom = buildPom( "merged-plugin-class-path-order/w-plugin-mngt/sub" );
575 assertEquals( 5, ( (List<?>) pom.getValue( "build/plugins[1]/dependencies" ) ).size() );
576 assertEquals( "c", pom.getValue( "build/plugins[1]/dependencies[1]/artifactId" ) );
577 assertEquals( "1", pom.getValue( "build/plugins[1]/dependencies[1]/version" ) );
578 assertEquals( "a", pom.getValue( "build/plugins[1]/dependencies[2]/artifactId" ) );
579 assertEquals( "2", pom.getValue( "build/plugins[1]/dependencies[2]/version" ) );
580 assertEquals( "b", pom.getValue( "build/plugins[1]/dependencies[3]/artifactId" ) );
581 assertEquals( "1", pom.getValue( "build/plugins[1]/dependencies[3]/version" ) );
582 assertEquals( "e", pom.getValue( "build/plugins[1]/dependencies[4]/artifactId" ) );
583 assertEquals( "1", pom.getValue( "build/plugins[1]/dependencies[4]/version" ) );
584 assertEquals( "d", pom.getValue( "build/plugins[1]/dependencies[5]/artifactId" ) );
585 assertEquals( "1", pom.getValue( "build/plugins[1]/dependencies[5]/version" ) );
586 }
587
588 public void testInterpolationOfNestedBuildDirectories()
589 throws Exception
590 {
591 PomTestWrapper pom = buildPom( "nested-build-dir-interpolation" );
592 assertEquals( new File( pom.getBasedir(), "target/classes/dir0" ),
593 new File( (String) pom.getValue( "properties/dir0" ) ) );
594 assertEquals( new File( pom.getBasedir(), "src/test/dir1" ),
595 new File( (String) pom.getValue( "properties/dir1" ) ) );
596 assertEquals( new File( pom.getBasedir(), "target/site/dir2" ),
597 new File( (String) pom.getValue( "properties/dir2" ) ) );
598 }
599
600 public void testAppendArtifactIdOfChildToInheritedUrls()
601 throws Exception
602 {
603 PomTestWrapper pom = buildPom( "url-inheritance/sub" );
604 assertEquals( "http://parent.url/child", pom.getValue( "url" ) );
605 assertEquals( "http://parent.url/org", pom.getValue( "organization/url" ) );
606 assertEquals( "http://parent.url/license.txt", pom.getValue( "licenses[1]/url" ) );
607 assertEquals( "http://parent.url/viewvc/child", pom.getValue( "scm/url" ) );
608 assertEquals( "http://parent.url/scm/child", pom.getValue( "scm/connection" ) );
609 assertEquals( "https://parent.url/scm/child", pom.getValue( "scm/developerConnection" ) );
610 assertEquals( "http://parent.url/issues", pom.getValue( "issueManagement/url" ) );
611 assertEquals( "http://parent.url/ci", pom.getValue( "ciManagement/url" ) );
612 assertEquals( "http://parent.url/dist", pom.getValue( "distributionManagement/repository/url" ) );
613 assertEquals( "http://parent.url/snaps", pom.getValue( "distributionManagement/snapshotRepository/url" ) );
614 assertEquals( "http://parent.url/site/child", pom.getValue( "distributionManagement/site/url" ) );
615 assertEquals( "http://parent.url/download", pom.getValue( "distributionManagement/downloadUrl" ) );
616 }
617
618
619 public void testAppendArtifactIdOfParentAndChildToInheritedUrls()
620 throws Exception
621 {
622 PomTestWrapper pom = buildPom( "url-inheritance/another-parent/sub" );
623 assertEquals( "http://parent.url/ap/child", pom.getValue( "url" ) );
624 assertEquals( "http://parent.url/org", pom.getValue( "organization/url" ) );
625 assertEquals( "http://parent.url/license.txt", pom.getValue( "licenses[1]/url" ) );
626 assertEquals( "http://parent.url/viewvc/ap/child", pom.getValue( "scm/url" ) );
627 assertEquals( "http://parent.url/scm/ap/child", pom.getValue( "scm/connection" ) );
628 assertEquals( "https://parent.url/scm/ap/child", pom.getValue( "scm/developerConnection" ) );
629 assertEquals( "http://parent.url/issues", pom.getValue( "issueManagement/url" ) );
630 assertEquals( "http://parent.url/ci", pom.getValue( "ciManagement/url" ) );
631 assertEquals( "http://parent.url/dist", pom.getValue( "distributionManagement/repository/url" ) );
632 assertEquals( "http://parent.url/snaps", pom.getValue( "distributionManagement/snapshotRepository/url" ) );
633 assertEquals( "http://parent.url/site/ap/child", pom.getValue( "distributionManagement/site/url" ) );
634 assertEquals( "http://parent.url/download", pom.getValue( "distributionManagement/downloadUrl" ) );
635 }
636 /
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736 public void testInterpolationOfBasedirInPomWithUnusualName()
737 throws Exception
738 {
739 PomTestWrapper pom = buildPom( "basedir-interpolation/pom-with-unusual-name.xml" );
740 assertEquals( pom.getBasedir(), new File( pom.getValue( "properties/prop0" ).toString() ) );
741 assertEquals( pom.getBasedir(), new File( pom.getValue( "properties/prop1" ).toString() ) );
742 }
743
744
745 public void testJoiningOfContainersWhenChildHasEmptyElements()
746 throws Exception
747 {
748 PomTestWrapper pom = buildPom( "id-container-joining-with-empty-elements/sub" );
749 assertNotNull( pom );
750 }
751
752 public void testOrderOfPluginConfigurationElementsWithoutPluginManagement()
753 throws Exception
754 {
755 PomTestWrapper pom = buildPom( "plugin-config-order/wo-plugin-mngt" );
756 assertEquals( "one", pom.getValue( "build/plugins[1]/configuration/stringParams/stringParam[1]" ) );
757 assertEquals( "two", pom.getValue( "build/plugins[1]/configuration/stringParams/stringParam[2]" ) );
758 assertEquals( "three", pom.getValue( "build/plugins[1]/configuration/stringParams/stringParam[3]" ) );
759 assertEquals( "four", pom.getValue( "build/plugins[1]/configuration/stringParams/stringParam[4]" ) );
760 }
761
762
763 public void testOrderOfPluginConfigurationElementsWithPluginManagement()
764 throws Exception
765 {
766 PomTestWrapper pom = buildPom( "plugin-config-order/w-plugin-mngt" );
767 assertEquals( "one", pom.getValue( "build/plugins[1]/configuration/stringParams/stringParam[1]" ) );
768 assertEquals( "two", pom.getValue( "build/plugins[1]/configuration/stringParams/stringParam[2]" ) );
769 assertEquals( "three", pom.getValue( "build/plugins[1]/configuration/stringParams/stringParam[3]" ) );
770 assertEquals( "four", pom.getValue( "build/plugins[1]/configuration/stringParams/stringParam[4]" ) );
771 }
772
773 public void testOrderOfPluginExecutionConfigurationElementsWithoutPluginManagement()
774 throws Exception
775 {
776 PomTestWrapper pom = buildPom( "plugin-exec-config-order/wo-plugin-mngt" );
777 String prefix = "build/plugins[1]/executions[1]/configuration/";
778 assertEquals( "one", pom.getValue( prefix + "stringParams/stringParam[1]" ) );
779 assertEquals( "two", pom.getValue( prefix + "stringParams/stringParam[2]" ) );
780 assertEquals( "three", pom.getValue( prefix + "stringParams/stringParam[3]" ) );
781 assertEquals( "four", pom.getValue( prefix + "stringParams/stringParam[4]" ) );
782 assertEquals( "key1", pom.getValue( prefix + "propertiesParam/property[1]/name" ) );
783 assertEquals( "key2", pom.getValue( prefix + "propertiesParam/property[2]/name" ) );
784 }
785
786
787 public void testOrderOfPluginExecutionConfigurationElementsWithPluginManagement()
788 throws Exception
789 {
790 PomTestWrapper pom = buildPom( "plugin-exec-config-order/w-plugin-mngt" );
791 String prefix = "build/plugins[1]/executions[1]/configuration/";
792 assertEquals( "one", pom.getValue( prefix + "stringParams/stringParam[1]" ) );
793 assertEquals( "two", pom.getValue( prefix + "stringParams/stringParam[2]" ) );
794 assertEquals( "three", pom.getValue( prefix + "stringParams/stringParam[3]" ) );
795 assertEquals( "four", pom.getValue( prefix + "stringParams/stringParam[4]" ) );
796 assertEquals( "key1", pom.getValue( prefix + "propertiesParam/property[1]/name" ) );
797 assertEquals( "key2", pom.getValue( prefix + "propertiesParam/property[2]/name" ) );
798 }
799
800
801 public void testMergeOfInheritedPluginConfiguration()
802 throws Exception
803 {
804 PomTestWrapper pom = buildPom( "plugin-config-merging/child" );
805
806 String prefix = "build/plugins[1]/configuration/";
807 assertEquals( "PASSED", pom.getValue( prefix + "propertiesFile" ) );
808 assertEquals( "PASSED", pom.getValue( prefix + "parent" ) );
809 assertEquals( "PASSED-1", pom.getValue( prefix + "stringParams/stringParam[1]" ) );
810 assertEquals( "PASSED-3", pom.getValue( prefix + "stringParams/stringParam[2]" ) );
811 assertEquals( "PASSED-2", pom.getValue( prefix + "stringParams/stringParam[3]" ) );
812 assertEquals( "PASSED-4", pom.getValue( prefix + "stringParams/stringParam[4]" ) );
813 assertEquals( "PASSED-1", pom.getValue( prefix + "listParam/listParam[1]" ) );
814 assertEquals( "PASSED-3", pom.getValue( prefix + "listParam/listParam[2]" ) );
815 assertEquals( "PASSED-2", pom.getValue( prefix + "listParam/listParam[3]" ) );
816 assertEquals( "PASSED-4", pom.getValue( prefix + "listParam/listParam[4]" ) );
817 }
818
819
820 public void testAppendOfInheritedPluginConfigurationWithNoProfile()
821 throws Exception
822 {
823 testAppendOfInheritedPluginConfiguration( "no-profile" );
824 }
825
826
827 public void testAppendOfInheritedPluginConfigurationWithActiveProfile()
828 throws Exception
829 {
830 testAppendOfInheritedPluginConfiguration( "with-profile" );
831 }
832
833 private void testAppendOfInheritedPluginConfiguration( String test )
834 throws Exception
835 {
836 PomTestWrapper pom = buildPom( "plugin-config-append/" + test + "/subproject" );
837 String prefix = "build/plugins[1]/configuration/";
838 assertEquals( "PARENT-1", pom.getValue( prefix + "stringParams/stringParam[1]" ) );
839 assertEquals( "PARENT-3", pom.getValue( prefix + "stringParams/stringParam[2]" ) );
840 assertEquals( "PARENT-2", pom.getValue( prefix + "stringParams/stringParam[3]" ) );
841 assertEquals( "PARENT-4", pom.getValue( prefix + "stringParams/stringParam[4]" ) );
842 assertEquals( "CHILD-1", pom.getValue( prefix + "stringParams/stringParam[5]" ) );
843 assertEquals( "CHILD-3", pom.getValue( prefix + "stringParams/stringParam[6]" ) );
844 assertEquals( "CHILD-2", pom.getValue( prefix + "stringParams/stringParam[7]" ) );
845 assertEquals( "CHILD-4", pom.getValue( prefix + "stringParams/stringParam[8]" ) );
846 assertEquals( null, pom.getValue( prefix + "stringParams/stringParam[9]" ) );
847 assertEquals( "PARENT-1", pom.getValue( prefix + "listParam/listParam[1]" ) );
848 assertEquals( "PARENT-3", pom.getValue( prefix + "listParam/listParam[2]" ) );
849 assertEquals( "PARENT-2", pom.getValue( prefix + "listParam/listParam[3]" ) );
850 assertEquals( "PARENT-4", pom.getValue( prefix + "listParam/listParam[4]" ) );
851 assertEquals( "CHILD-1", pom.getValue( prefix + "listParam/listParam[5]" ) );
852 assertEquals( "CHILD-3", pom.getValue( prefix + "listParam/listParam[6]" ) );
853 assertEquals( "CHILD-2", pom.getValue( prefix + "listParam/listParam[7]" ) );
854 assertEquals( "CHILD-4", pom.getValue( prefix + "listParam/listParam[8]" ) );
855 assertEquals( null, pom.getValue( prefix + "listParam/listParam[9]" ) );
856 }
857
858
859 public void testMultiplePluginExecutionsWithAndWithoutIdsWithoutPluginManagement()
860 throws Exception
861 {
862 PomTestWrapper pom = buildPom( "plugin-exec-w-and-wo-id/wo-plugin-mngt" );
863 assertEquals( 2, ( (List<?>) pom.getValue( "build/plugins[1]/executions" ) ).size() );
864 assertEquals( "log-string", pom.getValue( "build/plugins[1]/executions[1]/goals[1]" ) );
865 assertEquals( "log-string", pom.getValue( "build/plugins[1]/executions[2]/goals[1]" ) );
866 }
867
868 public void testMultiplePluginExecutionsWithAndWithoutIdsWithPluginManagement()
869 throws Exception
870 {
871 PomTestWrapper pom = buildPom( "plugin-exec-w-and-wo-id/w-plugin-mngt" );
872 assertEquals( 2, ( (List<?>) pom.getValue( "build/plugins[1]/executions" ) ).size() );
873 assertEquals( "log-string", pom.getValue( "build/plugins[1]/executions[1]/goals[1]" ) );
874 assertEquals( "log-string", pom.getValue( "build/plugins[1]/executions[2]/goals[1]" ) );
875 }
876
877 public void testDependencyOrderWithoutPluginManagement()
878 throws Exception
879 {
880 PomTestWrapper pom = buildPom( "dependency-order/wo-plugin-mngt" );
881 assertEquals( 4, ( (List<?>) pom.getValue( "dependencies" ) ).size() );
882 assertEquals( "a", pom.getValue( "dependencies[1]/artifactId" ) );
883 assertEquals( "c", pom.getValue( "dependencies[2]/artifactId" ) );
884 assertEquals( "b", pom.getValue( "dependencies[3]/artifactId" ) );
885 assertEquals( "d", pom.getValue( "dependencies[4]/artifactId" ) );
886 }
887
888 public void testDependencyOrderWithPluginManagement()
889 throws Exception
890 {
891 PomTestWrapper pom = buildPom( "dependency-order/w-plugin-mngt" );
892 assertEquals( 4, ( (List<?>) pom.getValue( "dependencies" ) ).size() );
893 assertEquals( "a", pom.getValue( "dependencies[1]/artifactId" ) );
894 assertEquals( "c", pom.getValue( "dependencies[2]/artifactId" ) );
895 assertEquals( "b", pom.getValue( "dependencies[3]/artifactId" ) );
896 assertEquals( "d", pom.getValue( "dependencies[4]/artifactId" ) );
897 }
898
899 public void testBuildDirectoriesUsePlatformSpecificFileSeparator()
900 throws Exception
901 {
902 PomTestWrapper pom = buildPom( "platform-file-separator" );
903 assertPathWithNormalizedFileSeparators( pom.getValue( "build/directory" ) );
904 assertPathWithNormalizedFileSeparators( pom.getValue( "build/outputDirectory" ) );
905 assertPathWithNormalizedFileSeparators( pom.getValue( "build/testOutputDirectory" ) );
906 assertPathWithNormalizedFileSeparators( pom.getValue( "build/sourceDirectory" ) );
907 assertPathWithNormalizedFileSeparators( pom.getValue( "build/testSourceDirectory" ) );
908 assertPathWithNormalizedFileSeparators( pom.getValue( "build/resources[1]/directory" ) );
909 assertPathWithNormalizedFileSeparators( pom.getValue( "build/testResources[1]/directory" ) );
910 assertPathWithNormalizedFileSeparators( pom.getValue( "build/filters[1]" ) );
911 assertPathWithNormalizedFileSeparators( pom.getValue( "reporting/outputDirectory" ) );
912 }
913
914
915 public void testMergedFilterOrder()
916 throws Exception
917 {
918 PomTestWrapper pom = buildPom( "merged-filter-order/sub" );
919
920 assertEquals( 7, ( (List<?>) pom.getValue( "build/filters" ) ).size() );
921 assertTrue( pom.getValue( "build/filters[1]" ).toString().endsWith( "child-a.properties" ) );
922 assertTrue( pom.getValue( "build/filters[2]" ).toString().endsWith( "child-c.properties" ) );
923 assertTrue( pom.getValue( "build/filters[3]" ).toString().endsWith( "child-b.properties" ) );
924 assertTrue( pom.getValue( "build/filters[4]" ).toString().endsWith( "child-d.properties" ) );
925 assertTrue( pom.getValue( "build/filters[5]" ).toString().endsWith( "parent-c.properties" ) );
926 assertTrue( pom.getValue( "build/filters[6]" ).toString().endsWith( "parent-b.properties" ) );
927 assertTrue( pom.getValue( "build/filters[7]" ).toString().endsWith( "parent-d.properties" ) );
928 }
929
930
931 public void testProfileInjectedDependencies()
932 throws Exception
933 {
934 PomTestWrapper pom = buildPom( "profile-injected-dependencies" );
935 assertEquals( 4, ( (List<?>) pom.getValue( "dependencies" ) ).size() );
936 assertEquals( "a", pom.getValue( "dependencies[1]/artifactId" ) );
937 assertEquals( "c", pom.getValue( "dependencies[2]/artifactId" ) );
938 assertEquals( "b", pom.getValue( "dependencies[3]/artifactId" ) );
939 assertEquals( "d", pom.getValue( "dependencies[4]/artifactId" ) );
940 }
941
942
943 public void testProfileDependenciesMultipleProfiles()
944 throws Exception
945 {
946 PomTestWrapper pom = buildPom( "profile-dependencies-multiple-profiles", "profile-1", "profile-2" );
947 assertEquals(2, ( (List<?>) pom.getValue( "dependencies" ) ).size() );
948 }
949
950 public void testDependencyInheritance()
951 throws Exception
952 {
953 PomTestWrapper pom = buildPom( "dependency-inheritance/sub" );
954 assertEquals(1, ( (List<?>) pom.getValue( "dependencies" ) ).size() );
955 assertEquals("4.4", pom.getValue("dependencies[1]/version") );
956 }
957
958
959 public void testManagedProfileDependency()
960 throws Exception
961 {
962 PomTestWrapper pom = this.buildPom( "managed-profile-dependency/sub", "maven-core-it" );
963 assertEquals( 1, ( (List<?>) pom.getValue( "dependencies" ) ).size() );
964 assertEquals( "org.apache.maven.its", pom.getValue( "dependencies[1]/groupId" ) );
965 assertEquals( "maven-core-it-support", pom.getValue( "dependencies[1]/artifactId" ) );
966 assertEquals( "1.3", pom.getValue( "dependencies[1]/version" ) );
967 assertEquals( "runtime", pom.getValue( "dependencies[1]/scope" ) );
968 assertEquals( 1, ( (List<?>) pom.getValue( "dependencies[1]/exclusions" ) ).size() );
969 assertEquals( "commons-lang", pom.getValue( "dependencies[1]/exclusions[1]/groupId" ) );
970 }
971
972
973 public void testProfileModuleInheritance()
974 throws Exception
975 {
976 PomTestWrapper pom = this.buildPom( "profile-module-inheritance/sub", "dist" );
977 assertEquals(0, ( (List<?>) pom.getValue( "modules" ) ).size());
978 }
979
980
981 public void testUncPath()
982 throws Exception
983 {
984 PomTestWrapper pom = this.buildPom( "unc-path/sub" );
985 assertEquals("file:////host/site/test-child", pom.getValue( "distributionManagement/site/url" ));
986 }
987
988
989 public void testUrlAppendWithChildPathAdjustment()
990 throws Exception
991 {
992 PomTestWrapper pom = this.buildPom( "url-append/child" );
993 assertEquals("http://project.url/child", pom.getValue( "url" ));
994 assertEquals("http://viewvc.project.url/child", pom.getValue( "scm/url" ));
995 assertEquals("http://scm.project.url/child", pom.getValue( "scm/connection" ));
996 assertEquals("https://scm.project.url/child", pom.getValue( "scm/developerConnection" ));
997 assertEquals("http://site.project.url/child", pom.getValue( "distributionManagement/site/url" ));
998 }
999
1000
1001 public void testRepoInheritance()
1002 throws Exception
1003 {
1004 PomTestWrapper pom = this.buildPom( "repo-inheritance" );
1005 assertEquals(1, ( (List<?>) pom.getValue( "repositories" ) ).size());
1006 assertEquals( "it0043", pom.getValue( "repositories[1]/name" ) );
1007 }
1008
1009 public void testEmptyScm()
1010 throws Exception
1011 {
1012 PomTestWrapper pom = this.buildPom( "empty-scm" );
1013 assertNull(pom.getValue( "scm" ));
1014 }
1015
1016 public void testPluginConfigurationUsingAttributesWithoutPluginManagement()
1017 throws Exception
1018 {
1019 PomTestWrapper pom = buildPom( "plugin-config-attributes/wo-plugin-mngt" );
1020 assertEquals( "src", pom.getValue( "build/plugins[1]/configuration/domParam/copy/@todir" ) );
1021 assertEquals( "true", pom.getValue( "build/plugins[1]/configuration/domParam/copy/@overwrite" ) );
1022 assertEquals( "target", pom.getValue( "build/plugins[1]/configuration/domParam/copy/fileset/@dir" ) );
1023 assertEquals( null, pom.getValue( "build/plugins[1]/configuration/domParam/copy/fileset/@todir" ) );
1024 assertEquals( null, pom.getValue( "build/plugins[1]/configuration/domParam/copy/fileset/@overwrite" ) );
1025 }
1026
1027
1028 public void testPluginConfigurationUsingAttributesWithPluginManagement()
1029 throws Exception
1030 {
1031 PomTestWrapper pom = buildPom( "plugin-config-attributes/w-plugin-mngt" );
1032 assertEquals( "src", pom.getValue( "build/plugins[1]/configuration/domParam/copy/@todir" ) );
1033 assertEquals( "true", pom.getValue( "build/plugins[1]/configuration/domParam/copy/@overwrite" ) );
1034 assertEquals( "target", pom.getValue( "build/plugins[1]/configuration/domParam/copy/fileset/@dir" ) );
1035 assertEquals( null, pom.getValue( "build/plugins[1]/configuration/domParam/copy/fileset/@todir" ) );
1036 assertEquals( null, pom.getValue( "build/plugins[1]/configuration/domParam/copy/fileset/@overwrite" ) );
1037 }
1038
1039 public void testPluginConfigurationUsingAttributesWithPluginManagementAndProfile()
1040 throws Exception
1041 {
1042 PomTestWrapper pom = buildPom( "plugin-config-attributes/w-profile", "maven-core-it" );
1043 assertEquals( "src", pom.getValue( "build/plugins[1]/configuration/domParam/copy/@todir" ) );
1044 assertEquals( "true", pom.getValue( "build/plugins[1]/configuration/domParam/copy/@overwrite" ) );
1045 assertEquals( "target", pom.getValue( "build/plugins[1]/configuration/domParam/copy/fileset/@dir" ) );
1046 assertEquals( null, pom.getValue( "build/plugins[1]/configuration/domParam/copy/fileset/@todir" ) );
1047 assertEquals( null, pom.getValue( "build/plugins[1]/configuration/domParam/copy/fileset/@overwrite" ) );
1048 }
1049
1050 public void testPomEncoding()
1051 throws Exception
1052 {
1053 PomTestWrapper pom = buildPom( "pom-encoding/utf-8" );
1054 assertEquals( "TEST-CHARS: \u00DF\u0131\u03A3\u042F\u05D0\u20AC", pom.getValue( "description" ) );
1055 pom = buildPom( "pom-encoding/latin-1" );
1056 assertEquals( "TEST-CHARS: \u00C4\u00D6\u00DC\u00E4\u00F6\u00FC\u00DF", pom.getValue( "description" ) );
1057 }
1058
1059
1060 public void testXmlWhitespaceHandling()
1061 throws Exception
1062 {
1063 PomTestWrapper pom = buildPom( "xml-whitespace/sub" );
1064 assertEquals( "org.apache.maven.its.mng4070", pom.getValue( "groupId" ) );
1065 }
1066
1067
1068 public void testInterpolationOfBaseUrl()
1069 throws Exception
1070 {
1071 PomTestWrapper pom = buildPom( "baseurl-interpolation/pom.xml" );
1072 assertEquals( pom.getBasedir().toURI().toString(), pom.getValue( "properties/prop1" ).toString() );
1073 }
1074
1075
1076 public void testReportingPluginConfig()
1077 throws Exception
1078 {
1079 PomTestWrapper pom = buildPom( "reporting-plugin-config/sub" );
1080
1081 assertEquals(2, ( (List<?>) pom.getValue( "reporting/plugins[1]/configuration/stringParams" ) ).size());
1082 assertEquals("parentParam", pom.getValue( "reporting/plugins[1]/configuration/stringParams[1]/stringParam[1]"));
1083 assertEquals("childParam", pom.getValue( "reporting/plugins[1]/configuration/stringParams[1]/stringParam[2]"));
1084 assertEquals("true", pom.getValue( "reporting/plugins[1]/configuration/booleanParam"));
1085 }
1086
1087 public void testPropertiesNoDuplication()
1088 throws Exception
1089 {
1090 PomTestWrapper pom = buildPom( "properties-no-duplication/sub" );
1091 assertEquals(1, ( (Properties) pom.getValue( "properties" ) ).size());
1092 assertEquals("child", pom.getValue( "properties/pomProfile" ) );
1093 }
1094
1095 public void testPomInheritance()
1096 throws Exception
1097 {
1098 PomTestWrapper pom = buildPom( "pom-inheritance/sub" );
1099 assertEquals( "parent-description", pom.getValue( "description" ) );
1100 assertEquals( "jar", pom.getValue( "packaging" ) );
1101 }
1102
1103 public void testCompleteModelWithoutParent()
1104 throws Exception
1105 {
1106 PomTestWrapper pom = buildPom( "complete-model/wo-parent" );
1107
1108 testCompleteModel( pom );
1109 }
1110
1111 public void testCompleteModelWithParent()
1112 throws Exception
1113 {
1114 PomTestWrapper pom = buildPom( "complete-model/w-parent/sub" );
1115
1116 testCompleteModel( pom );
1117 }
1118
1119 private void testCompleteModel( PomTestWrapper pom )
1120 throws Exception
1121 {
1122 assertEquals( "4.0.0", pom.getValue( "modelVersion" ) );
1123
1124 assertEquals( "org.apache.maven.its.mng", pom.getValue( "groupId" ) );
1125 assertEquals( "test", pom.getValue( "artifactId" ) );
1126 assertEquals( "0.2", pom.getValue( "version" ) );
1127 assertEquals( "pom", pom.getValue( "packaging" ) );
1128
1129 assertEquals( "project-name", pom.getValue( "name" ) );
1130 assertEquals( "project-description", pom.getValue( "description" ) );
1131 assertEquals( "http://project.url/", pom.getValue( "url" ) );
1132 assertEquals( "2009", pom.getValue( "inceptionYear" ) );
1133
1134 assertEquals( "project-org", pom.getValue( "organization/name" ) );
1135 assertEquals( "http://project-org.url/", pom.getValue( "organization/url" ) );
1136
1137 assertEquals( 1, ( (List<?>) pom.getValue( "licenses" ) ).size() );
1138 assertEquals( "project-license", pom.getValue( "licenses[1]/name" ) );
1139 assertEquals( "http://project.url/license", pom.getValue( "licenses[1]/url" ) );
1140 assertEquals( "repo", pom.getValue( "licenses[1]/distribution" ) );
1141 assertEquals( "free", pom.getValue( "licenses[1]/comments" ) );
1142
1143 assertEquals( 1, ( (List<?>) pom.getValue( "developers" ) ).size() );
1144 assertEquals( "dev", pom.getValue( "developers[1]/id" ) );
1145 assertEquals( "project-developer", pom.getValue( "developers[1]/name" ) );
1146 assertEquals( "developer@", pom.getValue( "developers[1]/email" ) );
1147 assertEquals( "http://developer", pom.getValue( "developers[1]/url" ) );
1148 assertEquals( "developer", pom.getValue( "developers[1]/organization" ) );
1149 assertEquals( "http://devel.org", pom.getValue( "developers[1]/organizationUrl" ) );
1150 assertEquals( "-1", pom.getValue( "developers[1]/timezone" ) );
1151 assertEquals( "yes", pom.getValue( "developers[1]/properties/developer" ) );
1152 assertEquals( 1, ( (List<?>) pom.getValue( "developers[1]/roles" ) ).size() );
1153 assertEquals( "devel", pom.getValue( "developers[1]/roles[1]" ) );
1154
1155 assertEquals( 1, ( (List<?>) pom.getValue( "contributors" ) ).size() );
1156 assertEquals( "project-contributor", pom.getValue( "contributors[1]/name" ) );
1157 assertEquals( "contributor@", pom.getValue( "contributors[1]/email" ) );
1158 assertEquals( "http://contributor", pom.getValue( "contributors[1]/url" ) );
1159 assertEquals( "contributor", pom.getValue( "contributors[1]/organization" ) );
1160 assertEquals( "http://contrib.org", pom.getValue( "contributors[1]/organizationUrl" ) );
1161 assertEquals( "+1", pom.getValue( "contributors[1]/timezone" ) );
1162 assertEquals( "yes", pom.getValue( "contributors[1]/properties/contributor" ) );
1163 assertEquals( 1, ( (List<?>) pom.getValue( "contributors[1]/roles" ) ).size() );
1164 assertEquals( "contrib", pom.getValue( "contributors[1]/roles[1]" ) );
1165
1166 assertEquals( 1, ( (List<?>) pom.getValue( "mailingLists" ) ).size() );
1167 assertEquals( "project-mailing-list", pom.getValue( "mailingLists[1]/name" ) );
1168 assertEquals( "subscribe@", pom.getValue( "mailingLists[1]/subscribe" ) );
1169 assertEquals( "unsubscribe@", pom.getValue( "mailingLists[1]/unsubscribe" ) );
1170 assertEquals( "post@", pom.getValue( "mailingLists[1]/post" ) );
1171 assertEquals( "mail-archive", pom.getValue( "mailingLists[1]/archive" ) );
1172 assertEquals( 1, ( (List<?>) pom.getValue( "mailingLists[1]/otherArchives" ) ).size() );
1173 assertEquals( "other-archive", pom.getValue( "mailingLists[1]/otherArchives[1]" ) );
1174
1175 assertEquals( "2.0.1", pom.getValue( "prerequisites/maven" ) );
1176
1177 assertEquals( "http://project.url/trunk", pom.getValue( "scm/url" ) );
1178 assertEquals( "http://project.url/scm", pom.getValue( "scm/connection" ) );
1179 assertEquals( "https://project.url/scm", pom.getValue( "scm/developerConnection" ) );
1180 assertEquals( "TAG", pom.getValue( "scm/tag" ) );
1181
1182 assertEquals( "issues", pom.getValue( "issueManagement/system" ) );
1183 assertEquals( "http://project.url/issues", pom.getValue( "issueManagement/url" ) );
1184
1185 assertEquals( "ci", pom.getValue( "ciManagement/system" ) );
1186 assertEquals( "http://project.url/ci", pom.getValue( "ciManagement/url" ) );
1187 assertEquals( 1, ( (List<?>) pom.getValue( "ciManagement/notifiers" ) ).size() );
1188 assertEquals( "irc", pom.getValue( "ciManagement/notifiers[1]/type" ) );
1189 assertEquals( "ci@", pom.getValue( "ciManagement/notifiers[1]/address" ) );
1190 assertEquals( Boolean.TRUE, pom.getValue( "ciManagement/notifiers[1]/sendOnError" ) );
1191 assertEquals( Boolean.FALSE, pom.getValue( "ciManagement/notifiers[1]/sendOnFailure" ) );
1192 assertEquals( Boolean.FALSE, pom.getValue( "ciManagement/notifiers[1]/sendOnWarning" ) );
1193 assertEquals( Boolean.FALSE, pom.getValue( "ciManagement/notifiers[1]/sendOnSuccess" ) );
1194 assertEquals( "ci", pom.getValue( "ciManagement/notifiers[1]/configuration/ciProp" ) );
1195
1196 assertEquals( "project.distros", pom.getValue( "distributionManagement/repository/id" ) );
1197 assertEquals( "distros", pom.getValue( "distributionManagement/repository/name" ) );
1198 assertEquals( "http://project.url/dist", pom.getValue( "distributionManagement/repository/url" ) );
1199 assertEquals( Boolean.TRUE, pom.getValue( "distributionManagement/repository/uniqueVersion" ) );
1200
1201 assertEquals( "project.snaps", pom.getValue( "distributionManagement/snapshotRepository/id" ) );
1202 assertEquals( "snaps", pom.getValue( "distributionManagement/snapshotRepository/name" ) );
1203 assertEquals( "http://project.url/snaps", pom.getValue( "distributionManagement/snapshotRepository/url" ) );
1204 assertEquals( Boolean.FALSE, pom.getValue( "distributionManagement/snapshotRepository/uniqueVersion" ) );
1205
1206 assertEquals( "project.site", pom.getValue( "distributionManagement/site/id" ) );
1207 assertEquals( "docs", pom.getValue( "distributionManagement/site/name" ) );
1208 assertEquals( "http://project.url/site", pom.getValue( "distributionManagement/site/url" ) );
1209
1210 assertEquals( "http://project.url/download", pom.getValue( "distributionManagement/downloadUrl" ) );
1211 assertEquals( "reloc-gid", pom.getValue( "distributionManagement/relocation/groupId" ) );
1212 assertEquals( "reloc-aid", pom.getValue( "distributionManagement/relocation/artifactId" ) );
1213 assertEquals( "reloc-version", pom.getValue( "distributionManagement/relocation/version" ) );
1214 assertEquals( "project-reloc-msg", pom.getValue( "distributionManagement/relocation/message" ) );
1215
1216 assertEquals( 1, ( (List<?>) pom.getValue( "modules" ) ).size() );
1217 assertEquals( "sub", pom.getValue( "modules[1]" ) );
1218
1219 assertEquals( 1, ( (Map<?, ?>) pom.getValue( "properties" ) ).size() );
1220 assertEquals( "project-property", pom.getValue( "properties[1]/itProperty" ) );
1221
1222 assertEquals( 1, ( (List<?>) pom.getValue( "dependencyManagement/dependencies" ) ).size() );
1223 assertEquals( "org.apache.maven.its", pom.getValue( "dependencyManagement/dependencies[1]/groupId" ) );
1224 assertEquals( "managed-dep", pom.getValue( "dependencyManagement/dependencies[1]/artifactId" ) );
1225 assertEquals( "0.1", pom.getValue( "dependencyManagement/dependencies[1]/version" ) );
1226 assertEquals( "war", pom.getValue( "dependencyManagement/dependencies[1]/type" ) );
1227 assertEquals( "runtime", pom.getValue( "dependencyManagement/dependencies[1]/scope" ) );
1228 assertEquals( Boolean.FALSE, pom.getValue( "dependencyManagement/dependencies[1]/optional" ) );
1229 assertEquals( 1, ( (List<?>) pom.getValue( "dependencyManagement/dependencies[1]/exclusions" ) ).size() );
1230 assertEquals( "org.apache.maven.its",
1231 pom.getValue( "dependencyManagement/dependencies[1]/exclusions[1]/groupId" ) );
1232 assertEquals( "excluded-managed-dep",
1233 pom.getValue( "dependencyManagement/dependencies[1]/exclusions[1]/artifactId" ) );
1234
1235 assertEquals( 1, ( (List<?>) pom.getValue( "dependencies" ) ).size() );
1236 assertEquals( "org.apache.maven.its", pom.getValue( "dependencies[1]/groupId" ) );
1237 assertEquals( "dep", pom.getValue( "dependencies[1]/artifactId" ) );
1238 assertEquals( "0.2", pom.getValue( "dependencies[1]/version" ) );
1239 assertEquals( "ejb", pom.getValue( "dependencies[1]/type" ) );
1240 assertEquals( "test", pom.getValue( "dependencies[1]/scope" ) );
1241 assertEquals( Boolean.TRUE, pom.getValue( "dependencies[1]/optional" ) );
1242 assertEquals( 1, ( (List<?>) pom.getValue( "dependencies[1]/exclusions" ) ).size() );
1243 assertEquals( "org.apache.maven.its", pom.getValue( "dependencies[1]/exclusions[1]/groupId" ) );
1244 assertEquals( "excluded-dep", pom.getValue( "dependencies[1]/exclusions[1]/artifactId" ) );
1245
1246 assertEquals( "test", pom.getValue( "build/defaultGoal" ) );
1247 assertEquals( "coreit", pom.getValue( "build/finalName" ) );
1248
1249 assertPathSuffixEquals( "build", pom.getValue( "build/directory" ) );
1250 assertPathSuffixEquals( "build/main", pom.getValue( "build/outputDirectory" ) );
1251 assertPathSuffixEquals( "build/test", pom.getValue( "build/testOutputDirectory" ) );
1252 assertPathSuffixEquals( "sources/main", pom.getValue( "build/sourceDirectory" ) );
1253 assertPathSuffixEquals( "sources/test", pom.getValue( "build/testSourceDirectory" ) );
1254 assertPathSuffixEquals( "sources/scripts", pom.getValue( "build/scriptSourceDirectory" ) );
1255
1256 assertEquals( 1, ( (List<?>) pom.getValue( "build/filters" ) ).size() );
1257 assertPathSuffixEquals( "src/main/filter/it.properties", pom.getValue( "build/filters[1]" ) );
1258
1259 assertEquals( 1, ( (List<?>) pom.getValue( "build/resources" ) ).size() );
1260 assertPathSuffixEquals( "res/main", pom.getValue( "build/resources[1]/directory" ) );
1261 assertPathSuffixEquals( "main", pom.getValue( "build/resources[1]/targetPath" ) );
1262 assertEquals( Boolean.TRUE, pom.getValue( "build/resources[1]/filtering" ) );
1263 assertEquals( 1, ( (List<?>) pom.getValue( "build/resources[1]/includes" ) ).size() );
1264 assertPathSuffixEquals( "main.included", pom.getValue( "build/resources[1]/includes[1]" ) );
1265 assertEquals( 1, ( (List<?>) pom.getValue( "build/resources[1]/excludes" ) ).size() );
1266 assertPathSuffixEquals( "main.excluded", pom.getValue( "build/resources[1]/excludes[1]" ) );
1267
1268 assertEquals( 1, ( (List<?>) pom.getValue( "build/testResources" ) ).size() );
1269 assertPathSuffixEquals( "res/test", pom.getValue( "build/testResources[1]/directory" ) );
1270 assertPathSuffixEquals( "test", pom.getValue( "build/testResources[1]/targetPath" ) );
1271 assertEquals( Boolean.TRUE, pom.getValue( "build/testResources[1]/filtering" ) );
1272 assertEquals( 1, ( (List<?>) pom.getValue( "build/testResources[1]/includes" ) ).size() );
1273 assertPathSuffixEquals( "test.included", pom.getValue( "build/testResources[1]/includes[1]" ) );
1274 assertEquals( 1, ( (List<?>) pom.getValue( "build/testResources[1]/excludes" ) ).size() );
1275 assertPathSuffixEquals( "test.excluded", pom.getValue( "build/testResources[1]/excludes[1]" ) );
1276
1277 assertEquals( 1, ( (List<?>) pom.getValue( "build/extensions" ) ).size() );
1278 assertEquals( "org.apache.maven.its.ext", pom.getValue( "build/extensions[1]/groupId" ) );
1279 assertEquals( "ext", pom.getValue( "build/extensions[1]/artifactId" ) );
1280 assertEquals( "3.0", pom.getValue( "build/extensions[1]/version" ) );
1281
1282 assertEquals( 1, ( (List<?>) pom.getValue( "build/plugins" ) ).size() );
1283 assertEquals( "org.apache.maven.its.plugins", pom.getValue( "build/plugins[1]/groupId" ) );
1284 assertEquals( "maven-it-plugin-build", pom.getValue( "build/plugins[1]/artifactId" ) );
1285 assertEquals( "2.1-SNAPSHOT", pom.getValue( "build/plugins[1]/version" ) );
1286 assertEquals( "test.properties", pom.getValue( "build/plugins[1]/configuration/outputFile" ) );
1287 assertEquals( 1, ( (List<?>) pom.getValue( "build/plugins[1]/executions" ) ).size() );
1288 assertEquals( "test", pom.getValue( "build/plugins[1]/executions[1]/id" ) );
1289 assertEquals( "validate", pom.getValue( "build/plugins[1]/executions[1]/phase" ) );
1290 assertEquals( "pom.properties", pom.getValue( "build/plugins[1]/executions[1]/configuration/outputFile" ) );
1291 assertEquals( 1, ( (List<?>) pom.getValue( "build/plugins[1]/executions[1]/goals" ) ).size() );
1292 assertEquals( "eval", pom.getValue( "build/plugins[1]/executions[1]/goals[1]" ) );
1293 assertEquals( 1, ( (List<?>) pom.getValue( "build/plugins[1]/dependencies" ) ).size() );
1294 assertEquals( "org.apache.maven.its", pom.getValue( "build/plugins[1]/dependencies[1]/groupId" ) );
1295 assertEquals( "build-plugin-dep", pom.getValue( "build/plugins[1]/dependencies[1]/artifactId" ) );
1296 assertEquals( "0.3", pom.getValue( "build/plugins[1]/dependencies[1]/version" ) );
1297 assertEquals( "zip", pom.getValue( "build/plugins[1]/dependencies[1]/type" ) );
1298 assertEquals( 1, ( (List<?>) pom.getValue( "build/plugins[1]/dependencies[1]/exclusions" ) ).size() );
1299 assertEquals( "org.apache.maven.its", pom.getValue( "build/plugins[1]/dependencies[1]/exclusions[1]/groupId" ) );
1300 assertEquals( "excluded-build-plugin-dep",
1301 pom.getValue( "build/plugins[1]/dependencies[1]/exclusions[1]/artifactId" ) );
1302
1303 assertEquals( Boolean.TRUE, pom.getValue( "reporting/excludeDefaults" ) );
1304 assertPathSuffixEquals( "docs", pom.getValue( "reporting/outputDirectory" ) );
1305
1306 assertEquals( 1, ( (List<?>) pom.getValue( "reporting/plugins" ) ).size() );
1307 assertEquals( "org.apache.maven.its.plugins", pom.getValue( "reporting/plugins[1]/groupId" ) );
1308 assertEquals( "maven-it-plugin-reporting", pom.getValue( "reporting/plugins[1]/artifactId" ) );
1309 assertEquals( "2.0-SNAPSHOT", pom.getValue( "reporting/plugins[1]/version" ) );
1310 assertEquals( "test.html", pom.getValue( "reporting/plugins[1]/configuration/outputFile" ) );
1311 assertEquals( 1, ( (List<?>) pom.getValue( "reporting/plugins[1]/reportSets" ) ).size() );
1312 assertEquals( "it", pom.getValue( "reporting/plugins[1]/reportSets[1]/id" ) );
1313 assertEquals( "index.html", pom.getValue( "reporting/plugins[1]/reportSets[1]/configuration/outputFile" ) );
1314 assertEquals( 1, ( (List<?>) pom.getValue( "reporting/plugins[1]/reportSets[1]/reports" ) ).size() );
1315 assertEquals( "run", pom.getValue( "reporting/plugins[1]/reportSets[1]/reports[1]" ) );
1316 }
1317
1318
1319
1320 public void testProfileInjectionOrder()
1321 throws Exception
1322 {
1323 PomTestWrapper pom =
1324 buildPom( "profile-injection-order", "pom-a", "pom-b", "pom-e", "pom-c", "pom-d" );
1325 assertEquals( "e", pom.getValue( "properties[1]/pomProperty" ) );
1326 }
1327
1328 public void testPropertiesInheritance()
1329 throws Exception
1330 {
1331 PomTestWrapper pom = buildPom( "properties-inheritance/sub" );
1332 assertEquals( "parent-property", pom.getValue( "properties/parentProperty" ) );
1333 assertEquals( "child-property", pom.getValue( "properties/childProperty" ) );
1334 assertEquals( "child-override", pom.getValue( "properties/overriddenProperty" ) );
1335 }
1336
1337
1338 public void testInheritedPropertiesInterpolatedWithValuesFromChildWithoutProfiles()
1339 throws Exception
1340 {
1341 PomTestWrapper pom = buildPom( "inherited-properties-interpolation/no-profile/sub" );
1342
1343 assertEquals( "CHILD", pom.getValue( "properties/overridden" ) );
1344 assertEquals( "CHILD", pom.getValue( "properties/interpolated" ) );
1345 }
1346
1347
1348 public void testInheritedPropertiesInterpolatedWithValuesFromChildWithActiveProfiles()
1349 throws Exception
1350 {
1351 PomTestWrapper pom = buildPom( "inherited-properties-interpolation/active-profile/sub" );
1352
1353 assertEquals(1, pom.getMavenProject().getModel().getProfiles().size());
1354
1355 buildPom( "inherited-properties-interpolation/active-profile/sub", "it-parent", "it-child" );
1356 assertEquals( "CHILD", pom.getValue( "properties/overridden" ) );
1357 assertEquals( "CHILD", pom.getValue( "properties/interpolated" ) );
1358 }
1359
1360
1361 public void testProfileDefaultActivation()
1362 throws Exception
1363 {
1364 PomTestWrapper pom = buildPom( "profile-default-deactivation" , "profile4");
1365 assertEquals(1, pom.getMavenProject().getActiveProfiles().size() );
1366 assertEquals(1, ( (List<?>) pom.getValue( "build/plugins" )).size() );
1367 assertEquals("2.1", pom.getValue( "build/plugins[1]/version" ));
1368 }
1369
1370
1371 public void testBooleanInterpolation()
1372 throws Exception
1373 {
1374 PomTestWrapper pom = buildPom( "boolean-interpolation" );
1375 assertTrue ((Boolean) pom.getValue( "repositories[1]/releases/enabled" ) );
1376 assertTrue((Boolean) pom.getValue( "build/resources[1]/filtering" ) );
1377 }
1378
1379
1380
1381 public void testBuildExtensionInheritance()
1382 throws Exception
1383 {
1384 PomTestWrapper pom = buildPom( "build-extension-inheritance/sub" );
1385 assertEquals(3, ( (List<?>) pom.getValue( "build/extensions" )).size() );
1386 assertEquals("b", pom.getValue( "build/extensions[1]/artifactId" ) );
1387 assertEquals("a", pom.getValue( "build/extensions[2]/artifactId" ) );
1388 assertEquals("0.2", pom.getValue( "build/extensions[2]/version" ) );
1389 assertEquals("c", pom.getValue( "build/extensions[3]/artifactId" ) );
1390 }
1391
1392
1393 public void testJdkActivation()
1394 throws Exception
1395 {
1396 Properties props = new Properties();
1397 props.put("java.version", "1.5.0_15");
1398
1399 PomTestWrapper pom = buildPom( "jdk-activation", props );
1400 assertEquals(3, pom.getMavenProject().getActiveProfiles().size());
1401 assertEquals("PASSED", pom.getValue("properties/jdkProperty3"));
1402 assertEquals("PASSED", pom.getValue("properties/jdkProperty2"));
1403 assertEquals("PASSED", pom.getValue("properties/jdkProperty1"));
1404 }
1405
1406
1407 public void testProfilePluginMngDependencies()
1408 throws Exception
1409 {
1410 PomTestWrapper pom = buildPom( "profile-plugin-mng-dependencies/sub" , "maven-core-it");
1411 assertEquals("a", pom.getValue( "build/plugins[1]/dependencies[1]/artifactId" ) );
1412 }
1413
1414
1415 public void testPercentEncodedUrlsMustNotBeDecoded()
1416 throws Exception
1417 {
1418 PomTestWrapper pom = this.buildPom( "url-no-decoding" );
1419 assertEquals( "http://maven.apache.org/spacy%20path", pom.getValue( "url" ) );
1420 assertEquals( "http://svn.apache.org/viewvc/spacy%20path", pom.getValue( "scm/url" ) );
1421 assertEquals( "scm:svn:svn+ssh://svn.apache.org/spacy%20path", pom.getValue( "scm/connection" ) );
1422 assertEquals( "scm:svn:svn+ssh://svn.apache.org/spacy%20path", pom.getValue( "scm/developerConnection" ) );
1423 assertEquals( "http://issues.apache.org/spacy%20path", pom.getValue( "issueManagement/url" ) );
1424 assertEquals( "http://ci.apache.org/spacy%20path", pom.getValue( "ciManagement/url" ) );
1425 assertEquals( "scm:svn:svn+ssh://dist.apache.org/spacy%20path",
1426 pom.getValue( "distributionManagement/repository/url" ) );
1427 assertEquals( "scm:svn:svn+ssh://snap.apache.org/spacy%20path",
1428 pom.getValue( "distributionManagement/snapshotRepository/url" ) );
1429 assertEquals( "scm:svn:svn+ssh://site.apache.org/spacy%20path",
1430 pom.getValue( "distributionManagement/site/url" ) );
1431 }
1432
1433 public void testPluginManagementInheritance()
1434 throws Exception
1435 {
1436 PomTestWrapper pom = this.buildPom( "plugin-management-inheritance");
1437 assertEquals("0.1-stub-SNAPSHOT", pom.getValue( "build/pluginManagement/plugins[@artifactId='maven-compiler-plugin']/version" ) );
1438 }
1439
1440 public void testProfilePlugins()
1441 throws Exception
1442 {
1443 PomTestWrapper pom = this.buildPom( "profile-plugins", "standard");
1444 assertEquals( 2, ( (List<?>) pom.getValue( "build/plugins" ) ).size() );
1445 assertEquals("maven-assembly2-plugin", pom.getValue( "build/plugins[2]/artifactId" ) );
1446 }
1447
1448 public void testPluginInheritanceSimple()
1449 throws Exception
1450 {
1451 PomTestWrapper pom = this.buildPom( "plugin-inheritance-simple/sub");
1452 assertEquals( 2, ( (List<?>) pom.getValue( "build/plugins" ) ).size() );
1453 }
1454
1455 public void testPluginManagementDuplicate()
1456 throws Exception
1457 {
1458 PomTestWrapper pom = this.buildPom( "plugin-management-duplicate/sub");
1459 assertEquals( 12, ( (List<?>) pom.getValue( "build/pluginManagement/plugins" ) ).size() );
1460 }
1461
1462 public void testDistributionManagement()
1463 throws Exception
1464 {
1465 PomTestWrapper pom = this.buildPom( "distribution-management");
1466 assertEquals("legacy", pom.getValue( "distributionManagement/repository/layout" ));
1467 }
1468
1469 public void testDependencyScopeInheritance()
1470 throws Exception
1471 {
1472 PomTestWrapper pom = buildPom( "dependency-scope-inheritance/sub" );
1473 String scope = (String) pom.getValue("dependencies[1]/scope");
1474 assertEquals( "compile", scope );
1475 }
1476
1477 public void testDependencyScope()
1478 throws Exception
1479 {
1480 PomTestWrapper pom = buildPom( "dependency-scope/sub" );
1481 }
1482
1483
1484 public void testDependencyManagementWithInterpolation()
1485 throws Exception
1486 {
1487 PomTestWrapper pom = buildPom( "dependency-management-with-interpolation/sub" );
1488 }
1489
1490 public void testInterpolationWithSystemProperty()
1491 throws Exception
1492 {
1493 Properties sysProps = new Properties();
1494 sysProps.setProperty( "system.property", "PASSED" );
1495 PomTestWrapper pom = buildPom( "sytem-property-interpolation", sysProps );
1496 assertEquals( "PASSED", pom.getValue( "name" ) );
1497 }
1498
1499
1500 public void testPluginExecutionInheritanceWhenChildDoesNotDeclarePlugin()
1501 throws Exception
1502 {
1503 PomTestWrapper pom = buildPom( "plugin-exec-inheritance/wo-merge" );
1504 List<PluginExecution> executions =
1505 (List<PluginExecution>) pom.getValue( "build/pluginsAsMap[@name='org.apache.maven.its.plugins:maven-it-plugin-log-file']/executions" );
1506 assertEquals( 1, executions.size() );
1507 assertEquals( "inherited-execution", executions.get( 0 ).getId() );
1508 }
1509
1510 public void testPluginExecutionInheritanceWhenChildDoesDeclarePluginAsWell()
1511 throws Exception
1512 {
1513 PomTestWrapper pom = buildPom( "plugin-exec-inheritance/w-merge" );
1514 List<PluginExecution> executions =
1515 (List<PluginExecution>) pom.getValue( "build/pluginsAsMap[@name='org.apache.maven.its.plugins:maven-it-plugin-log-file']/executions" );
1516 assertEquals( 1, executions.size() );
1517 assertEquals( "inherited-execution", executions.get( 0 ).getId() );
1518 }
1519
1520
1521 public void testValidationErrorUponNonUniqueArtifactRepositoryId()
1522 throws Exception
1523 {
1524 try
1525 {
1526 buildPom( "unique-repo-id/artifact-repo" );
1527 fail( "Non-unique repository ids did not cause validation error" );
1528 }
1529 catch ( ProjectBuildingException e )
1530 {
1531
1532 }
1533 }
1534
1535
1536 public void testValidationErrorUponNonUniquePluginRepositoryId()
1537 throws Exception
1538 {
1539 try
1540 {
1541 buildPom( "unique-repo-id/plugin-repo" );
1542 fail( "Non-unique repository ids did not cause validation error" );
1543 }
1544 catch ( ProjectBuildingException e )
1545 {
1546
1547 }
1548 }
1549
1550
1551 public void testValidationErrorUponNonUniqueArtifactRepositoryIdInProfile()
1552 throws Exception
1553 {
1554 try
1555 {
1556 buildPom( "unique-repo-id/artifact-repo-in-profile" );
1557 fail( "Non-unique repository ids did not cause validation error" );
1558 }
1559 catch ( ProjectBuildingException e )
1560 {
1561
1562 }
1563 }
1564
1565
1566 public void testValidationErrorUponNonUniquePluginRepositoryIdInProfile()
1567 throws Exception
1568 {
1569 try
1570 {
1571 buildPom( "unique-repo-id/plugin-repo-in-profile" );
1572 fail( "Non-unique repository ids did not cause validation error" );
1573 }
1574 catch ( ProjectBuildingException e )
1575 {
1576
1577 }
1578 }
1579
1580
1581 public void testPrerequisitesAreNotInherited()
1582 throws Exception
1583 {
1584 PomTestWrapper pom = buildPom( "prerequisites-inheritance/child" );
1585 assertSame( null, pom.getValue( "prerequisites" ) );
1586 }
1587
1588 public void testLicensesAreInheritedButNotAggregated()
1589 throws Exception
1590 {
1591 PomTestWrapper pom = buildPom( "licenses-inheritance/child-2" );
1592 assertEquals( 1, ( (List<?>) pom.getValue( "licenses" ) ).size() );
1593 assertEquals( "child-license", pom.getValue( "licenses[1]/name" ) );
1594 assertEquals( "http://child.url/license", pom.getValue( "licenses[1]/url" ) );
1595 }
1596
1597 public void testDevelopersAreInheritedButNotAggregated()
1598 throws Exception
1599 {
1600 PomTestWrapper pom = buildPom( "developers-inheritance/child-2" );
1601 assertEquals( 1, ( (List<?>) pom.getValue( "developers" ) ).size() );
1602 assertEquals( "child-developer", pom.getValue( "developers[1]/name" ) );
1603 }
1604
1605 public void testContributorsAreInheritedButNotAggregated()
1606 throws Exception
1607 {
1608 PomTestWrapper pom = buildPom( "contributors-inheritance/child-2" );
1609 assertEquals( 1, ( (List<?>) pom.getValue( "contributors" ) ).size() );
1610 assertEquals( "child-contributor", pom.getValue( "contributors[1]/name" ) );
1611 }
1612
1613 public void testMailingListsAreInheritedButNotAggregated()
1614 throws Exception
1615 {
1616 PomTestWrapper pom = buildPom( "mailing-lists-inheritance/child-2" );
1617 assertEquals( 1, ( (List<?>) pom.getValue( "mailingLists" ) ).size() );
1618 assertEquals( "child-mailing-list", pom.getValue( "mailingLists[1]/name" ) );
1619 }
1620
1621 public void testPluginInheritanceOrder()
1622 throws Exception
1623 {
1624 PomTestWrapper pom = buildPom( "plugin-inheritance-order/child" );
1625
1626 assertEquals( "maven-it-plugin-log-file", pom.getValue( "build/plugins[1]/artifactId" ) );
1627 assertEquals( "maven-it-plugin-expression", pom.getValue( "build/plugins[2]/artifactId" ) );
1628 assertEquals( "maven-it-plugin-configuration", pom.getValue( "build/plugins[3]/artifactId" ) );
1629
1630 assertEquals( "maven-it-plugin-log-file", pom.getValue( "reporting/plugins[1]/artifactId" ) );
1631 assertEquals( "maven-it-plugin-expression", pom.getValue( "reporting/plugins[2]/artifactId" ) );
1632 assertEquals( "maven-it-plugin-configuration", pom.getValue( "reporting/plugins[3]/artifactId" ) );
1633 }
1634
1635 public void testCliPropsDominateProjectPropsDuringInterpolation()
1636 throws Exception
1637 {
1638 Properties props = new Properties();
1639 props.setProperty( "testProperty", "PASSED" );
1640 PomTestWrapper pom = buildPom( "interpolation-cli-wins", props );
1641
1642 assertEquals( "PASSED", pom.getValue( "properties/interpolatedProperty" ) );
1643 }
1644
1645 public void testParentPomPackagingMustBePom()
1646 throws Exception
1647 {
1648 try
1649 {
1650 buildPom( "parent-pom-packaging/sub" );
1651 fail( "Wrong packaging of parent POM was not rejected" );
1652 }
1653 catch ( ProjectBuildingException e )
1654 {
1655
1656 }
1657 }
1658
1659
1660 public void testManagedPluginConfigurationAppliesToImplicitPluginsIntroducedByPackaging()
1661 throws Exception
1662 {
1663 PomTestWrapper pom = buildPom( "plugin-management-for-implicit-plugin/child" );
1664 assertEquals( "passed.txt",
1665 pom.getValue( "build/plugins[@artifactId='maven-resources-plugin']/configuration/pathname" ) );
1666 assertEquals( "passed.txt",
1667 pom.getValue( "build/plugins[@artifactId='maven-it-plugin-log-file']/configuration/logFile" ) );
1668 }
1669
1670 public void testDefaultPluginsExecutionContributedByPackagingExecuteBeforeUserDefinedExecutions()
1671 throws Exception
1672 {
1673 PomTestWrapper pom = buildPom( "plugin-exec-order-and-default-exec" );
1674 List<PluginExecution> executions =
1675 (List<PluginExecution>) pom.getValue( "build/plugins[@artifactId='maven-resources-plugin']/executions" );
1676 assertNotNull( executions );
1677 assertEquals( 4, executions.size() );
1678 assertEquals( "default-resources", executions.get( 0 ).getId() );
1679 assertEquals( "default-testResources", executions.get( 1 ).getId() );
1680 assertEquals( "test-1", executions.get( 2 ).getId() );
1681 assertEquals( "test-2", executions.get( 3 ).getId() );
1682 }
1683
1684 public void testPluginDeclarationsRetainPomOrderAfterInjectionOfDefaultPlugins()
1685 throws Exception
1686 {
1687 PomTestWrapper pom = buildPom( "plugin-exec-order-with-lifecycle" );
1688 List<Plugin> plugins = (List<Plugin>) pom.getValue( "build/plugins" );
1689 int resourcesPlugin = -1;
1690 int customPlugin = -1;
1691 for ( int i = 0; i < plugins.size(); i++ )
1692 {
1693 Plugin plugin = plugins.get( i );
1694 if ( "maven-resources-plugin".equals( plugin.getArtifactId() ) )
1695 {
1696 assertTrue( resourcesPlugin < 0 );
1697 resourcesPlugin = i;
1698 }
1699 else if ( "maven-it-plugin-log-file".equals( plugin.getArtifactId() ) )
1700 {
1701 assertTrue( customPlugin < 0 );
1702 customPlugin = i;
1703 }
1704 }
1705 assertTrue( plugins.toString(), customPlugin == resourcesPlugin - 1 );
1706 }
1707
1708
1709 public void testPluginOrderAfterMergingWithInheritedPlugins()
1710 throws Exception
1711 {
1712 PomTestWrapper pom = buildPom( "plugin-inheritance-merge-order/sub" );
1713
1714 List<String> expected = new ArrayList<String>();
1715 expected.add( "maven-it-plugin-error" );
1716 expected.add( "maven-it-plugin-configuration" );
1717 expected.add( "maven-it-plugin-dependency-resolution" );
1718 expected.add( "maven-it-plugin-packaging" );
1719 expected.add( "maven-it-plugin-log-file" );
1720 expected.add( "maven-it-plugin-expression" );
1721 expected.add( "maven-it-plugin-fork" );
1722 expected.add( "maven-it-plugin-touch" );
1723
1724 List<String> actual = new ArrayList<String>();
1725 for ( Plugin plugin : (List<Plugin>) pom.getValue( "build/plugins" ) )
1726 {
1727 actual.add( plugin.getArtifactId() );
1728 }
1729
1730 actual.retainAll( expected );
1731
1732 assertEquals( actual, expected );
1733 }
1734
1735
1736 public void testPluginOrderAfterMergingWithInjectedPlugins()
1737 throws Exception
1738 {
1739 PomTestWrapper pom = buildPom( "plugin-injection-merge-order" );
1740
1741 List<String> expected = new ArrayList<String>();
1742 expected.add( "maven-it-plugin-error" );
1743 expected.add( "maven-it-plugin-configuration" );
1744 expected.add( "maven-it-plugin-dependency-resolution" );
1745 expected.add( "maven-it-plugin-packaging" );
1746 expected.add( "maven-it-plugin-log-file" );
1747 expected.add( "maven-it-plugin-expression" );
1748 expected.add( "maven-it-plugin-fork" );
1749 expected.add( "maven-it-plugin-touch" );
1750
1751 List<String> actual = new ArrayList<String>();
1752 for ( Plugin plugin : (List<Plugin>) pom.getValue( "build/plugins" ) )
1753 {
1754 actual.add( plugin.getArtifactId() );
1755 }
1756
1757 actual.retainAll( expected );
1758
1759 assertEquals( actual, expected );
1760 }
1761
1762 public void testProjectArtifactIdIsNotInheritedButMandatory()
1763 throws Exception
1764 {
1765 try
1766 {
1767 buildPom( "artifact-id-inheritance/child" );
1768 fail( "Missing artifactId did not cause validation error" );
1769 }
1770 catch ( ProjectBuildingException e )
1771 {
1772
1773 }
1774 }
1775
1776 private void assertPathSuffixEquals( String expected, Object actual )
1777 {
1778 String a = actual.toString();
1779 a = a.substring( a.length() - expected.length() ).replace( '\\', '/' );
1780 assertEquals( expected, a );
1781 }
1782
1783 private void assertPathWithNormalizedFileSeparators( Object value )
1784 {
1785 assertEquals( new File( value.toString() ).getPath(), value.toString() );
1786 }
1787
1788 private PomTestWrapper buildPom( String pomPath, String... profileIds )
1789 throws ProjectBuildingException
1790 {
1791 return buildPom( pomPath, null, profileIds );
1792 }
1793
1794 private PomTestWrapper buildPom( String pomPath, Properties executionProperties, String... profileIds )
1795 throws ProjectBuildingException
1796 {
1797 return buildPom( pomPath, false, executionProperties, profileIds );
1798 }
1799
1800 private PomTestWrapper buildPom( String pomPath, boolean lenientValidation, Properties executionProperties,
1801 String... profileIds )
1802 throws ProjectBuildingException
1803 {
1804 File pomFile = new File( testDirectory, pomPath );
1805 if ( pomFile.isDirectory() )
1806 {
1807 pomFile = new File( pomFile, "pom.xml" );
1808 }
1809
1810 ProjectBuildingRequest config = new DefaultProjectBuildingRequest();
1811
1812 String localRepoUrl =
1813 System.getProperty( "maven.repo.local", System.getProperty( "user.home" ) + "/.m2/repository" );
1814 localRepoUrl = "file://" + localRepoUrl;
1815 config.setLocalRepository( repositorySystem.createArtifactRepository( "local", localRepoUrl, new DefaultRepositoryLayout(), null, null ) );
1816 config.setActiveProfileIds( Arrays.asList( profileIds ) );
1817 config.setSystemProperties( executionProperties );
1818 config.setUserProperties( executionProperties );
1819 config.setValidationLevel( lenientValidation ? ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0
1820 : ModelBuildingRequest.VALIDATION_LEVEL_STRICT );
1821 MavenRepositorySystemSession repoSession = new MavenRepositorySystemSession();
1822 repoSession.setLocalRepositoryManager( new SimpleLocalRepositoryManager(
1823 new File(
1824 config.getLocalRepository().getBasedir() ) ) );
1825 config.setRepositorySession( repoSession );
1826
1827 return new PomTestWrapper( pomFile, projectBuilder.build( pomFile, config ).getProject() );
1828 }
1829
1830 protected void assertModelEquals( PomTestWrapper pom, Object expected, String expression )
1831 {
1832 assertEquals( expected, pom.getValue( expression ) );
1833 }
1834
1835 private static String createPath( List<String> elements )
1836 {
1837 StringBuilder buffer = new StringBuilder( 256 );
1838 for ( String s : elements )
1839 {
1840 buffer.append( s ).append( File.separator );
1841 }
1842 return buffer.toString().substring( 0, buffer.toString().length() - 1 );
1843 }
1844 }