Search in sources :

Example 1 with DirSet

use of org.apache.tools.ant.types.DirSet in project groovy by apache.

the class Groovydoc method parsePackages.

/**
     * Add the directories matched by the nested dirsets to the resulting
     * packages list and the base directories of the dirsets to the Path.
     * It also handles the packages and excludepackages attributes and
     * elements.
     *
     * @param resultantPackages a list to which we add the packages found
     * @param sourcePath a path to which we add each basedir found
     * @since 1.5
     */
private void parsePackages(List<String> resultantPackages, Path sourcePath) {
    List<String> addedPackages = new ArrayList<String>();
    List<DirSet> dirSets = new ArrayList<DirSet>(packageSets);
    // and nested excludepackage elements
    if (this.sourcePath != null) {
        PatternSet ps = new PatternSet();
        if (!packageNames.isEmpty()) {
            for (String pn : packageNames) {
                String pkg = pn.replace('.', '/');
                if (pkg.endsWith("*")) {
                    pkg += "*";
                }
                ps.createInclude().setName(pkg);
            }
        } else {
            ps.createInclude().setName("**");
        }
        for (String epn : excludePackageNames) {
            String pkg = epn.replace('.', '/');
            if (pkg.endsWith("*")) {
                pkg += "*";
            }
            ps.createExclude().setName(pkg);
        }
        String[] pathElements = this.sourcePath.list();
        for (String pathElement : pathElements) {
            File dir = new File(pathElement);
            if (dir.isDirectory()) {
                DirSet ds = new DirSet();
                ds.setDefaultexcludes(useDefaultExcludes);
                ds.setDir(dir);
                ds.createPatternSet().addConfiguredPatternset(ps);
                dirSets.add(ds);
            } else {
                log.warn("Skipping " + pathElement + " since it is no directory.");
            }
        }
    }
    for (DirSet ds : dirSets) {
        File baseDir = ds.getDir(getProject());
        log.debug("scanning " + baseDir + " for packages.");
        DirectoryScanner dsc = ds.getDirectoryScanner(getProject());
        String[] dirs = dsc.getIncludedDirectories();
        boolean containsPackages = false;
        for (String dir : dirs) {
            // are there any groovy or java files in this directory?
            File pd = new File(baseDir, dir);
            String[] files = pd.list(new FilenameFilter() {

                public boolean accept(File dir1, String name) {
                    if (!includeNoSourcePackages && name.equals("package.html"))
                        return true;
                    final StringTokenizer tokenizer = new StringTokenizer(extensions, ":");
                    while (tokenizer.hasMoreTokens()) {
                        String ext = tokenizer.nextToken();
                        if (name.endsWith(ext))
                            return true;
                    }
                    return false;
                }
            });
            for (String filename : Arrays.asList(files)) {
                sourceFilesToDoc.add(dir + File.separator + filename);
            }
            if (files.length > 0) {
                if ("".equals(dir)) {
                    log.warn(baseDir + " contains source files in the default package," + " you must specify them as source files not packages.");
                } else {
                    containsPackages = true;
                    String pn = dir.replace(File.separatorChar, '.');
                    if (!addedPackages.contains(pn)) {
                        addedPackages.add(pn);
                        resultantPackages.add(pn);
                    }
                }
            }
        }
        if (containsPackages) {
            // We don't need to care for duplicates here,
            // Path.list does it for us.
            sourcePath.createPathElement().setLocation(baseDir);
        } else {
            log.verbose(baseDir + " doesn't contain any packages, dropping it.");
        }
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) DirSet(org.apache.tools.ant.types.DirSet) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) PatternSet(org.apache.tools.ant.types.PatternSet) File(java.io.File)

Example 2 with DirSet

use of org.apache.tools.ant.types.DirSet in project groovy-core by groovy.

the class Groovydoc method parsePackages.

/**
     * Add the directories matched by the nested dirsets to the resulting
     * packages list and the base directories of the dirsets to the Path.
     * It also handles the packages and excludepackages attributes and
     * elements.
     *
     * @param resultantPackages a list to which we add the packages found
     * @param sourcePath a path to which we add each basedir found
     * @since 1.5
     */
private void parsePackages(List<String> resultantPackages, Path sourcePath) {
    List<String> addedPackages = new ArrayList<String>();
    List<DirSet> dirSets = new ArrayList<DirSet>(packageSets);
    // and nested excludepackage elements
    if (this.sourcePath != null) {
        PatternSet ps = new PatternSet();
        if (packageNames.size() > 0) {
            for (String pn : packageNames) {
                String pkg = pn.replace('.', '/');
                if (pkg.endsWith("*")) {
                    pkg += "*";
                }
                ps.createInclude().setName(pkg);
            }
        } else {
            ps.createInclude().setName("**");
        }
        for (String epn : excludePackageNames) {
            String pkg = epn.replace('.', '/');
            if (pkg.endsWith("*")) {
                pkg += "*";
            }
            ps.createExclude().setName(pkg);
        }
        String[] pathElements = this.sourcePath.list();
        for (String pathElement : pathElements) {
            File dir = new File(pathElement);
            if (dir.isDirectory()) {
                DirSet ds = new DirSet();
                ds.setDefaultexcludes(useDefaultExcludes);
                ds.setDir(dir);
                ds.createPatternSet().addConfiguredPatternset(ps);
                dirSets.add(ds);
            } else {
                log.warn("Skipping " + pathElement + " since it is no directory.");
            }
        }
    }
    for (DirSet ds : dirSets) {
        File baseDir = ds.getDir(getProject());
        log.debug("scanning " + baseDir + " for packages.");
        DirectoryScanner dsc = ds.getDirectoryScanner(getProject());
        String[] dirs = dsc.getIncludedDirectories();
        boolean containsPackages = false;
        for (String dir : dirs) {
            // are there any groovy or java files in this directory?
            File pd = new File(baseDir, dir);
            String[] files = pd.list(new FilenameFilter() {

                public boolean accept(File dir1, String name) {
                    if (!includeNoSourcePackages && name.equals("package.html"))
                        return true;
                    final StringTokenizer tokenizer = new StringTokenizer(extensions, ":");
                    while (tokenizer.hasMoreTokens()) {
                        String ext = tokenizer.nextToken();
                        if (name.endsWith(ext))
                            return true;
                    }
                    return false;
                }
            });
            for (String filename : Arrays.asList(files)) {
                sourceFilesToDoc.add(dir + File.separator + filename);
            }
            if (files.length > 0) {
                if ("".equals(dir)) {
                    log.warn(baseDir + " contains source files in the default package," + " you must specify them as source files not packages.");
                } else {
                    containsPackages = true;
                    String pn = dir.replace(File.separatorChar, '.');
                    if (!addedPackages.contains(pn)) {
                        addedPackages.add(pn);
                        resultantPackages.add(pn);
                    }
                }
            }
        }
        if (containsPackages) {
            // We don't need to care for duplicates here,
            // Path.list does it for us.
            sourcePath.createPathElement().setLocation(baseDir);
        } else {
            log.verbose(baseDir + " doesn't contain any packages, dropping it.");
        }
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) DirSet(org.apache.tools.ant.types.DirSet) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) PatternSet(org.apache.tools.ant.types.PatternSet) File(java.io.File)

Example 3 with DirSet

use of org.apache.tools.ant.types.DirSet 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 4 with DirSet

use of org.apache.tools.ant.types.DirSet in project gcontracts by andresteingress.

the class ContractGroovyDoc method parsePackages.

/**
     * Add the directories matched by the nested dirsets to the resulting
     * packages list and the base directories of the dirsets to the Path.
     * It also handles the packages and excludepackages attributes and
     * elements.
     *
     * @param resultantPackages a list to which we add the packages found
     * @param sourcePath a path to which we add each basedir found
     * @since 1.5
     */
private void parsePackages(List<String> resultantPackages, Path sourcePath) {
    List<String> addedPackages = new ArrayList<String>();
    List<DirSet> dirSets = new ArrayList<DirSet>(packageSets);
    // and nested excludepackage elements
    if (this.sourcePath != null) {
        PatternSet ps = new PatternSet();
        if (packageNames.size() > 0) {
            for (String pn : packageNames) {
                String pkg = pn.replace('.', '/');
                if (pkg.endsWith("*")) {
                    pkg += "*";
                }
                ps.createInclude().setName(pkg);
            }
        } else {
            ps.createInclude().setName("**");
        }
        for (String epn : excludePackageNames) {
            String pkg = epn.replace('.', '/');
            if (pkg.endsWith("*")) {
                pkg += "*";
            }
            ps.createExclude().setName(pkg);
        }
        String[] pathElements = this.sourcePath.list();
        for (String pathElement : pathElements) {
            File dir = new File(pathElement);
            if (dir.isDirectory()) {
                DirSet ds = new DirSet();
                ds.setDefaultexcludes(useDefaultExcludes);
                ds.setDir(dir);
                ds.createPatternSet().addConfiguredPatternset(ps);
                dirSets.add(ds);
            } else {
                log.warn("Skipping " + pathElement + " since it is no directory.");
            }
        }
    }
    for (DirSet ds : dirSets) {
        File baseDir = ds.getDir(getProject());
        log.debug("scanning " + baseDir + " for packages.");
        DirectoryScanner dsc = ds.getDirectoryScanner(getProject());
        String[] dirs = dsc.getIncludedDirectories();
        boolean containsPackages = false;
        for (String dir : dirs) {
            // are there any groovy or java files in this directory?
            File pd = new File(baseDir, dir);
            String[] files = pd.list(new FilenameFilter() {

                public boolean accept(File dir1, String name) {
                    if (!includeNoSourcePackages && name.equals("package.html"))
                        return true;
                    final StringTokenizer tokenizer = new StringTokenizer(extensions, ":");
                    while (tokenizer.hasMoreTokens()) {
                        String ext = tokenizer.nextToken();
                        if (name.endsWith(ext))
                            return true;
                    }
                    return false;
                }
            });
            for (String filename : Arrays.asList(files)) {
                sourceFilesToDoc.add(dir + File.separator + filename);
            }
            if (files.length > 0) {
                if ("".equals(dir)) {
                    log.warn(baseDir + " contains source files in the default package," + " you must specify them as source files not packages.");
                } else {
                    containsPackages = true;
                    String pn = dir.replace(File.separatorChar, '.');
                    if (!addedPackages.contains(pn)) {
                        addedPackages.add(pn);
                        resultantPackages.add(pn);
                    }
                }
            }
        }
        if (containsPackages) {
            // We don't need to care for duplicates here,
            // Path.list does it for us.
            sourcePath.createPathElement().setLocation(baseDir);
        } else {
            log.verbose(baseDir + " doesn't contain any packages, dropping it.");
        }
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) DirSet(org.apache.tools.ant.types.DirSet) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) PatternSet(org.apache.tools.ant.types.PatternSet) File(java.io.File)

Aggregations

File (java.io.File)4 FilenameFilter (java.io.FilenameFilter)4 DirectoryScanner (org.apache.tools.ant.DirectoryScanner)4 DirSet (org.apache.tools.ant.types.DirSet)4 PatternSet (org.apache.tools.ant.types.PatternSet)4 Enumeration (java.util.Enumeration)1 Vector (java.util.Vector)1