1 package org.codehaus.plexus.util; 2 3 /* 4 * Copyright The Codehaus Foundation. 5 * 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 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 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. 17 */ 18 19 import java.io.File; 20 import java.util.Comparator; 21 22 /** 23 * Scan a directory tree for files, with specified inclusions and exclusions. 24 */ 25 public interface Scanner 26 { 27 28 /** 29 * Sets the list of include patterns to use. All '/' and '\' characters are replaced by 30 * <code>File.separatorChar</code>, so the separator used need not match <code>File.separatorChar</code>. 31 * <p> 32 * When a pattern ends with a '/' or '\', "**" is appended. 33 * 34 * @param includes A list of include patterns. May be <code>null</code>, indicating that all files should be 35 * included. If a non-<code>null</code> list is given, all elements must be non-<code>null</code>. 36 */ 37 void setIncludes( String[] includes ); 38 39 /** 40 * Sets the list of exclude patterns to use. All '/' and '\' characters are replaced by 41 * <code>File.separatorChar</code>, so the separator used need not match <code>File.separatorChar</code>. 42 * <p> 43 * When a pattern ends with a '/' or '\', "**" is appended. 44 * 45 * @param excludes A list of exclude patterns. May be <code>null</code>, indicating that no files should be 46 * excluded. If a non-<code>null</code> list is given, all elements must be non-<code>null</code>. 47 */ 48 void setExcludes( String[] excludes ); 49 50 /** 51 * Adds default exclusions to the current exclusions set. 52 */ 53 void addDefaultExcludes(); 54 55 /** 56 * Scans the base directory for files which match at least one include pattern and don't match any exclude patterns. 57 * 58 * @exception IllegalStateException if the base directory was set incorrectly (i.e. if it is <code>null</code>, 59 * doesn't exist, or isn't a directory). 60 */ 61 void scan(); 62 63 /** 64 * Returns the names of the files which matched at least one of the include patterns and none of the exclude 65 * patterns. The names are relative to the base directory. 66 * 67 * @return the names of the files which matched at least one of the include patterns and none of the exclude 68 * patterns. 69 */ 70 String[] getIncludedFiles(); 71 72 /** 73 * Returns the names of the directories which matched at least one of the include patterns and none of the exclude 74 * patterns. The names are relative to the base directory. 75 * 76 * @return the names of the directories which matched at least one of the include patterns and none of the exclude 77 * patterns. 78 */ 79 String[] getIncludedDirectories(); 80 81 /** 82 * Returns the base directory to be scanned. This is the directory which is scanned recursively. 83 * 84 * @return the base directory to be scanned 85 */ 86 File getBasedir(); 87 88 /** 89 * Use a filename comparator in each directory when scanning. 90 * 91 * @param filenameComparator the Comparator instance to use 92 * @since 3.3.0 93 */ 94 void setFilenameComparator( Comparator<String> filenameComparator ); 95 }