1   package org.apache.maven.project.inheritance.t10;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.File;
23  import java.util.Collection;
24  import java.util.List;
25  import java.util.Map;
26  import java.util.Iterator;
27  
28  import org.apache.maven.model.Build;
29  import org.apache.maven.model.MailingList;
30  import org.apache.maven.model.Plugin;
31  import org.apache.maven.model.PluginExecution;
32  import org.apache.maven.model.Dependency;
33  import org.apache.maven.project.MavenProject;
34  import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase;
35  import org.apache.maven.artifact.Artifact;
36  import org.codehaus.plexus.util.xml.Xpp3Dom;
37  import org.codehaus.plexus.logging.LoggerManager;
38  import org.codehaus.plexus.logging.Logger;
39  
40  /**
41   * Verifies scope inheritence of direct and transitive dependencies.
42   * 
43   * Should show three behaviors:
44   * 
45   * 1. dependencyManagement should override the scope of transitive dependencies.
46   * 2. Direct dependencies should override the scope of dependencyManagement.
47   * 3. Direct dependencies should inherit scope from dependencyManagement when
48   *    they do not explicitly state a scope.
49   *
50   * @author <a href="mailto:pschneider@gmail.com">Patrick Schneider</a>
51   * @version $Id: ProjectInheritanceTest.java 640549 2008-03-24 20:05:11Z bentmann $
52   */
53  public class ProjectInheritanceTest
54      extends AbstractProjectInheritanceTestCase
55  {
56      // ----------------------------------------------------------------------
57      //
58      // p1 inherits from p0
59      // p0 inhertis from super model
60      //
61      // or we can show it graphically as:
62      //
63      // p1 ---> p0 --> super model
64  	//
65      // ----------------------------------------------------------------------
66  
67      public void testDependencyManagementOverridesTransitiveDependencyVersion()
68          throws Exception
69      {
70          File localRepo = getLocalRepositoryPath();
71  
72          File pom0 = new File( localRepo, "p0/pom.xml" );
73          File pom0Basedir = pom0.getParentFile();
74          File pom1 = new File( pom0Basedir, "p1/pom.xml" );
75  
76          // load the child project, which inherits from p0...
77          MavenProject project0 = getProjectWithDependencies( pom0 );
78          MavenProject project1 = getProjectWithDependencies( pom1 );
79  
80          assertEquals( pom0Basedir, project1.getParent().getBasedir() );
81          System.out.println("Project " + project1.getId() + " " + project1);
82          Map map = project1.getArtifactMap();
83          assertNotNull("No artifacts", map);
84          assertTrue("No Artifacts", map.size() > 0);
85          assertTrue("Set size should be 3, is " + map.size(), map.size() == 3);
86          
87          Artifact a = (Artifact) map.get("maven-test:maven-test-a");
88          Artifact b = (Artifact) map.get("maven-test:maven-test-b");
89          Artifact c = (Artifact) map.get("maven-test:maven-test-c");
90          
91          // inherited from depMgmt
92          assertTrue("Incorrect scope for " + a.getDependencyConflictId(), a.getScope().equals("test"));
93          
94          // transitive dep, overridden b depMgmt
95          assertTrue("Incorrect scope for " + b.getDependencyConflictId(), b.getScope().equals("runtime"));
96          
97          // direct dep, overrides depMgmt
98          assertTrue("Incorrect scope for " + c.getDependencyConflictId(), c.getScope().equals("runtime"));
99  
100     }
101 }