Browse Source

time checking on gzip, with tests.

submitted by Jeff Martin <jeff@custommonkey.org>


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271573 13f79535-47bb-0310-9956-ffa450edef68
master
Steve Loughran 23 years ago
parent
commit
0005305ea6
4 changed files with 39 additions and 4 deletions
  1. +3
    -0
      WHATSNEW
  2. +5
    -0
      src/etc/testcases/taskdefs/gzip.xml
  3. +10
    -4
      src/main/org/apache/tools/ant/taskdefs/Pack.java
  4. +21
    -0
      src/testcases/org/apache/tools/ant/taskdefs/GzipTest.java

+ 3
- 0
WHATSNEW View File

@@ -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 <loadfile> to load a whole file into a property

* New task <echoproperties> to list your current properties to the screen


+ 5
- 0
src/etc/testcases/taskdefs/gzip.xml View File

@@ -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>


+ 10
- 4
src/main/org/apache/tools/ant/taskdefs/Pack.java View File

@@ -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)


+ 21
- 0
src/testcases/org/apache/tools/ant/taskdefs/GzipTest.java View File

@@ -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");
}

}

Loading…
Cancel
Save