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