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