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.t10;
20  
21  import java.io.File;
22  import java.util.Map;
23  
24  import org.apache.maven.artifact.Artifact;
25  import org.apache.maven.project.MavenProject;
26  import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase;
27  import org.junit.jupiter.api.Test;
28  
29  import static org.junit.jupiter.api.Assertions.assertEquals;
30  import static org.junit.jupiter.api.Assertions.assertNotNull;
31  import static org.junit.jupiter.api.Assertions.assertTrue;
32  
33  /**
34   * Verifies scope inheritance of direct and transitive dependencies.
35   *
36   * Should show three behaviors:
37   *
38   * 1. dependencyManagement should override the scope of transitive dependencies.
39   * 2. Direct dependencies should override the scope of dependencyManagement.
40   * 3. Direct dependencies should inherit scope from dependencyManagement when
41   *    they do not explicitly state a scope.
42   *
43   */
44  @Deprecated
45  class ProjectInheritanceTest extends AbstractProjectInheritanceTestCase {
46      // ----------------------------------------------------------------------
47      //
48      // p1 inherits from p0
49      // p0 inherits from super model
50      //
51      // or we can show it graphically as:
52      //
53      // p1 ---> p0 --> super model
54      //
55      // ----------------------------------------------------------------------
56  
57      @Test
58      void testDependencyManagementOverridesTransitiveDependencyVersion() throws Exception {
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(map, "No artifacts");
73          assertTrue(map.size() > 0, "No Artifacts");
74          assertTrue(map.size() == 3, "Set size should be 3, is " + map.size());
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(a.getScope().equals("test"), "Incorrect scope for " + a.getDependencyConflictId());
87  
88          // transitive dep, overridden b depMgmt
89          assertTrue(b.getScope().equals("runtime"), "Incorrect scope for " + b.getDependencyConflictId());
90  
91          // direct dep, overrides depMgmt
92          assertTrue(c.getScope().equals("runtime"), "Incorrect scope for " + c.getDependencyConflictId());
93      }
94  }