You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by "Frode E. Moe" <fr...@CoreTrek.no> on 2005/06/07 16:07:47 UTC

custom selector which examines multiple files before returning an answer

Hi, I'm trying to implement a way to detect duplicate .jar files (where
only the version differ) and delete all duplicates except the newest.
The way I hoped to implement this was to use the <delete> task together
with a custom Selector, like this:
  <delete>
    <fileset dir="lib" includes="**/*.jar">
      <custom classname="com.coretrek.DuplicateSElector" />
    </fileset>
  </delete>

Unfortunately this doesn't seem to work out very well, because the
FileSelector interface's "isSelected()" requires my class to provide an
answer for each file on the fly, while I need to read and sort 
the entire "candidate" fileset before selecting out the dupes.

Is there another way to implement a FileSet filtering mechanism that
would work for this purpose, or do I have to write a custom
"DeleteDuplicates" task?


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


Re: custom selector which examines multiple files before returning an answer

Posted by "Frode E. Moe" <fr...@CoreTrek.no>.
On Tue, Jun 07, 2005 at 08:05:51 -0700, Matt Benson wrote:
> In Ant 1.7 you will be able to do this 
(...)
> Unfortunately this doesn't help you particularly now,
(...) 

No problem, thanks for the quick answer - which saved me some time
searching the ant 1.6.x source for something which wouldn't be there.
I'll just make it a custom task instead (and update it as you described
whenever 1.7 is out)!

- Frode


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


Re: custom selector which examines multiple files before returning an answer

Posted by Matt Benson <gu...@yahoo.com>.
--- Matt Benson <gu...@yahoo.com> wrote:
> - restrict the sorted collection to the first
> returned
> (mental note on my part to write a <first>
> resourceselector) and store as reference "bar".

Actually, after thinking about this, <first> will not
be a resource selector for use with the <restrict>
collection; <first> will merely be a resource
collection that wraps another and returns only its
first element.

-Matt


		
__________________________________ 
Discover Yahoo! 
Stay in touch with email, IM, photo sharing and more. Check it out! 
http://discover.yahoo.com/stayintouch.html

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


Re: custom selector which examines multiple files before returning an answer

Posted by Matt Benson <gu...@yahoo.com>.
(excuse the top-post)

In Ant 1.7 you will be able to do this using
ResourceCollections which include the ability to sort
as well as select.  The correct approach would then be
very like what you are proposing:

- select files matching the specified name, store as
reference "foo".
- reverse-sort "foo" by date.
- restrict the sorted collection to the first returned
(mental note on my part to write a <first>
resourceselector) and store as reference "bar".
- <delete> the resourcecollection that is the
difference between "foo" and "bar" (resource
collections will include such "set logic" collections
as this).

Unfortunately this doesn't help you particularly now,
especially as even the HEAD version of many Ant tasks
(including <delete>) does not yet support resource
collections.  My apologies.

-Matt

--- "Frode E. Moe" <fr...@CoreTrek.no> wrote:

> Hi, I'm trying to implement a way to detect
> duplicate .jar files (where
> only the version differ) and delete all duplicates
> except the newest.
> The way I hoped to implement this was to use the
> <delete> task together
> with a custom Selector, like this:
>   <delete>
>     <fileset dir="lib" includes="**/*.jar">
>       <custom
> classname="com.coretrek.DuplicateSElector" />
>     </fileset>
>   </delete>
> 
> Unfortunately this doesn't seem to work out very
> well, because the
> FileSelector interface's "isSelected()" requires my
> class to provide an
> answer for each file on the fly, while I need to
> read and sort 
> the entire "candidate" fileset before selecting out
> the dupes.
> 
> Is there another way to implement a FileSet
> filtering mechanism that
> would work for this purpose, or do I have to write a
> custom
> "DeleteDuplicates" task?
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> user-unsubscribe@ant.apache.org
> For additional commands, e-mail:
> user-help@ant.apache.org
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

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