View Javadoc

1   /**
2    * Copyright 2004-2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.apache.torque.util;
17  
18  import java.io.File;
19  import java.util.ArrayList;
20  import java.util.List;
21  
22  import org.codehaus.plexus.util.DirectoryScanner;
23  
24  /**
25   * This class provides a simple method for scanning a directory for files that match include/exclude patterns
26   */
27  public class SimpleScanner extends DirectoryScanner {
28  	private static final String FS = System.getProperty("file.separator");
29  
30  	public SimpleScanner() {
31  		this(null, null, null);
32  	}
33  
34  	public SimpleScanner(File baseDir, String include, String exclude) {
35  		super();
36  		if (baseDir != null) {
37  			setBasedir(baseDir);
38  		}
39  		if (include != null) {
40  			setIncludes(new String[] { include });
41  		}
42  		if (exclude != null) {
43  			setExcludes(new String[] { exclude });
44  		}
45  	}
46  
47  	/**
48  	 * This method returns files that match an include pattern but do not match an exclude pattern
49  	 */
50  	public List<File> getFiles() {
51  		scan();
52  		String[] includedFiles = getIncludedFiles();
53  		List<File> files = new ArrayList<File>();
54  		for (String includedFile : includedFiles) {
55  			String filename = getBasedir().getAbsolutePath() + FS + includedFile;
56  			File file = new File(filename);
57  			files.add(file);
58  		}
59  		return files;
60  	}
61  }