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