com.ovea.tadjin.util.fs.AntFileScanner Maven / Gradle / Ivy
The newest version!
/**
* Copyright (C) 2011 Ovea
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ovea.tadjin.util.fs;
import org.apache.tools.ant.DirectoryScanner;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import static java.util.Arrays.copyOf;
/**
* @author Mathieu Carbou ([email protected])
*/
public final class AntFileScanner {
private final String[] includes;
private final String[] excludes;
private AntFileScanner(String[] includes, String[] excludes, boolean useDefaultExcludes) {
this.includes = copyOf(includes, includes.length);
this.excludes = copyOf(excludes, excludes.length + (useDefaultExcludes ? DEFAULT_EXCLUDES.length : 0));
if (useDefaultExcludes)
System.arraycopy(DEFAULT_EXCLUDES, 0, this.excludes, excludes.length, DEFAULT_EXCLUDES.length);
}
public List scan(final File baseDir) {
DirectoryScanner scanner = new DirectoryScanner();
scanner.setBasedir(baseDir);
if (excludes.length > 0)
scanner.setExcludes(excludes);
if (includes.length > 0)
scanner.setIncludes(includes);
scanner.scan();
List files = new ArrayList(scanner.getIncludedFilesCount());
for (String f : scanner.getIncludedFiles())
try {
files.add(new File(baseDir, f).getCanonicalFile());
} catch (IOException e) {
throw new RuntimeException(e.getMessage(), e);
}
return files;
}
private static final String[] DEFAULT_EXCLUDES = {
// Miscellaneous typical temporary files
"**/*~",
"**/#*#",
"**/.#*",
"**/%*%",
"**/._*",
// CVS
"**/CVS",
"**/CVS/**",
"**/.cvsignore",
// RCS
"**/RCS",
"**/RCS/**",
// SCCS
"**/SCCS",
"**/SCCS/**",
// Visual SourceSafe
"**/vssver.scc",
// Subversion
"**/.svn",
"**/.svn/**",
// Arch
"**/.arch-ids",
"**/.arch-ids/**",
//Bazaar
"**/.bzr",
"**/.bzr/**",
//SurroundSCM
"**/.MySCMServerInfo",
// Mac
"**/.DS_Store",
// Serena Dimensions Version 10
"**/.metadata",
"**/.metadata/**",
// Mercurial
"**/.hg",
"**/.hg/**",
// git
"**/.git",
"**/.git/**",
// BitKeeper
"**/BitKeeper",
"**/BitKeeper/**",
"**/ChangeSet",
"**/ChangeSet/**",
// darcs
"**/_darcs",
"**/_darcs/**",
"**/.darcsrepo",
"**/.darcsrepo/**",
"**/-darcs-backup*",
"**/.darcs-temp-mail"
};
public static AntFileScanner create(boolean useDefaultExcludes, String[] includes, String[] excludes) {
return new AntFileScanner(includes, excludes, useDefaultExcludes);
}
}