ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rebhan, Gilbert" <>
Subject RE: How do I do text manipulation on a property string?
Date Mon, 30 Apr 2007 06:39:46 GMT

-----Original Message-----
From: George Storm [] 
Sent: Monday, April 30, 2007 1:05 AM
Subject: How do I do text manipulation on a property string?

I have a property value (string) that I receive from a command line
as lowercase text.

On some platforms I need it to be converted to Title case, on others I
it to be converted to UPPER case before passing it on to my build tools.

Is there a preferred method to perform case conversions in ant scripts?

simply choose a scripting language running in bsf 
(jruby,groovy,javascript,beanshell, jython,judoscript ...)
and use it for string conversion combined with calling ant api

method setProperty() for overwriting an existing property
method setNewPropery for creating a new property

example =

<project name="bla" default="main" basedir=".">
    <!-- // Properties -->
    <property name="myprop" value="foobar"/>
    <!-- Properties // -->

    <target name="depends">

        <script language="ruby">
            $project.setProperty "str.toupper", $myprop.upcase
            $project.setProperty "str.capitalize", $myprop.capitalize
            $project.setProperty "str.chop", $myprop.chop
            $project.setProperty "str.delete", $myprop.delete("o","b")
            $project.setProperty "str.reverse", $myprop.reverse
            $project.setProperty "str.slice", $myprop.slice(3..6)

    <target name="main" depends="depends">

    <echoproperties prefix="str" />


[echoproperties] #Ant properties
[echoproperties] #Mon Apr 30 08:33:52 CEST 2007
[echoproperties] str.delete=foobar
[echoproperties] str.reverse=raboof
[echoproperties] str.toupper=FOOBAR
[echoproperties] str.chop=fooba
[echoproperties] str.slice=bar
[echoproperties] str.capitalize=Foobar
Total time: 2 seconds

Regards, Gilbert

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message