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.Map;
24
25 import org.apache.maven.artifact.Artifact;
26 import org.apache.maven.project.MavenProject;
27 import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase;
28
29 /**
30 * Verifies scope inheritence of direct and transitive dependencies.
31 *
32 * Should show three behaviors:
33 *
34 * 1. dependencyManagement should override the scope of transitive dependencies.
35 * 2. Direct dependencies should override the scope of dependencyManagement.
36 * 3. Direct dependencies should inherit scope from dependencyManagement when
37 * they do not explicitly state a scope.
38 *
39 * @author <a href="mailto:pschneider@gmail.com">Patrick Schneider</a>
40 * @version $Id: ProjectInheritanceTest.java 948687 2010-05-27 06:37:07Z bentmann $
41 */
42 public class ProjectInheritanceTest
43 extends AbstractProjectInheritanceTestCase
44 {
45 // ----------------------------------------------------------------------
46 //
47 // p1 inherits from p0
48 // p0 inhertis from super model
49 //
50 // or we can show it graphically as:
51 //
52 // p1 ---> p0 --> super model
53 //
54 // ----------------------------------------------------------------------
55
56 public void testDependencyManagementOverridesTransitiveDependencyVersion()
57 throws Exception
58 {
59 File localRepo = getLocalRepositoryPath();
60
61 File pom0 = new File( localRepo, "p0/pom.xml" );
62 File pom0Basedir = pom0.getParentFile();
63 File pom1 = new File( pom0Basedir, "p1/pom.xml" );
64
65 // load the child project, which inherits from p0...
66 MavenProject project0 = getProjectWithDependencies( pom0 );
67 MavenProject project1 = getProjectWithDependencies( pom1 );
68
69 assertEquals( pom0Basedir, project1.getParent().getBasedir() );
70 System.out.println("Project " + project1.getId() + " " + project1);
71 Map map = project1.getArtifactMap();
72 assertNotNull("No artifacts", map);
73 assertTrue("No Artifacts", map.size() > 0);
74 assertTrue("Set size should be 3, is " + map.size(), map.size() == 3);
75
76 Artifact a = (Artifact) map.get("maven-test:t10-a");
77 Artifact b = (Artifact) map.get("maven-test:t10-b");
78 Artifact c = (Artifact) map.get("maven-test:t10-c");
79
80 assertNotNull( a );
81 assertNotNull( b );
82 assertNotNull( c );
83
84 // inherited from depMgmt
85 System.out.println(a.getScope());
86 assertTrue("Incorrect scope for " + a.getDependencyConflictId(), a.getScope().equals("test"));
87
88 // transitive dep, overridden b depMgmt
89 assertTrue("Incorrect scope for " + b.getDependencyConflictId(), b.getScope().equals("runtime"));
90
91 // direct dep, overrides depMgmt
92 assertTrue("Incorrect scope for " + c.getDependencyConflictId(), c.getScope().equals("runtime"));
93
94 }
95 }