1

I don't want to use propertyregex in the AntContrib task, but I need to modify a property. I am using the cabarc command (I can't get the <cab> task to work), and I need to strip out the drive name.

${basedir} = "D:\some\directory\blah\blah"
${cwd} = some\directory\blah\blah"

I need this in order to strip out the path in cabarc (but still using directories). I've ended up doing the following:

<!-- Create a property set with just basedir -->
<!-- Needed for loadproperties to work -->

<propertyset id="cwd">
    <propertyref name="basedir"/>
</propertyset>

<loadproperties>
     <propertyset refid="cwd"/>
     <filterchain>
         <tokenfilter>
              <replaceregex pattern=".:\\"
                   replace="cwd="/>
         </tokenfilter>
     </filterchain>
</loadproperties>

That works, but it's a little complex and will be hard to maintain.

Is there an easier way to do this?

David W.
  • 105,218
  • 39
  • 216
  • 337
  • Other ways in a similar question: [Ant loadfile override property](http://stackoverflow.com/questions/5358525/ant-loadfile-override-property/10717634#10717634) – Jarekczek May 23 '12 at 10:30

1 Answers1

1

get into the groove ;-)

<groovy>
properties.'cwd' = properties.'basedir'[3..-1]
</groovy>

or with Ant Plugin Flaka :

<project xmlns:fl="antlib:it.haefelinger.flaka" name="World">
  <!-- simple echo -->
  <fl:echo>#{replace('${basedir}', '$1' , '.:\\\\(.+)' )}</fl:echo>
  <!-- set property -->
  <fl:let>cwd := replace('${basedir}', '$1' , '.:\\\\(.+)' )</fl:let>
</project>

Disclosure = i'm participating as committer in the Flaka project

Rebse
  • 10,307
  • 2
  • 38
  • 66
  • I guess it's time to learn groovy. I don't want to use Ant Plugin Flaka for the same reason I don't want to use AntContrib if I don't have to. – David W. Jun 17 '11 at 18:51
  • you won't regret learning groovy. It's useful in ant as it has its own task beside – Rebse Jun 17 '11 at 19:27