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 legacy artifact discoverer.
30 * @author <a href="mailto:brett@apache.org">Brett Porter</a>
32 * @todo share as much as possible with default via abstract test case
34 public class LegacyArtifactDiscovererTest
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, "legacy" );
50 factory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
52 repositoryLocation = getTestFile( "src/test/legacy-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.sql/**", 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/jars/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 testKickoutWithLongPath()
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( "invalid/jars/1.0/invalid-1.0.jar" );
142 assertTrue( "Check kickout was found", found );
144 for ( Iterator i = artifacts.iterator(); i.hasNext(); )
146 Artifact a = (Artifact) i.next();
147 assertFalse( "Check not invalid-1.0.jar", a.getFile().getName().equals( "invalid-1.0.jar" ) );
151 public void testKickoutWithInvalidType()
153 List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, false );
154 assertNotNull( "Check artifacts not null", artifacts );
155 boolean found = false;
156 for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
158 String path = (String) i.next();
160 found = path.replace( '\\', '/' ).equals( "invalid/foo/invalid-1.0.foo" );
162 assertTrue( "Check kickout was found", found );
164 for ( Iterator i = artifacts.iterator(); i.hasNext(); )
166 Artifact a = (Artifact) i.next();
167 assertFalse( "Check not invalid-1.0.foo", a.getFile().getName().equals( "invalid-1.0.foo" ) );
171 public void testKickoutWithNoExtension()
173 List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, false );
174 assertNotNull( "Check artifacts not null", artifacts );
175 boolean found = false;
176 for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
178 String path = (String) i.next();
180 found = path.replace( '\\', '/' ).equals( "invalid/jars/no-extension" );
182 assertTrue( "Check kickout was found", found );
184 for ( Iterator i = artifacts.iterator(); i.hasNext(); )
186 Artifact a = (Artifact) i.next();
187 assertFalse( "Check not 'no-extension'", a.getFile().getName().equals( "no-extension" ) );
191 public void testKickoutWithWrongExtension()
193 List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, false );
194 assertNotNull( "Check artifacts not null", artifacts );
195 boolean found = false;
196 for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
198 String path = (String) i.next();
200 found = path.replace( '\\', '/' ).equals( "invalid/jars/invalid-1.0.rar" );
202 assertTrue( "Check kickout was found", found );
204 for ( Iterator i = artifacts.iterator(); i.hasNext(); )
206 Artifact a = (Artifact) i.next();
207 assertFalse( "Check not 'invalid-1.0.rar'", a.getFile().getName().equals( "invalid-1.0.rar" ) );
211 public void testKickoutWithNoVersion()
213 List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, false );
214 assertNotNull( "Check artifacts not null", artifacts );
215 boolean found = false;
216 for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
218 String path = (String) i.next();
220 found = path.replace( '\\', '/' ).equals( "invalid/jars/invalid.jar" );
222 assertTrue( "Check kickout was found", found );
224 for ( Iterator i = artifacts.iterator(); i.hasNext(); )
226 Artifact a = (Artifact) i.next();
227 assertFalse( "Check not 'invalid.jar'", a.getFile().getName().equals( "invalid.jar" ) );
231 public void testInclusion()
233 List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, true );
234 assertNotNull( "Check artifacts not null", artifacts );
236 assertTrue( "Check normal included",
237 artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0" ) ) );
240 public void testTextualVersion()
242 List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, true );
243 assertNotNull( "Check artifacts not null", artifacts );
245 assertTrue( "Check normal included",
246 artifacts.contains( createArtifact( "org.apache.maven", "testing", "UNKNOWN" ) ) );
249 public void testArtifactWithClassifier()
251 List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, true );
252 assertNotNull( "Check artifacts not null", artifacts );
254 assertTrue( "Check normal included",
255 artifacts.contains( createArtifact( "org.apache.maven", "some-ejb", "1.0", "jar", "client" ) ) );
258 public void testJavaSourcesInclusion()
260 List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, true );
261 assertNotNull( "Check artifacts not null", artifacts );
263 assertTrue( "Check normal included",
264 artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0", "java-source" ) ) );
267 public void testDistributionInclusion()
269 List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, true );
270 assertNotNull( "Check artifacts not null", artifacts );
272 assertTrue( "Check zip included",
273 artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0", "distribution-zip" ) ) );
275 assertTrue( "Check tar.gz included",
276 artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0", "distribution-tgz" ) ) );
279 public void testSnapshotInclusion()
281 List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, true );
282 assertNotNull( "Check artifacts not null", artifacts );
284 assertTrue( "Check normal included", artifacts.contains( createArtifact( "javax.sql", "jdbc", "2.0" ) ) );
285 assertTrue( "Check snapshot included",
286 artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0-20050611.112233-1" ) ) );
289 public void testSnapshotExclusion()
291 List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, false );
292 assertNotNull( "Check artifacts not null", artifacts );
294 assertTrue( "Check normal included", artifacts.contains( createArtifact( "javax.sql", "jdbc", "2.0" ) ) );
295 assertFalse( "Check snapshot included",
296 artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0-20050611.112233-1" ) ) );
299 private Artifact createArtifact( String groupId, String artifactId, String version )
301 return factory.createArtifact( groupId, artifactId, version, null, "jar" );
304 private Artifact createArtifact( String groupId, String artifactId, String version, String type )
306 return factory.createArtifact( groupId, artifactId, version, null, type );
309 private Artifact createArtifact( String groupId, String artifactId, String version, String type, String classifier )
311 return factory.createArtifactWithClassifier( groupId, artifactId, version, type, classifier );