ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jose Alberto Fernandez <JFernan...@viquity.com>
Subject RE: Proposed refactoring of scanDir() functionality
Date Fri, 03 Nov 2000 22:24:15 GMT
> From: Stefan Bodewig [mailto:bodewig@bost.de]
> 
> 
> Hi,
> 
> most every task that uses filesets (whether explicit or implicit) has
> a scanDir() method that takes all files from the fileset, compares
> their timestamps to the one(s) of a target file (some target files)
> and builds up a list of those files that need to be handled by the
> task.
> 
> You can find a lot of duplicated code here, so I'd like to separate
> this logic into another class with just a 
> 
> public static String[] scanDir(File srcDir, File destDir, 
> String[] files,
>                                FileNameMapper mapper)
> 
> where FileNameMapper is an interface with the single method
> 
> public String[] mapFileName(String fileName)
> 
+1 But please do not use static methods. Define a proper class so
that in the future people can override functionality if they please.

It would be also nice if different statages of the scanning process
are defined in protected methods that can be overrided by subclasses
in the future. Just to keep the architecture open.

> 
> <move fromdir todir>
>   <mapper type="glob" argument="*.oldext/*.newext" />
> </move>
> 
I lile the concept of a mapper as a datatype.
So that they can be declared like filesets.

> 
> I'd also base new tasks transform and jtransform on this.
> 
> Things I'm not really sure about yet:
> 
> (1) should scanDir return a File[] instead of a String[]?
> 
+1 As long as they are constructed by File(srcDir, <filename>)
the point being File.getName() must be as absolute/relative as srcDir is.

> (2) same for mapFileName
> 
-1, This should return a String relative to srcDir/destDir.
The input argument should be just filename relative to srcDir
and the output String will be considered relative to destDir.
This means that defining the javac mapping is just changing
suffixes, nothing else:

  // do sanity checks and then
  return fileName.substring(0, fileName.lastIndexOf('.')) + ".class";

That should be it. This will also simplify defining a mapping.

> (3) should we move destdir as an attribute to the FileNameMapper
> instead of passing it to scanDir.
> 

-1 This seem to be part of the Scanner job. The mapper should just produce
mapping pairs.

> Comments?
> 
Notice that the arrangement above allows for the user of the mapper to scan 
in more than one location. So you could implement a Scanner that searches
in several places.

That is why I would like the scanner to not have static methods, so that
people can overload functionality, if they please.

Jose Alberto


Mime
View raw message