1 package org.apache.maven.archiva.discoverer;
4 * Copyright 2005-2006 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.repository.ArtifactRepository;
21 import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
24 import java.util.ArrayList;
25 import java.util.Iterator;
26 import java.util.List;
29 * Base class for artifact discoverers.
32 * @author Brett Porter
34 public abstract class AbstractArtifactDiscoverer
35 extends AbstractDiscoverer
36 implements ArtifactDiscoverer
39 * Standard patterns to exclude from discovery as they are not artifacts.
41 private static final String[] STANDARD_DISCOVERY_EXCLUDES = {"bin/**", "reports/**", ".index", ".reports/**",
42 ".maven/**", "**/*.md5", "**/*.MD5", "**/*.sha1", "**/*.SHA1", "**/*snapshot-version", "*/website/**",
43 "*/licenses/**", "*/licences/**", "**/.htaccess", "**/*.html", "**/*.asc", "**/*.txt", "**/*.xml", "**/README*",
44 "**/CHANGELOG*", "**/KEYS*"};
46 private List scanForArtifactPaths( File repositoryBase, List blacklistedPatterns )
48 return scanForArtifactPaths( repositoryBase, blacklistedPatterns, null, STANDARD_DISCOVERY_EXCLUDES );
51 public List discoverArtifacts( ArtifactRepository repository, List blacklistedPatterns, ArtifactFilter filter )
52 throws DiscovererException
54 if ( !"file".equals( repository.getProtocol() ) )
56 throw new UnsupportedOperationException( "Only filesystem repositories are supported" );
59 File repositoryBase = new File( repository.getBasedir() );
61 List artifacts = new ArrayList();
63 List artifactPaths = scanForArtifactPaths( repositoryBase, blacklistedPatterns );
65 for ( Iterator i = artifactPaths.iterator(); i.hasNext(); )
67 String path = (String) i.next();
71 Artifact artifact = buildArtifactFromPath( path, repository );
73 if ( filter.include( artifact ) )
75 artifacts.add( artifact );
79 addExcludedPath( path, "Omitted by filter" );
82 catch ( DiscovererException e )
84 addKickedOutPath( path, e.getMessage() );
92 * Returns an artifact object that is represented by the specified path in a repository
94 * @param path The path that is pointing to an artifact
95 * @param repository The repository of the artifact
97 * @throws DiscovererException when the specified path does correspond to an artifact
99 public Artifact buildArtifactFromPath( String path, ArtifactRepository repository )
100 throws DiscovererException
102 Artifact artifact = buildArtifact( path );
104 if ( artifact != null )
106 artifact.setRepository( repository );
107 artifact.setFile( new File( repository.getBasedir(), path ) );