1 package org.apache.maven.project.inheritance.t09;
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 import java.io.File;
22 import java.util.Map;
23
24 import org.apache.maven.project.MavenProject;
25 import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase;
26
27 /**
28 * Verifies exclusions listed in dependencyManagement are valid for
29 * transitive dependencies.
30 *
31 * @author <a href="mailto:pschneider@gmail.com">Patrick Schneider</a>
32 */
33 public class ProjectInheritanceTest
34 extends AbstractProjectInheritanceTestCase
35 {
36 // ----------------------------------------------------------------------
37 //
38 // p1 inherits from p0
39 // p0 inhertis from super model
40 //
41 // or we can show it graphically as:
42 //
43 // p1 ---> p0 --> super model
44 //
45 // ----------------------------------------------------------------------
46
47 /**
48 * How the test project is set up:
49 *
50 * 1. dependencyManagement lists dependencies on a & b,
51 * with an exclusion on c in b.
52 * 2. the child project lists a dependency on project a only
53 * 3. a depends on b (which is transitive to the child project),
54 * and b depends on c.
55 *
56 * We should see that the resulting size of collected artifacts is two:
57 * a & b only.
58 */
59 public void testDependencyManagementExclusionsExcludeTransitively()
60 throws Exception
61 {
62 File localRepo = getLocalRepositoryPath();
63
64 File pom0 = new File( localRepo, "p0/pom.xml" );
65 File pom0Basedir = pom0.getParentFile();
66 File pom1 = new File( pom0Basedir, "p1/pom.xml" );
67
68 // load the child project, which inherits from p0...
69 MavenProject project0 = getProjectWithDependencies( pom0 );
70 MavenProject project1 = getProjectWithDependencies( pom1 );
71
72 assertNotNull("Parent is null", project1.getParent());
73 assertEquals( pom0Basedir, project1.getParent().getBasedir() );
74 Map map = project1.getArtifactMap();
75
76 assertNotNull("No artifacts", map);
77 assertTrue("No Artifacts", map.size() > 0);
78 assertTrue("Set size should be 2, is " + map.size(), map.size() == 2);
79
80 assertTrue("maven-test:t09-a is not in the project", map.containsKey( "maven-test:t09-a" ));
81 assertTrue("maven-test:t09-b is not in the project", map.containsKey( "maven-test:t09-b" ));
82 assertFalse("maven-test:t09-c is in the project", map.containsKey( "maven-test:t09-c" ));
83 }
84
85 /**
86 * Setup exactly the same as the above test, except that the child project
87 * now depends upon d, which has a transitive dependency on c. Even though
88 * we did list an exclusion on c, it was only from within the context of
89 * project b. We will pick up project c in this case because no
90 * restrictions were placed on d. This demonstrates that a, b, c, & d will
91 * all be collected.
92 *
93 * @throws Exception
94 */
95 public void testDependencyManagementExclusionDoesNotOverrideGloballyForTransitives()
96 throws Exception
97 {
98 File localRepo = getLocalRepositoryPath();
99
100 File pom0 = new File( localRepo, "p0/pom.xml" );
101 File pom0Basedir = pom0.getParentFile();
102 File pom2 = new File( pom0Basedir, "p2/pom.xml" );
103
104 // load the child project, which inherits from p0...
105 MavenProject project0 = getProjectWithDependencies( pom0 );
106 MavenProject project2 = getProjectWithDependencies( pom2 );
107
108 assertEquals( pom0Basedir, project2.getParent().getBasedir() );
109 Map map = project2.getArtifactMap();
110 assertNotNull( "No artifacts", map );
111 assertTrue( "No Artifacts", map.size() > 0 );
112 assertTrue( "Set size should be 4, is " + map.size(), map.size() == 4 );
113
114 assertTrue( "maven-test:t09-a is not in the project", map.containsKey( "maven-test:t09-a" ) );
115 assertTrue( "maven-test:t09-b is not in the project", map.containsKey( "maven-test:t09-b" ) );
116 assertTrue( "maven-test:t09-c is not in the project", map.containsKey( "maven-test:t09-c" ) );
117 assertTrue( "maven-test:t09-d is not in the project", map.containsKey( "maven-test:t09-d" ) );
118 }
119 }