ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/types FileSet.java
Date Thu, 27 Sep 2001 10:41:50 GMT
bodewig     01/09/27 03:41:50

  Modified:    .        Tag: ANT_14_BRANCH WHATSNEW
               docs/manual/CoreTypes Tag: ANT_14_BRANCH fileset.html
               src/main/org/apache/tools/ant Tag: ANT_14_BRANCH
                        DirectoryScanner.java FileScanner.java
               src/main/org/apache/tools/ant/types Tag: ANT_14_BRANCH
                        FileSet.java
  Log:
  add attribute to fileset to allow case insensitive matches.
  
  PR: 368
  Submitted by:	Magesh Umasankar <umagesh@rediffmail.com>
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.144.2.15 +4 -0      jakarta-ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/WHATSNEW,v
  retrieving revision 1.144.2.14
  retrieving revision 1.144.2.15
  diff -u -r1.144.2.14 -r1.144.2.15
  --- WHATSNEW	2001/09/27 10:10:51	1.144.2.14
  +++ WHATSNEW	2001/09/27 10:41:49	1.144.2.15
  @@ -32,6 +32,10 @@
   * XmlLogger and <antstructure> now add an encoding declaration to the
     XML files they generate.
   
  +* <fileset> has a new attribute "casesensitive" to make it match
  +  filenames in a case insensitive way (if you set it to false) - by
  +  default filesets remain case sensitive.
  +
   Changes from Ant 1.3 to Ant 1.4
   ===========================================
   
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.4.2.1   +7 -1      jakarta-ant/docs/manual/CoreTypes/fileset.html
  
  Index: fileset.html
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/docs/manual/CoreTypes/fileset.html,v
  retrieving revision 1.4
  retrieving revision 1.4.2.1
  diff -u -r1.4 -r1.4.2.1
  --- fileset.html	2001/08/01 09:08:55	1.4
  +++ fileset.html	2001/09/27 10:41:50	1.4.2.1
  @@ -62,11 +62,17 @@
         taken to be an exclude pattern.</td>
       <td valign="top" align="center">No</td>
     </tr>
  +  <tr>
  +    <td valign="top">casesensitive</td>
  +    <td valign="top">Must the file system be treated in a case sensitive way?
  +        Defaults to true.</td>
  +    <td valign="top" align="center">No</td>
  +  </tr>
   </table>
   
   <h4>Examples</h4>
   <blockquote><pre>
  -&lt;fileset dir=&quot;${server.src}&quot; &gt;
  +&lt;fileset dir=&quot;${server.src}&quot; casesensitive=&quot;yes&quot;
&gt;
     &lt;patternset id=&quot;non.test.sources&quot; &gt;
       &lt;include name=&quot;**/*.java&quot;/&gt;
       &lt;exclude name=&quot;**/*Test*&quot;/&gt;
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.15.2.1  +110 -19   jakarta-ant/src/main/org/apache/tools/ant/DirectoryScanner.java
  
  Index: DirectoryScanner.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/DirectoryScanner.java,v
  retrieving revision 1.15
  retrieving revision 1.15.2.1
  diff -u -r1.15 -r1.15.2.1
  --- DirectoryScanner.java	2001/07/12 13:02:42	1.15
  +++ DirectoryScanner.java	2001/09/27 10:41:50	1.15.2.1
  @@ -113,6 +113,9 @@
    * "**\test\**\XYZ*" matches all files/dirs that start with "XYZ" and where
    * there is a parent directory called test (e.g. "abc\test\def\ghi\XYZ123").
    * <p>
  + * Case sensitivity may be turned off if necessary.  By default, it is
  + * turned on.
  + * <p>
    * Example of usage:
    * <pre>
    *   String[] includes = {"**\\*.class"};
  @@ -120,6 +123,7 @@
    *   ds.setIncludes(includes);
    *   ds.setExcludes(excludes);
    *   ds.setBasedir(new File("test"));
  + *   ds.setCaseSensitive(true);
    *   ds.scan();
    *
    *   System.out.println("FILES:");
  @@ -132,6 +136,7 @@
    * .class files in all directories under a directory called "modules"
    *
    * @author Arnout J. Kuiper <a href="mailto:ajkuiper@wxs.nl">ajkuiper@wxs.nl</a>
  + * @author <a href="mailto:umagesh@rediffmail.com">Magesh Umasankar</a>
    */
   public class DirectoryScanner implements FileScanner {
   
  @@ -208,6 +213,11 @@
       protected boolean haveSlowResults = false;
   
       /**
  +     * Should the file system be treated as a case sensitive one?
  +     */
  +    protected boolean isCaseSensitive = true;
  +
  +    /**
        * Constructor.
        */
       public DirectoryScanner() {
  @@ -216,7 +226,7 @@
   
       /**
        * Does the path match the start of this pattern up to the first "**".
  -     +
  +     *
        * <p>This is not a general purpose test and should only be used if you
        * can live with false positives.</p>
        *
  @@ -226,6 +236,23 @@
        * @param str     the (non-null) string (path) to match
        */
       protected static boolean matchPatternStart(String pattern, String str) {
  +        return matchPatternStart(pattern, str, true);
  +    }
  +
  +    /**
  +     * Does the path match the start of this pattern up to the first "**".
  +     *
  +     * <p>This is not a general purpose test and should only be used if you
  +     * can live with false positives.</p>
  +     *
  +     * <p><code>pattern=**\\a</code> and <code>str=b</code>
will yield true.
  +     *
  +     * @param pattern             the (non-null) pattern to match against
  +     * @param str                 the (non-null) string (path) to match
  +     * @param isCaseSensitive     must matches be case sensitive?
  +     */
  +    protected static boolean matchPatternStart(String pattern, String str,
  +                                               boolean isCaseSensitive) {
           // When str starts with a File.separator, pattern has to start with a
           // File.separator.
           // When pattern starts with a File.separator, str has to start with a
  @@ -258,7 +285,7 @@
               if (patDir.equals("**")) {
                   break;
               }
  -            if (!match(patDir,(String)strDirs.elementAt(strIdxStart))) {
  +            if (!match(patDir,(String)strDirs.elementAt(strIdxStart), isCaseSensitive))
{
                   return false;
               }
               patIdxStart++;
  @@ -288,6 +315,20 @@
        *         <code>false</code> otherwise.
        */
       protected static boolean matchPath(String pattern, String str) {
  +        return matchPath(pattern, str, true);
  +    }
  +
  +    /**
  +     * Matches a path against a pattern.
  +     *
  +     * @param pattern            the (non-null) pattern to match against
  +     * @param str                the (non-null) string (path) to match
  +     * @param isCaseSensitive    must a case sensitive match be done?
  +     *
  +     * @return <code>true</code> when the pattern matches against the string.
  +     *         <code>false</code> otherwise.
  +     */
  +    protected static boolean matchPath(String pattern, String str, boolean isCaseSensitive)
{
           // When str starts with a File.separator, pattern has to start with a
           // File.separator.
           // When pattern starts with a File.separator, str has to start with a
  @@ -320,7 +361,7 @@
               if (patDir.equals("**")) {
                   break;
               }
  -            if (!match(patDir,(String)strDirs.elementAt(strIdxStart))) {
  +            if (!match(patDir,(String)strDirs.elementAt(strIdxStart), isCaseSensitive))
{
                   return false;
               }
               patIdxStart++;
  @@ -347,7 +388,7 @@
               if (patDir.equals("**")) {
                   break;
               }
  -            if (!match(patDir,(String)strDirs.elementAt(strIdxEnd))) {
  +            if (!match(patDir,(String)strDirs.elementAt(strIdxEnd), isCaseSensitive)) {
                   return false;
               }
               patIdxEnd--;
  @@ -386,7 +427,7 @@
                   for (int j = 0; j < patLength; j++) {
                       String subPat = (String)patDirs.elementAt(patIdxStart+j+1);
                       String subStr = (String)strDirs.elementAt(strIdxStart+i+j);
  -                    if (!match(subPat,subStr)) {
  +                    if (!match(subPat,subStr, isCaseSensitive)) {
                           continue strLoop;
                       }
                   }
  @@ -413,7 +454,6 @@
       }
   
   
  -
       /**
        * Matches a string against a pattern. The pattern contains two special
        * characters:
  @@ -428,6 +468,24 @@
        *         <code>false</code> otherwise.
        */
       protected static boolean match(String pattern, String str) {
  +        return match(pattern, str, true);
  +    }
  +
  +
  +    /**
  +     * Matches a string against a pattern. The pattern contains two special
  +     * characters:
  +     * '*' which means zero or more characters,
  +     * '?' which means one and only one character.
  +     *
  +     * @param pattern the (non-null) pattern to match against
  +     * @param str     the (non-null) string that must be matched against the
  +     *                pattern
  +     *
  +     * @return <code>true</code> when the string matches against the pattern,
  +     *         <code>false</code> otherwise.
  +     */
  +    protected static boolean match(String pattern, String str, boolean isCaseSensitive)
{
           char[] patArr = pattern.toCharArray();
           char[] strArr = str.toCharArray();
           int patIdxStart = 0;
  @@ -451,21 +509,33 @@
               }
               for (int i = 0; i <= patIdxEnd; i++) {
                   ch = patArr[i];
  -                if (ch != '?' && ch != strArr[i]) {
  -                    return false; // Character mismatch
  +                if (ch != '?') {
  +                    if (isCaseSensitive && ch != strArr[i]) {
  +                        return false;// Character mismatch
  +                    }
  +                    if (!isCaseSensitive && Character.toUpperCase(ch) !=
  +                        Character.toUpperCase(strArr[i])) {
  +                        return false; // Character mismatch
  +                    }
                   }
               }
               return true; // String matches against pattern
           }
  -
  +        
           if (patIdxEnd == 0) {
               return true; // Pattern contains only '*', which matches anything
           }
   
           // Process characters before first star
           while((ch = patArr[patIdxStart]) != '*' && strIdxStart <= strIdxEnd)
{
  -            if (ch != '?' && ch != strArr[strIdxStart]) {
  -                return false;
  +            if (ch != '?') {
  +                if (isCaseSensitive && ch != strArr[strIdxStart]) {
  +                    return false;// Character mismatch
  +                }
  +                if (!isCaseSensitive && Character.toUpperCase(ch) !=
  +                    Character.toUpperCase(strArr[strIdxStart])) {
  +                    return false;// Character mismatch
  +                }
               }
               patIdxStart++;
               strIdxStart++;
  @@ -483,8 +553,14 @@
   
           // Process characters after last star
           while((ch = patArr[patIdxEnd]) != '*' && strIdxStart <= strIdxEnd) {
  -            if (ch != '?' && ch != strArr[strIdxEnd]) {
  -                return false;
  +            if (ch != '?') {
  +                if (isCaseSensitive && ch != strArr[strIdxEnd]) {
  +                    return false;// Character mismatch
  +                }
  +                if (!isCaseSensitive && Character.toUpperCase(ch) !=
  +                    Character.toUpperCase(strArr[strIdxEnd])) {
  +                    return false;// Character mismatch
  +                }
               }
               patIdxEnd--;
               strIdxEnd--;
  @@ -520,12 +596,18 @@
               int patLength = (patIdxTmp-patIdxStart-1);
               int strLength = (strIdxEnd-strIdxStart+1);
               int foundIdx  = -1;
  -strLoop:
  +            strLoop:
               for (int i = 0; i <= strLength - patLength; i++) {
                   for (int j = 0; j < patLength; j++) {
                       ch = patArr[patIdxStart+j+1];
  -                    if (ch != '?' && ch != strArr[strIdxStart+i+j]) {
  -                        continue strLoop;
  +                    if (ch != '?') {
  +                        if (isCaseSensitive && ch != strArr[strIdxStart+i+j]) {
  +                            continue strLoop;
  +                        }
  +                        if (!isCaseSensitive && Character.toUpperCase(ch) !=
  +                            Character.toUpperCase(strArr[strIdxStart+i+j])) {
  +                            continue strLoop;
  +                        }
                       }
                   }
   
  @@ -592,6 +674,15 @@
   
   
       /**
  +     * Sets the case sensitivity of the file system
  +     *
  +     * @param specifies if the filesystem is case sensitive
  +     */
  +    public void setCaseSensitive(boolean isCaseSensitive) {
  +        this.isCaseSensitive = isCaseSensitive;
  +    }
  +
  +    /**
        * Sets the set of include patterns to use. All '/' and '\' characters are
        * replaced by <code>File.separatorChar</code>. So the separator used need
        * not match <code>File.separatorChar</code>.
  @@ -808,7 +899,7 @@
        */
       protected boolean isIncluded(String name) {
           for (int i = 0; i < includes.length; i++) {
  -            if (matchPath(includes[i],name)) {
  +            if (matchPath(includes[i],name, isCaseSensitive)) {
                   return true;
               }
           }
  @@ -824,7 +915,7 @@
        */
       protected boolean couldHoldIncluded(String name) {
           for (int i = 0; i < includes.length; i++) {
  -            if (matchPatternStart(includes[i],name)) {
  +            if (matchPatternStart(includes[i],name, isCaseSensitive)) {
                   return true;
               }
           }
  @@ -840,7 +931,7 @@
        */
       protected boolean isExcluded(String name) {
           for (int i = 0; i < excludes.length; i++) {
  -            if (matchPath(excludes[i],name)) {
  +            if (matchPath(excludes[i],name, isCaseSensitive)) {
                   return true;
               }
           }
  
  
  
  1.4.4.1   +6 -0      jakarta-ant/src/main/org/apache/tools/ant/FileScanner.java
  
  Index: FileScanner.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/FileScanner.java,v
  retrieving revision 1.4
  retrieving revision 1.4.4.1
  diff -u -r1.4 -r1.4.4.1
  --- FileScanner.java	2001/01/03 14:18:26	1.4
  +++ FileScanner.java	2001/09/27 10:41:50	1.4.4.1
  @@ -152,4 +152,10 @@
        * @param includes list of include patterns
        */
       public void setIncludes(String[] includes);
  +    /**
  +     * Sets the case sensitivity of the file system
  +     *
  +     * @param specifies if the filesystem is case sensitive
  +     */
  +    public void setCaseSensitive(boolean isCaseSensitive);
   }
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.17.2.1  +14 -0     jakarta-ant/src/main/org/apache/tools/ant/types/FileSet.java
  
  Index: FileSet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/types/FileSet.java,v
  retrieving revision 1.17
  retrieving revision 1.17.2.1
  diff -u -r1.17 -r1.17.2.1
  --- FileSet.java	2001/08/01 09:08:55	1.17
  +++ FileSet.java	2001/09/27 10:41:50	1.17.2.1
  @@ -72,6 +72,7 @@
    * @author Sam Ruby <a href="mailto:rubys@us.ibm.com">rubys@us.ibm.com</a>
    * @author Jon S. Stevens <a href="mailto:jon@clearink.com">jon@clearink.com</a>
    * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
  + * @author <a href="mailto:umagesh@rediffmail.com">Magesh Umasankar</a>
    */
   public class FileSet extends DataType {
       
  @@ -80,6 +81,7 @@
   
       private File dir;
       private boolean useDefaultExcludes = true;
  +    private boolean isCaseSensitive = true;
   
       public FileSet() {
           super();
  @@ -90,6 +92,7 @@
           this.defaultPatterns = fileset.defaultPatterns;
           this.additionalPatterns = fileset.additionalPatterns;
           this.useDefaultExcludes = fileset.useDefaultExcludes;
  +        this.isCaseSensitive = fileset.isCaseSensitive;
       }
       
       
  @@ -245,6 +248,16 @@
       }
   
       /**
  +     * Sets case sensitivity of the file system
  +     *
  +     * @param isCaseSensitive "true"|"on"|"yes" if file system is case
  +     *                           sensitive, "false"|"off"|"no" when not.
  +     */
  +    public void setCaseSensitive(boolean isCaseSensitive) {
  +        this.isCaseSensitive = isCaseSensitive;
  +    }
  +
  +    /**
        * Returns the directory scanner needed to access the files to process.
        */
       public DirectoryScanner getDirectoryScanner(Project p) {
  @@ -287,6 +300,7 @@
           ds.setIncludes(defaultPatterns.getIncludePatterns(p));
           ds.setExcludes(defaultPatterns.getExcludePatterns(p));
           if (useDefaultExcludes) ds.addDefaultExcludes();
  +        ds.setCaseSensitive(isCaseSensitive);
       }
   
       /**
  
  
  

Mime
View raw message