tags:

views:

42

answers:

2

Hi I'm having an issue with writing out a property which holds the value of a directory path into a property file.

My script originally reads in this particular property, call it 'appserver.home', from a props file using the <property file="source.props"/>. I've echoed the value coming in and it reads correctly as *C\:\\somedir\\jboss_4_2_3.*

What my script needs to do next is provide this value to another properties file (used by another ant script - though that's not important). To create this other file I'm using a kind off template file with place holders surrounded by $....$ to insert the correct values in the correct place, using the following :-

 <copy file="template_file.props" tofile="target.props">
    <filterset begintoken="$" endtoken="$">
        <filter token="appServerDir" value="${appserver.home}"/>
        <filter token="dbusername" value="${database.name}"/>
        ....
    </filterset>
 </copy>                

The problem is that the value now in the target.props is *C:\somedir\jboss_4_2_3* ie it's lost the escape characters. When the next ant script uses this file it interprets the property value as *C:somedirjboss_4_2_3*.

So the question how do I tell ant that the value I'm writing is a file path ? Note I have tried the following, which actually works :-

<propertyfile file="target.props">
    <entry key="appServerDir" value="${appserver.home}"/>
</propertyfile>

.. ie it outputs the name as *c\:\\somedir\\jboss4_2_3*, but I'd rather not use this technique and rather use the template file technique, as it contains some properties which are always static, as well as comments etc.

Thanks in advance

A: 

I just tested the following using Eclipse integrated ant support:

         <copy file="test.props" tofile="target.props">
        <filterset begintoken="$" endtoken="$">
            <filter token="appServerDir" value="C\:\\somedir\\jboss_4_2_3"/>
        </filterset>
     </copy> 

and it generates the following file:

C\:\\somedir\\jboss_4_2_3

What ant version are you using ?

Manuel Selva
I'm using ant 1.7.1. But your example is slightly different to mine as you're passing in the value directly ie hardcoded.- have you tried setting some property, and passing in the value of that instead ?
Neil
@Neil Yes I tried and the output is the same: C\:\\somedir\\jboss_4_2_3
Manuel Selva
@Manuel - what version of ant are you using with Eclipse ?
Neil
@Neil <echo>${ant.version}</echo> print: Apache Ant version 1.7.1 compiled on June 27 2008
Manuel Selva
@Manuel - Thanks for trying to help out. But - I get the same exact output as you for Ant version, yet different behaviour. When I do <property name="blah" value="C\:\\somedir\\jboss_4_2_3"/> and pass this into the filterset, it is still written out as C:\somedir\jboss_4_2_3 - which for my requirements is wrong because I do not want lose the escape characters. I guess the only difference is that, it sounds like, you're running with eclipse - whereas I'm running from the command prompt. Have you tried doing this yourself ?
Neil
Yes it also works from command line. How do you check the output file content ? (Which editor ?). Are you on Windows or Linux ? Are you sure that before calling the file copy the variable content is ok ?
Manuel Selva
I'm running on Windows. I've tried setting dummy properties directly before the copy and the result is always the same. It's not just viewing the output file that I see the problem, the ant script which runs after the file is generated cannot read the directory path in correctly because the escape '\' characters are missing.
Neil
A: 

As a workaround, you could also write your initial property using forward slashes as C:/somedir/jboss_4_2_3, which should need no escape characters.

Jörn Horstmann
That would work, but unfortunately I don't have control of the process that creates the initial property file (!). Thanks.
Neil