diff --git a/WHATSNEW b/WHATSNEW index 9d9f277f4..5b67ef947 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -75,6 +75,9 @@ Fixed bugs: Other changes: -------------- +* gzip now checks that the zipfile is older than the source file + before rebuilding the zipfile. + * New task to load a whole file into a property * New task to list your current properties to the screen diff --git a/src/etc/testcases/taskdefs/gzip.xml b/src/etc/testcases/taskdefs/gzip.xml index c62e0577c..a59973505 100644 --- a/src/etc/testcases/taskdefs/gzip.xml +++ b/src/etc/testcases/taskdefs/gzip.xml @@ -22,6 +22,11 @@ + + + + + diff --git a/src/main/org/apache/tools/ant/taskdefs/Pack.java b/src/main/org/apache/tools/ant/taskdefs/Pack.java index 09ad4d8f4..5fb9972bc 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Pack.java +++ b/src/main/org/apache/tools/ant/taskdefs/Pack.java @@ -83,11 +83,11 @@ public abstract class Pack extends Task { } private void validate() { - if (zipFile == null) { + if (zipFile == null || zipFile.getName().equals("")) { throw new BuildException("zipfile attribute is required", location); } - if (source == null) { + if (source == null || source.getName().equals("")) { throw new BuildException("src attribute is required", location); } @@ -99,8 +99,14 @@ public abstract class Pack extends Task { public void execute() throws BuildException { validate(); - log("Building: " + zipFile.getAbsolutePath()); - pack(); + + if(zipFile.lastModified() < source.lastModified()){ + log("Building: " + zipFile.getAbsolutePath()); + pack(); + }else{ + log("Nothing to do: " + zipFile.getAbsolutePath() + + " is up to date."); + } } private void zipFile(InputStream in, OutputStream zOut) diff --git a/src/testcases/org/apache/tools/ant/taskdefs/GzipTest.java b/src/testcases/org/apache/tools/ant/taskdefs/GzipTest.java index b871d68e7..58fa948b8 100644 --- a/src/testcases/org/apache/tools/ant/taskdefs/GzipTest.java +++ b/src/testcases/org/apache/tools/ant/taskdefs/GzipTest.java @@ -86,4 +86,25 @@ public class GzipTest extends BuildFileTest { expectBuildException("test4", "attribute zipfile invalid"); } + public void testGZip(){ + executeTarget("realTest"); + String log = getLog(); + assertTrue("Expecting message starting with 'Building:' but got '" + + log + "'", log.startsWith("Building:")); + assertTrue("Expecting message ending with 'asf-logo.gif.gz' but got '" + + log + "'", log.endsWith("asf-logo.gif.gz")); + } + + public void testDateCheck(){ + executeTarget("testDateCheck"); + String log = getLog(); + assertTrue( + "Expecting message ending with 'asf-logo.gif.gz is up to date.' but got '" + log + "'", + log.endsWith("asf-logo.gif.gz is up to date.")); + } + + public void tearDown(){ + executeTarget("cleanup"); + } + }