1 package org.apache.maven.project.artifact;
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 org.apache.maven.repository.RepositorySystem;
23 import org.codehaus.plexus.PlexusTestCase;
24
25 public class MavenMetadataSourceTest
26 extends PlexusTestCase
27 {
28 private RepositorySystem repositorySystem;
29
30 protected void setUp()
31 throws Exception
32 {
33 super.setUp();
34 repositorySystem = lookup( RepositorySystem.class );
35 }
36
37 @Override
38 protected void tearDown()
39 throws Exception
40 {
41 repositorySystem = null;
42 super.tearDown();
43 }
44
45 public void testShouldNotCarryExclusionsOverFromDependencyToDependency()
46 throws Exception
47 {
48 /*
49 Dependency dep1 = new Dependency();
50 dep1.setGroupId( "test" );
51 dep1.setArtifactId( "test-artifact" );
52 dep1.setVersion( "1" );
53 dep1.setType( "jar" );
54
55 Exclusion exc = new Exclusion();
56 exc.setGroupId( "test" );
57 exc.setArtifactId( "test-artifact3" );
58
59 dep1.addExclusion( exc );
60
61 Dependency dep2 = new Dependency();
62 dep2.setGroupId( "test" );
63 dep2.setArtifactId( "test-artifact2" );
64 dep2.setVersion( "1" );
65 dep2.setType( "jar" );
66
67 List deps = new ArrayList();
68 deps.add( dep1 );
69 deps.add( dep2 );
70
71 ArtifactFactory factory = lookup( ArtifactFactory.class );
72
73 ArtifactFilter dependencyFilter = new ScopeArtifactFilter( Artifact.SCOPE_COMPILE );
74
75 MavenProject project = new MavenProject( new Model() );
76
77 Set result = project.createArtifacts( dependencyFilter );
78
79 for ( Iterator it = result.iterator(); it.hasNext(); )
80 {
81 Artifact artifact = ( Artifact ) it.next();
82
83 if ( "test-artifact2".equals( artifact.getArtifactId() ) )
84 {
85 ArtifactFilter filter = artifact.getDependencyFilter();
86
87 assertSame( dependencyFilter, filter );
88 }
89 }
90 */
91 }
92
93 //TODO: restore these if it makes sense
94 /*
95 public void testShouldUseCompileScopeIfDependencyScopeEmpty()
96 throws Exception
97 {
98 String groupId = "org.apache.maven";
99 String artifactId = "maven-model";
100
101 Dependency dep = new Dependency();
102
103 dep.setGroupId( groupId );
104 dep.setArtifactId( artifactId );
105 dep.setVersion( "2.0-alpha-3" );
106
107 Model model = new Model();
108
109 model.addDependency( dep );
110
111 MavenProject project = new MavenProject( model, repositorySystem );
112
113 project.setArtifacts( project.createArtifacts( null ) );
114
115 String key = ArtifactUtils.versionlessKey( groupId, artifactId );
116
117 Map artifactMap = project.getArtifactMap();
118
119 assertNotNull( "artifact-map should not be null.", artifactMap );
120 assertEquals( "artifact-map should contain 1 element.", 1, artifactMap.size() );
121
122 Artifact artifact = (Artifact) artifactMap.get( key );
123
124 assertNotNull( "dependency artifact not found in map.", artifact );
125 assertEquals( "dependency artifact has wrong scope.", Artifact.SCOPE_COMPILE, artifact.getScope() );
126
127 //check for back-propagation of default scope.
128 assertEquals( "default scope NOT back-propagated to dependency.", Artifact.SCOPE_COMPILE, dep.getScope() );
129 }
130
131 public void testShouldUseInjectedTestScopeFromDependencyManagement()
132 throws Exception
133 {
134 String groupId = "org.apache.maven";
135 String artifactId = "maven-model";
136
137 Dependency dep = new Dependency();
138
139 dep.setGroupId( groupId );
140 dep.setArtifactId( artifactId );
141 dep.setVersion( "2.0-alpha-3" );
142
143 Model model = new Model();
144
145 model.addDependency( dep );
146
147 Dependency mgd = new Dependency();
148 mgd.setGroupId( groupId );
149 mgd.setArtifactId( artifactId );
150 mgd.setScope( Artifact.SCOPE_TEST );
151
152 DependencyManagement depMgmt = new DependencyManagement();
153
154 depMgmt.addDependency( mgd );
155
156 model.setDependencyManagement( depMgmt );
157
158 MavenProject project = new MavenProject( model, repositorySystem );
159
160 TestModelDefaultsInjector injector = new TestModelDefaultsInjector();
161
162 injector.injectDefaults( model );
163
164 project.setArtifacts( project.createArtifacts( null ) );
165
166 String key = ArtifactUtils.versionlessKey( groupId, artifactId );
167
168 Map artifactMap = project.getArtifactMap();
169
170 assertNotNull( "artifact-map should not be null.", artifactMap );
171 assertEquals( "artifact-map should contain 1 element.", 1, artifactMap.size() );
172
173 Artifact artifact = (Artifact) artifactMap.get( key );
174
175 assertNotNull( "dependency artifact not found in map.", artifact );
176 assertEquals( "dependency artifact has wrong scope.", Artifact.SCOPE_TEST, artifact.getScope() );
177
178 //check for back-propagation of default scope.
179 assertEquals( "default scope NOT back-propagated to dependency.", Artifact.SCOPE_TEST, dep.getScope() );
180 }
181 */
182
183 }