Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Ant setting property by regexp substitution on an existing property

0 views
Skip to first unread message

kevin cline

unread,
Jul 25, 2008, 12:39:32 PM7/25/08
to
I've come across the following Ant task:

<!-- complicated way to set the oracle.app.username from the
version.platform property
by writing a property file, then hacking it with replaceregexp
and then rereading it.
TODO: find simpler way to do this
-->
<target name="create-oracle-username" unless="oracle.app.username">
<mkdir dir="${basedir}/build"/>
<delete file="${oracle.app.username.file}"/>
<propertyfile file="${oracle.app.username.file}">
<entry key="changeme" value="user_${version.platform}"/>
</propertyfile>
<replaceregexp file="${oracle.app.username.file}" match="\."
replace="_" flags="g"/>
<replaceregexp file="${oracle.app.username.file}" match="changeme"
replace="oracle.app.username"/>
<property file="${oracle.app.username.file}"/>
<delete file="${oracle.app.username.file}"/>

Is there some simpler way of setting the oracle.app.username property
from the value of version.platform? This would be one line in a
makefile.

Zig

unread,
Jul 25, 2008, 1:34:43 PM7/25/08
to
On Fri, 25 Jul 2008 12:39:32 -0400, kevin cline <kevin...@gmail.com>
wrote:

> I've come across the following Ant task:
>
> <!-- complicated way to set the oracle.app.username from the
> version.platform property
> by writing a property file, then hacking it with replaceregexp
> and then rereading it.
> TODO: find simpler way to do this
> -->
> <target name="create-oracle-username" unless="oracle.app.username">
> <mkdir dir="${basedir}/build"/>
> <delete file="${oracle.app.username.file}"/>

> <propertyfile file="${oracle.app.username.file+}">


> <entry key="changeme" value="user_${version.platform}"/>
> </propertyfile>
> <replaceregexp file="${oracle.app.username.file}" match="\."
> replace="_" flags="g"/>
> <replaceregexp file="${oracle.app.username.file}" match="changeme"
> replace="oracle.app.username"/>
> <property file="${oracle.app.username.file}"/>
> <delete file="${oracle.app.username.file}"/>
>
> Is there some simpler way of setting the oracle.app.username property
> from the value of version.platform? This would be one line in a
> makefile.

Can't think of a way to get this to one line, but you might could try
something like:

<loadresource property="oracle.app.username">
<propertyresource name="version.platform" />
<filterchain>
<concat>
<header>_user</header>
<replacestring from="." to="_" />
</concat>
</filterchain>
</loadresource>

While I haven't actually tried that, loadresource + a filterchain may make
the logic a bit more clear.

HTH,

-Zig

kevin cline

unread,
Jul 25, 2008, 3:57:39 PM7/25/08
to
On Jul 25, 12:34 pm, Zig <n...@nowhere.net> wrote:
> On Fri, 25 Jul 2008 12:39:32 -0400, kevin cline <kevin.cl...@gmail.com>  

Thanks. It's still ugly, but definitely an improvement over the
gratuitous introduction of a temporary file just to do a string
replacement.

Gilbert Rebhan

unread,
Jul 26, 2008, 10:21:01 AM7/26/08
to kevin cline
kevin cline wrote:
[...]

> Is there some simpler way of setting the oracle.app.username property
> from the value of version.platform? This would be one line in a
> makefile.

use a scripting language and make use of the ant api,
method project.setProperty(String name, String value).
something like f.e.

if ${version.platform} is already set before, it's
as easy as =

<script language="ruby">
<![CDATA[
$project.setProperty "oracle.app.username",
"user_"+$project.getProperty('$version.platform').gsub!(/\./,'_')
]]>
</script>


you could use any scripting language that runs via bsf in VM,f.e.
(J)ruby), groovy, beanshell, javascript(rhino from Mozilla) ...

Regards, Gilbert

0 new messages