From 43cb5f9b25a5e32a7211994d49e60cc40e1f86c9 Mon Sep 17 00:00:00 2001 From: Matthew Jason Benson Date: Fri, 25 Feb 2005 22:23:07 +0000 Subject: [PATCH] get with usetimestamp did not work on Java 1.2 . git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@277740 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 2 + src/etc/testcases/taskdefs/get.xml | 44 +++++++++++++++++++ .../org/apache/tools/ant/taskdefs/Get.java | 11 ++++- .../apache/tools/ant/taskdefs/GetTest.java | 13 +++--- 4 files changed, 62 insertions(+), 8 deletions(-) diff --git a/WHATSNEW b/WHATSNEW index 1a43ebf3a..155382501 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -345,6 +345,8 @@ Fixed bugs: * created an invalid command line when running the Symantec Java compiler. +* Get with usetimestamp did not work on Java 1.2. + Changes from Ant 1.6.1 to Ant 1.6.2 =================================== diff --git a/src/etc/testcases/taskdefs/get.xml b/src/etc/testcases/taskdefs/get.xml index 3c6c20cc6..74a81d5f2 100644 --- a/src/etc/testcases/taskdefs/get.xml +++ b/src/etc/testcases/taskdefs/get.xml @@ -24,6 +24,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/org/apache/tools/ant/taskdefs/Get.java b/src/main/org/apache/tools/ant/taskdefs/Get.java index e0c1ef721..58e2ae785 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Get.java +++ b/src/main/org/apache/tools/ant/taskdefs/Get.java @@ -21,6 +21,7 @@ import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; import org.apache.tools.ant.util.FileUtils; +import org.apache.tools.ant.util.JavaEnvUtils; import java.io.File; import java.io.FileOutputStream; @@ -137,7 +138,7 @@ public class Get extends Task { URLConnection connection = source.openConnection(); //modify the headers //NB: things like user authentication could go in here too. - if (useTimestamp && hasTimestamp) { + if (hasTimestamp) { connection.setIfModifiedSince(timestamp); } // prepare Java 1.1 style credentials @@ -160,13 +161,19 @@ public class Get extends Task { HttpURLConnection httpConnection = (HttpURLConnection) connection; if (httpConnection.getResponseCode() - == HttpURLConnection.HTTP_NOT_MODIFIED) { + == HttpURLConnection.HTTP_NOT_MODIFIED + //workaround: doesn't work on 1.2 + || (hasTimestamp + && JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_2) + && timestamp > httpConnection.getLastModified())) { //not modified so no file download. just return //instead and trace out something so the user //doesn't think that the download happened when it //didn't log("Not modified - so not downloaded", logLevel); return false; + // also, if timestamp is roughly >= now, HTTP_NOT_MODIFIED is _not_ + // returned... We may want to remove the 1.2 qualifier above. } // test for 401 result (HTTP only) if (httpConnection.getResponseCode() diff --git a/src/testcases/org/apache/tools/ant/taskdefs/GetTest.java b/src/testcases/org/apache/tools/ant/taskdefs/GetTest.java index 56706855a..a0d2f03ea 100644 --- a/src/testcases/org/apache/tools/ant/taskdefs/GetTest.java +++ b/src/testcases/org/apache/tools/ant/taskdefs/GetTest.java @@ -32,6 +32,10 @@ public class GetTest extends BuildFileTest { configureProject("src/etc/testcases/taskdefs/get.xml"); } + public void tearDown() { + executeTarget("cleanup"); + } + public void test1() { expectBuildException("test1", "required argument missing"); } @@ -54,13 +58,10 @@ public class GetTest extends BuildFileTest { public void test6() { executeTarget("test6"); - java.io.File f = new File(getProjectDir(), "get.tmp"); - if (!f.exists()) { - fail("get failed"); - } else { - f.delete(); - } + } + public void testUseTimestamp() { + executeTarget("testUseTimestamp"); } }