Search in sources :

Example 11 with PatternSet

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

the class Javadoc 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(final List<String> pn, final Path sp) {
    final Set<String> addedPackages = new HashSet<>();
    final List<DirSet> dirSets = new ArrayList<>(packageSets);
    // and nested excludepackage elements
    if (sourcePath != null) {
        final PatternSet ps = new PatternSet();
        ps.setProject(getProject());
        if (packageNames.isEmpty()) {
            ps.createInclude().setName("**");
        } else {
            packageNames.stream().map(PackageName::getName).map(s -> s.replace('.', '/').replaceFirst("\\*$", "**")).forEach(pkg -> ps.createInclude().setName(pkg));
        }
        excludePackageNames.stream().map(PackageName::getName).map(s -> s.replace('.', '/').replaceFirst("\\*$", "**")).forEach(pkg -> ps.createExclude().setName(pkg));
        for (String pathElement : sourcePath.list()) {
            final File dir = new File(pathElement);
            if (dir.isDirectory()) {
                final DirSet ds = new DirSet();
                ds.setProject(getProject());
                ds.setDefaultexcludes(useDefaultExcludes);
                ds.setDir(dir);
                ds.createPatternSet().addConfiguredPatternset(ps);
                dirSets.add(ds);
            } else {
                log("Skipping " + pathElement + " since it is no directory.", Project.MSG_WARN);
            }
        }
    }
    for (DirSet ds : dirSets) {
        final File baseDir = ds.getDir(getProject());
        log("scanning " + baseDir + " for packages.", Project.MSG_DEBUG);
        final DirectoryScanner dsc = ds.getDirectoryScanner(getProject());
        boolean containsPackages = false;
        for (String dir : dsc.getIncludedDirectories()) {
            // are there any java files in this directory?
            final File pd = new File(baseDir, dir);
            final String[] files = pd.list((directory, name) -> name.endsWith(".java") || (includeNoSourcePackages && name.equals("package.html")));
            if (files.length > 0) {
                if ("".equals(dir)) {
                    log(baseDir + " contains source files in the default package, you must specify them as source files not packages.", Project.MSG_WARN);
                } else {
                    containsPackages = true;
                    final String packageName = dir.replace(File.separatorChar, '.');
                    if (!addedPackages.contains(packageName)) {
                        addedPackages.add(packageName);
                        pn.add(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 : Commandline(org.apache.tools.ant.types.Commandline) DirSet(org.apache.tools.ant.types.DirSet) Enumeration(java.util.Enumeration) URL(java.net.URL) Task(org.apache.tools.ant.Task) JavaEnvUtils(org.apache.tools.ant.util.JavaEnvUtils) ResourceCollection(org.apache.tools.ant.types.ResourceCollection) ArrayList(java.util.ArrayList) Path(org.apache.tools.ant.types.Path) HashSet(java.util.HashSet) Vector(java.util.Vector) Locale(java.util.Locale) StringTokenizer(java.util.StringTokenizer) FileSet(org.apache.tools.ant.types.FileSet) OutputStreamWriter(java.io.OutputStreamWriter) Project(org.apache.tools.ant.Project) ProjectComponent(org.apache.tools.ant.ProjectComponent) FileUtils(org.apache.tools.ant.util.FileUtils) Resource(org.apache.tools.ant.types.Resource) Iterator(java.util.Iterator) MalformedURLException(java.net.MalformedURLException) Files(java.nio.file.Files) BufferedWriter(java.io.BufferedWriter) FileWriter(java.io.FileWriter) Set(java.util.Set) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) List(java.util.List) EnumeratedAttribute(org.apache.tools.ant.types.EnumeratedAttribute) PatternSet(org.apache.tools.ant.types.PatternSet) FileProvider(org.apache.tools.ant.types.resources.FileProvider) StringUtils(org.apache.tools.ant.util.StringUtils) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) Collections(java.util.Collections) MagicNames(org.apache.tools.ant.MagicNames) InputStream(java.io.InputStream) Reference(org.apache.tools.ant.types.Reference) ArrayList(java.util.ArrayList) DirSet(org.apache.tools.ant.types.DirSet) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) PatternSet(org.apache.tools.ant.types.PatternSet) File(java.io.File) HashSet(java.util.HashSet)

Example 12 with PatternSet

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

the class Files method clone.

/**
 * Create a deep clone of this instance, except for the nested selectors
 * (the list of selectors is a shallow clone of this instance's list).
 * @return a cloned Object.
 */
@Override
public synchronized Object clone() {
    if (isReference()) {
        return getRef().clone();
    }
    Files f = (Files) super.clone();
    f.defaultPatterns = (PatternSet) defaultPatterns.clone();
    f.additionalPatterns = new Vector<PatternSet>(additionalPatterns.size());
    for (PatternSet ps : additionalPatterns) {
        f.additionalPatterns.add((PatternSet) ps.clone());
    }
    return f;
}
Also used : PatternSet(org.apache.tools.ant.types.PatternSet)

Example 13 with PatternSet

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

the class Files method createPatternSet.

/**
 * Create a nested patternset.
 * @return <code>PatternSet</code>.
 */
public synchronized PatternSet createPatternSet() {
    if (isReference()) {
        throw noChildrenAllowed();
    }
    PatternSet patterns = new PatternSet();
    additionalPatterns.addElement(patterns);
    ds = null;
    setChecked(false);
    return patterns;
}
Also used : PatternSet(org.apache.tools.ant.types.PatternSet)

Example 14 with PatternSet

use of org.apache.tools.ant.types.PatternSet in project lwjgl by LWJGL.

the class PackageList method matchPatterns.

/**
 * @param i_entryName
 */
private boolean matchPatterns(String i_entryName) {
    if (patternsets != null && patternsets.size() > 0) {
        boolean included = false;
        String name = i_entryName.replace('/', File.separatorChar).replace('\\', File.separatorChar);
        Set<String> includePatterns = new HashSet<String>();
        Set<String> excludePatterns = new HashSet<String>();
        for (int v = 0, size = patternsets.size(); v < size; v++) {
            PatternSet p = (PatternSet) patternsets.elementAt(v);
            String[] incls = p.getIncludePatterns(getProject());
            if (incls == null || incls.length == 0) {
                // no include pattern implicitly means includes="**"
                incls = new String[] { "**" };
            }
            for (int w = 0; w < incls.length; w++) {
                String pattern = incls[w].replace('/', File.separatorChar).replace('\\', File.separatorChar);
                if (pattern.endsWith(File.separator)) {
                    pattern += "**";
                }
                includePatterns.add(pattern);
            }
            String[] excls = p.getExcludePatterns(getProject());
            if (excls != null) {
                for (int w = 0; w < excls.length; w++) {
                    String pattern = excls[w].replace('/', File.separatorChar).replace('\\', File.separatorChar);
                    if (pattern.endsWith(File.separator)) {
                        pattern += "**";
                    }
                    excludePatterns.add(pattern);
                }
            }
        }
        for (Iterator<String> iter = includePatterns.iterator(); !included && iter.hasNext(); ) {
            String pattern = iter.next();
            included = SelectorUtils.matchPath(pattern, name);
        }
        for (Iterator<String> iter = excludePatterns.iterator(); included && iter.hasNext(); ) {
            String pattern = iter.next();
            included = !SelectorUtils.matchPath(pattern, name);
        }
        return included;
    }
    return true;
}
Also used : PatternSet(org.apache.tools.ant.types.PatternSet) HashSet(java.util.HashSet)

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