1 package org.apache.maven.repository.discovery;
4 * Copyright 2001-2005 The Apache Software Foundation.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 import org.apache.maven.artifact.Artifact;
20 import org.apache.maven.artifact.factory.ArtifactFactory;
21 import org.codehaus.plexus.PlexusTestCase;
24 import java.util.Iterator;
25 import java.util.List;
28 * Test the default artifact discoverer.
30 * @author <a href="mailto:brett@apache.org">Brett Porter</a>
32 * @todo test location of poms, checksums
34 public class DefaultArtifactDiscovererTest
35 extends PlexusTestCase
37 private ArtifactDiscoverer discoverer;
39 private ArtifactFactory factory;
41 private File repositoryLocation;
43 protected void setUp()
48 discoverer = (ArtifactDiscoverer) lookup( ArtifactDiscoverer.ROLE, "default" );
50 factory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
52 repositoryLocation = getTestFile( "src/test/repository" );
55 public void testDefaultExcludes()
57 List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, false );
58 assertNotNull( "Check artifacts not null", artifacts );
59 boolean found = false;
60 for ( Iterator i = discoverer.getExcludedPathsIterator(); i.hasNext() && !found; )
62 String path = (String) i.next();
64 found = path.indexOf( ".svn" ) >= 0;
66 assertTrue( "Check exclusion was found", found );
68 for ( Iterator i = artifacts.iterator(); i.hasNext(); )
70 Artifact a = (Artifact) i.next();
71 assertFalse( "Check not .svn", a.getFile().getPath().indexOf( ".svn" ) >= 0 );
75 public void testStandardExcludes()
77 List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, false );
78 assertNotNull( "Check artifacts not null", artifacts );
79 boolean found = false;
80 for ( Iterator i = discoverer.getExcludedPathsIterator(); i.hasNext() && !found; )
82 String path = (String) i.next();
84 found = path.equals( "KEYS" );
86 assertTrue( "Check exclusion was found", found );
88 for ( Iterator i = artifacts.iterator(); i.hasNext(); )
90 Artifact a = (Artifact) i.next();
91 assertFalse( "Check not KEYS", a.getFile().getName().equals( "KEYS" ) );
95 public void testBlacklistedExclude()
97 List artifacts = discoverer.discoverArtifacts( repositoryLocation, "javax/**", false );
98 assertNotNull( "Check artifacts not null", artifacts );
99 boolean found = false;
100 for ( Iterator i = discoverer.getExcludedPathsIterator(); i.hasNext() && !found; )
102 String path = (String) i.next();
104 found = path.replace( '\\', '/' ).equals( "javax/sql/jdbc/2.0/jdbc-2.0.jar" );
106 assertTrue( "Check exclusion was found", found );
108 assertFalse( "Check jdbc not included", artifacts.contains( createArtifact( "javax.sql", "jdbc", "2.0" ) ) );
111 public void testKickoutWithShortPath()
113 List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, false );
114 assertNotNull( "Check artifacts not null", artifacts );
115 boolean found = false;
116 for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
118 String path = (String) i.next();
120 found = path.replace( '\\', '/' ).equals( "invalid/invalid-1.0.jar" );
122 assertTrue( "Check kickout was found", found );
124 for ( Iterator i = artifacts.iterator(); i.hasNext(); )
126 Artifact a = (Artifact) i.next();
127 assertFalse( "Check not invalid-1.0.jar", a.getFile().getName().equals( "invalid-1.0.jar" ) );
131 public void testKickoutWithWrongArtifactId()
133 List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, false );
134 assertNotNull( "Check artifacts not null", artifacts );
135 boolean found = false;
136 for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
138 String path = (String) i.next();
140 found = path.replace( '\\', '/' ).equals(
141 "org/apache/maven/test/1.0-SNAPSHOT/wrong-artifactId-1.0-20050611.112233-1.jar" );
143 assertTrue( "Check kickout was found", found );
145 for ( Iterator i = artifacts.iterator(); i.hasNext(); )
147 Artifact a = (Artifact) i.next();
148 assertFalse( "Check not wrong jar",
149 a.getFile().getName().equals( "wrong-artifactId-1.0-20050611.112233-1.jar" ) );
153 public void testKickoutWithNoType()
155 List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, false );
156 assertNotNull( "Check artifacts not null", artifacts );
157 boolean found = false;
158 for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
160 String path = (String) i.next();
162 found = path.replace( '\\', '/' ).equals( "invalid/invalid/1/invalid-1" );
164 assertTrue( "Check kickout was found", found );
166 for ( Iterator i = artifacts.iterator(); i.hasNext(); )
168 Artifact a = (Artifact) i.next();
169 assertFalse( "Check not 'invalid-1'", a.getFile().getName().equals( "invalid-1" ) );
173 public void testKickoutWithWrongVersion()
175 List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, false );
176 assertNotNull( "Check artifacts not null", artifacts );
177 boolean found = false;
178 for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
180 String path = (String) i.next();
182 found = path.replace( '\\', '/' ).equals( "invalid/invalid/1.0/invalid-2.0.jar" );
184 assertTrue( "Check kickout was found", found );
186 for ( Iterator i = artifacts.iterator(); i.hasNext(); )
188 Artifact a = (Artifact) i.next();
189 assertFalse( "Check not 'invalid-2.0.jar'", a.getFile().getName().equals( "invalid-2.0.jar" ) );
193 public void testKickoutWithLongerVersion()
195 List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, false );
196 assertNotNull( "Check artifacts not null", artifacts );
197 boolean found = false;
198 for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
200 String path = (String) i.next();
202 found = path.replace( '\\', '/' ).equals( "invalid/invalid/1.0/invalid-1.0b.jar" );
204 assertTrue( "Check kickout was found", found );
206 for ( Iterator i = artifacts.iterator(); i.hasNext(); )
208 Artifact a = (Artifact) i.next();
209 assertFalse( "Check not 'invalid-1.0b.jar'", a.getFile().getName().equals( "invalid-1.0b.jar" ) );
213 public void testKickoutWithWrongSnapshotVersion()
215 List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, false );
216 assertNotNull( "Check artifacts not null", artifacts );
217 boolean found = false;
218 for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
220 String path = (String) i.next();
222 found = path.replace( '\\', '/' ).equals( "invalid/invalid/1.0-SNAPSHOT/invalid-1.0.jar" );
224 assertTrue( "Check kickout was found", found );
226 for ( Iterator i = artifacts.iterator(); i.hasNext(); )
228 Artifact a = (Artifact) i.next();
229 assertFalse( "Check not 'invalid-1.0.jar'", a.getFile().getName().equals( "invalid-1.0.jar" ) );
233 public void testKickoutWithSnapshotBaseVersion()
235 List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, false );
236 assertNotNull( "Check artifacts not null", artifacts );
237 boolean found = false;
238 for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
240 String path = (String) i.next();
242 found = path.replace( '\\', '/' ).equals(
243 "invalid/invalid/1.0-20050611.123456-1/invalid-1.0-20050611.123456-1.jar" );
245 assertTrue( "Check kickout was found", found );
247 for ( Iterator i = artifacts.iterator(); i.hasNext(); )
249 Artifact a = (Artifact) i.next();
250 assertFalse( "Check not 'invalid-1.0-20050611-123456-1.jar'",
251 a.getFile().getName().equals( "invalid-1.0-20050611.123456-1.jar" ) );
255 public void testInclusion()
257 List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, true );
258 assertNotNull( "Check artifacts not null", artifacts );
260 assertTrue( "Check normal included",
261 artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0" ) ) );
264 public void testArtifactWithClassifier()
266 List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, true );
267 assertNotNull( "Check artifacts not null", artifacts );
269 assertTrue( "Check normal included",
270 artifacts.contains( createArtifact( "org.apache.maven", "some-ejb", "1.0", "jar", "client" ) ) );
273 public void testJavaSourcesInclusion()
275 List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, true );
276 assertNotNull( "Check artifacts not null", artifacts );
278 assertTrue( "Check normal included",
279 artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0", "java-source" ) ) );
282 public void testDistributionInclusion()
284 List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, true );
285 assertNotNull( "Check artifacts not null", artifacts );
287 assertTrue( "Check zip included",
288 artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0", "distribution-zip" ) ) );
290 assertTrue( "Check tar.gz included",
291 artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0", "distribution-tgz" ) ) );
294 public void testSnapshotInclusion()
296 List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, true );
297 assertNotNull( "Check artifacts not null", artifacts );
299 assertTrue( "Check normal included", artifacts.contains( createArtifact( "javax.sql", "jdbc", "2.0" ) ) );
300 assertTrue( "Check snapshot included",
301 artifacts.contains( createArtifact( "org.apache.maven", "test", "1.0-20050611.112233-1" ) ) );
304 public void testSnapshotInclusionWithClassifier()
306 List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, true );
307 assertNotNull( "Check artifacts not null", artifacts );
309 assertTrue( "Check snapshot included", artifacts.contains(
310 createArtifact( "org.apache.maven", "test", "1.0-20050611.112233-1", "jar", "javadoc" ) ) );
313 public void testSnapshotExclusion()
315 List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, false );
316 assertNotNull( "Check artifacts not null", artifacts );
318 assertTrue( "Check normal included", artifacts.contains( createArtifact( "javax.sql", "jdbc", "2.0" ) ) );
319 assertFalse( "Check snapshot included",
320 artifacts.contains( createArtifact( "org.apache.maven", "test", "1.0-SNAPSHOT" ) ) );
323 private Artifact createArtifact( String groupId, String artifactId, String version )
325 return factory.createArtifact( groupId, artifactId, version, null, "jar" );
328 private Artifact createArtifact( String groupId, String artifactId, String version, String type )
330 return factory.createArtifact( groupId, artifactId, version, null, type );
333 private Artifact createArtifact( String groupId, String artifactId, String version, String type, String classifier )
335 return factory.createArtifactWithClassifier( groupId, artifactId, version, type, classifier );