1

I tried to use ants loadproperties with expandproperties: This works for simple text properties but i get weird results when a property contains a windows path.

<property name="myAntFile" value="${ant.file}" />

<loadproperties srcFile="my.properties">
    <filterchain>
        <expandproperties />
    </filterchain>
</loadproperties>

<echo message="$${external} = ${external}"  />

the properties file looks like this:

external=${myAntFile}

the result is:

Buildfile: C:\projects\trunk\build.xml
...
[echo] ${external} = C:projects\trunkbuild.xml

I know that for properties files there are escape rules for backslashes and special whitespace characters. However i dont see how i can translate the buildscripts properties to that special meaning.

Anyone has a idea how to solve that or is this a ant bug (maybe the expandproperties chain should get a additional property for escaping when used in property file contexts?)?

Community
  • 1
  • 1
dag
  • 1,133
  • 12
  • 25
  • What exactly is the problem and what are your trying to accomplish? Do the Windows paths cause trouble only when echoing them or do they not work when determining files/directories/etc.? – bassim Oct 30 '14 at 10:36

1 Answers1

0

With ant you can use a forward slash / as the path separator when defining paths, even on Windows: C:/projects/trunk/build.xml

If ${ant.file} returns the path using backslashes, convert this path first before you load the properties file.

Unfortunately I haven't yet found the definitive way to convert paths from C:\a\path to C:/a/path and back. Supposedly pathconvert can do the trick...

<pathconvert targetos="unix" property="myAntFile.withForwardSlashes">
    <path location="${myAntFile}"/>
</pathconvert>

... but it confuses relative and absolute paths and I couldn't make it work while testing this on my OS X machine.

bassim
  • 886
  • 1
  • 21
  • 33
  • Thanks for your answer. I know that forward slashes are working on Windows too, but i was looking for a general solution. The ${ant.file} property is just a example. In my build process there are literaly dozens of file base properties, some of wich my build script doesn't even know about, so trying to convert them just in case a user maintained property file uses them is futile. And even if I try the property file editor has to know about that special handling... – dag Oct 30 '14 at 09:30
  • I see. Nevertheless, the general solution must be to automatically convert Windows paths, because usually it is easier to convert them before using them in a situation where the backslashes cause trouble than to try to suppress the escaping of backslashes in those situations. – bassim Oct 30 '14 at 10:34
  • Yea after all this is not just related to windwos paths, it's about all Strings that somehow contain character sequences that need to be escaped in property files. Expandproperties in this situation is by no means a text replacement as one expects... – dag Oct 30 '14 at 16:37