use of org.apache.tools.ant.DirectoryScanner in project checkstyle by checkstyle.
the class CheckstyleAntTask method scanFileSets.
/**
* Returns the list of files (full path name) to process.
*
* @return the list of files included via the filesets.
*/
protected List<File> scanFileSets() {
final List<File> allFiles = new ArrayList<>();
for (int i = 0; i < fileSets.size(); i++) {
final FileSet fileSet = fileSets.get(i);
final DirectoryScanner scanner = fileSet.getDirectoryScanner(getProject());
final List<File> scannedFiles = retrieveAllScannedFiles(scanner, i);
allFiles.addAll(scannedFiles);
}
return allFiles;
}
use of org.apache.tools.ant.DirectoryScanner in project checkstyle by checkstyle.
the class CheckstyleAntTask method scanPath.
/**
* Scans the given path and retrieves all files for the given path.
*
* @param path A path to scan.
* @param pathIndex The index of the given path. Used in log messages only.
* @return A list of files, extracted from the given path.
*/
private List<File> scanPath(Path path, int pathIndex) {
final String[] resources = path.list();
log(pathIndex + ") Scanning path " + path, Project.MSG_VERBOSE);
final List<File> allFiles = new ArrayList<>();
int concreteFilesCount = 0;
for (String resource : resources) {
final File file = new File(resource);
if (file.isFile()) {
concreteFilesCount++;
allFiles.add(file);
} else {
final DirectoryScanner scanner = new DirectoryScanner();
scanner.setBasedir(file);
scanner.scan();
final List<File> scannedFiles = retrieveAllScannedFiles(scanner, pathIndex);
allFiles.addAll(scannedFiles);
}
}
if (concreteFilesCount > 0) {
log(String.format(Locale.ROOT, "%d) Adding %d files from path %s", pathIndex, concreteFilesCount, path), Project.MSG_VERBOSE);
}
return allFiles;
}
use of org.apache.tools.ant.DirectoryScanner in project jangaroo-tools by CoreMedia.
the class JoocTask method execute.
/**
* Executes the task.
*/
public void execute() throws BuildException {
checkParameters();
resetFileLists();
sourcepath = "";
// scan source directories and dest directory to build up
// compile lists
String[] list = src.list();
for (String aList : list) {
File srcDir = getProject().resolveFile(aList);
if (!srcDir.exists()) {
throw new BuildException("srcdir \"" + srcDir.getPath() + "\" does not exist!", getLocation());
}
if (!sourcepath.isEmpty()) {
sourcepath += File.pathSeparator;
}
sourcepath += srcDir.getAbsolutePath();
DirectoryScanner ds = this.getDirectoryScanner(srcDir);
String[] files = ds.getIncludedFiles();
scanDir(srcDir, destDir != null ? destDir : srcDir, files);
}
compile();
}
use of org.apache.tools.ant.DirectoryScanner in project jangaroo-tools by CoreMedia.
the class JoodocTask method parsePackages.
/**
* Add the directories matched by the nested dirsets to the Vector
* and the base directories of the dirsets to the Path. It also
* handles the packages and excludepackages attributes and
* elements.
*
* @since 1.5
*/
private void parsePackages(Vector pn, Path sp) {
Vector addedPackages = new Vector();
Vector dirSets = (Vector) packageSets.clone();
// and nested excludepackage elements
if (sourcePath != null && packageNames.size() > 0) {
PatternSet ps = new PatternSet();
Enumeration e = packageNames.elements();
while (e.hasMoreElements()) {
PackageName p = (PackageName) e.nextElement();
String pkg = p.getName().replace('.', '/');
if (pkg.endsWith("*")) {
pkg += "*";
}
ps.createInclude().setName(pkg);
}
e = excludePackageNames.elements();
while (e.hasMoreElements()) {
PackageName p = (PackageName) e.nextElement();
String pkg = p.getName().replace('.', '/');
if (pkg.endsWith("*")) {
pkg += "*";
}
ps.createExclude().setName(pkg);
}
String[] pathElements = sourcePath.list();
for (int i = 0; i < pathElements.length; i++) {
DirSet ds = new DirSet();
ds.setDefaultexcludes(useDefaultExcludes);
ds.setDir(new File(pathElements[i]));
ds.createPatternSet().addConfiguredPatternset(ps);
dirSets.addElement(ds);
}
}
Enumeration e = dirSets.elements();
while (e.hasMoreElements()) {
DirSet ds = (DirSet) e.nextElement();
File baseDir = ds.getDir(getProject());
log("scanning " + baseDir + " for packages.", Project.MSG_DEBUG);
DirectoryScanner dsc = ds.getDirectoryScanner(getProject());
String[] dirs = dsc.getIncludedDirectories();
boolean containsPackages = false;
for (int i = 0; i < dirs.length; i++) {
// are there any java files in this directory?
File pd = new File(baseDir, dirs[i]);
String[] files = pd.list(new FilenameFilter() {
public boolean accept(File dir1, String name) {
if (name.endsWith(".java")) {
return true;
}
// ignore dirs
return false;
}
});
if (files.length > 0) {
containsPackages = true;
String packageName = dirs[i].replace(File.separatorChar, '.');
if (!addedPackages.contains(packageName)) {
addedPackages.addElement(packageName);
pn.addElement(packageName);
}
}
}
if (containsPackages) {
// We don't need to care for duplicates here,
// Path.list does it for us.
sp.createPathElement().setLocation(baseDir);
} else {
log(baseDir + " doesn\'t contain any packages, dropping it.", Project.MSG_VERBOSE);
}
}
}
use of org.apache.tools.ant.DirectoryScanner in project jangaroo-tools by CoreMedia.
the class ExmlcTask method execute.
/**
* Executes the task.
*/
public void execute() throws BuildException {
checkParameters();
resetFileLists();
sourcepath = "";
// scan source directories and dest directory to build up
// compile lists
String[] list = src.list();
for (String aList : list) {
File srcDir = getProject().resolveFile(aList);
if (!srcDir.exists()) {
throw new BuildException("srcdir \"" + srcDir.getPath() + "\" does not exist!", getLocation());
}
if (!sourcepath.isEmpty()) {
sourcepath += File.pathSeparator;
}
sourcepath += srcDir.getAbsolutePath();
DirectoryScanner ds = this.getDirectoryScanner(srcDir);
String[] files = ds.getIncludedFiles();
scanDir(srcDir, destDir != null ? destDir : srcDir, files);
}
compile();
}
Aggregations