peterreilly 2005/01/28 02:06:25
Modified: src/main/org/apache/tools/ant/util Tag: ANT_16_BRANCH
GlobPatternMapper.java RegexpPatternMapper.java
Log:
OPPS: forgot to sync the casesensivity and dirchar glob/regexp mapper support
Revision Changes Path
No revision
No revision
1.6.2.5 +51 -3
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.6.2.4
retrieving revision 1.6.2.5
diff -u -r1.6.2.4 -r1.6.2.5
--- GlobPatternMapper.java 9 Mar 2004 17:01:57 -0000 1.6.2.4
+++ GlobPatternMapper.java 28 Jan 2005 10:06:24 -0000 1.6.2.5
@@ -1,5 +1,5 @@
/*
- * Copyright 2000,2002,2004 The Apache Software Foundation
+ * Copyright 2000,2002,2004-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -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,28 @@
/**
* 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.10.2.5 +49 -3
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.10.2.4
retrieving revision 1.10.2.5
diff -u -r1.10.2.4 -r1.10.2.5
--- RegexpPatternMapper.java 9 Mar 2004 17:01:57 -0000 1.10.2.4
+++ RegexpPatternMapper.java 28 Jan 2005 10:06:24 -0000 1.10.2.5
@@ -1,5 +1,5 @@
/*
- * Copyright 2000,2002-2004 The Apache Software Foundation
+ * Copyright 2000,2002-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,12 +32,46 @@
protected char[] to = null;
protected StringBuffer result = new StringBuffer();
+ /**
+ * Constructor for RegexpPatternMapper.
+ * @throws BuildException on error.
+ */
public RegexpPatternMapper() throws BuildException {
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.
+ * @param from the from pattern.
+ * @throws BuildException on error.
*/
public void setFrom(String from) throws BuildException {
try {
@@ -52,6 +86,8 @@
/**
* Sets the "to" pattern. Required.
+ * @param to the to pattern.
+ * @throws BuildException on error.
*/
public void setTo(String to) {
this.to = to.toCharArray();
@@ -61,10 +97,18 @@
* 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 source file name
+ * @return a one-element array containing the translated file or
+ * null if the to pattern did not match
*/
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)};
@@ -73,9 +117,11 @@
/**
* Replace all backreferences in the to pattern with the matched
* groups of the source.
+ * @param source the source file name.
+ * @return the translated file name.
*/
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]