You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Diane Holt <ho...@yahoo.com> on 2002/07/01 07:45:18 UTC

Possible bug in Delete task

A user posted a question about using <delete> with 'includeEmptyDirs' set
(see: http://marc.theaimsgroup.com/?l=ant-user&m=102546976217819&w=2), and
from looking at Delete.java, I don't see it ever handling this -- but the
doc seems to say it can (but maybe I missed how it's supposed to work).

I've modified Delete.java so it does it now, but I had to do some (maybe
kind of weird?) things to get the potentially empty directories from the
fileset into the "dirs" array -- which is set by a call to
getIncludedDirectories() (which is why I had to do the maybe weird stuff,
to get an already set array to "grow" to include the other dir names),
except the call to getIncludedDirectories() doesn't actually return any
names (which is why the code that's supposed to delete the now-empty
directories never gets executed), and I'm not really sure if that's
expected or not (if it's not, then I've probably made the wrong fix, and
what needs to get fixed instead is getting the names of the file's
directories into "dirs" from the start).

Since this isn't exactly what you'd call a real straightforward change
(although it's actually fairly small, despite the convoluted description
:), I'd really appreciate it if some of the other committers take a look
at it before I submit it. I've done my usual test-by-hand thing, and it
seems to work fine -- but of course, you'll want real testcases stuff as
well, right? (Ugh.)

Diane

=====
(holtdl@yahoo.com)



__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com

Re: Possible bug in Delete task

Posted by Diane Holt <ho...@yahoo.com>.
--- Stefan Bodewig <bo...@apache.org> wrote:
> On Sun, 30 Jun 2002, Diane Holt <ho...@yahoo.com> wrote:
> 
> > A user posted a question about using <delete> with
> > 'includeEmptyDirs' set, and from looking at Delete.java, I don't see
> > it ever handling this -- but the doc seems to say it can (but maybe
> > I missed how it's supposed to work).
> 
> The task assumes that your include pattern matches the directories to
> remove - i.e. the dirs are part of getIncludedDirectories.

So, for something like:
  build/a/foo.class
  build/a/b/foo.class
  build/a/b/c/foo.class
  build/a/b/c/d/foo.class

Using <delete> as it currently exists, how would you specify the task in
such a way so that any of the subdirs under build that get included in the
fileset (because they include .class files) are deleted if the dir becomes
empty once the .class files in it are deleted. I've tried about a zillion
different ways, and none of them work -- so either I'm just being
incredibly dense, or the current code doesn't do it for you.

> Let's say you have
> 
> <delete includeemptydirs="true">
>   <fileset dir="foo">
>     <include name="**/*.java" />
>   </fileset>
> </delete>
> 
> and a structure like
> 
> foo
>    /bar
>    /baz/A.java
> 
> Is bar going to be removed?  If yes, why?  If not, why not?

I would say not, since it's not a directory included in the generated
fileset, since it doesn't have any .java files. But at this point, I'm so
unclear about what 'includeEmptyDirs' is really suppposed to do (much less
what it actually does do) that my opinion may be meaningless.

> I didn't actually scan for it, but some of your lines didn't look
> properly indented.  You are not using tabs, are you? 8-)

Never -- but I indent my own stuff 2 spaces not 4, so I may have simply
not hit enough spaces at some points.

> You'd probably have to ensure you are not adding directories that are
> explicitly excluded by accident.  Something like
> 
> <delete includeemptydirs="true">
>   <fileset dir="foo">
>     <include name="**/*.java" />
>     <exclude name="baz" />
>   </fileset>
> </delete>
> 
> Your code would delete baz.

It would? How? The directory names that are added to the list are a direct
result of what's returned from the <fileset>, so how is "baz" going to end
up in the list?

Diane

=====
(holtdl@yahoo.com)



__________________________________________________
Do You Yahoo!?
Sign up for SBC Yahoo! Dial - First Month Free
http://sbc.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Possible bug in Delete task

Posted by Stefan Bodewig <bo...@apache.org>.
On Sun, 30 Jun 2002, Diane Holt <ho...@yahoo.com> wrote:

> A user posted a question about using <delete> with
> 'includeEmptyDirs' set, and from looking at Delete.java, I don't see
> it ever handling this -- but the doc seems to say it can (but maybe
> I missed how it's supposed to work).

The task assumes that your include pattern matches the directories to
remove - i.e. the dirs are part of getIncludedDirectories.

Let's say you have

<delete includeemptydirs="true">
  <fileset dir="foo">
    <include name="**/*.java" />
  </fileset>
</delete>

and a structure like

foo
   /bar
   /baz/A.java

Is bar going to be removed?  If yes, why?  If not, why not?

I'm not saying that the task's current behavior is correct, just that
it is one possible interpretation among several alternatives.  We
probably have to understand which behavior we want and document (and
potentially implement) it.

> I've modified Delete.java so it does it now, but I had to do some
> (maybe kind of weird?) things to get the potentially empty
> directories from the fileset into the "dirs" array

Hmm, yes.  Some points.

Your code uses Java 2 collection methods, no big deal.

You can avoid reversing the directory list you are putting together by
using Vector#insertElementAt(obj, 0) instead of Vector#add(obj).
After that you are done with two straight System.arraycopy calls.
Performance may suffer, but it looks cleaner.

I didn't actually scan for it, but some of your lines didn't look
properly indented.  You are not using tabs, are you? 8-)

You'd probably have to ensure you are not adding directories that are
explicitly excluded by accident.  Something like

<delete includeemptydirs="true">
  <fileset dir="foo">
    <include name="**/*.java" />
    <exclude name="baz" />
  </fileset>
</delete>

Your code would delete baz.

Stefan

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>