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
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 static final String[] EMPTY_STRING_ARRAY = new String[0];
47 private List excludedPaths = new ArrayList();
49 private List kickedOutPaths = new ArrayList();
52 * Scan the repository for artifact paths.
54 protected String[] scanForArtifactPaths( File repositoryBase, String blacklistedPatterns )
56 return scanForArtifactPaths( repositoryBase, blacklistedPatterns, null, STANDARD_DISCOVERY_EXCLUDES );
60 * Scan the repository for artifact paths.
62 protected String[] scanForArtifactPaths( File repositoryBase, String blacklistedPatterns, String[] includes,
65 List allExcludes = new ArrayList();
66 allExcludes.addAll( FileUtils.getDefaultExcludesAsList() );
67 if ( excludes != null )
69 allExcludes.addAll( Arrays.asList( excludes ) );
72 if ( blacklistedPatterns != null && blacklistedPatterns.length() > 0 )
74 allExcludes.addAll( Arrays.asList( blacklistedPatterns.split( "," ) ) );
77 DirectoryScanner scanner = new DirectoryScanner();
78 scanner.setBasedir( repositoryBase );
79 if ( includes != null )
81 scanner.setIncludes( includes );
83 scanner.setExcludes( (String[]) allExcludes.toArray( EMPTY_STRING_ARRAY ) );
87 excludedPaths.addAll( Arrays.asList( scanner.getExcludedFiles() ) );
89 return scanner.getIncludedFiles();
93 * Add a path to the list of files that were kicked out due to being invalid.
95 * @param path the path to add
98 protected void addKickedOutPath( String path )
100 kickedOutPaths.add( path );
103 public Iterator getExcludedPathsIterator()
105 return excludedPaths.iterator();
108 public Iterator getKickedOutPathsIterator()
110 return kickedOutPaths.iterator();