ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rick Sansburn" <rsansb...@clareos.com>
Subject RE: 2nd try: Creating property using regular expression on string/property value
Date Wed, 19 Feb 2003 14:21:00 GMT
Not sure if this is what you are looking for but here is another answer
to your problem.


I am using ant to update the build number in one of our files.  It
searches for the string INTERNAL_VERSION 12345 and replaces it with the
string INTERNAL_VERSION ${build.version}.  You can use any of the
standard regular expression matching strings as I did here.  (\d matches
for any number)

<target name="update_internal_version" depends="set_version_number"
  description="Update INTERNAL_VERSION string">
  <replaceregexp file="${main.dir}/resource.h"
    match="INTERNAL_VERSION \d\d\d\d\d" 
    replace="INTERNAL_VERSION ${build.version}" >
  </replaceregexp>
</target>

-- Rick


-----Original Message-----
From: SimonRichardson2@hbosts.com [mailto:SimonRichardson2@hbosts.com] 
Sent: Wednesday, February 19, 2003 8:13 AM
To: user@ant.apache.org
Subject: RE: 2nd try: Creating property using regular expression on
string/property value


You can't change the values of properties because they're immutable.

But you could create a second property based on the value of your string
by:
1) creating a property file
2) using regular expression to change the value in the property file.
3) source the properties

Some example ..

    <target name="foo.default"
            description="create newchangestring from string1">
        <!-- 1) create a property file. -->
        <property name="string1" value="tom dick"/>
        <echo message="changestring=${string1}"/>
        <propertyfile file="temp.properties">
            <entry key="changestring" value="${string1}"/>
        </propertyfile>
        <!-- 2) change the value in the property file. -->
        <replaceregexp file="temp.properties"
            match="changestring=(.*)"
            replace="newchangestring=\1\ and\ harry"/>
        <!-- 3) source the properties -->
        <property file="temp.properties"/>
        <echo message="newchangestring=${newchangestring}"/>
    </target>


output..

foo.default:
     [echo] changestring=tom dick
[propertyfile] Updating property file: /temp/temp.properties
     [echo] newchangestring=tom dick and harry

HTH

Simon

> -----Original Message-----
> From: Tony Obermeit [mailto:tonyob@compuserve.com]
> Sent: 19 February 2003 12:36
> To: ant-user@jakarta.apache.org
> Subject: 2nd try: Creating property using regular expression on 
> string/property value
> 
> 
> I'm still trying to find an answer for this question.  I've
> searched the 
> documentation on regexp which appears to apply to mapping or 
> selecting 
> filenames based on a regular expression.  I just want to do a string 
> replace on a property value using a regular expression.  Any other 
> ideas?  Just point me to the appropriate ant documentation.
> 
> thanks
> 
> Tony
> 
> >Date: Mon, 17 Feb 2003 07:02:34 +1000
> >To: ant-user@jakarta.apache.org
> >From: Tony Obermeit <tonyob@compuserve.com>
> >Subject: Creating property using regular expression on
> string/property value
> >
> >I have a property value that I want to use for part of a
> file name but the
> >property value sometimes includes spaces that I don't want
> to include in
> >the filename.  I am looking to create a new property value
> but apply a
> >regular expression to an existing property value when I
> create it.  The
> >examples I've seen seem to do this with replacing tokens within an
> >existing file, I want to do it effectively within a string 
> in my build script.
> >
> >Thanks
> >
> >Tony
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 
> 
> 

-- 

------------------------------------------------------------------------
------
For more information on HBOS Treasury Services, please visit
http://www.HBOSTS.com

Or for details of our online FX & Deposit services, please go to
http://www.HBOSdeal.com

HBOS Treasury Services plc is part of the HBOS Group, which also
includes Halifax plc and Bank of Scotland. Registered Office: 33 Old
Broad Street, London EC2N 1HZ. Registered No. 2692890. Registered in
England. Regulated by the Financial Services Authority.

The information contained in this message is confidential and is
intended for the addressee only. If you have received this message in
error or there are any problems please notify the originator
immediately. The unauthorised use, disclosure, copying or alteration of
this message is strictly forbidden. This mail and any attachments have
been scanned for viruses prior to leaving the HBOS Treasury Services plc
network. HBOS Treasury Services plc will not be liable for direct,
special, indirect or consequential damages arising from alteration of
the contents of this message by a third party or as a result of any
virus being passed on.

HBOS Treasury Services plc reserves the right to monitor and record
e-mail messages sent to and from this address for the purposes of
investigating or detecting any unauthorised use of its system and
ensuring its effective operation.

========================================================================
======


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


Mime
View raw message