ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nico Seessle" <n...@seessle.de>
Subject Re: <delete> unable to remove a file
Date Mon, 02 Oct 2000 07:31:55 GMT
----- Original Message -----
From: "Diane Holt" <holtdl@yahoo.com>
To: <ant-dev@jakarta.apache.org>
Sent: Monday, October 02, 2000 6:49 AM
Subject: <delete> unable to remove a file


> What would cause <delete> to be unable to remove a file that I can 'rm' at
> the command line (so it's not permission problems)?

You do the rm after ant fails right?

> It's a file that's
> generated in an earlier target, then read in by <property>, and if it
> doesn't actually have a valid property-setting line in it, then the
> property doesn't get set, so the target that checks whether the property
> is set will echo an error message, delete the file (theoretically), then
> do a <fail>. All of that works except the file deletion. The (verbose) log
> snippet is:

How is this file generated? Is it generated by the 'inofficial'
propertyFile-task which was send to the list? This gave me some trouble too,
but if you use the modified Version I mailed to you then it may work (I had
the same problems, seems to be too much file activity for windows somehow).

> So the BUILD FAILED is actually a result of the <delete> not being able to
> complete, not a result of the <fail> that follows it (which never
> executes, because ant exits on the <delete> failing). Reading the file in
> with <property> wouldn't somehow keep the file in use, would it?

If it's not the propertyFile-task you may try to change 'loadFile' in
Property.java as follows:

    private void loadFile (File file) throws BuildException {
        Properties props = new Properties();
        log("Loading " + file.getAbsolutePath(), Project.MSG_VERBOSE);
        try {
            if (file.exists())

                FileInputStream fis = new FileInputStream(file);
                props.load(fis);
                fis.close();
                addProperties(props);
            } else {
                log("Unable to find " + file.getAbsolutePath(),
                    Project.MSG_VERBOSE);
            }
        } catch(Exception ex) {
            throw new BuildException(ex.getMessage(), ex, location);
        }
    }

I'm not sure what Java is 'required to do' if you use something like
'props.load(new FileInputStream(file));' - it can immediately close the file
after loading, but will it do in all cases?

If this does not help also you may want (maybe) try to use the included
'sleep'task just before the delete?

Example usage:

   <taskdef name="sleep"
classname="org.apache.tools.ant.taskdefs.optional.Sleep"/>

   <target name="default">
     <echo message="1"/>
     <sleep seconds="5" gc="true"/>
     <echo message="2"/>
   </target>

Nico


Mime
View raw message