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