001 /** 002 * Copyright 2004-2012 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.apache.torque.util; 017 018 import java.io.File; 019 import java.util.ArrayList; 020 import java.util.List; 021 022 import org.codehaus.plexus.util.DirectoryScanner; 023 024 /** 025 * This class provides a simple method for scanning a directory for files that match include/exclude patterns 026 */ 027 public class SimpleScanner extends DirectoryScanner { 028 private static final String FS = System.getProperty("file.separator"); 029 030 public SimpleScanner() { 031 this(null, null, null); 032 } 033 034 public SimpleScanner(File baseDir, String include, String exclude) { 035 super(); 036 if (baseDir != null) { 037 setBasedir(baseDir); 038 } 039 if (include != null) { 040 setIncludes(new String[] { include }); 041 } 042 if (exclude != null) { 043 setExcludes(new String[] { exclude }); 044 } 045 } 046 047 /** 048 * This method returns files that match an include pattern but do not match an exclude pattern 049 */ 050 public List<File> getFiles() { 051 scan(); 052 String[] includedFiles = getIncludedFiles(); 053 List<File> files = new ArrayList<File>(); 054 for (String includedFile : includedFiles) { 055 String filename = getBasedir().getAbsolutePath() + FS + includedFile; 056 File file = new File(filename); 057 files.add(file); 058 } 059 return files; 060 } 061 }