1 package org.apache.maven.project.inheritance.t13;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.artifact.Artifact;
23 import org.apache.maven.artifact.repository.ArtifactRepository;
24 import org.apache.maven.artifact.repository.DefaultArtifactRepository;
25 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
26 import org.apache.maven.model.Dependency;
27 import org.apache.maven.project.MavenProject;
28 import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase;
29
30 import java.io.File;
31 import java.util.List;
32
33
34
35
36
37 public class ProjectInheritanceTest
38 extends AbstractProjectInheritanceTestCase
39 {
40 protected ArtifactRepository getLocalRepository()
41 throws Exception
42 {
43 ArtifactRepositoryLayout repoLayout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE,
44 "default" );
45
46 ArtifactRepository r = new DefaultArtifactRepository( "local",
47 "file://" + getLocalRepositoryPath().getAbsolutePath() + "/repo",
48 repoLayout );
49
50 return r;
51 }
52
53
54
55
56
57
58
59
60
61
62
63
64 public void testChildDependenciesAddedAheadOfParentDependencies()
65 throws Exception
66 {
67 File localRepo = getLocalRepositoryPath();
68
69 File pom0 = new File( localRepo, "p0/pom.xml" );
70 File pom0Basedir = pom0.getParentFile();
71 File pom1 = new File( pom0Basedir, "p1/pom.xml" );
72
73 getProjectWithDependencies( pom0 );
74 MavenProject project1 = getProjectWithDependencies( pom1 );
75
76 List dependencies = project1.getDependencies();
77
78 assertNotNull( "Must contain dependencies.", dependencies );
79 assertEquals( "Must contain 2 dependencies.", 2, dependencies.size() );
80
81 Dependency dep1 = (Dependency) dependencies.get( 0 );
82 assertEquals( "Child dependency should be listed first.", "test-from-child", dep1.getArtifactId() );
83 assertEquals( "Child dependency should have version '1'.", "1", dep1.getVersion() );
84
85 Dependency dep2 = (Dependency) dependencies.get( 1 );
86 assertEquals( "Parent dependency should be listed last.", "test-from-parent", dep2.getArtifactId() );
87
88 List compileArtifacts = project1.getCompileArtifacts();
89 assertNotNull( "Must contain compile-scoped artifacts.", compileArtifacts );
90 assertEquals( "Must contain 2 compile-scoped artifacts.", 2, compileArtifacts.size() );
91
92 Artifact artifact1 = (Artifact) compileArtifacts.get( 0 );
93 assertEquals( "Child dependency should be listed first in compile-scoped artifacts list.", "test-from-child", artifact1.getArtifactId() );
94
95 Artifact artifact2 = (Artifact) compileArtifacts.get( 1 );
96 assertEquals( "Parent dependency should be listed last in compile-scoped artifacts list.", "test-from-parent", artifact2.getArtifactId() );
97 }
98 }