You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bo...@apache.org on 2008/09/15 10:28:45 UTC

svn commit: r695379 - in /ant/core/trunk/src/main/org/apache/tools/ant: DirectoryScanner.java types/selectors/SelectorUtils.java

Author: bodewig
Date: Mon Sep 15 01:28:44 2008
New Revision: 695379

URL: http://svn.apache.org/viewvc?rev=695379&view=rev
Log:
extract constant

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/DirectoryScanner.java
    ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/SelectorUtils.java

Modified: ant/core/trunk/src/main/org/apache/tools/ant/DirectoryScanner.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/DirectoryScanner.java?rev=695379&r1=695378&r2=695379&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/DirectoryScanner.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/DirectoryScanner.java Mon Sep 15 01:28:44 2008
@@ -145,33 +145,41 @@
      */
     protected static final String[] DEFAULTEXCLUDES = {
         // 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/**",
-        "**/.cvsignore",
+        SelectorUtils.DEEP_ROOT_MATCH + "CVS",
+        SelectorUtils.DEEP_ROOT_MATCH + "CVS" + SelectorUtils.DEEP_LEAVES_MATCH,
+        SelectorUtils.DEEP_ROOT_MATCH + ".cvsignore",
 
         // SCCS
-        "**/SCCS",
-        "**/SCCS/**",
+        SelectorUtils.DEEP_ROOT_MATCH + "SCCS",
+        SelectorUtils.DEEP_ROOT_MATCH + "SCCS" + SelectorUtils.DEEP_LEAVES_MATCH,
 
         // Visual SourceSafe
-        "**/vssver.scc",
+        SelectorUtils.DEEP_ROOT_MATCH + "vssver.scc",
 
         // Subversion
-        "**/.svn",
-        "**/.svn/**",
+        SelectorUtils.DEEP_ROOT_MATCH + ".svn",
+        SelectorUtils.DEEP_ROOT_MATCH + ".svn" + SelectorUtils.DEEP_LEAVES_MATCH,
 
         // 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;
+    /**
+     * 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.";
 
     /** Helper. */
@@ -765,7 +773,7 @@
         String pattern = p.replace('/', File.separatorChar)
             .replace('\\', File.separatorChar);
         if (pattern.endsWith(File.separator)) {
-            pattern += "**";
+            pattern += SelectorUtils.DEEP_TREE_MATCH;
         }
         return pattern;
     }
@@ -825,7 +833,8 @@
 
                 // set in/excludes to reasonable defaults if needed:
                 boolean nullIncludes = (includes == null);
-                includes = nullIncludes ? new String[] {"**"} : includes;
+                includes = nullIncludes
+                    ? new String[] {SelectorUtils.DEEP_TREE_MATCH} : includes;
                 boolean nullExcludes = (excludes == null);
                 excludes = nullExcludes ? new String[0] : excludes;
 
@@ -1049,7 +1058,8 @@
 
                 // set in/excludes to reasonable defaults if needed:
                 boolean nullIncludes = (includes == null);
-                includes = nullIncludes ? new String[] {"**"} : includes;
+                includes = nullIncludes
+                    ? new String[] {SelectorUtils.DEEP_TREE_MATCH} : includes;
                 boolean nullExcludes = (excludes == null);
                 excludes = nullExcludes ? new String[0] : excludes;
 
@@ -1305,7 +1315,7 @@
      */
     private boolean isDeeper(String pattern, String name) {
         Vector p = SelectorUtils.tokenizePath(pattern);
-        if (!p.contains("**")) {
+        if (!p.contains(SelectorUtils.DEEP_TREE_MATCH)) {
             Vector n = SelectorUtils.tokenizePath(name);
             return p.size() > n.size();
         }
@@ -1331,7 +1341,7 @@
      */
     private boolean isMorePowerfulThanExcludes(String name,
                                                String includepattern) {
-        String soughtexclude = name + File.separator + "**";
+        String soughtexclude = name + SelectorUtils.DEEP_LEAVES_MATCH;
         for (int counter = 0; counter < excludes.length; counter++) {
             if (excludes[counter].equals(soughtexclude))  {
                 return false;
@@ -1349,7 +1359,7 @@
         name = (name.endsWith(File.separator)) ? name : name + File.separator;
         for (int i = 0; i < excludes.length; 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())) {
                 return true;
             }

Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/SelectorUtils.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/SelectorUtils.java?rev=695379&r1=695378&r2=695379&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/SelectorUtils.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/SelectorUtils.java Mon Sep 15 01:28:44 2008
@@ -38,6 +38,26 @@
  */
 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 FileUtils FILE_UTILS = FileUtils.getFileUtils();
 
@@ -115,7 +135,7 @@
         // up to first '**'
         while (patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd) {
             String patDir = patDirs[patIdxStart];
-            if (patDir.equals("**")) {
+            if (patDir.equals(DEEP_TREE_MATCH)) {
                 break;
             }
             if (!match(patDir, strDirs[strIdxStart], isCaseSensitive)) {
@@ -201,7 +221,7 @@
         // up to first '**'
         while (patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd) {
             String patDir = tokenizedPattern[patIdxStart];
-            if (patDir.equals("**")) {
+            if (patDir.equals(DEEP_TREE_MATCH)) {
                 break;
             }
             if (!match(patDir, strDirs[strIdxStart], isCaseSensitive)) {
@@ -213,7 +233,7 @@
         if (strIdxStart > strIdxEnd) {
             // String is exhausted
             for (int i = patIdxStart; i <= patIdxEnd; i++) {
-                if (!tokenizedPattern[i].equals("**")) {
+                if (!tokenizedPattern[i].equals(DEEP_TREE_MATCH)) {
                     return false;
                 }
             }
@@ -228,7 +248,7 @@
         // up to last '**'
         while (patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd) {
             String patDir = tokenizedPattern[patIdxEnd];
-            if (patDir.equals("**")) {
+            if (patDir.equals(DEEP_TREE_MATCH)) {
                 break;
             }
             if (!match(patDir, strDirs[strIdxEnd], isCaseSensitive)) {
@@ -240,7 +260,7 @@
         if (strIdxStart > strIdxEnd) {
             // String is exhausted
             for (int i = patIdxStart; i <= patIdxEnd; i++) {
-                if (!tokenizedPattern[i].equals("**")) {
+                if (!tokenizedPattern[i].equals(DEEP_TREE_MATCH)) {
                     return false;
                 }
             }
@@ -250,7 +270,7 @@
         while (patIdxStart != patIdxEnd && strIdxStart <= strIdxEnd) {
             int patIdxTmp = -1;
             for (int i = patIdxStart + 1; i <= patIdxEnd; i++) {
-                if (tokenizedPattern[i].equals("**")) {
+                if (tokenizedPattern[i].equals(DEEP_TREE_MATCH)) {
                     patIdxTmp = i;
                     break;
                 }
@@ -288,7 +308,7 @@
         }
 
         for (int i = patIdxStart; i <= patIdxEnd; i++) {
-            if (!tokenizedPattern[i].equals("**")) {
+            if (!tokenizedPattern[i].equals(DEEP_TREE_MATCH)) {
                 return false;
             }
         }