diff --git a/src/main/org/apache/tools/ant/util/GlobPatternMapper.java b/src/main/org/apache/tools/ant/util/GlobPatternMapper.java index cd257d2cb..b58c45a0e 100644 --- a/src/main/org/apache/tools/ant/util/GlobPatternMapper.java +++ b/src/main/org/apache/tools/ant/util/GlobPatternMapper.java @@ -31,6 +31,7 @@ package org.apache.tools.ant.util; * */ public class GlobPatternMapper implements FileNameMapper { + /** * Part of "from" pattern before the *. */ @@ -61,8 +62,33 @@ public class GlobPatternMapper implements FileNameMapper { */ 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 @@ public class GlobPatternMapper implements FileNameMapper { /** * Sets the "to" pattern. Required. + * @param to a string */ public void setTo(String to) { int index = to.lastIndexOf("*"); @@ -95,11 +122,13 @@ public class GlobPatternMapper implements FileNameMapper { * 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 @@ public class GlobPatternMapper implements FileNameMapper { /** * 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; + } } diff --git a/src/main/org/apache/tools/ant/util/RegexpPatternMapper.java b/src/main/org/apache/tools/ant/util/RegexpPatternMapper.java index 8ee9bb17b..e315d4f26 100644 --- a/src/main/org/apache/tools/ant/util/RegexpPatternMapper.java +++ b/src/main/org/apache/tools/ant/util/RegexpPatternMapper.java @@ -36,6 +36,34 @@ public class RegexpPatternMapper implements FileNameMapper { 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 @@ public class RegexpPatternMapper implements FileNameMapper { * 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 @@ public class RegexpPatternMapper implements FileNameMapper { * 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++) {