Just a small patch to change the gzip task (& testcase) so that it
compares the dates of the source and target files to see if it needs to
execute.
--
Jeff Martin
Memetic Engineer
http://www.custommonkey.org/
Index: src/etc/testcases/taskdefs/gzip.xml
===================================================================
RCS file: /home/cvspublic/jakarta-ant/src/etc/testcases/taskdefs/gzip.xml,v
retrieving revision 1.5
diff -u -r1.5 gzip.xml
--- src/etc/testcases/taskdefs/gzip.xml 19 Nov 2001 15:53:14 -0000 1.5
+++ src/etc/testcases/taskdefs/gzip.xml 26 Feb 2002 10:33:15 -0000
@@ -22,6 +22,11 @@
<gzip src="../asf-logo.gif" zipfile="asf-logo.gif.gz" />
</target>
+ <target name="testDateCheck">
+ <touch file="asf-logo.gif.gz"/>
+ <gzip src="../asf-logo.gif" zipfile="asf-logo.gif.gz" />
+ </target>
+
<target name="cleanup">
<delete file="asf-logo.gif.gz" />
</target>
Index: src/main/org/apache/tools/ant/taskdefs/Pack.java
===================================================================
RCS file:
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Pack.java,v
retrieving revision 1.2
diff -u -r1.2 Pack.java
--- src/main/org/apache/tools/ant/taskdefs/Pack.java 10 Jan 2002 13:59:31
-0000 1.2
+++ src/main/org/apache/tools/ant/taskdefs/Pack.java 26 Feb 2002 10:33:15
-0000
@@ -83,11 +83,11 @@
}
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 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)
Index: src/testcases/org/apache/tools/ant/taskdefs/GzipTest.java
===================================================================
RCS file:
/home/cvspublic/jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/GzipTest.java,v
retrieving revision 1.6
diff -u -r1.6 GzipTest.java
--- src/testcases/org/apache/tools/ant/taskdefs/GzipTest.java 10 Jan 2002
10:13:12 -0000 1.6
+++ src/testcases/org/apache/tools/ant/taskdefs/GzipTest.java 26 Feb 2002
10:33:15 -0000
@@ -86,4 +86,25 @@
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");
+ }
+
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>