0

In Ant, does anyone know of a concise way to go about having a build.xml fail if, when copying a file, token replacement for a particular token does not occur. I.e., the token was not found in the file, and thus was not replaced.

The idea behind this is that in certain circumstances it may be crucial for a tokenised file to have certain tokens replaced, and so it's worth validating that those tokens exist in the file to begin with - by default Ant would just do nothing if the token isn't there.

I've looked at the docs for filter and filterset but they don't seem to have an attribute for failing if the token searched for is not present.

Perhaps this could be done with a regex task to check if the token is present. Are there any neater ways people can think of?

AlBlue
  • 23,254
  • 14
  • 71
  • 91
Rhys
  • 1,439
  • 1
  • 11
  • 23

1 Answers1

2

you could definitely do like this:

ant filtering - fail if property not set

<loadfile property="all-build-properties" srcFile="build.properties"/>
<condition property="missing-properties">
    <matches pattern="@[^@]*@" string="${all-build-properties}"/>
</condition>
<fail message="Some properties not set!" if="missing-properties"/>

All rights to Jason Day

dovetalk solutions is fine too:

<fail unless="my.property">
    Computer says no. You forgot to set 'my.property'!
</fail>
Community
  • 1
  • 1
Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
  • this is neat and with no regex :) – acostache Dec 19 '12 at 19:43
  • This isn't quite what i'm after. I really need the token to first be found, and then replaced. Both of those things must be true. If either of those things is not true, the build must FAIL, which this also doesn't account for. Thanks anyway. – Rhys Dec 19 '12 at 23:39