001package org.apache.maven.project.inheritance.t10; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import java.io.File; 023import java.util.Map; 024 025import org.apache.maven.artifact.Artifact; 026import org.apache.maven.project.MavenProject; 027import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase; 028 029/** 030 * Verifies scope inheritence of direct and transitive dependencies. 031 * 032 * Should show three behaviors: 033 * 034 * 1. dependencyManagement should override the scope of transitive dependencies. 035 * 2. Direct dependencies should override the scope of dependencyManagement. 036 * 3. Direct dependencies should inherit scope from dependencyManagement when 037 * they do not explicitly state a scope. 038 * 039 * @author <a href="mailto:pschneider@gmail.com">Patrick Schneider</a> 040 */ 041public class ProjectInheritanceTest 042 extends AbstractProjectInheritanceTestCase 043{ 044 // ---------------------------------------------------------------------- 045 // 046 // p1 inherits from p0 047 // p0 inhertis from super model 048 // 049 // or we can show it graphically as: 050 // 051 // p1 ---> p0 --> super model 052 // 053 // ---------------------------------------------------------------------- 054 055 public void testDependencyManagementOverridesTransitiveDependencyVersion() 056 throws Exception 057 { 058 File localRepo = getLocalRepositoryPath(); 059 060 File pom0 = new File( localRepo, "p0/pom.xml" ); 061 File pom0Basedir = pom0.getParentFile(); 062 File pom1 = new File( pom0Basedir, "p1/pom.xml" ); 063 064 // load the child project, which inherits from p0... 065 MavenProject project0 = getProjectWithDependencies( pom0 ); 066 MavenProject project1 = getProjectWithDependencies( pom1 ); 067 068 assertEquals( pom0Basedir, project1.getParent().getBasedir() ); 069 System.out.println("Project " + project1.getId() + " " + project1); 070 Map map = project1.getArtifactMap(); 071 assertNotNull("No artifacts", map); 072 assertTrue("No Artifacts", map.size() > 0); 073 assertTrue("Set size should be 3, is " + map.size(), map.size() == 3); 074 075 Artifact a = (Artifact) map.get("maven-test:t10-a"); 076 Artifact b = (Artifact) map.get("maven-test:t10-b"); 077 Artifact c = (Artifact) map.get("maven-test:t10-c"); 078 079 assertNotNull( a ); 080 assertNotNull( b ); 081 assertNotNull( c ); 082 083 // inherited from depMgmt 084 System.out.println(a.getScope()); 085 assertTrue("Incorrect scope for " + a.getDependencyConflictId(), a.getScope().equals("test")); 086 087 // transitive dep, overridden b depMgmt 088 assertTrue("Incorrect scope for " + b.getDependencyConflictId(), b.getScope().equals("runtime")); 089 090 // direct dep, overrides depMgmt 091 assertTrue("Incorrect scope for " + c.getDependencyConflictId(), c.getScope().equals("runtime")); 092 093 } 094}