You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by "Bailey, Darragh" <db...@hp.com> on 2010/07/01 15:26:40 UTC

RE: Constructing patterns for use in fileset includes

> -----Original Message-----
> From: Matt Benson [mailto:gudnabrsam@gmail.com] 
> Sent: 30 June 2010 15:57
> To: Ant Users List
> Subject: Re: Constructing patterns for use in fileset includes

<snipage>
 
> You're in luck.  I would recommend using antcontrib:for to 
> iterate over a <tokens> resourcecollection built from your 
> property + the new <augment> task.  See 
> http://markmail.org/thread/4qskrvmiyk6qpjdg for a discussion 
> of a similar strategy for another problem.
> 
> HTH,
> Matt

It helped lots thanks! 
That augment task seems very useful, solves the problem perfectly. Never would have occurred to me to use it.

Not sure about how you were suggesting to use the <tokens> resource collector though?

Here's what I came up with:

Property packages.rpm.build is set to a list of package names to build, minus version and src.rpm extension and comma delimited.

    <fileset dir="${src}" id="rpmstobuild" />
    <!-- perform some manipulations using ant-contrib -->
    <antcontrib:for list="${packages.rpm.build}" param="rpmpkg">
      <sequential>
        <augment id="rpmstobuild">
          <include name="**/@{rpmpkg}*" />
        </augment>
      </sequential>
    </antcontrib:for>

    <apply executable="/usr/bin/rpmbuild" os="Linux" >
      <arg value="--rebuild" />
      <arg value="--define" />
      <arg value="_topdir ${rpm.topdir}" />
      <fileset refid="rpmstobuild" />
    </apply>

How would the <tokens> resource collector fit into this?

Obviously I've a little bit of work to do with adding a mapper to track the outputted rpms to help stop the task re-running if it's not necessary.

--
Regards,
Darragh Bailey

Systems Software Engineer
Hewlett Packard Galway Ltd.

Postal Address:    Hewlett Packard Galway Limited, Ballybrit Business Park, Galway
Registered Office: Hewlett Packard Galway Limited, 63-74 Sir John Rogerson's Quay Dublin 2
Registered Number: 361933 


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


Re: Constructing patterns for use in fileset includes

Posted by Matt Benson <gu...@gmail.com>.
On Jul 5, 2010, at 10:17 AM, Bailey, Darragh wrote:

>
> Thought I'd send the final results of what I got working to the list.
>
[SNIP]

I must say this is probably the first example of <augment> used in  
anger in the wild.  I'm gratified that it's working so well for you.  :)

Regards,
Matt

> --
> Regards,
> Darragh Bailey
>
> Systems Software Engineer
> Hewlett Packard Galway Ltd.
>
> Postal Address:    Hewlett Packard Galway Limited, Ballybrit  
> Business Park, Galway
> Registered Office: Hewlett Packard Galway Limited, 63-74 Sir John  
> Rogerson's Quay Dublin 2
> Registered Number: 361933
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>


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


RE: Constructing patterns for use in fileset includes

Posted by "Bailey, Darragh" <db...@hp.com>.
Thought I'd send the final results of what I got working to the list.

Interestingly I ran into a problem where trying to use <compositemapper refid="..."/> would throw an error about that task not supporting the refid attribute. I eventually hit on the solution that I could use the generic mapper task with the refid even though according to the documentation "The composite mapper has no corresponding <mapper type> attribute.". 

It does seem less than intuitive that when you use the augment task to modify a composite mapper, that you need to use the <mapper> attribute to refid it.

Any way here's what I came up with in the end, thanks for the suggestions.

    <!-- determine the rpm architecture -->
    <exec executable="rpm" outputproperty="rpm.target" os="Linux">
      <arg value="--eval" />
      <arg value="%{_target_cpu}" />
    </exec>


    <!-- build rpms supplied as src -->
    <fileset dir="${src}" id="rpmstobuild" />
    <!-- perform some manipulations using ant-contrib -->
    <!-- generate the file list of packages to be rebuilt -->
    <antcontrib:for list="${packages.rpm.build}" param="rpmpkg">
      <sequential>
        <augment id="rpmstobuild">
          <include name="**/@{rpmpkg}*" />
        </augment>
      </sequential>
    </antcontrib:for>

    <compositemapper id="rpmstobuildmapper" />
    <!-- generate the mappers to identify the resulting packages -->
    <antcontrib:for list="${packages.rpm.build}" param="rpmpkg">
      <sequential>

        <!-- first, what's the name of the main package, direct translation to binary rpm or
             is it called something else -->
        <local name="default-pkg" />
        <antcontrib:if>
          <isset property="packages.rpm.@{rpmpkg}.default" />
          <antcontrib:then>
            <property name="default-pkg" value="${packages.rpm.@{rpmpkg}.default}" />
          </antcontrib:then>
          <antcontrib:else>
            <property name="default-pkg" value="@{rpmpkg}" />
          </antcontrib:else>
        </antcontrib:if>
        <augment id="rpmstobuildmapper">
          <regexpmapper from="(@{rpmpkg})(.*)\.src\.rpm" to="${rpm.target}/${default-pkg}\2.${rpm.target}.rpm" />
        </augment>

        <!-- next test if the extra packages property is set, in which case we'll need to loop over them to
              generate the necessary augments to suit -->
        <antcontrib:if>
          <isset property="packages.rpm.@{rpmpkg}.extra" />
          <antcontrib:then>
            <antcontrib:for list="${packages.rpm.@{rpmpkg}.extra}" param="extrarpmpkg">
              <sequential>
                <augment id="rpmstobuildmapper">
                  <regexpmapper from="(@{rpmpkg})(.*)\.src\.rpm" to="${rpm.target}/@{extrarpmpkg}\2.${rpm.target}.rpm" />
                </augment>
              </sequential>
            </antcontrib:for>
          </antcontrib:then>
        </antcontrib:if>

      </sequential>
    </antcontrib:for>

    <apply executable="/usr/bin/rpmbuild" os="Linux" dest="${rpm.rpmdir}">
      <arg value="--rebuild" />
      <arg value="--define" />
      <arg value="_topdir ${rpm.topdir}" />
      <fileset refid="rpmstobuild" />
      <mapper refid="rpmstobuildmapper" />
    </apply>

    <!-- copy rpms provided as binary -->
    <fileset dir="${src}" id="rpmstocopy" />
    <!-- perform some manipulations using ant-contrib -->
    <antcontrib:for list="${packages.rpm.copy}" param="rpmpkg">
      <sequential>
        <augment id="rpmstocopy">
          <include name="**/@{rpmpkg}*" />
        </augment>
      </sequential>
    </antcontrib:for>



--
Regards,
Darragh Bailey

Systems Software Engineer
Hewlett Packard Galway Ltd.

Postal Address:    Hewlett Packard Galway Limited, Ballybrit Business Park, Galway
Registered Office: Hewlett Packard Galway Limited, 63-74 Sir John Rogerson's Quay Dublin 2
Registered Number: 361933 


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


Re: Constructing patterns for use in fileset includes

Posted by Matt Benson <gu...@gmail.com>.
On Jul 1, 2010, at 8:26 AM, Bailey, Darragh wrote:

>> -----Original Message-----
>> From: Matt Benson [mailto:gudnabrsam@gmail.com]
>> Sent: 30 June 2010 15:57
>> To: Ant Users List
>> Subject: Re: Constructing patterns for use in fileset includes
>
> <snipage>
>
>> You're in luck.  I would recommend using antcontrib:for to
>> iterate over a <tokens> resourcecollection built from your
>> property + the new <augment> task.  See
>> http://markmail.org/thread/4qskrvmiyk6qpjdg for a discussion
>> of a similar strategy for another problem.
>>
>> HTH,
>> Matt
>
> It helped lots thanks!
> That augment task seems very useful, solves the problem perfectly.  
> Never would have occurred to me to use it.
>
> Not sure about how you were suggesting to use the <tokens> resource  
> collector though?
>
> Here's what I came up with:
>
> Property packages.rpm.build is set to a list of package names to  
> build, minus version and src.rpm extension and comma delimited.
>
>     <fileset dir="${src}" id="rpmstobuild" />
>     <!-- perform some manipulations using ant-contrib -->
>     <antcontrib:for list="${packages.rpm.build}" param="rpmpkg">
>       <sequential>
>         <augment id="rpmstobuild">
>           <include name="**/@{rpmpkg}*" />
>         </augment>
>       </sequential>
>     </antcontrib:for>
>
>     <apply executable="/usr/bin/rpmbuild" os="Linux" >
>       <arg value="--rebuild" />
>       <arg value="--define" />
>       <arg value="_topdir ${rpm.topdir}" />
>       <fileset refid="rpmstobuild" />
>     </apply>
>
> How would the <tokens> resource collector fit into this?

Honestly, I was so swept up in stuff-I-wrote that I forgot  
momentarily that <for> could iterate over a comma-delimited list out  
of the box.  As it can also iterate over any Iterable, tokenizing  
your property into a resource collection is also doable with <for>,  
while being completely unnecessary.  ;)

-Matt

>
> Obviously I've a little bit of work to do with adding a mapper to  
> track the outputted rpms to help stop the task re-running if it's  
> not necessary.
>
> --
> Regards,
> Darragh Bailey
>
> Systems Software Engineer
> Hewlett Packard Galway Ltd.
>
> Postal Address:    Hewlett Packard Galway Limited, Ballybrit  
> Business Park, Galway
> Registered Office: Hewlett Packard Galway Limited, 63-74 Sir John  
> Rogerson's Quay Dublin 2
> Registered Number: 361933
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>


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