View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.project.inheritance.t09;
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  import org.junit.jupiter.api.Test;
27  
28  import static org.junit.jupiter.api.Assertions.assertEquals;
29  import static org.junit.jupiter.api.Assertions.assertFalse;
30  import static org.junit.jupiter.api.Assertions.assertNotNull;
31  import static org.junit.jupiter.api.Assertions.assertTrue;
32  
33  /**
34   * Verifies exclusions listed in dependencyManagement are valid for
35   * transitive dependencies.
36   *
37   */
38  @Deprecated
39  class ProjectInheritanceTest extends AbstractProjectInheritanceTestCase {
40      // ----------------------------------------------------------------------
41      //
42      // p1 inherits from p0
43      // p0 inherits from super model
44      //
45      // or we can show it graphically as:
46      //
47      // p1 ---> p0 --> super model
48      //
49      // ----------------------------------------------------------------------
50  
51      /**
52       * How the test project is set up:
53       *
54       * 1. dependencyManagement lists dependencies on a & b,
55       *    with an exclusion on c in b.
56       * 2. the child project lists a dependency on project a only
57       * 3. a depends on b (which is transitive to the child project),
58       *    and b depends on c.
59       *
60       * We should see that the resulting size of collected artifacts is two:
61       * a & b only.
62       */
63      @Test
64      void testDependencyManagementExclusionsExcludeTransitively() throws Exception {
65          File localRepo = getLocalRepositoryPath();
66  
67          File pom0 = new File(localRepo, "p0/pom.xml");
68          File pom0Basedir = pom0.getParentFile();
69          File pom1 = new File(pom0Basedir, "p1/pom.xml");
70  
71          // load the child project, which inherits from p0...
72          MavenProject project0 = getProjectWithDependencies(pom0);
73          MavenProject project1 = getProjectWithDependencies(pom1);
74  
75          assertNotNull(project1.getParent(), "Parent is null");
76          assertEquals(pom0Basedir, project1.getParent().getBasedir());
77          Map map = project1.getArtifactMap();
78  
79          assertNotNull(map, "No artifacts");
80          assertTrue(map.size() > 0, "No Artifacts");
81          assertTrue(map.size() == 2, "Set size should be 2, is " + map.size());
82  
83          assertTrue(map.containsKey("maven-test:t09-a"), "maven-test:t09-a is not in the project");
84          assertTrue(map.containsKey("maven-test:t09-b"), "maven-test:t09-b is not in the project");
85          assertFalse(map.containsKey("maven-test:t09-c"), "maven-test:t09-c is in the project");
86      }
87  
88      /**
89       * Setup exactly the same as the above test, except that the child project
90       * now depends upon d, which has a transitive dependency on c.  Even though
91       * we did list an exclusion on c, it was only from within the context of
92       * project b.  We will pick up project c in this case because no
93       * restrictions were placed on d.  This demonstrates that a, b, c, & d will
94       * all be collected.
95       *
96       * @throws Exception
97       */
98      @Test
99      void testDependencyManagementExclusionDoesNotOverrideGloballyForTransitives() throws Exception {
100         File localRepo = getLocalRepositoryPath();
101 
102         File pom0 = new File(localRepo, "p0/pom.xml");
103         File pom0Basedir = pom0.getParentFile();
104         File pom2 = new File(pom0Basedir, "p2/pom.xml");
105 
106         // load the child project, which inherits from p0...
107         MavenProject project0 = getProjectWithDependencies(pom0);
108         MavenProject project2 = getProjectWithDependencies(pom2);
109 
110         assertEquals(pom0Basedir, project2.getParent().getBasedir());
111         Map map = project2.getArtifactMap();
112         assertNotNull(map, "No artifacts");
113         assertTrue(map.size() > 0, "No Artifacts");
114         assertTrue(map.size() == 4, "Set size should be 4, is " + map.size());
115 
116         assertTrue(map.containsKey("maven-test:t09-a"), "maven-test:t09-a is not in the project");
117         assertTrue(map.containsKey("maven-test:t09-b"), "maven-test:t09-b is not in the project");
118         assertTrue(map.containsKey("maven-test:t09-c"), "maven-test:t09-c is not in the project");
119         assertTrue(map.containsKey("maven-test:t09-d"), "maven-test:t09-d is not in the project");
120     }
121 }