in src/main/org/apache/tools/ant/DirectoryScanner.java [931:1034]
private void checkIncludePatterns() {
ensureNonPatternSetsReady();
final Map<TokenizedPath, String> newroots = new HashMap<>();
// put in the newroots map the include patterns without
// wildcard tokens
for (TokenizedPattern includePattern : includePatterns) {
final String pattern = includePattern.toString();
if (!shouldSkipPattern(pattern)) {
newroots.put(includePattern.rtrimWildcardTokens(), pattern);
}
}
for (final Map.Entry<String, TokenizedPath> entry : includeNonPatterns
.entrySet()) {
final String pattern = entry.getKey();
if (!shouldSkipPattern(pattern)) {
newroots.put(entry.getValue(), pattern);
}
}
if (newroots.containsKey(TokenizedPath.EMPTY_PATH)
&& basedir != null) {
// we are going to scan everything anyway
scandir(basedir, "", true);
} else {
File canonBase = null;
if (basedir != null) {
try {
canonBase = basedir.getCanonicalFile();
} catch (final IOException ex) {
throw new BuildException(ex);
}
}
// only scan directories that can include matched files or
// directories
for (final Map.Entry<TokenizedPath, String> entry : newroots.entrySet()) {
TokenizedPath currentPath = entry.getKey();
String currentelement = currentPath.toString();
if (basedir == null && !FileUtils.isAbsolutePath(currentelement)) {
continue;
}
File myfile = new File(basedir, currentelement);
if (myfile.exists()) {
// may be on a case insensitive file system. We want
// the results to show what's really on the disk, so
// we need to double check.
try {
final String path = (basedir == null)
? myfile.getCanonicalPath()
: FILE_UTILS.removeLeadingPath(canonBase,
myfile.getCanonicalFile());
if (!path.equals(currentelement) || ON_VMS) {
myfile = currentPath.findFile(basedir, true);
if (myfile != null && basedir != null) {
currentelement = FILE_UTILS.removeLeadingPath(
basedir, myfile);
if (!currentPath.toString().equals(currentelement)) {
currentPath = new TokenizedPath(currentelement);
}
}
}
} catch (final IOException ex) {
throw new BuildException(ex);
}
}
if ((myfile == null || !myfile.exists()) && !isCaseSensitive()) {
final File f = currentPath.findFile(basedir, false);
if (f != null && f.exists()) {
// adapt currentelement to the case we've
// actually found
currentelement = (basedir == null)
? f.getAbsolutePath()
: FILE_UTILS.removeLeadingPath(basedir, f);
myfile = f;
currentPath = new TokenizedPath(currentelement);
}
}
if (myfile != null && myfile.exists()) {
if (!followSymlinks && currentPath.isSymlink(basedir)) {
accountForNotFollowedSymlink(currentPath, myfile);
continue;
}
if (myfile.isDirectory()) {
if (isIncluded(currentPath) && !currentelement.isEmpty()) {
accountForIncludedDir(currentPath, myfile, true);
} else {
scandir(myfile, currentPath, true);
}
} else if (myfile.isFile()) {
final String originalpattern = entry.getValue();
final boolean included = isCaseSensitive()
? originalpattern.equals(currentelement)
: originalpattern.equalsIgnoreCase(currentelement);
if (included) {
accountForIncludedFile(currentPath, myfile);
}
}
}
}
}
}