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