ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gilbert Rebhan <gil...@maksimo.de>
Subject Re: Change property value
Date Fri, 18 Feb 2011 23:26:51 GMT
-------- Original Message  --------
Subject: Change property value
From: shaffic <safic4u@gmail.com>
To: user@ant.apache.org
Date: Fri Feb 18 2011 14:24:22 GMT+0100 (CET)

> 
> is the any alter method to change the property value which is initializd
> 
> Thanks
> Shaffic

In core ant properties are immutable - for good reasons.
But there are circumstances where property immutability is cumbersome.

solution 1, use some ant plugin :

many people used antcontrib for that purpose, but antcontrib development
has stopped in 2006, i recommend an up-to-date alternative with very
innovative features => flaka [1]

<project xmlns:fl="antlib:it.haefelinger.flaka">
<fl:install-property-handler />

<property name="foo" value="bar"/>

<target name="main">
  <fl:let>
    <!-- define a variable -->
    myvariable = 'whatever'
    <!-- define a new property -->
    myproperty := 'somevalue'
    <!-- overwrite existing property -->
    foo        ::= 'baz'
  </fl:let>

  <echo>
  myvariable => #{myvariable}
  myproperty => ${myproperty}
  foo        => ${foo}
  </echo>
  </target>
</project>

solution 2, use some scripting language running in JVM
and make use of ant api. Groovy [2] recommended, because IMO (after
using javascript/rhino and jruby in ant before) groovy has the best
compatibility to java and the <groovy> task is great

<project>
<taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy"/>
<property name="foo" value="bar"/>

<target name="main">
 <groovy>
  <!-- define a new property -->
  properties.'myproperty' = 'somevalue'
  <!-- overwrite existing property -->
  properties.'foo' = 'baz'
 </groovy>

  <echo>
  myproperty => ${myproperty}
  foo        => ${foo}
  </echo>
 </target>
</project>


[1] flaka  http://code.google.com/p/flaka/
[2] groovy http://groovy.codehaus.org/


Regards, Gilbert



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message