On 2010-01-20, <dan.bad...@stfc.ac.uk> wrote:

> I have a very specific question about some ant code, I hope this is the
> correct place to post it.

It is.

> I have been using part of the ant project to unGzip and unBzip2 files as
> I wanted a Java way of doing this and I stumbled across the ant classes
> that implement this.

> Anyway I was experiencing a curious behavior of the classes
> org.apache.tools.ant.taskdefs.GUnzip and
> org.apache.tools.ant.taskdefs.BUnzip2.

I don't think you should use the tasks but rather the stream
implementation used by them under the covers directly.  An alternative
may be the Apache Commons Compress library[1].

> When the extract method is called with files I was receiving from a
> Webserver nothing was happening. Upon further investigation I noticed
> that my files were failing the check:

> if (source.lastModified() > dest.lastModified()) {

> I was wondering though, what is the purpose or use case for this check?

This is done by the tasks to avoid an unnecessary step in build
processes.  You usually have a process that downloads a file and then
uncompresses it to a destination.  Since uncompressing may be a time
consuming task you don't want to do that unless you've really downloaded
a new file.

> And also, would it not be nice to have an exception thrown or some
> logging when an extract is not attempted due to this check evaluating as
> false?

If the test fails this is a pretty normal state during a build process.

Say your build requires a third party archive, so it downloads it using
<get> and then uncompresses it.  It will do so each time you run the
build.  Unless you remove what you've downloaded the last time, <get>
will not do anything unless the file on the server has changed.
Likewise <gunzip> won't do anything unless a new file has been
downloaded (or the uncompressed file been removed).  You don't need to
put this conditional logic into the build file, in Ant the tasks check
themselves whether they need to do anything.

> From looking at the code I cannot understand what the need is for this
> check and furthermore why it should ever pass (if I create a new Dest
> file and I am using an unmodified source file then surely
> dest.lastModified > source.lastModified),

You don't create a dest file before that check at all.  If it doesn't
exist, the test will fail.

Stefan

[1] http://commons.apache.org/compress/

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

Reply via email to