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