View Javadoc

1   /**
2    * Copyright 2011-2014 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.kuali.maven.plugins.externals;
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, getArray(null), getArray(null));
32  	}
33  
34  	public SimpleScanner(File baseDir, String include, String exclude) {
35  		this(baseDir, getArray(include), getArray(exclude));
36  	}
37  
38  	public SimpleScanner(File baseDir, String[] includes, String[] excludes) {
39  		super();
40  		setBasedir(baseDir);
41  		setIncludes(includes);
42  		setExcludes(excludes);
43  	}
44  
45  	protected static final String[] getArray(String s) {
46  		if (s == null) {
47  			return null;
48  		} else {
49  			return new String[] { s };
50  		}
51  	}
52  
53  	/**
54  	 * This method returns files that match an include pattern but do not match an exclude pattern
55  	 */
56  	public List<File> getFiles() {
57  		scan();
58  		String[] includedFiles = getIncludedFiles();
59  		List<File> files = new ArrayList<File>();
60  		for (String includedFile : includedFiles) {
61  			String filename = getBasedir().getAbsolutePath() + FS + includedFile;
62  			File file = new File(filename);
63  			files.add(file);
64  		}
65  		return files;
66  	}
67  }