1 package org.apache.maven.repository.discovery;
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.codehaus.plexus.logging.AbstractLogEnabled;
20 import org.codehaus.plexus.util.DirectoryScanner;
21 import org.codehaus.plexus.util.FileUtils;
24 import java.util.ArrayList;
25 import java.util.Arrays;
26 import java.util.Iterator;
27 import java.util.List;
30 * Base class for artifact discoverers.
33 * @author Brett Porter
35 public abstract class AbstractArtifactDiscoverer
36 extends AbstractLogEnabled
37 implements ArtifactDiscoverer
40 * Standard patterns to exclude from discovery as they are not artifacts.
42 private static final String[] STANDARD_DISCOVERY_EXCLUDES = {"bin/**", "reports/**", ".maven/**", "**/*.md5",
43 "**/*.MD5", "**/*.sha1", "**/*.SHA1", "**/*snapshot-version", "*/website/**", "*/licenses/**", "*/licences/**",
44 "**/.htaccess", "**/*.html", "**/*.asc", "**/*.txt", "**/*.xml", "**/README*", "**/CHANGELOG*", "**/KEYS*"};
46 private static final String[] EMPTY_STRING_ARRAY = new String[0];
48 private List excludedPaths = new ArrayList();
50 private List kickedOutPaths = new ArrayList();
53 * Scan the repository for artifact paths.
55 * @todo replace blacklisted patterns by an artifact filter
57 protected String[] scanForArtifactPaths( File repositoryBase, String blacklistedPatterns )
59 List allExcludes = new ArrayList();
60 allExcludes.addAll( FileUtils.getDefaultExcludesAsList() );
61 allExcludes.addAll( Arrays.asList( STANDARD_DISCOVERY_EXCLUDES ) );
63 if ( blacklistedPatterns != null && blacklistedPatterns.length() > 0 )
65 allExcludes.addAll( Arrays.asList( blacklistedPatterns.split( "," ) ) );
68 DirectoryScanner scanner = new DirectoryScanner();
69 scanner.setBasedir( repositoryBase );
70 scanner.setExcludes( (String[]) allExcludes.toArray( EMPTY_STRING_ARRAY ) );
74 excludedPaths.addAll( Arrays.asList( scanner.getExcludedFiles() ) );
76 return scanner.getIncludedFiles();
80 * Add a path to the list of files that were kicked out due to being invalid.
82 * @param path the path to add
85 protected void addKickedOutPath( String path )
87 kickedOutPaths.add( path );
90 public Iterator getExcludedPathsIterator()
92 return excludedPaths.iterator();
95 public Iterator getKickedOutPathsIterator()
97 return kickedOutPaths.iterator();