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