/** * 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. */ public synchronized Object clone() { if (isReference()) { return getRef().clone(); } Files f = (Files) super.clone(); f.defaultPatterns = (PatternSet) defaultPatterns.clone(); f.additionalPatterns = new Vector(additionalPatterns.size()); for (Iterator iter = additionalPatterns.iterator(); iter.hasNext(); ) { PatternSet ps = (PatternSet) iter.next(); f.additionalPatterns.add(ps.clone()); } return f; }
/** * Get the merged patterns for this Files collection. * * @param p Project instance. * @return the default patternset merged with the additional sets in a new PatternSet instance. */ public synchronized PatternSet mergePatterns(Project p) { if (isReference()) { return getRef().mergePatterns(p); } dieOnCircularReference(); PatternSet ps = new PatternSet(); ps.append(defaultPatterns, p); final int count = additionalPatterns.size(); for (int i = 0; i < count; i++) { Object o = additionalPatterns.elementAt(i); ps.append((PatternSet) o, p); } return ps; }
private synchronized void ensureDirectoryScannerSetup() { dieOnCircularReference(); if (ds == null) { ds = new DirectoryScanner(); PatternSet ps = mergePatterns(getProject()); ds.setIncludes(ps.getIncludePatterns(getProject())); ds.setExcludes(ps.getExcludePatterns(getProject())); ds.setSelectors(getSelectors(getProject())); if (useDefaultExcludes) { ds.addDefaultExcludes(); } ds.setCaseSensitive(caseSensitive); ds.setFollowSymlinks(followSymlinks); } }
/** * Add a name entry to the excludes files list. * * @return <code>PatternSet.NameEntry</code>. */ public synchronized PatternSet.NameEntry createExcludesFile() { if (isReference()) { throw noChildrenAllowed(); } ds = null; return defaultPatterns.createExcludesFile(); }
/** * Append <code>excludes</code> to the current list of include patterns. * * @param excludes array containing the exclude patterns. */ public synchronized void appendExcludes(String[] excludes) { checkAttributesAllowed(); if (excludes != null) { for (int i = 0; i < excludes.length; i++) { defaultPatterns.createExclude().setName(excludes[i]); } ds = null; } }
/** * 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); // for each sourcePath entry, add a directoryset with includes // taken from packagenames attribute and nested package // elements and excludes taken from excludepackages attribute // 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."); } } }
private boolean hasPatterns(PatternSet ps) { String[] includePatterns = ps.getIncludePatterns(getProject()); String[] excludePatterns = ps.getExcludePatterns(getProject()); return (includePatterns != null && includePatterns.length > 0) || (includePatterns != null && excludePatterns.length > 0); }
/** * Set the <code>File</code> containing the excludes patterns. * * @param excl <code>File</code> instance. * @throws BuildException if there is a problem. */ public synchronized void setExcludesfile(File excl) throws BuildException { checkAttributesAllowed(); defaultPatterns.setExcludesfile(excl); ds = null; }
/** * Append <code>excludes</code> to the current list of exclude patterns. * * <p>Patterns may be separated by a comma or a space. * * @param excludes the <code>String</code> containing the exclude patterns. */ public synchronized void setExcludes(String excludes) { checkAttributesAllowed(); defaultPatterns.setExcludes(excludes); ds = null; }