Search in sources :

Example 76 with DirectoryScanner

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;
}
Also used : FileSet(org.apache.tools.ant.types.FileSet) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) ArrayList(java.util.ArrayList) File(java.io.File)

Example 77 with DirectoryScanner

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;
}
Also used : DirectoryScanner(org.apache.tools.ant.DirectoryScanner) ArrayList(java.util.ArrayList) File(java.io.File)

Example 78 with DirectoryScanner

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();
}
Also used : DirectoryScanner(org.apache.tools.ant.DirectoryScanner) BuildException(org.apache.tools.ant.BuildException) File(java.io.File)

Example 79 with DirectoryScanner

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);
        }
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) Enumeration(java.util.Enumeration) DirSet(org.apache.tools.ant.types.DirSet) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) Vector(java.util.Vector) PatternSet(org.apache.tools.ant.types.PatternSet) File(java.io.File)

Example 80 with DirectoryScanner

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();
}
Also used : DirectoryScanner(org.apache.tools.ant.DirectoryScanner) BuildException(org.apache.tools.ant.BuildException) File(java.io.File)

Aggregations

DirectoryScanner (org.apache.tools.ant.DirectoryScanner)150 File (java.io.File)122 FileSet (org.apache.tools.ant.types.FileSet)84 BuildException (org.apache.tools.ant.BuildException)73 IOException (java.io.IOException)38 ArrayList (java.util.ArrayList)32 Project (org.apache.tools.ant.Project)14 Resource (org.apache.tools.ant.types.Resource)11 Test (org.junit.Test)11 FileResource (org.apache.tools.ant.types.resources.FileResource)8 HashMap (java.util.HashMap)7 Path (org.apache.tools.ant.types.Path)7 Hashtable (java.util.Hashtable)6 PatternSet (org.apache.tools.ant.types.PatternSet)6 FileWriter (java.io.FileWriter)5 LinkedList (java.util.LinkedList)5 List (java.util.List)5 StringTokenizer (java.util.StringTokenizer)5 Vector (java.util.Vector)5 DirSet (org.apache.tools.ant.types.DirSet)5