ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "David Weintraub" <qazw...@gmail.com>
Subject Re: Filter on copy with directory contents
Date Fri, 22 Feb 2008 01:41:56 GMT
Well, the @REPLACE@ could be handled by a <filterchain> inside a copy.
The tricky part is finding the value for ${replacing}.

You might be able to do something with the AntContrib <PropertyRegex>
task. This can take a property and munge it.

Let's say you do something like this:

<path id="replaceme">
    <fileset dir="${replace.dir}">
        <include name="*.jar"/>
    </fileset>
</path>

<property name="replace.string" refid="replaceme"/>

This will give you ${replace.string} = "foo.jar:bar.jar:fobar.jar"

Not what you want, but then you can use <propertyregex>

<propertyregex
     property="munge.replace"
     input="${replace.string}"
     regexp="[;:]"
     replace="</string>"<string>"
     global="true"/>

That will give you ${munge.replace} =
"foo.jar</string><string>bar.jar</string><string>foobar.jar"

Then, we need to add a prefix and suffix:

<property name="munge.replace2"
    value="<string>${munge.replace}</string>"/>

It's all on a single line and not separate lines, but XML doesn't care.

<copy toDir="${dest.dir}">
  <fileset dir="${src.dir}">
    <include name="*.jar">
  </fileset>
  <filterset
    token="REPLACEME"
    value="${munge.replace2"/>
</copy>

Haven't tested it, but something like that should work.

On Wed, Feb 20, 2008 at 4:20 PM, Paul J. Lucas <pauljlucas@mac.com> wrote:
> Given a file that contains:
>
>         @REPLACEME@
>
>  I want to use <copy> to copy the file and replace @REPLACEME@ with
>  contents like:
>
>         <string>foo.jar</string>
>         <string>bar.jar</string>
>         ...
>
>  where "foo" and "bar" are the names of the file(s) in a particular
>  directory that match a certain pattern (in this case *.jar).
>
>  Is there a way to do that?  I've read the docs but the answer isn't
>  all that obvious.  Thanks.
>
>  - Paul
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>  For additional commands, e-mail: user-help@ant.apache.org
>
>



-- 
--
David Weintraub
qazwart@gmail.com

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


Mime
View raw message