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/**", ".maven/**", "**/*.md5",
42 "**/*.MD5", "**/*.sha1", "**/*.SHA1", "**/*snapshot-version", "*/website/**", "*/licenses/**", "*/licences/**",
43 "**/.htaccess", "**/*.html", "**/*.asc", "**/*.txt", "**/*.xml", "**/README*", "**/CHANGELOG*", "**/KEYS*"};
45 private List scanForArtifactPaths( File repositoryBase, List blacklistedPatterns )
47 return scanForArtifactPaths( repositoryBase, blacklistedPatterns, null, STANDARD_DISCOVERY_EXCLUDES );
50 public List discoverArtifacts( ArtifactRepository repository, List blacklistedPatterns, ArtifactFilter filter )
51 throws DiscovererException
53 if ( !"file".equals( repository.getProtocol() ) )
55 throw new UnsupportedOperationException( "Only filesystem repositories are supported" );
58 File repositoryBase = new File( repository.getBasedir() );
60 List artifacts = new ArrayList();
62 List artifactPaths = scanForArtifactPaths( repositoryBase, blacklistedPatterns );
64 for ( Iterator i = artifactPaths.iterator(); i.hasNext(); )
66 String path = (String) i.next();
70 Artifact artifact = buildArtifactFromPath( path, repository );
72 if ( filter.include( artifact ) )
74 artifacts.add( artifact );
76 // TODO: else add to excluded? [!]
78 catch ( DiscovererException e )
80 addKickedOutPath( path, e.getMessage() );
88 * Returns an artifact object that is represented by the specified path in a repository
90 * @param path The path that is pointing to an artifact
91 * @param repository The repository of the artifact
93 * @throws DiscovererException when the specified path does correspond to an artifact
95 public Artifact buildArtifactFromPath( String path, ArtifactRepository repository )
96 throws DiscovererException
98 Artifact artifact = buildArtifact( path );
100 if ( artifact != null )
102 artifact.setRepository( repository );
103 artifact.setFile( new File( repository.getBasedir(), path ) );