|
@@ -31,6 +31,7 @@ package org.apache.tools.ant.util; |
|
|
* |
|
|
* |
|
|
*/ |
|
|
*/ |
|
|
public class GlobPatternMapper implements FileNameMapper { |
|
|
public class GlobPatternMapper implements FileNameMapper { |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Part of "from" pattern before the *. |
|
|
* Part of "from" pattern before the *. |
|
|
*/ |
|
|
*/ |
|
@@ -61,8 +62,33 @@ public class GlobPatternMapper implements FileNameMapper { |
|
|
*/ |
|
|
*/ |
|
|
protected String toPostfix = null; |
|
|
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. |
|
|
* Sets the "from" pattern. Required. |
|
|
|
|
|
* @param from a string |
|
|
*/ |
|
|
*/ |
|
|
public void setFrom(String from) { |
|
|
public void setFrom(String from) { |
|
|
int index = from.lastIndexOf("*"); |
|
|
int index = from.lastIndexOf("*"); |
|
@@ -79,6 +105,7 @@ public class GlobPatternMapper implements FileNameMapper { |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Sets the "to" pattern. Required. |
|
|
* Sets the "to" pattern. Required. |
|
|
|
|
|
* @param to a string |
|
|
*/ |
|
|
*/ |
|
|
public void setTo(String to) { |
|
|
public void setTo(String to) { |
|
|
int index = to.lastIndexOf("*"); |
|
|
int index = to.lastIndexOf("*"); |
|
@@ -95,11 +122,13 @@ public class GlobPatternMapper implements FileNameMapper { |
|
|
* Returns null if the source file name doesn't match the |
|
|
* Returns null if the source file name doesn't match the |
|
|
* "from" pattern, an one-element array containing the |
|
|
* "from" pattern, an one-element array containing the |
|
|
* translated file otherwise. |
|
|
* translated file otherwise. |
|
|
|
|
|
* @param sourceFileName the filename to map |
|
|
|
|
|
* @return a list of converted filenames |
|
|
*/ |
|
|
*/ |
|
|
public String[] mapFileName(String sourceFileName) { |
|
|
public String[] mapFileName(String sourceFileName) { |
|
|
if (fromPrefix == null |
|
|
if (fromPrefix == null |
|
|
|| !sourceFileName.startsWith(fromPrefix) |
|
|
|
|
|
|| !sourceFileName.endsWith(fromPostfix)) { |
|
|
|
|
|
|
|
|
|| !modifyName(sourceFileName).startsWith(modifyName(fromPrefix)) |
|
|
|
|
|
|| !modifyName(sourceFileName).endsWith(modifyName(fromPostfix))) { |
|
|
return null; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
return new String[] {toPrefix |
|
|
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 |
|
|
* Returns the part of the given string that matches the * in the |
|
|
* "from" pattern. |
|
|
* "from" pattern. |
|
|
|
|
|
* @param name the source file name |
|
|
|
|
|
* @return the variable part of the name |
|
|
*/ |
|
|
*/ |
|
|
protected String extractVariablePart(String name) { |
|
|
protected String extractVariablePart(String name) { |
|
|
return name.substring(prefixLength, |
|
|
return name.substring(prefixLength, |
|
|
name.length() - postfixLength); |
|
|
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; |
|
|
|
|
|
} |
|
|
} |
|
|
} |