John Oxley
John Oxley

Reputation: 14990

Ant Tokenizer: Selecting an individual Token

I have the following ant task:

<loadfile property="proj.version" srcfile="build.py">
    <filterchain>
        <striplinecomments>
            <comment value="#"/>
        </striplinecomments>
        <linecontains>
            <contains value="Version" />
        </linecontains>
    </filterchain>
</loadfile>
<echo message="${proj.version}" />

And the output is

 [echo] config ["Version"]          = "v1.0.10-r4.2"

How do I then use a tokenizer to get only v1.0.10-r4.2, the equivalent of

| cut -d'"' -f4

Upvotes: 1

Views: 1163

Answers (1)

VonC
VonC

Reputation: 1324935

You could use a containsregex element within your filterchain as tokenfilter.

This should filter any line with "Version" in it, and return as content the only group captured: 'vx.y.zz....'

<containsregex pattern="^.?\"Version\".\"(v[^\"]+?)\"." replace="\1" /> does not work.
May be <containsregex pattern='^.
?"Version"."(v[^\"]+?)".' replace="\1" /> could work (with single quotes for the parameter attribute, allowing for non-escaped double-quotes inside the parameter value)

Actually the OP John Oxley provides a working solution with the double quotes (\") replaced by &quot;:

<containsregex
        pattern="^.*?&quot;Version&quot;.*&quot;(v[^&quot;]+?)&quot;.*"
        replace="\1" />

Upvotes: 3

Related Questions