You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by didge <di...@foundrylogic.com> on 2003/12/31 19:53:51 UTC

cygpath task

Folks,

The $ANT_HOME/bin/ant shell script automatically converts a number of paths
from cygwin to windows when executed in a cygwin shell, including JAVA_HOME,
CLASSPATH, ANT_HOME, and CYGHOME.

However, there are often paths defined in my cygwin shell that also need to
be converted.  To this end, I've written a task to convert cygwin paths to
windows paths, but only when executed in a cygwin shell.  Below is a
detailed description and example.

Is this something of general interest to ant users?

It works like this:

  <cygpath properties="[properties]"/>

where [properties] is a comma separated list of properties containing simple
or compound cygwin paths.  The value of each property is converted in place.

Here is an example that demonstrates the task with both a simple and a
compound path:

<project name="cygpath example" default="cygpath">
  <taskdef name="cygpath" classname="foundrylogic.cyg.task.Cygpath"/>
  <target name="cygpath">
    <property name="somepath0" value="/cygdrive/c/foo"/>
    <property name="somepath1" value="/cygdrive/c/bar:/cygdrive/c/oof"/>

    <echo message="before cygpath:"/>
    <echo message="somepath0='${somepath0}'"/>
    <echo message="somepath1='${somepath1}'"/>

    <cygpath properties="somepath0, somepath1"/>

    <echo message="after cygpath:"/>
    <echo message="somepath0='${somepath0}'"/>
    <echo message="somepath1='${somepath1}'"/>

  </target>
</project>

Here is the output after running it:

Buildfile: build.xml

cygpath:
     [echo] before cygpath:
     [echo] somepath0='/cygdrive/c/foo'
     [echo] somepath1='/cygdrive/c/bar:/cygdrive/c/oof'
     [echo] after cygpath:
     [echo] somepath0='c:\foo'
     [echo] somepath1='c:\bar;c:\oof'

BUILD SUCCESSFUL

A couple of other notes:
- Cygpath modifies the value of the user properties given to it.
- Cygpath only executes when run in a cygwin shell.  If run from a dos shell
or a non-cygwin unix shell, Cygpath does nothing.  Detection of the cygwin
shell is based on the property cygwin.user.home being defined by the
$ANT_HOME/bin/ant script.  If this property is not defined, then Cygpath is
effectively a no-op.
- Cygpath delegates the actual conversion to the cygpath executable, so
cygpath must be in your PATH.


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