Browse Source

extract constant

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@695379 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 17 years ago
parent
commit
4c6cba963c
2 changed files with 57 additions and 27 deletions
  1. +30
    -20
      src/main/org/apache/tools/ant/DirectoryScanner.java
  2. +27
    -7
      src/main/org/apache/tools/ant/types/selectors/SelectorUtils.java

+ 30
- 20
src/main/org/apache/tools/ant/DirectoryScanner.java View File

@@ -145,33 +145,41 @@ public class DirectoryScanner
*/ */
protected static final String[] DEFAULTEXCLUDES = { protected static final String[] DEFAULTEXCLUDES = {
// Miscellaneous typical temporary files // Miscellaneous typical temporary files
"**/*~",
"**/#*#",
"**/.#*",
"**/%*%",
"**/._*",
SelectorUtils.DEEP_ROOT_MATCH + "*~",
SelectorUtils.DEEP_ROOT_MATCH + "#*#",
SelectorUtils.DEEP_ROOT_MATCH + ".#*",
SelectorUtils.DEEP_ROOT_MATCH + "%*%",
SelectorUtils.DEEP_ROOT_MATCH + "._*",


// CVS // CVS
"**/CVS",
"**/CVS/**",
"**/.cvsignore",
SelectorUtils.DEEP_ROOT_MATCH + "CVS",
SelectorUtils.DEEP_ROOT_MATCH + "CVS" + SelectorUtils.DEEP_LEAVES_MATCH,
SelectorUtils.DEEP_ROOT_MATCH + ".cvsignore",


// SCCS // SCCS
"**/SCCS",
"**/SCCS/**",
SelectorUtils.DEEP_ROOT_MATCH + "SCCS",
SelectorUtils.DEEP_ROOT_MATCH + "SCCS" + SelectorUtils.DEEP_LEAVES_MATCH,


// Visual SourceSafe // Visual SourceSafe
"**/vssver.scc",
SelectorUtils.DEEP_ROOT_MATCH + "vssver.scc",


// Subversion // Subversion
"**/.svn",
"**/.svn/**",
SelectorUtils.DEEP_ROOT_MATCH + ".svn",
SelectorUtils.DEEP_ROOT_MATCH + ".svn" + SelectorUtils.DEEP_LEAVES_MATCH,


// Mac // Mac
"**/.DS_Store"
SelectorUtils.DEEP_ROOT_MATCH + ".DS_Store"
}; };


/**
* default value for {@link #maxLevelsOfSymlinks maxLevelsOfSymlinks}
* @since Ant 1.8.0
*/
public static final int MAX_LEVELS_OF_SYMLINKS = 1; public static final int MAX_LEVELS_OF_SYMLINKS = 1;
/**
* The end of the exception message if something that should be
* there doesn't exist.
*/
public static final String DOES_NOT_EXIST_POSTFIX = " does not exist."; public static final String DOES_NOT_EXIST_POSTFIX = " does not exist.";


/** Helper. */ /** Helper. */
@@ -765,7 +773,7 @@ public class DirectoryScanner
String pattern = p.replace('/', File.separatorChar) String pattern = p.replace('/', File.separatorChar)
.replace('\\', File.separatorChar); .replace('\\', File.separatorChar);
if (pattern.endsWith(File.separator)) { if (pattern.endsWith(File.separator)) {
pattern += "**";
pattern += SelectorUtils.DEEP_TREE_MATCH;
} }
return pattern; return pattern;
} }
@@ -825,7 +833,8 @@ public class DirectoryScanner


// set in/excludes to reasonable defaults if needed: // set in/excludes to reasonable defaults if needed:
boolean nullIncludes = (includes == null); boolean nullIncludes = (includes == null);
includes = nullIncludes ? new String[] {"**"} : includes;
includes = nullIncludes
? new String[] {SelectorUtils.DEEP_TREE_MATCH} : includes;
boolean nullExcludes = (excludes == null); boolean nullExcludes = (excludes == null);
excludes = nullExcludes ? new String[0] : excludes; excludes = nullExcludes ? new String[0] : excludes;


@@ -1049,7 +1058,8 @@ public class DirectoryScanner


// set in/excludes to reasonable defaults if needed: // set in/excludes to reasonable defaults if needed:
boolean nullIncludes = (includes == null); boolean nullIncludes = (includes == null);
includes = nullIncludes ? new String[] {"**"} : includes;
includes = nullIncludes
? new String[] {SelectorUtils.DEEP_TREE_MATCH} : includes;
boolean nullExcludes = (excludes == null); boolean nullExcludes = (excludes == null);
excludes = nullExcludes ? new String[0] : excludes; excludes = nullExcludes ? new String[0] : excludes;


@@ -1305,7 +1315,7 @@ public class DirectoryScanner
*/ */
private boolean isDeeper(String pattern, String name) { private boolean isDeeper(String pattern, String name) {
Vector p = SelectorUtils.tokenizePath(pattern); Vector p = SelectorUtils.tokenizePath(pattern);
if (!p.contains("**")) {
if (!p.contains(SelectorUtils.DEEP_TREE_MATCH)) {
Vector n = SelectorUtils.tokenizePath(name); Vector n = SelectorUtils.tokenizePath(name);
return p.size() > n.size(); return p.size() > n.size();
} }
@@ -1331,7 +1341,7 @@ public class DirectoryScanner
*/ */
private boolean isMorePowerfulThanExcludes(String name, private boolean isMorePowerfulThanExcludes(String name,
String includepattern) { String includepattern) {
String soughtexclude = name + File.separator + "**";
String soughtexclude = name + SelectorUtils.DEEP_LEAVES_MATCH;
for (int counter = 0; counter < excludes.length; counter++) { for (int counter = 0; counter < excludes.length; counter++) {
if (excludes[counter].equals(soughtexclude)) { if (excludes[counter].equals(soughtexclude)) {
return false; return false;
@@ -1349,7 +1359,7 @@ public class DirectoryScanner
name = (name.endsWith(File.separator)) ? name : name + File.separator; name = (name.endsWith(File.separator)) ? name : name + File.separator;
for (int i = 0; i < excludes.length; i++) { for (int i = 0; i < excludes.length; i++) {
String e = excludes[i]; String e = excludes[i];
if (e.endsWith("**") && SelectorUtils.matchPath(
if (e.endsWith(SelectorUtils.DEEP_TREE_MATCH) && SelectorUtils.matchPath(
e.substring(0, e.length() - 2), name, isCaseSensitive())) { e.substring(0, e.length() - 2), name, isCaseSensitive())) {
return true; return true;
} }


+ 27
- 7
src/main/org/apache/tools/ant/types/selectors/SelectorUtils.java View File

@@ -38,6 +38,26 @@ import org.apache.tools.ant.types.resources.FileResource;
*/ */
public final class SelectorUtils { public final class SelectorUtils {


/**
* The pattern that matches an arbitrary number of directories.
* @since Ant 1.8.0
*/
public static final String DEEP_TREE_MATCH = "**";

/**
* The pattern that matches an arbitrary number of directories at
* the leaves.
* @since Ant 1.8.0
*/
public static final String DEEP_LEAVES_MATCH = File.separatorChar + "**";

/**
* The pattern that matches an arbitrary number of directories at
* the root.
* @since Ant 1.8.0
*/
public static final String DEEP_ROOT_MATCH = "**" + File.separatorChar;

private static final SelectorUtils instance = new SelectorUtils(); private static final SelectorUtils instance = new SelectorUtils();
private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();


@@ -115,7 +135,7 @@ public final class SelectorUtils {
// up to first '**' // up to first '**'
while (patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd) { while (patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd) {
String patDir = patDirs[patIdxStart]; String patDir = patDirs[patIdxStart];
if (patDir.equals("**")) {
if (patDir.equals(DEEP_TREE_MATCH)) {
break; break;
} }
if (!match(patDir, strDirs[strIdxStart], isCaseSensitive)) { if (!match(patDir, strDirs[strIdxStart], isCaseSensitive)) {
@@ -201,7 +221,7 @@ public final class SelectorUtils {
// up to first '**' // up to first '**'
while (patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd) { while (patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd) {
String patDir = tokenizedPattern[patIdxStart]; String patDir = tokenizedPattern[patIdxStart];
if (patDir.equals("**")) {
if (patDir.equals(DEEP_TREE_MATCH)) {
break; break;
} }
if (!match(patDir, strDirs[strIdxStart], isCaseSensitive)) { if (!match(patDir, strDirs[strIdxStart], isCaseSensitive)) {
@@ -213,7 +233,7 @@ public final class SelectorUtils {
if (strIdxStart > strIdxEnd) { if (strIdxStart > strIdxEnd) {
// String is exhausted // String is exhausted
for (int i = patIdxStart; i <= patIdxEnd; i++) { for (int i = patIdxStart; i <= patIdxEnd; i++) {
if (!tokenizedPattern[i].equals("**")) {
if (!tokenizedPattern[i].equals(DEEP_TREE_MATCH)) {
return false; return false;
} }
} }
@@ -228,7 +248,7 @@ public final class SelectorUtils {
// up to last '**' // up to last '**'
while (patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd) { while (patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd) {
String patDir = tokenizedPattern[patIdxEnd]; String patDir = tokenizedPattern[patIdxEnd];
if (patDir.equals("**")) {
if (patDir.equals(DEEP_TREE_MATCH)) {
break; break;
} }
if (!match(patDir, strDirs[strIdxEnd], isCaseSensitive)) { if (!match(patDir, strDirs[strIdxEnd], isCaseSensitive)) {
@@ -240,7 +260,7 @@ public final class SelectorUtils {
if (strIdxStart > strIdxEnd) { if (strIdxStart > strIdxEnd) {
// String is exhausted // String is exhausted
for (int i = patIdxStart; i <= patIdxEnd; i++) { for (int i = patIdxStart; i <= patIdxEnd; i++) {
if (!tokenizedPattern[i].equals("**")) {
if (!tokenizedPattern[i].equals(DEEP_TREE_MATCH)) {
return false; return false;
} }
} }
@@ -250,7 +270,7 @@ public final class SelectorUtils {
while (patIdxStart != patIdxEnd && strIdxStart <= strIdxEnd) { while (patIdxStart != patIdxEnd && strIdxStart <= strIdxEnd) {
int patIdxTmp = -1; int patIdxTmp = -1;
for (int i = patIdxStart + 1; i <= patIdxEnd; i++) { for (int i = patIdxStart + 1; i <= patIdxEnd; i++) {
if (tokenizedPattern[i].equals("**")) {
if (tokenizedPattern[i].equals(DEEP_TREE_MATCH)) {
patIdxTmp = i; patIdxTmp = i;
break; break;
} }
@@ -288,7 +308,7 @@ public final class SelectorUtils {
} }


for (int i = patIdxStart; i <= patIdxEnd; i++) { for (int i = patIdxStart; i <= patIdxEnd; i++) {
if (!tokenizedPattern[i].equals("**")) {
if (!tokenizedPattern[i].equals(DEEP_TREE_MATCH)) {
return false; return false;
} }
} }


Loading…
Cancel
Save