ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 26901] New: - regex with file mapper incorrectly handles ${file.separator}
Date Thu, 12 Feb 2004 22:46:51 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=26901>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=26901

regex with file mapper incorrectly handles ${file.separator}

           Summary: regex with file mapper incorrectly handles
                    ${file.separator}
           Product: Ant
           Version: 1.6.0
          Platform: PC
        OS/Version: Windows XP
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: Core
        AssignedTo: dev@ant.apache.org
        ReportedBy: rxh@gers.com


The documentation for <mapper> states: 
"Note that Ant will not automatically convert / or \ characters in the to and
from attributes to the correct directory separator of your current platform. If
you need to specify this separator, use ${file.separator} instead."

We are using <mapper type="regex"> to copy a directory structure that looks like
this:
/Root/
  /sub1/
    /src/scripts/files..
  /sub2/
    /src/scripts/files..
  /sub3/
    /src/scripts/files..
  /sub4/
    /src/scripts/files..

to this:
/NewRoot/
  /sub1/
    /files..
  /sub2/
    /files..
  /sub3/
    /files..
  /sub4/
    /files..

To do it we are using <mapper> with <copy> like this:
<copy todir="NewRoot">
  <mapper type="regexp" 
    from="(.*?).src.scripts.(.*)" 
    to="\1${file.separator}\2"/> 
  <fileset dir="Root">
    <include name="**/src/scripts/*"/>
  </fileset>
</copy>

The problem happens with the ${file.separator}, we expect the results as stated
above, what we are actually getting is this:
/NewRoot/
  /sub1/
    /2
  /sub2/
    /2
  /sub3/
    /2
  /sub4/
    /2
(the 2's are files)
If we modify the mapper's "to" regex to this:
  to="\1${file.separator}${file.separator}\2"

The results are what we expect.  I believe the problem lies in the handling of
regular expressions and how ant is using substitution.  We are on a windows
machine, so the "to" regex (in the buggy case) will resolve to something like
this before sending the regular expression off to Java (using the standard Reg
ex handling with Java 1.4):
  sub1\\2

Java then interprets the 2 "\"s to be a literal "\" and ant is then left to map
everything to the filename "2".

Let me know if you need more information.

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


Mime
View raw message