ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ken Gentle <j.kenneth.gen...@acm.org>
Subject RE: NOT A SOLUTION: Modifying a DirSet (or any AbstractFileSet) f rom within a <script>
Date Mon, 15 Sep 2003 14:47:26 GMT
Thanks Jan!

Last night I finished up an entirely unsatisfying solution that is sort of 
like your Quick Solution.

I developed a <sortfileset> task, extending MatchingTask, that will take 
the following additional attributes:

         refId:          an existing fileset to be sorted
         name:           the id of the resulting sorted fileset
         sortorder:      one of "ascending" or "descending"
         sortfield:      one of "name", "size", "modified"

Right now it only operates on the refId-ed fileset, but I hope to add the 
logic to process nested <fileset>elements.  I don't think it will be to 
hard, but I need to look at some other tasks that do similar id vs. nested 
filesets.

I'd thought the ideal longer term solution would be to create a 
DirectoryScanner interface (maybe just implementing the three interfaces 
that DirectoryScanner currently uses), moving the current DirectoryScanner 
to DirectoryScannerImpl to allow an easy approach to "Decorating" 
DirectoryScanners.

Then the AbstractFileScanner could add a factory method to create a 
"Decorated" DirectoryScanner.

Part of the problem is that AbstractFileSet creates a new DirectoryScanner 
on each call to "getDirectoryScanner" which, along with the lack of an 
Interface for DirectoryScanner, makes it damned near impossible to apply 
the Decorator pattern cleanly.

It's taken me three classes to get my solution in place:

         SortFileSet             - task
         SortedFileSet           - extension of FileSet
         SortedFileScanner       - extension of DirectoryScanner

and after refactoring and other cleanup there may be one or two more.

Looking at the Ant sources, one can kind of see how things got this way, 
through adding features and behavior to DirectoryScanner.  But it sure 
makes any low-impact enhancement a real pain.

         Ken

At 01:26 AM 9/15/2003, you wrote:
>Quick solution: implement a task that do the sort
>    <sort refid="" includes="" excludes="" .../>
>    - refid:    the id of the fileset
>    - includes: the name of the property which should hold the sorted
>includes
>    - excludes: the name of the property which should hold the sorted
>excludes
>    - ... more files from directory scanner ...
>
>Design solution: <fileset>, <dirset>, <path>, ... supports ONE nested
<sort>
>element,
>so the sorting can be done via plugin.
>
>
>Jan
>
>
> > -----Original Message-----
> > From: Ken Gentle [mailto:j.kenneth.gentle@acm.org]
> > Sent: Saturday, September 13, 2003 4:44 PM
> > To: Ant Users List
> > Subject: NOT A SOLUTION: Modifying a DirSet (or any AbstractFileSet)
> > from within a <script>
> >
> >
> > My apologies for posting something with insufficient testing.
> >  The code
> > below executes cleanly, but the JavaScript subclass of
> > DirectoryScanner
> > does not appear to actually replace the DirectoryScanner for
> > the FileSet.
> >
> > On Windows, the fileset appears to always come out in alpha-numeric,
> > ascending order, so even though I munged the order within the
> > Javascript
> > before sorting, it always appeared sorted.  I mistakenly
> > thought that meant
> > it was working.
> >
> > Dominique and I independently tried some variations (like
> > reverse order, or
> > sorting on file size), and none of these have worked.
> >
> > I'm still pursuing an answer to this issue, working with a
> > Java extension
> > to the base fileset.
> >
> > Arghh!  This seemed like such a simple problem, too.
> >
> >          Ken
> >
> >
> > At 08:03 2003-09-11, you wrote:
> > >At 01:57 AM 9/11/2003, you wrote:
> > >
> > >>By default only the "java" package is imported. So you have
> > >>to import that special class or the whole package with
> > >>     importClass(Package.org.apache.tools.ant.DirectoryScanner);
> > >
> > >I caught this right before I left last night.  Importing the class
> > >resolved that problem, just as you've described.
> > >
> > >>I will update the doc about this error message.
> > >
> > >Cool...
> > >
> > >
> > >>Where I can get more infos about the adapter?
> > >
> > >I found the only documentation to JavaAdapter in the
> > >netscape.public.mozilla.jseng forum
> > >(http://groups.google.com/groups?q=JavaAdapter+group:netscape
>.public.mozilla.jseng+group:netscape.public.mozilla.jseng&hl=en&lr=&ie=UTF-8
>&oe=UTF-8&newwindow=1&group=netscape.public.mozilla.jseng&selm=391EEC3C.5236
>D929%40yahoo.com&rnum=1)
> >
> >
> >My current solution looks like this:
> >
> >     <script language="javascript">
> >       <![CDATA[
> >         importPackage(Packages.java.lang);
> >       prj = self.getProject();
> >       dirset = prj.getReference("dirset.qa.releases");
> >
> >       scanner = dirset.getDirectoryScanner(prj);
> >       fromDir = dirset.getDir(prj);
> >       srcDirs = scanner.getIncludedDirectories();
> >
> >       obj = { getIncludedDirectories:
> >         function(){
> >           importPackage(Packages.java.util);
> >           incDirs = super$getIncludedDirectories();
> >           Arrays.sort(incDirs);
> >           return incDirs;
> >         }
> >       };
> >
> >       importClass(Packages.org.apache.tools.ant.DirectoryScanner);
> >       sordidScanner = new JavaAdapter (DirectoryScanner,obj);
> >       dirset.setupDirectoryScanner (sordidScanner, prj);
> >       ]]>
> >     </script>
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> >For additional commands, e-mail: user-help@ant.apache.org
>
>=============================================================
>J. Kenneth Gentle (Ken)    | Phone: (610) 255-0361
>Gentle Software, LLC       | Email: j.kenneth.gentle@acm.org
>=============================================================
>
>
>---------------------------------------------------------------------
>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


Mime
View raw message