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