1   package org.apache.maven.project.inheritance.t07;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.File;
23  import java.util.List;
24  import java.util.Set;
25  import java.util.Iterator;
26  
27  import org.apache.maven.model.Build;
28  import org.apache.maven.model.MailingList;
29  import org.apache.maven.model.Plugin;
30  import org.apache.maven.model.PluginExecution;
31  import org.apache.maven.model.Dependency;
32  import org.apache.maven.project.MavenProject;
33  import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase;
34  import org.apache.maven.artifact.Artifact;
35  import org.codehaus.plexus.util.xml.Xpp3Dom;
36  import org.codehaus.plexus.logging.LoggerManager;
37  import org.codehaus.plexus.logging.Logger;
38  
39  /**
40   * A test which demonstrates maven's dependency management
41   *
42   * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
43   * @version $Id: ProjectInheritanceTest.java 640549 2008-03-24 20:05:11Z bentmann $
44   */
45  public class ProjectInheritanceTest
46      extends AbstractProjectInheritanceTestCase
47  {
48      // ----------------------------------------------------------------------
49      //
50      // p1 inherits from p0
51      // p0 inhertis from super model
52      //
53      // or we can show it graphically as:
54      //
55      // p1 ---> p0 --> super model
56      //
57      // ----------------------------------------------------------------------
58  
59      public void testDependencyManagement()
60          throws Exception
61      {
62          File localRepo = getLocalRepositoryPath();
63          File pom0 = new File( localRepo, "p0/pom.xml" );
64  
65          File pom0Basedir = pom0.getParentFile();
66  
67          File pom1 = new File( pom0Basedir, "p1/pom.xml" );
68  
69          // load everything...
70          MavenProject project0 = getProjectWithDependencies( pom0 );
71          MavenProject project1 = getProjectWithDependencies( pom1 );
72  
73          assertEquals( pom0Basedir, project1.getParent().getBasedir() );
74          System.out.println("Project " + project1.getId() + " " + project1);
75          Set set = project1.getArtifacts();
76          assertNotNull("No artifacts", set);
77          assertTrue("No Artifacts", set.size() > 0);
78          Iterator iter = set.iterator();
79          assertTrue("Set size should be 3, is " + set.size(), set.size() == 3);
80          
81          while (iter.hasNext())
82          {
83              Artifact artifact = (Artifact)iter.next();
84              assertFalse("", artifact.getArtifactId().equals("maven-test-d"));
85              System.out.println("Artifact: " + artifact.getDependencyConflictId() + " " + artifact.getVersion() +
86                " Optional=" + (artifact.isOptional() ? "true" : "false"));
87              assertTrue("Incorrect version for " + artifact.getDependencyConflictId(), artifact.getVersion().equals("1.0"));
88          }
89  
90      }
91  }