Search in sources :

Example 6 with PatternSet

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

use of org.apache.tools.ant.types.PatternSet 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<>();
    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((dir1, 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;
            });
            if (files != null) {
                for (String filename : files) {
                    sourceFilesToDoc.add(dir + File.separator + filename);
                }
                if (files.length > 0) {
                    if (dir.isEmpty()) {
                        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 : StringTokenizer(java.util.StringTokenizer) DirSet(org.apache.tools.ant.types.DirSet) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) ArrayList(java.util.ArrayList) PatternSet(org.apache.tools.ant.types.PatternSet) File(java.io.File)

Example 8 with PatternSet

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

use of org.apache.tools.ant.types.PatternSet in project intellij-community by JetBrains.

the class ExtractedDirContent method build.

@Override
public List<LayoutFileSet> build(TempFileFactory temp) {
    final File outputDir = temp.allocateTempFile("extractedDir");
    expandTask.setProject(getProject());
    expandTask.setSrc(new File(jarPath.replace('/', File.separatorChar)));
    File target = outputDir;
    if (!pathInJar.endsWith("/")) {
        pathInJar += "/";
    }
    if (pathInJar.startsWith("/")) {
        pathInJar = pathInJar.substring(1);
    }
    if (pathInJar.length() > 0) {
        final PatternSet patternSet = new PatternSet();
        patternSet.createInclude().setName(pathInJar + "**");
        expandTask.addPatternset(patternSet);
        target = new File(outputDir, pathInJar.replace('/', File.separatorChar));
    }
    expandTask.setDest(outputDir);
    expandTask.perform();
    final LayoutFileSet fileSet = new LayoutFileSet();
    fileSet.setDir(target);
    return Collections.singletonList(fileSet);
}
Also used : LayoutFileSet(jetbrains.antlayout.util.LayoutFileSet) File(java.io.File) PatternSet(org.apache.tools.ant.types.PatternSet)

Example 10 with PatternSet

use of org.apache.tools.ant.types.PatternSet in project JessMA by ldcsaa.

the class UnArchiver method getTask.

/**
 * 获取解压任务对象
 */
@Override
protected Task getTask() {
    Project project = new Project();
    Expand expand = getExpand();
    PatternSet ps = getPatternSet();
    expand.setProject(project);
    expand.setSrc(getSourceFile());
    expand.setDest(getTargetDir());
    expand.setOverwrite(isOverwrite());
    if (ps != null) {
        ps.setProject(project);
        expand.addPatternset(ps);
    }
    return expand;
}
Also used : Project(org.apache.tools.ant.Project) Expand(org.apache.tools.ant.taskdefs.Expand) PatternSet(org.apache.tools.ant.types.PatternSet)

Aggregations

PatternSet (org.apache.tools.ant.types.PatternSet)14 File (java.io.File)8 DirectoryScanner (org.apache.tools.ant.DirectoryScanner)7 DirSet (org.apache.tools.ant.types.DirSet)5 FilenameFilter (java.io.FilenameFilter)3 HashSet (java.util.HashSet)3 FileNotFoundException (java.io.FileNotFoundException)2 ArrayList (java.util.ArrayList)2 Enumeration (java.util.Enumeration)2 StringTokenizer (java.util.StringTokenizer)2 Vector (java.util.Vector)2 Project (org.apache.tools.ant.Project)2 FileSet (org.apache.tools.ant.types.FileSet)2 BufferedReader (java.io.BufferedReader)1 BufferedWriter (java.io.BufferedWriter)1 FileReader (java.io.FileReader)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1