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 */
41 public class ProjectInheritanceTest
42 extends AbstractProjectInheritanceTestCase
43 {
44 // ----------------------------------------------------------------------
45 //
46 // p1 inherits from p0
47 // p0 inhertis from super model
48 //
49 // or we can show it graphically as:
50 //
51 // p1 ---> p0 --> super model
52 //
53 // ----------------------------------------------------------------------
54
55 public void testDependencyManagementOverridesTransitiveDependencyVersion()
56 throws Exception
57 {
58 File localRepo = getLocalRepositoryPath();
59
60 File pom0 = new File( localRepo, "p0/pom.xml" );
61 File pom0Basedir = pom0.getParentFile();
62 File pom1 = new File( pom0Basedir, "p1/pom.xml" );
63
64 // load the child project, which inherits from p0...
65 MavenProject project0 = getProjectWithDependencies( pom0 );
66 MavenProject project1 = getProjectWithDependencies( pom1 );
67
68 assertEquals( pom0Basedir, project1.getParent().getBasedir() );
69 System.out.println("Project " + project1.getId() + " " + project1);
70 Map map = project1.getArtifactMap();
71 assertNotNull("No artifacts", map);
72 assertTrue("No Artifacts", map.size() > 0);
73 assertTrue("Set size should be 3, is " + map.size(), map.size() == 3);
74
75 Artifact a = (Artifact) map.get("maven-test:t10-a");
76 Artifact b = (Artifact) map.get("maven-test:t10-b");
77 Artifact c = (Artifact) map.get("maven-test:t10-c");
78
79 assertNotNull( a );
80 assertNotNull( b );
81 assertNotNull( c );
82
83 // inherited from depMgmt
84 System.out.println(a.getScope());
85 assertTrue("Incorrect scope for " + a.getDependencyConflictId(), a.getScope().equals("test"));
86
87 // transitive dep, overridden b depMgmt
88 assertTrue("Incorrect scope for " + b.getDependencyConflictId(), b.getScope().equals("runtime"));
89
90 // direct dep, overrides depMgmt
91 assertTrue("Incorrect scope for " + c.getDependencyConflictId(), c.getScope().equals("runtime"));
92
93 }
94 }