You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by pe...@apache.org on 2004/12/17 14:06:35 UTC

cvs commit: ant/src/main/org/apache/tools/ant/util GlobPatternMapper.java RegexpPatternMapper.java

peterreilly    2004/12/17 05:06:35

  Modified:    src/main/org/apache/tools/ant/util GlobPatternMapper.java
                        RegexpPatternMapper.java
  Log:
  add casesensitive and handledirchar to globmapper and regexpmapper
  PR: 16686 and 32487
  
  Revision  Changes    Path
  1.11      +51 -2     ant/src/main/org/apache/tools/ant/util/GlobPatternMapper.java
  
  Index: GlobPatternMapper.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/util/GlobPatternMapper.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- GlobPatternMapper.java	9 Mar 2004 16:48:51 -0000	1.10
  +++ GlobPatternMapper.java	17 Dec 2004 13:06:35 -0000	1.11
  @@ -31,6 +31,7 @@
    *
    */
   public class GlobPatternMapper implements FileNameMapper {
  +
       /**
        * Part of "from" pattern before the *.
        */
  @@ -61,8 +62,33 @@
        */
       protected String toPostfix = null;
   
  +    private boolean handleDirChar = false;
  +    private boolean caseSensitive = true;
  +
  +    /**
  +     * Attribute specifing whether to ignore the difference
  +     * between / and \ (the two common directory characters).
  +     * @param handleDirChar a boolean, default is false.
  +     * @since Ant 1.6.3
  +     */
  +    public void setHandleDirChar(boolean handleDirChar) {
  +        this.handleDirChar = handleDirChar;
  +    }
  +
  +    /**
  +     * Attribute specifing whether to ignore the case difference
  +     * in the names.
  +     *
  +     * @param caseSensitive a boolean, default is false.
  +     * @since Ant 1.6.3
  +     */
  +    public void setCaseSensitive(boolean caseSensitive) {
  +        this.caseSensitive = caseSensitive;
  +    }
  +
       /**
        * Sets the "from" pattern. Required.
  +     * @param from a string
        */
       public void setFrom(String from) {
           int index = from.lastIndexOf("*");
  @@ -79,6 +105,7 @@
   
       /**
        * Sets the "to" pattern. Required.
  +     * @param to a string
        */
       public void setTo(String to) {
           int index = to.lastIndexOf("*");
  @@ -95,11 +122,13 @@
        * Returns null if the source file name doesn't match the
        * "from" pattern, an one-element array containing the
        * translated file otherwise.
  +     * @param sourceFileName the filename to map
  +     * @return a list of converted filenames
        */
       public String[] mapFileName(String sourceFileName) {
           if (fromPrefix == null
  -            || !sourceFileName.startsWith(fromPrefix)
  -            || !sourceFileName.endsWith(fromPostfix)) {
  +            || !modifyName(sourceFileName).startsWith(modifyName(fromPrefix))
  +            || !modifyName(sourceFileName).endsWith(modifyName(fromPostfix))) {
               return null;
           }
           return new String[] {toPrefix
  @@ -110,9 +139,29 @@
       /**
        * Returns the part of the given string that matches the * in the
        * "from" pattern.
  +     * @param name the source file name
  +     * @return the variable part of the name
        */
       protected String extractVariablePart(String name) {
           return name.substring(prefixLength,
                                 name.length() - postfixLength);
  +    }
  +
  +
  +    /**
  +     * modify string based on dir char mapping and case sensitivity
  +     * @param name the name to convert
  +     * @return the converted name
  +     */
  +    private String modifyName(String name) {
  +        if (!caseSensitive) {
  +            name = name.toLowerCase();
  +        }
  +        if (handleDirChar) {
  +            if (name.indexOf('\\') != -1) {
  +                name = name.replace('\\', '/');
  +            }
  +        }
  +        return name;
       }
   }
  
  
  
  1.15      +35 -2     ant/src/main/org/apache/tools/ant/util/RegexpPatternMapper.java
  
  Index: RegexpPatternMapper.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/util/RegexpPatternMapper.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- RegexpPatternMapper.java	9 Mar 2004 16:48:52 -0000	1.14
  +++ RegexpPatternMapper.java	17 Dec 2004 13:06:35 -0000	1.15
  @@ -36,6 +36,34 @@
           reg = (new RegexpMatcherFactory()).newRegexpMatcher();
       }
   
  +    private boolean handleDirChar = false;
  +    private int     regexpOptions = 0;
  +
  +    /**
  +     * Attribute specifing whether to ignore the difference
  +     * between / and \ (the two common directory characters).
  +     * @param handleDirChar a boolean, default is false.
  +     * @since Ant 1.6.3
  +     */
  +    public void setHandleDirChar(boolean handleDirChar) {
  +        this.handleDirChar = handleDirChar;
  +    }
  +
  +    /**
  +     * Attribute specifing whether to ignore the case difference
  +     * in the names.
  +     *
  +     * @param caseSensitive a boolean, default is false.
  +     * @since Ant 1.6.3
  +     */
  +    public void setCaseSensitive(boolean caseSensitive) {
  +        if (!caseSensitive) {
  +            regexpOptions = RegexpMatcher.MATCH_CASE_INSENSITIVE;
  +        } else {
  +            regexpOptions = 0;
  +        }
  +    }
  +
       /**
        * Sets the "from" pattern. Required.
        */
  @@ -63,8 +91,13 @@
        * translated file otherwise.
        */
       public String[] mapFileName(String sourceFileName) {
  +        if (handleDirChar) {
  +            if (sourceFileName.indexOf("\\") != -1) {
  +                sourceFileName = sourceFileName.replace('\\', '/');
  +            }
  +        }
           if (reg == null  || to == null
  -            || !reg.matches(sourceFileName)) {
  +            || !reg.matches(sourceFileName, regexpOptions)) {
               return null;
           }
           return new String[] {replaceReferences(sourceFileName)};
  @@ -75,7 +108,7 @@
        * groups of the source.
        */
       protected String replaceReferences(String source) {
  -        Vector v = reg.getGroups(source);
  +        Vector v = reg.getGroups(source, regexpOptions);
   
           result.setLength(0);
           for (int i = 0; i < to.length; i++) {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org