https://issues.apache.org/bugzilla/show_bug.cgi?id=46506
Summary: Unexpected results from globmapper
Product: Ant
Version: 1.7.1
Platform: PC
OS/Version: Windows XP
Status: NEW
Severity: normal
Priority: P2
Component: Core
AssignedTo: [email protected]
ReportedBy: [email protected]
In a build process, I want to move a file named in the pattern of a-[x.x].jar
to a.jar, where [x.x] is a version number of the library. I used the following
globmapper as a nested element in the move task.
<mapper type="glob" from="a*.jar" to="a.jar"/>
I would expect the result as a.jar. Instead, it turns out to be a.jar-[x.x].
I looked into the source code and found that the code always expect the
variable part also exists in the "to" file name. Not sure if it is by design
spec or just a missing case.
The fix should be easy by introducing a flag: hasVarInTo initialized to true.
Then modify the two methods as following.
public void setTo(String to) {
int index = to.lastIndexOf("*");
if (index == -1) {
toPrefix = to;
toPostfix = "";
hasVarInTo = false; // THIS IS ADDED FOR THE FIX
} else {
toPrefix = to.substring(0, index);
toPostfix = to.substring(index + 1);
}
}
public String[] mapFileName(String sourceFileName) {
if (fromPrefix == null
|| !modifyName(sourceFileName).startsWith(modifyName(fromPrefix))
|| !modifyName(sourceFileName).endsWith(modifyName(fromPostfix))) {
return null;
}
return new String[] {toPrefix
+ (hasVarInTo?
extractVariablePart(sourceFileName)
+ toPostfix : "")}; // THIS IS MODIFIED TO
// FIX THE ISSUE
}
For the "from" part, we can always assume there will be a variable since it is
what globmapper is used for.
If it is by design spec, it should be noted in the document at the minimum.
Thanks,
Feng
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.