You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Craig Goss <cg...@madriver.com> on 2003/01/13 18:18:29 UTC

ant apply and file.separator

It doesn't appear that there's an easy way to convert file separators from
'\' to '/' within an Ant apply task.  Am I wrong about that?

The following invokes an executable compiled under Cygwin on Windows XP.
Java knows I'm a Windows user and always returns a backslash in the
<sourcefile> and <targetfile> parameters which isn't OK with Cygwin which
expects unix format forward slashes.  The obvious thing is to convert the
slashes before calling my executable ... simple, right?  If so, I'm having
trouble saying how.

The simplest fix would be to tell Ant and/or Java that file.separator is
actually '/' prior to invocation.  Perhaps I'm being dense here, but I don't
seem to be able to make this work.  I've set 'ANT_OPS=-Dfile.separator=/' to
no effect.  Perhaps I'm doing something incorrectly?

The other easy solution would be to supply throw in a <pathconvert> but far
as I can tell that isn't allowed inside an <apply>.  A <mapper> allows me to
fudge the format to some extent but it isn't flexible enough.  The 'glob'
type only allows a single '*' for myriad of different path configuration, so
that isn't good enough. The 'regexp' type is another possibility but unless
I'm missing something Ant's regex implementation doesn't offer a means to
globally replace every '\' with '/'.

Suggestions anyone?

  <target name="translate_xml" depends="init, configure">
  <echo message="translate_xml"/>
  <apply executable="${cygwin.path}/bin/bash.exe" dir="${src.dir}"
relative="true" dest="${src.dir}" vmlauncher="true">
    <arg value="-c"/>
    <!-- quote insures that ':' in path isn't misinterpeted by cygwin
bash'-->
    <arg value="&quot;${cygwin.path}/usr/local/bin/xsltproc"/>
    <arg value="-o"/>
    <targetfile/>
    <arg value="xml/stylesheets/copyxml.xsl"/>
    <srcfile/>
    <!-- end quote-->
    <arg value="&quot;"/>
    <fileset dir="${src.dir}" id="templates.id">
      <include name="xml/templates/**/*.xml"/>
    </fileset>
    <mapper type="glob" from="xml\templates\*.xml"
to="xmlgen/translations/*.xml"/>
    </apply>
  </target>

For the record, I also tried this using 'foreach' from the contrib.  Once
again path manipulations are hampered by the fact that <pathconvert> is not
allowed.  I'd prefer to stick with <apply> if there's any way to do it, but
other solutions that process multiple files in varying formats ... and allow
path conversion ... are appreciated.




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: ant apply and file.separator

Posted by Stefan Bodewig <bo...@apache.org>.
On Tue, 14 Jan 2003, Craig Goss <cg...@madriver.com> wrote:

> In case that hint was aimed at me ;^) ...

Nah 8-)

> PS. Sitting here in blissful ignorance it occurs to me that it might
> be easy to add support for an existing task <pathconvert> to <apply>
> and <cvs>.

I happen to think the opposite is true, it isn't really that difficult
to add a new attribute (one method and one private boolean) and do a
replace('\\', '/') on all stuff that is know to be a filename if that
boolean is true.

Embedding a <pathconvert> is not any more difficult than adding a
method, but making it do something useful is a completely different
issue.

Stefan

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: ant apply and file.separator

Posted by Craig Goss <cg...@madriver.com>.
In case that hint was aimed at me ;^) ... I'm going to beg off as I'm on a
tighter than tight schedule that won't allow for distractions.  I have a
temporary work-around that functions as long as it is invoked from a Cygwin
shell.  It screws up my seamless build since Cygwin's not my day-to-day work
environment (I'm using Eclipse), but this is the fastest way from point A to
point B for the time being.

PS. Sitting here in blissful ignorance it occurs to me that it might be easy
to add support for an existing task <pathconvert> to <apply> and <cvs>.  No
doubt you have your reasons for suggesting a new attribute, but it leaves me
wondering how your solution would be different from / easier to implement
than support for <pathconvert>.  I'm not very familiar with Ant's source
code and am just tuning in to the news group, so forgive me if there's a
heap-o-reasons why the approach you suggest would be better.

Thanks Stefan and I'd love to hear about it if that attribute comes to pass.

-----Original Message-----
From: Stefan Bodewig [mailto:bodewig@apache.org]
Sent: Tuesday, January 14, 2003 2:19 AM
To: ant-user@jakarta.apache.org
Subject: Re: ant apply and file.separator


On Mon, 13 Jan 2003, Craig Goss <cg...@madriver.com> wrote:

> The following invokes an executable compiled under Cygwin on Windows
> XP.  Java knows I'm a Windows user and always returns a backslash in
> the <sourcefile> and <targetfile> parameters which isn't OK with
> Cygwin which expects unix format forward slashes.

A very similar issue has been brought up for Cygwin's version of CVS
and some cvs tasks in Ant on cactus-dev.  I'm contemplating on a
unixstyle attribute that would force Ant to use forward slashes in
those tasks (and could extend it to <apply> as well).

Could become reality faster if anybody wants to lend a hand 8-)

Stefan

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: ant apply and file.separator

Posted by Stefan Bodewig <bo...@apache.org>.
On Mon, 13 Jan 2003, Craig Goss <cg...@madriver.com> wrote:

> The following invokes an executable compiled under Cygwin on Windows
> XP.  Java knows I'm a Windows user and always returns a backslash in
> the <sourcefile> and <targetfile> parameters which isn't OK with
> Cygwin which expects unix format forward slashes.

A very similar issue has been brought up for Cygwin's version of CVS
and some cvs tasks in Ant on cactus-dev.  I'm contemplating on a
unixstyle attribute that would force Ant to use forward slashes in
those tasks (and could extend it to <apply> as well).

Could become reality faster if anybody wants to lend a hand 8-)

Stefan

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: ant apply and file.separator

Posted by Craig Goss <cg...@madriver.com>.
1. Doesn't ${file.separator} just pick up the system file.separator for the
platform?  For example, if I'm running on Windows, the system separator is
'\', so <arg
value="xml${file.separator}stylesheets${file.separator}copyxml.xsl"/> will
turn out to be exactly the opposite of what I want?  I examined Ant's shell
file and it does accommodate Cygwin at launch by modifying path formats to
use forward slashes, but as far as I can tell there's no residual effect
once Ant is running.  Just to make sure I wasn't crazy I tried your
suggestion and the result matched my expectations ... back slashes instead
of forward slashes.

2. You can only use ${file.separator} when you're specifying a path in the
build file.  Ant's <apply> task executes an operation for each file in a
file set.  It constructs the path for the individual files with the help of
a few hints from a <mapper>.  At execution time you can change specify the
location of the file names in an argument list, but there doesn't appear to
be any way to modify the parameters (<sourcefile> and <targetfile>).

    <!-- can't modify targetfile since because
         it is pre-determined by the apply task
    -->
    <arg value="-o"/>
    <targetfile/>

In summary, I can see how ${file.separator} is a good solution when
switching between platforms, but the property has to be right to begin with
in order for it to work.  In this case I'm running on a Windows platform but
the executable expects that all paths will be in Unix format.  Since Ant
doesn't really know that, it doesn't make any accommodation.  It seems to me
that Ant often allows for this kind of thing by allowing the developer to
use <pathconvert> etc, but in the case of <apply> that's not allowed.

-----Original Message-----
From: Elizabeth Cooper [mailto:ecooper@ergotech.com]
Sent: Monday, January 13, 2003 12:36 PM
To: Ant Users List
Subject: Re: ant apply and file.separator


Try this:

Instead of "hard-coding" the slash in the ant code, use ${file.separator}.
It makes the statement longer but always works.

For example instead of:
${cygwin.path}/bin/bash.exe

you type:
${cygwin.path}${file.separator}bin${file.separator}bash.exe






--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: ant apply and file.separator

Posted by Elizabeth Cooper <ec...@ergotech.com>.
Try this:

Instead of "hard-coding" the slash in the ant code, use ${file.separator}. 
It makes the statement longer but always works.

For example instead of:
${cygwin.path}/bin/bash.exe

you type:
${cygwin.path}${file.separator}bin${file.separator}bash.exe


At 12:18 PM 1/13/2003 -0500, you wrote:
>It doesn't appear that there's an easy way to convert file separators from
>'\' to '/' within an Ant apply task.  Am I wrong about that?
>
>The following invokes an executable compiled under Cygwin on Windows XP.
>Java knows I'm a Windows user and always returns a backslash in the
><sourcefile> and <targetfile> parameters which isn't OK with Cygwin which
>expects unix format forward slashes.  The obvious thing is to convert the
>slashes before calling my executable ... simple, right?  If so, I'm having
>trouble saying how.
>
>The simplest fix would be to tell Ant and/or Java that file.separator is
>actually '/' prior to invocation.  Perhaps I'm being dense here, but I don't
>seem to be able to make this work.  I've set 'ANT_OPS=-Dfile.separator=/' to
>no effect.  Perhaps I'm doing something incorrectly?
>
>The other easy solution would be to supply throw in a <pathconvert> but far
>as I can tell that isn't allowed inside an <DEFANGED_apply>.  A <mapper> 
>allows me to
>fudge the format to some extent but it isn't flexible enough.  The 'glob'
>type only allows a single '*' for myriad of different path configuration, so
>that isn't good enough. The 'regexp' type is another possibility but unless
>I'm missing something Ant's regex implementation doesn't offer a means to
>globally replace every '\' with '/'.
>
>Suggestions anyone?
>
>   <target name="translate_xml" depends="init, configure">
>   <echo message="translate_xml"/>
>   <DEFANGED_apply executable="${cygwin.path}/bin/bash.exe" dir="${src.dir}"
>relative="true" dest="${src.dir}" vmlauncher="true">
>     <arg value="-c"/>
>     <!-- quote insures that ':' in path isn't misinterpeted by cygwin
>bash'-->
>     <arg value="&quot;${cygwin.path}/usr/local/bin/xsltproc"/>
>     <arg value="-o"/>
>     <targetfile/>
>     <arg value="xml/stylesheets/copyxml.xsl"/>
>     <srcfile/>
>     <!-- end quote-->
>     <arg value="&quot;"/>
>     <fileset dir="${src.dir}" id="templates.id">
>       <include name="xml/templates/**/*.xml"/>
>     </fileset>
>     <mapper type="glob" from="xml\templates\*.xml"
>to="xmlgen/translations/*.xml"/>
>     </apply>
>   </target>
>
>For the record, I also tried this using 'foreach' from the contrib.  Once
>again path manipulations are hampered by the fact that <pathconvert> is not
>allowed.  I'd prefer to stick with <DEFANGED_apply> if there's any way to 
>do it, but
>other solutions that process multiple files in varying formats ... and allow
>path conversion ... are appreciated.
>
>
>
>
>--
>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>