001    package org.apache.torque.util;
002    
003    import java.io.File;
004    import java.util.ArrayList;
005    import java.util.List;
006    
007    import org.codehaus.plexus.util.DirectoryScanner;
008    
009    /**
010     * This class provides a simple method for scanning a directory for files that match include/exclude patterns
011     */
012    public class SimpleScanner extends DirectoryScanner {
013            private static final String FS = System.getProperty("file.separator");
014    
015            public SimpleScanner() {
016                    this(null, null, null);
017            }
018    
019            public SimpleScanner(File baseDir, String include, String exclude) {
020                    super();
021                    if (baseDir != null) {
022                            setBasedir(baseDir);
023                    }
024                    if (include != null) {
025                            setIncludes(new String[] { include });
026                    }
027                    if (exclude != null) {
028                            setExcludes(new String[] { exclude });
029                    }
030            }
031    
032            /**
033             * This method returns files that match an include pattern but do not match an exclude pattern
034             */
035            public List<File> getFiles() {
036                    scan();
037                    String[] includedFiles = getIncludedFiles();
038                    List<File> files = new ArrayList<File>();
039                    for (String includedFile : includedFiles) {
040                            String filename = getBasedir().getAbsolutePath() + FS + includedFile;
041                            File file = new File(filename);
042                            files.add(file);
043                    }
044                    return files;
045            }
046    }