Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ant convert path separator

Tags:

path

ant

Within an ant file, I am trying to convert windows style path separators to unix style. I have the following:

<path id="basedir.path">
    <!-- ${basedir} is a project attribute. -->
    <pathelement path="${basedir}" />
</path>
<pathconvert property="adjusted_basedir" refid="basedir.path">
    <mapper>
        <globmapper from="*" to="*" handledirsep="yes"/>
    </mapper>
</pathconvert>
<echo level="verbose" message="Basedir: ${basedir}" /> 
<echo level="verbose" message="Adj Basedir: ${adjusted_basedir}" />

but the output of adjusted_basedir is the same as basedir. I have tried using

<mapper type="regexp" from="\\" to="/" />

but then the output of adjusted_basedir is simply "/". How do I convert path separators from windows to unix style? I want to avoid using add-ons to ant for this (so ant-contrib is out).

like image 759
Jon Avatar asked Aug 15 '26 09:08

Jon


1 Answers

Try using a filtermapper:

<pathconvert property="adjusted_basedir" refid="basedir.path">
    <filtermapper>
        <replacestring from="\" to="/" />
    </filtermapper>
</pathconvert>

See https://ant.apache.org/manual/Types/mapper.html.

There is also an attribute to do this in the pathconvert task:

<pathconvert property="adjusted_basedir" refid="basedir.path" dirsep="/" />
like image 192
M A Avatar answered Aug 19 '26 01:08

M A



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!