import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.util.DirectoryScanner;
+import org.codehaus.plexus.util.FileUtils;
import java.io.File;
import java.util.ArrayList;
*/
protected String[] scanForArtifactPaths( File repositoryBase, String blacklistedPatterns )
{
- String[] blacklisted;
+ List allExcludes = new ArrayList();
+ allExcludes.addAll( FileUtils.getDefaultExcludesAsList() );
+ allExcludes.addAll( Arrays.asList( STANDARD_DISCOVERY_EXCLUDES ) );
+
if ( blacklistedPatterns != null && blacklistedPatterns.length() > 0 )
{
- blacklisted = blacklistedPatterns.split( "," );
- }
- else
- {
- blacklisted = EMPTY_STRING_ARRAY;
+ allExcludes.addAll( Arrays.asList( blacklistedPatterns.split( "," ) ) );
}
- String[] allExcludes = new String[STANDARD_DISCOVERY_EXCLUDES.length + blacklisted.length];
-
- System.arraycopy( STANDARD_DISCOVERY_EXCLUDES, 0, allExcludes, 0, STANDARD_DISCOVERY_EXCLUDES.length );
- System.arraycopy( blacklisted, 0, allExcludes, STANDARD_DISCOVERY_EXCLUDES.length, blacklisted.length );
-
DirectoryScanner scanner = new DirectoryScanner();
scanner.setBasedir( repositoryBase );
- scanner.setExcludes( allExcludes );
+ scanner.setExcludes( (String[]) allExcludes.toArray( EMPTY_STRING_ARRAY ) );
scanner.scan();
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.codehaus.plexus.util.StringUtils;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;
pathParts.remove( 0 );
// the remaining are the groupId.
- StringBuffer groupBuffer = new StringBuffer();
-
- boolean firstPart = true;
- for ( Iterator it = pathParts.iterator(); it.hasNext(); )
- {
- String part = (String) it.next();
-
- groupBuffer.append( part );
+ Collections.reverse( pathParts );
+ String groupId = StringUtils.join( pathParts.iterator(), "." );
- if ( firstPart )
- {
- firstPart = false;
- }
- else if ( it.hasNext() )
- {
- groupBuffer.append( "." );
- }
- }
+ result = artifactFactory.createArtifact( groupId, artifactId, version, Artifact.SCOPE_RUNTIME, "jar" );
- result = artifactFactory.createArtifact( groupBuffer.toString(), artifactId, version, Artifact.SCOPE_RUNTIME,
- "jar" );
+ result.setFile( new File( path ) );
return result;
}
* limitations under the License.
*/
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
import org.codehaus.plexus.PlexusTestCase;
import java.io.File;
{
private ArtifactDiscoverer discoverer;
+ private ArtifactFactory factory;
+
private File repositoryLocation;
protected void setUp()
discoverer = (ArtifactDiscoverer) lookup( ArtifactDiscoverer.ROLE, "default" );
+ factory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
+
repositoryLocation = getTestFile( "src/test/repository" );
}
public void testDefaultExcludes()
{
List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, false );
- assertNotNull( "Check artifacts returned", artifacts );
- assertTrue( "Check no artifacts returned", artifacts.isEmpty() );
+ assertNotNull( "Check artifacts not null", artifacts );
boolean found = false;
- for ( Iterator i = discoverer.getExcludedPathsIterator(); i.hasNext(); )
+ for ( Iterator i = discoverer.getExcludedPathsIterator(); i.hasNext() && !found; )
{
String path = (String) i.next();
- if ( !path.startsWith( ".svn" ) )
- {
- assertEquals( "Check the excluded path", "KEYS", path );
- if ( found )
- {
- fail( "KEYS entry found twice" );
- }
- found = true;
- }
+ found = path.indexOf( ".svn" ) >= 0;
}
assertTrue( "Check exclusion was found", found );
+
+ for ( Iterator i = artifacts.iterator(); i.hasNext(); )
+ {
+ Artifact a = (Artifact) i.next();
+ assertFalse( "Check not .svn", a.getFile().getPath().indexOf( ".svn" ) >= 0 );
+ }
}
+
+ public void testStandardExcludes()
+ {
+ List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, false );
+ assertNotNull( "Check artifacts not null", artifacts );
+ boolean found = false;
+ for ( Iterator i = discoverer.getExcludedPathsIterator(); i.hasNext() && !found; )
+ {
+ String path = (String) i.next();
+
+ found = path.equals( "KEYS" );
+ }
+ assertTrue( "Check exclusion was found", found );
+
+ for ( Iterator i = artifacts.iterator(); i.hasNext(); )
+ {
+ Artifact a = (Artifact) i.next();
+ assertFalse( "Check not KEYS", a.getFile().getName().equals( "KEYS" ) );
+ }
+ }
+
+ public void testBlacklistedExclude()
+ {
+ List artifacts = discoverer.discoverArtifacts( repositoryLocation, "javax/**", false );
+ assertNotNull( "Check artifacts not null", artifacts );
+ boolean found = false;
+ for ( Iterator i = discoverer.getExcludedPathsIterator(); i.hasNext() && !found; )
+ {
+ String path = (String) i.next();
+
+ found = path.replace( '\\', '/' ).equals( "javax/sql/jdbc/2.0/jdbc-2.0.jar" );
+ }
+ assertTrue( "Check exclusion was found", found );
+
+ assertFalse( "Check jdbc not included", artifacts.contains( createArtifact( "javax.sql", "jdbc", "2.0" ) ) );
+ }
+
+ public void testSnapshotInclusion()
+ {
+ List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, true );
+ assertNotNull( "Check artifacts not null", artifacts );
+
+ assertTrue( "Check normal included", artifacts.contains( createArtifact( "javax.sql", "jdbc", "2.0" ) ) );
+ assertTrue( "Check snapshot included",
+ artifacts.contains( createArtifact( "org.apache.maven", "test", "1.0-SNAPSHOT" ) ) );
+ }
+
+ public void testSnapshotExclusion()
+ {
+ List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, false );
+ assertNotNull( "Check artifacts not null", artifacts );
+
+ assertTrue( "Check normal included", artifacts.contains( createArtifact( "javax.sql", "jdbc", "2.0" ) ) );
+ assertFalse( "Check snapshot included",
+ artifacts.contains( createArtifact( "org.apache.maven", "test", "1.0-SNAPSHOT" ) ) );
+ }
+
+ private Artifact createArtifact( String groupId, String artifactId, String version )
+ {
+ return factory.createArtifact( groupId, artifactId, version, null, "jar" );
+ }
+
}