001/**
002 * Copyright 2010-2014 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 */
016package org.kuali.common.util;
017
018import java.io.File;
019import java.util.ArrayList;
020import java.util.List;
021
022import 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 * @deprecated
028 */
029@Deprecated
030public class SimpleScanner extends DirectoryScanner {
031
032        private static final String FS = File.separator;
033
034        public SimpleScanner() {
035                this((File) null, (String) null, (String) null);
036        }
037
038        public SimpleScanner(File baseDir, String include, String exclude) {
039                this(baseDir, CollectionUtils.toEmptyList(include), CollectionUtils.toEmptyList(exclude));
040        }
041
042        public SimpleScanner(File baseDir, List<String> includes, List<String> excludes) {
043                if (baseDir != null) {
044                        setBasedir(baseDir);
045                }
046                if (!CollectionUtils.isEmpty(includes)) {
047                        setIncludes(CollectionUtils.toStringArray(includes));
048                }
049                if (!CollectionUtils.isEmpty(excludes)) {
050                        setExcludes(CollectionUtils.toStringArray(excludes));
051                }
052        }
053
054        /**
055         * This method scans the file system starting at <code>basedir</code> and returns files matching the provided include/exclude patterns
056         */
057        public List<File> getFiles() {
058                scan();
059                String[] includedFiles = getIncludedFiles();
060                List<File> files = new ArrayList<File>();
061                for (String includedFile : includedFiles) {
062                        String filename = getBasedir().getAbsolutePath() + FS + includedFile;
063                        File file = new File(filename);
064                        files.add(file);
065                }
066                return files;
067        }
068
069        /**
070         * This method scans the file system starting at <code>basedir</code> and returns directory names matching the provided include/exclude patterns
071         */
072        public List<String> getDirectories() {
073                scan();
074                String[] includedDirectories = getIncludedDirectories();
075                List<String> directories = new ArrayList<String>();
076                for (String includedDirectory : includedDirectories) {
077                        directories.add(includedDirectory);
078                }
079                return directories;
080        }
081}