ant-user mailing list archives

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

-----Original Message-----
From: George Storm [mailto:gstorm@divxcorp.com] 
Sent: Monday, April 30, 2007 1:05 AM
To: user@ant.apache.org
Subject: How do I do text manipulation on a property string?

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

On some platforms I need it to be converted to Title case, on others I
need
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">
        <![CDATA[
            $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)
            
		]]>
        </script>			
        
    </target>

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

    <echoproperties prefix="str" />

    </target>
</project>

main:
[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
BUILD SUCCESSFUL
Total time: 2 seconds


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