ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Lennart Hellström (HF/EBC) <lennart.hellst...@ericsson.com>
Subject RE: Reading file attributes
Date Wed, 29 Sep 2004 11:16:27 GMT
 
> On Sep 28, 2004, at 5:04 AM, Lennart Hellström (HF/EBC) wrote:
> > I want to copy a file to a destination file only if the destination
> > file is not readonly (it might be checked in on the version control 
> > system)
> >
> > I tried using <copy> with failOnError="false" but strangely 
> the build
> > fails anyway when the destination file is readonly.
> >
> > Is there some way to look at the file's attributes before 
> deciding to
> > copy or not?
> > <Attrib> seems to only change the file attributes, and 
> that's not what 
> > I want.
> 
> There may be other ways to do this, but as an example of writing a 
> custom selector I do this:
> 
>    <typedef name="readonly"
>             classname="ReadOnlySelector"
>             classpath="build/classes"
>    />
> 
>    <copy todir="build/copy">
>      <fileset dir="src">
>        <readonly/>
>      </fileset>
>    </copy>
> 
> Where ReadOnlySelector is this:
> 
> import org.apache.tools.ant.types.selectors.FileSelector;
> import org.apache.tools.ant.BuildException;
> 
> import java.io.File;
> 
> public class ReadOnlySelector implements FileSelector {
>    public boolean isSelected(File basedir,
>                              String filename,
>                              File file) throws BuildException {
>      return !file.canWrite() && file.canRead();
>    }
> }
> 

Fine, thanks!
With that implemented I now get the following error in my ant script:
"The <fileset> data type doesn't support the nested "readonly" element. at line 296"

Is there something else I need to do to make ant accept my custom selection?

/ Lelle

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


Mime
View raw message