Bug 51167 - Support string replacement as part of property expansion
Summary: Support string replacement as part of property expansion
Status: NEW
Alias: None
Product: Ant
Classification: Unclassified
Component: Core (show other bugs)
Version: nightly
Hardware: PC Linux
: P2 enhancement (vote)
Target Milestone: ---
Assignee: Ant Notifications List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-07 17:11 UTC by Keith D Gregory
Modified: 2011-05-08 03:59 UTC (History)
0 users



Attachments
Patch for 'replaceAll:' property prefix (against trunk as-of right now) (4.94 KB, patch)
2011-05-07 17:11 UTC, Keith D Gregory
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Keith D Gregory 2011-05-07 17:11:44 UTC
Created attachment 26968 [details]
Patch for 'replaceAll:' property prefix (against trunk as-of right now)

It is occasionally useful to take one property value and transform it with a simple string replace. For example, if you have a comma-delimited list of locales, you might want to generate a fileset from it (this example shows a BASH-style substitution; see below):

    <property name="locales" value="en_US,en_GB,en_CA,fr_FR,fr_CA"/>
    <property name="locale.regex" value="${locales/,/|}"/>

    <fileset dir="${resource.dir}">
        <filename regex="${locale.regex}.txt"/>
    </fileset>

It's currently possible to do this using the ant-contrib PropertyRegex task. However, using that task requires getting the ant-contrib JARfile and adding it to your classpath.

While I think the BASH-style expansions are cleaner, in keeping with current practice I suggest adding a "replaceAll:" prefix:

    <property name="locale.regex" value="${replaceAll:locales/,/|}"/>

I've attached a patch that implements this, with tests and changes to docs.
Comment 1 Matt Benson 2011-05-08 03:59:41 UTC
Seen http://ant.apache.org/antlibs/props/index.html ?

The stringops PropertyEvaluator implements bash style string handling.