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.apache.maven.artifact.factory.ArtifactFactory;
20 import org.codehaus.plexus.logging.AbstractLogEnabled;
21 import org.codehaus.plexus.util.DirectoryScanner;
22 import org.codehaus.plexus.util.FileUtils;
25 import java.util.ArrayList;
26 import java.util.Arrays;
27 import java.util.Iterator;
28 import java.util.List;
31 * Base class for the artifact and metadata discoverers.
33 * @author <a href="mailto:brett@apache.org">Brett Porter</a>
35 public abstract class AbstractDiscoverer
36 extends AbstractLogEnabled
38 private List kickedOutPaths = new ArrayList();
43 protected ArtifactFactory artifactFactory;
45 private static final String[] EMPTY_STRING_ARRAY = new String[0];
47 private List excludedPaths = new ArrayList();
50 * Add a path to the list of files that were kicked out due to being invalid.
52 * @param path the path to add
55 protected void addKickedOutPath( String path )
57 kickedOutPaths.add( path );
60 public Iterator getKickedOutPathsIterator()
62 return kickedOutPaths.iterator();
66 * Scan the repository for artifact paths.
68 protected String[] scanForArtifactPaths( File repositoryBase, String blacklistedPatterns, String[] includes,
71 List allExcludes = new ArrayList();
72 allExcludes.addAll( FileUtils.getDefaultExcludesAsList() );
73 if ( excludes != null )
75 allExcludes.addAll( Arrays.asList( excludes ) );
78 if ( blacklistedPatterns != null && blacklistedPatterns.length() > 0 )
80 allExcludes.addAll( Arrays.asList( blacklistedPatterns.split( "," ) ) );
83 DirectoryScanner scanner = new DirectoryScanner();
84 scanner.setBasedir( repositoryBase );
85 if ( includes != null )
87 scanner.setIncludes( includes );
89 scanner.setExcludes( (String[]) allExcludes.toArray( EMPTY_STRING_ARRAY ) );
93 excludedPaths.addAll( Arrays.asList( scanner.getExcludedFiles() ) );
95 return scanner.getIncludedFiles();
98 public Iterator getExcludedPathsIterator()
100 return excludedPaths.iterator();