You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Ravi Roy <ra...@gmail.com> on 2008/01/29 09:52:42 UTC

How to set a new property based on value of another property in Ant ?

Hi All,

I want to set a property based on a value of the other property in my
build script :

Already defined property in a build file :

 <property foo.1="prop.1" value="xx" />

Want to set another property based on the value of this property like.

  <property foo.2="prop2. value="x.x" />

Which means addding  "." character after first character in the value
of foo.1 property.

Is it possible in ant ?

Thanks for pointers.

Regards,
Ravi.

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


Re: How to set a new property based on value of another property in Ant ?

Posted by Matt Benson <gu...@yahoo.com>.
You might also see whether you get any use out of the
props sandbox antlib, which requires a svn trunk
(v1.8.x) build of Ant.

-Matt

--- Ravi Roy <ra...@gmail.com> wrote:

> Thanks Jan, I created my own task and integrated
> into my build
> process, but initial reason to ask this to the group
> was that if Ant
> has a standard way to achieve this then why I should
> create seperate
> task, at last for my own task I have to maintain and
> document the
> same, which would not have been the case in case of
> standard Ant task
> ;-)
> 
> Thanks again for your help.
> 
> Regards,
> Ravi.
> 
> On 1/29/08, Jan.Materne@rzf.fin-nrw.de
> <Ja...@rzf.fin-nrw.de> wrote:
> > I dont know any task.
> > Which means: implement your own ;)
> >
> > Jan
> >
> >
> > <project>
> >
> >  <scriptdef name="insert" language="javascript">
> >      <!-- the string where to insert -->
> >      <attribute name="input"/>
> >      <!-- the string to insert -->
> >      <attribute name="string"/>
> >      <!-- the position where to insert -->
> >      <attribute name="position"/>
> >      <!-- property name for the result -->
> >      <attribute name="property"/>
> >      <![CDATA[
> >          // Access to attributes
> >          pos      = attributes.get("position");
> >          input    = attributes.get("input");
> >          property = attributes.get("property");
> >          str      = attributes.get("string");
> >
> >          // Compute new value
> >          if (pos >= str.length) {
> >              newValue = input + str;
> >          } else {
> >              newValue = input.substring(0, pos) +
> str + input.substring(pos);
> >          }
> >
> >          // Store result
> >          project.setNewProperty(property,
> newValue);
> >      ]]>
> >  </scriptdef>
> >
> >  <insert input="xx" string="." position="1"
> property="out"/>
> >  <echo>${out}</echo>
> >
> > </project>
> >
> > > -----Ursprüngliche Nachricht-----
> > > Von: Ravi Roy [mailto:ravi.aroy@gmail.com]
> > > Gesendet: Dienstag, 29. Januar 2008 11:09
> > > An: Ant Users List
> > > Betreff: Re: How to set a new property based on
> value of
> > > another property in Ant ?
> > >
> > > On 1/29/08, Jan.Materne@rzf.fin-nrw.de
> > > <Ja...@rzf.fin-nrw.de> wrote:
> > > > You could load different property files
> according to a base property
> > > >    <property file="${user.name}.properties"/>
> > > >
> > > > And with AntContrib you could copy contents
> > > >    <property name="text.en" value="Hello
> World"/>
> > > >    <property name="text.de" value="Hallo
> Welt"/>
> > > >    <property name="language" value="en"/>
> > > >    <antcontrib:propertycopy name="text"
> from="text.${language}"/>
> > > >    <echo>${text} = Hello World</echo>
> > > >
> > > > see also
> > >
>
http://ant.apache.org/faq.html#propertyvalue-as-name-for-property
> > > >
> > > >
> > > > Jan
> > >
> > > Thanks Jan,
> > >
> > > But initially, I was looking for how to
> manipulate the string like -
> > > pushing "." in between value of the property
> using ant.
> > >
> > > Regards,
> > > Ravi
> > >
> > > >
> > > > > -----Ursprüngliche Nachricht-----
> > > > > Von: Ravi Roy [mailto:ravi.aroy@gmail.com]
> > > > > Gesendet: Dienstag, 29. Januar 2008 09:53
> > > > > An: user@ant.apache.org
> > > > > Betreff: How to set a new property based on
> value of another
> > > > > property in Ant ?
> > > > >
> > > > > Hi All,
> > > > >
> > > > > I want to set a property based on a value of
> the other
> > > property in my
> > > > > build script :
> > > > >
> > > > > Already defined property in a build file :
> > > > >
> > > > >  <property foo.1="prop.1" value="xx" />
> > > > >
> > > > > Want to set another property based on the
> value of this
> > > property like.
> > > > >
> > > > >   <property foo.2="prop2. value="x.x" />
> > > > >
> > > > > Which means addding  "." character after
> first character
> > > in the value
> > > > > of foo.1 property.
> > > > >
> > > > > Is it possible in ant ?
> > > > >
> > > > > Thanks for pointers.
> > > > >
> > > > > Regards,
> > > > > Ravi.
> > > > >
> > > > >
> > >
>
---------------------------------------------------------------------
> > > > > To unsubscribe, e-mail:
> user-unsubscribe@ant.apache.org
> > > > > For additional commands, e-mail:
> user-help@ant.apache.org
> > > > >
> > > > >
> > > >
> > > >
> > >
>
---------------------------------------------------------------------
> > > > To unsubscribe, e-mail:
> user-unsubscribe@ant.apache.org
> > > > For additional commands, e-mail:
> user-help@ant.apache.org
> > > >
> > > >
> > >
> > >
>
---------------------------------------------------------------------
> > > To unsubscribe, e-mail:
> user-unsubscribe@ant.apache.org
> > > For additional commands, e-mail:
> user-help@ant.apache.org
> > >
> > >
> >
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> user-unsubscribe@ant.apache.org
> > For additional commands, e-mail:
> user-help@ant.apache.org
> >
> >
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> user-unsubscribe@ant.apache.org
> For additional commands, e-mail:
> user-help@ant.apache.org
> 
> 



      ____________________________________________________________________________________
Looking for last minute shopping deals?  
Find them fast with Yahoo! Search.  http://tools.search.yahoo.com/newsearch/category.php?category=shopping

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


Re: How to set a new property based on value of another property in Ant ?

Posted by Ravi Roy <ra...@gmail.com>.
Thanks Jan, I created my own task and integrated into my build
process, but initial reason to ask this to the group was that if Ant
has a standard way to achieve this then why I should create seperate
task, at last for my own task I have to maintain and document the
same, which would not have been the case in case of standard Ant task
;-)

Thanks again for your help.

Regards,
Ravi.

On 1/29/08, Jan.Materne@rzf.fin-nrw.de <Ja...@rzf.fin-nrw.de> wrote:
> I dont know any task.
> Which means: implement your own ;)
>
> Jan
>
>
> <project>
>
>  <scriptdef name="insert" language="javascript">
>      <!-- the string where to insert -->
>      <attribute name="input"/>
>      <!-- the string to insert -->
>      <attribute name="string"/>
>      <!-- the position where to insert -->
>      <attribute name="position"/>
>      <!-- property name for the result -->
>      <attribute name="property"/>
>      <![CDATA[
>          // Access to attributes
>          pos      = attributes.get("position");
>          input    = attributes.get("input");
>          property = attributes.get("property");
>          str      = attributes.get("string");
>
>          // Compute new value
>          if (pos >= str.length) {
>              newValue = input + str;
>          } else {
>              newValue = input.substring(0, pos) + str + input.substring(pos);
>          }
>
>          // Store result
>          project.setNewProperty(property, newValue);
>      ]]>
>  </scriptdef>
>
>  <insert input="xx" string="." position="1" property="out"/>
>  <echo>${out}</echo>
>
> </project>
>
> > -----Ursprüngliche Nachricht-----
> > Von: Ravi Roy [mailto:ravi.aroy@gmail.com]
> > Gesendet: Dienstag, 29. Januar 2008 11:09
> > An: Ant Users List
> > Betreff: Re: How to set a new property based on value of
> > another property in Ant ?
> >
> > On 1/29/08, Jan.Materne@rzf.fin-nrw.de
> > <Ja...@rzf.fin-nrw.de> wrote:
> > > You could load different property files according to a base property
> > >    <property file="${user.name}.properties"/>
> > >
> > > And with AntContrib you could copy contents
> > >    <property name="text.en" value="Hello World"/>
> > >    <property name="text.de" value="Hallo Welt"/>
> > >    <property name="language" value="en"/>
> > >    <antcontrib:propertycopy name="text" from="text.${language}"/>
> > >    <echo>${text} = Hello World</echo>
> > >
> > > see also
> > http://ant.apache.org/faq.html#propertyvalue-as-name-for-property
> > >
> > >
> > > Jan
> >
> > Thanks Jan,
> >
> > But initially, I was looking for how to manipulate the string like -
> > pushing "." in between value of the property using ant.
> >
> > Regards,
> > Ravi
> >
> > >
> > > > -----Ursprüngliche Nachricht-----
> > > > Von: Ravi Roy [mailto:ravi.aroy@gmail.com]
> > > > Gesendet: Dienstag, 29. Januar 2008 09:53
> > > > An: user@ant.apache.org
> > > > Betreff: How to set a new property based on value of another
> > > > property in Ant ?
> > > >
> > > > Hi All,
> > > >
> > > > I want to set a property based on a value of the other
> > property in my
> > > > build script :
> > > >
> > > > Already defined property in a build file :
> > > >
> > > >  <property foo.1="prop.1" value="xx" />
> > > >
> > > > Want to set another property based on the value of this
> > property like.
> > > >
> > > >   <property foo.2="prop2. value="x.x" />
> > > >
> > > > Which means addding  "." character after first character
> > in the value
> > > > of foo.1 property.
> > > >
> > > > Is it possible in ant ?
> > > >
> > > > Thanks for pointers.
> > > >
> > > > Regards,
> > > > Ravi.
> > > >
> > > >
> > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> > > > For additional commands, e-mail: user-help@ant.apache.org
> > > >
> > > >
> > >
> > >
> > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> > > For additional commands, e-mail: user-help@ant.apache.org
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> > For additional commands, e-mail: user-help@ant.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>

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


AW: How to set a new property based on value of another property in Ant ?

Posted by Ja...@rzf.fin-nrw.de.
I dont know any task.
Which means: implement your own ;)

Jan


<project>

  <scriptdef name="insert" language="javascript">
      <!-- the string where to insert -->
      <attribute name="input"/>
      <!-- the string to insert -->
      <attribute name="string"/>
      <!-- the position where to insert -->
      <attribute name="position"/>
      <!-- property name for the result -->
      <attribute name="property"/>
      <![CDATA[
          // Access to attributes
          pos      = attributes.get("position");
          input    = attributes.get("input");
          property = attributes.get("property");
          str      = attributes.get("string");
          
          // Compute new value
          if (pos >= str.length) {
              newValue = input + str;
          } else {
              newValue = input.substring(0, pos) + str + input.substring(pos);
          }
          
          // Store result
          project.setNewProperty(property, newValue);
      ]]>
  </scriptdef>
  
  <insert input="xx" string="." position="1" property="out"/>
  <echo>${out}</echo>

</project> 

> -----Ursprüngliche Nachricht-----
> Von: Ravi Roy [mailto:ravi.aroy@gmail.com] 
> Gesendet: Dienstag, 29. Januar 2008 11:09
> An: Ant Users List
> Betreff: Re: How to set a new property based on value of 
> another property in Ant ?
> 
> On 1/29/08, Jan.Materne@rzf.fin-nrw.de 
> <Ja...@rzf.fin-nrw.de> wrote:
> > You could load different property files according to a base property
> >    <property file="${user.name}.properties"/>
> >
> > And with AntContrib you could copy contents
> >    <property name="text.en" value="Hello World"/>
> >    <property name="text.de" value="Hallo Welt"/>
> >    <property name="language" value="en"/>
> >    <antcontrib:propertycopy name="text" from="text.${language}"/>
> >    <echo>${text} = Hello World</echo>
> >
> > see also 
> http://ant.apache.org/faq.html#propertyvalue-as-name-for-property
> >
> >
> > Jan
> 
> Thanks Jan,
> 
> But initially, I was looking for how to manipulate the string like -
> pushing "." in between value of the property using ant.
> 
> Regards,
> Ravi
> 
> >
> > > -----Ursprüngliche Nachricht-----
> > > Von: Ravi Roy [mailto:ravi.aroy@gmail.com]
> > > Gesendet: Dienstag, 29. Januar 2008 09:53
> > > An: user@ant.apache.org
> > > Betreff: How to set a new property based on value of another
> > > property in Ant ?
> > >
> > > Hi All,
> > >
> > > I want to set a property based on a value of the other 
> property in my
> > > build script :
> > >
> > > Already defined property in a build file :
> > >
> > >  <property foo.1="prop.1" value="xx" />
> > >
> > > Want to set another property based on the value of this 
> property like.
> > >
> > >   <property foo.2="prop2. value="x.x" />
> > >
> > > Which means addding  "." character after first character 
> in the value
> > > of foo.1 property.
> > >
> > > Is it possible in ant ?
> > >
> > > Thanks for pointers.
> > >
> > > Regards,
> > > Ravi.
> > >
> > > 
> ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> > > For additional commands, e-mail: user-help@ant.apache.org
> > >
> > >
> >
> > 
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> > For additional commands, e-mail: user-help@ant.apache.org
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 
> 

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


Re: How to set a new property based on value of another property in Ant ?

Posted by Ravi Roy <ra...@gmail.com>.
On 1/29/08, Jan.Materne@rzf.fin-nrw.de <Ja...@rzf.fin-nrw.de> wrote:
> You could load different property files according to a base property
>    <property file="${user.name}.properties"/>
>
> And with AntContrib you could copy contents
>    <property name="text.en" value="Hello World"/>
>    <property name="text.de" value="Hallo Welt"/>
>    <property name="language" value="en"/>
>    <antcontrib:propertycopy name="text" from="text.${language}"/>
>    <echo>${text} = Hello World</echo>
>
> see also http://ant.apache.org/faq.html#propertyvalue-as-name-for-property
>
>
> Jan

Thanks Jan,

But initially, I was looking for how to manipulate the string like -
pushing "." in between value of the property using ant.

Regards,
Ravi

>
> > -----Ursprüngliche Nachricht-----
> > Von: Ravi Roy [mailto:ravi.aroy@gmail.com]
> > Gesendet: Dienstag, 29. Januar 2008 09:53
> > An: user@ant.apache.org
> > Betreff: How to set a new property based on value of another
> > property in Ant ?
> >
> > Hi All,
> >
> > I want to set a property based on a value of the other property in my
> > build script :
> >
> > Already defined property in a build file :
> >
> >  <property foo.1="prop.1" value="xx" />
> >
> > Want to set another property based on the value of this property like.
> >
> >   <property foo.2="prop2. value="x.x" />
> >
> > Which means addding  "." character after first character in the value
> > of foo.1 property.
> >
> > Is it possible in ant ?
> >
> > Thanks for pointers.
> >
> > Regards,
> > Ravi.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> > For additional commands, e-mail: user-help@ant.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>

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


AW: How to set a new property based on value of another property in Ant ?

Posted by Ja...@rzf.fin-nrw.de.
You could load different property files according to a base property
    <property file="${user.name}.properties"/>

And with AntContrib you could copy contents
    <property name="text.en" value="Hello World"/>
    <property name="text.de" value="Hallo Welt"/>
    <property name="language" value="en"/>
    <antcontrib:propertycopy name="text" from="text.${language}"/>
    <echo>${text} = Hello World</echo>

see also http://ant.apache.org/faq.html#propertyvalue-as-name-for-property


Jan

> -----Ursprüngliche Nachricht-----
> Von: Ravi Roy [mailto:ravi.aroy@gmail.com] 
> Gesendet: Dienstag, 29. Januar 2008 09:53
> An: user@ant.apache.org
> Betreff: How to set a new property based on value of another 
> property in Ant ?
> 
> Hi All,
> 
> I want to set a property based on a value of the other property in my
> build script :
> 
> Already defined property in a build file :
> 
>  <property foo.1="prop.1" value="xx" />
> 
> Want to set another property based on the value of this property like.
> 
>   <property foo.2="prop2. value="x.x" />
> 
> Which means addding  "." character after first character in the value
> of foo.1 property.
> 
> Is it possible in ant ?
> 
> Thanks for pointers.
> 
> Regards,
> Ravi.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 
> 

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