You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by da...@stfc.ac.uk on 2010/01/20 18:13:58 UTC

Questions regarding GUnzip and BUnzip2 extract methods.

Hello there,

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

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. 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()) {

 

It turned out that my source file had a lastModified =  0, so before
calling the extract method I would manually ensure that the modified
fields of the source and dest files were correct to pass this check.

 I was wondering though, what is the purpose or use case for this check?
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? 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), so I am very intrigued as to
why it is used. Any information on this would be much appreciated.

Finally I would like to say that I have found the ant tool very useful
for deploying complex java projects to Glassfish etc and apart from this
strange behavior, resulting from files that have their lastModified
fields set incorrectly, that the Untar/GUnzip/BUnzip2 classes work very
well indeed and have been an excellent solution to my problem.

Regards,

Dan.

 


-- 
Scanned by iCritical.


Re: Questions regarding GUnzip and BUnzip2 extract methods.

Posted by Stefan Bodewig <bo...@apache.org>.
On 2010-01-20, <da...@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-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org