001package org.apache.maven.project.inheritance.t05; 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.Set; 024 025import org.apache.maven.artifact.Artifact; 026import org.apache.maven.project.MavenProject; 027import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase; 028 029/** 030 * A test which demonstrates maven's dependency management 031 * 032 * @author <a href="rgoers@apache.org">Ralph Goers</a> 033 */ 034public class ProjectInheritanceTest 035 extends AbstractProjectInheritanceTestCase 036{ 037 // ---------------------------------------------------------------------- 038 // 039 // p1 inherits from p0 040 // p0 inhertis from super model 041 // 042 // or we can show it graphically as: 043 // 044 // p1 ---> p0 --> super model 045 // 046 // ---------------------------------------------------------------------- 047 048 public void testDependencyManagement() 049 throws Exception 050 { 051 File localRepo = getLocalRepositoryPath(); 052 File pom0 = new File( localRepo, "p0/pom.xml" ); 053 054 File pom0Basedir = pom0.getParentFile(); 055 056 File pom1 = new File( pom0Basedir, "p1/pom.xml" ); 057 058 // load everything... 059 MavenProject project0 = getProjectWithDependencies( pom0 ); 060 MavenProject project1 = getProjectWithDependencies( pom1 ); 061 062 assertEquals( pom0Basedir, project1.getParent().getBasedir() ); 063 Set set = project1.getArtifacts(); 064 assertNotNull( "No artifacts", set ); 065 assertTrue( "No Artifacts", set.size() > 0 ); 066 067 for ( Object aSet : set ) 068 { 069 Artifact artifact = (Artifact) aSet; 070 System.out.println( 071 "Artifact: " + artifact.getDependencyConflictId() + " " + artifact.getVersion() + " Scope: " 072 + artifact.getScope() ); 073 assertTrue( "Incorrect version for " + artifact.getDependencyConflictId(), 074 artifact.getVersion().equals( "1.0" ) ); 075 } 076 077 } 078}