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.t07;
20  
21  import java.io.File;
22  import java.util.Set;
23  
24  import org.apache.maven.artifact.Artifact;
25  import org.apache.maven.project.MavenProject;
26  import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase;
27  
28  /**
29   * A test which demonstrates maven's dependency management
30   *
31   * @author Jason van Zyl
32   */
33  public class ProjectInheritanceTest extends AbstractProjectInheritanceTestCase {
34      // ----------------------------------------------------------------------
35      //
36      // p1 inherits from p0
37      // p0 inherits from super model
38      //
39      // or we can show it graphically as:
40      //
41      // p1 ---> p0 --> super model
42      //
43      // ----------------------------------------------------------------------
44  
45      public void testDependencyManagement() throws Exception {
46          File localRepo = getLocalRepositoryPath();
47          File pom0 = new File(localRepo, "p0/pom.xml");
48  
49          File pom0Basedir = pom0.getParentFile();
50  
51          File pom1 = new File(pom0Basedir, "p1/pom.xml");
52  
53          // load everything...
54          MavenProject project1 = getProjectWithDependencies(pom1);
55  
56          assertEquals(pom0Basedir, project1.getParent().getBasedir());
57          System.out.println("Project " + project1.getId() + " " + project1);
58          Set set = project1.getArtifacts();
59          assertNotNull("No artifacts", set);
60          assertTrue("No Artifacts", set.size() > 0);
61          assertTrue("Set size should be 3, is " + set.size(), set.size() == 3);
62  
63          for (Object aSet : set) {
64              Artifact artifact = (Artifact) aSet;
65              assertFalse("", artifact.getArtifactId().equals("t07-d"));
66              System.out.println("Artifact: " + artifact.getDependencyConflictId() + " " + artifact.getVersion()
67                      + " Optional=" + (artifact.isOptional() ? "true" : "false"));
68              assertTrue(
69                      "Incorrect version for " + artifact.getDependencyConflictId(),
70                      artifact.getVersion().equals("1.0"));
71          }
72      }
73  }