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);
}
}
}
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;
}
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;
}
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;
}
Aggregations