001 package org.apache.maven.project.inheritance.t09;
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 import java.io.File;
022 import java.util.Map;
023
024 import org.apache.maven.project.MavenProject;
025 import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase;
026
027 /**
028 * Verifies exclusions listed in dependencyManagement are valid for
029 * transitive dependencies.
030 *
031 * @author <a href="mailto:pschneider@gmail.com">Patrick Schneider</a>
032 */
033 public class ProjectInheritanceTest
034 extends AbstractProjectInheritanceTestCase
035 {
036 // ----------------------------------------------------------------------
037 //
038 // p1 inherits from p0
039 // p0 inhertis from super model
040 //
041 // or we can show it graphically as:
042 //
043 // p1 ---> p0 --> super model
044 //
045 // ----------------------------------------------------------------------
046
047 /**
048 * How the test project is set up:
049 *
050 * 1. dependencyManagement lists dependencies on a & b,
051 * with an exclusion on c in b.
052 * 2. the child project lists a dependency on project a only
053 * 3. a depends on b (which is transitive to the child project),
054 * and b depends on c.
055 *
056 * We should see that the resulting size of collected artifacts is two:
057 * a & b only.
058 */
059 public void testDependencyManagementExclusionsExcludeTransitively()
060 throws Exception
061 {
062 File localRepo = getLocalRepositoryPath();
063
064 File pom0 = new File( localRepo, "p0/pom.xml" );
065 File pom0Basedir = pom0.getParentFile();
066 File pom1 = new File( pom0Basedir, "p1/pom.xml" );
067
068 // load the child project, which inherits from p0...
069 MavenProject project0 = getProjectWithDependencies( pom0 );
070 MavenProject project1 = getProjectWithDependencies( pom1 );
071
072 assertNotNull("Parent is null", project1.getParent());
073 assertEquals( pom0Basedir, project1.getParent().getBasedir() );
074 Map map = project1.getArtifactMap();
075
076 assertNotNull("No artifacts", map);
077 assertTrue("No Artifacts", map.size() > 0);
078 assertTrue("Set size should be 2, is " + map.size(), map.size() == 2);
079
080 assertTrue("maven-test:t09-a is not in the project", map.containsKey( "maven-test:t09-a" ));
081 assertTrue("maven-test:t09-b is not in the project", map.containsKey( "maven-test:t09-b" ));
082 assertFalse("maven-test:t09-c is in the project", map.containsKey( "maven-test:t09-c" ));
083 }
084
085 /**
086 * Setup exactly the same as the above test, except that the child project
087 * now depends upon d, which has a transitive dependency on c. Even though
088 * we did list an exclusion on c, it was only from within the context of
089 * project b. We will pick up project c in this case because no
090 * restrictions were placed on d. This demonstrates that a, b, c, & d will
091 * all be collected.
092 *
093 * @throws Exception
094 */
095 public void testDependencyManagementExclusionDoesNotOverrideGloballyForTransitives()
096 throws Exception
097 {
098 File localRepo = getLocalRepositoryPath();
099
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 }