Browse Source

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
master
Matthew Jason Benson 20 years ago
parent
commit
43cb5f9b25
4 changed files with 62 additions and 8 deletions
  1. +2
    -0
      WHATSNEW
  2. +44
    -0
      src/etc/testcases/taskdefs/get.xml
  3. +9
    -2
      src/main/org/apache/tools/ant/taskdefs/Get.java
  4. +7
    -6
      src/testcases/org/apache/tools/ant/taskdefs/GetTest.java

+ 2
- 0
WHATSNEW View File

@@ -345,6 +345,8 @@ Fixed bugs:
* <javac debug="false"> created an invalid command line when running * <javac debug="false"> created an invalid command line when running
the Symantec Java compiler. 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 Changes from Ant 1.6.1 to Ant 1.6.2
=================================== ===================================




+ 44
- 0
src/etc/testcases/taskdefs/get.xml View File

@@ -24,6 +24,50 @@


<target name="test6"> <target name="test6">
<get src="http://www.apache.org/" dest="get.tmp"/> <get src="http://www.apache.org/" dest="get.tmp"/>

<fileset id="t6" file="get.tmp" />
<pathconvert property="t6" refid="t6" setonempty="false" />

<fail message="get failed">
<condition>
<not>
<isset property="t6" />
</not>
</condition>
</fail>
</target>

<target name="testUseTimestamp">
<property name="pat" value="yyyyMMddHHmm" />

<tstamp>
<format property="dt" pattern="${pat}" offset="-90" unit="second" />
</tstamp>

<touch file="get.tmp" datetime="${dt}" pattern="${pat}" />

<get src="http://www.apache.org/" dest="get.tmp"
usetimestamp="true" verbose="true" />

<fileset id="ts" file="get.tmp">
<date when="equal" datetime="${dt}" pattern="${pat}" />
</fileset>

<pathconvert property="ts" refid="ts" setonempty="false" />

<fail message="get w/ timestamp should have failed.">
<condition>
<not>
<isset property="ts" />
</not>
</condition>
</fail>
</target>

<target name="cleanup">
<delete>
<fileset dir="${basedir}" includes="get.tmp" />
</delete>
</target> </target>


</project> </project>

+ 9
- 2
src/main/org/apache/tools/ant/taskdefs/Get.java View File

@@ -21,6 +21,7 @@ import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project; import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task; import org.apache.tools.ant.Task;
import org.apache.tools.ant.util.FileUtils; import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.util.JavaEnvUtils;


import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@@ -137,7 +138,7 @@ public class Get extends Task {
URLConnection connection = source.openConnection(); URLConnection connection = source.openConnection();
//modify the headers //modify the headers
//NB: things like user authentication could go in here too. //NB: things like user authentication could go in here too.
if (useTimestamp && hasTimestamp) {
if (hasTimestamp) {
connection.setIfModifiedSince(timestamp); connection.setIfModifiedSince(timestamp);
} }
// prepare Java 1.1 style credentials // prepare Java 1.1 style credentials
@@ -160,13 +161,19 @@ public class Get extends Task {
HttpURLConnection httpConnection HttpURLConnection httpConnection
= (HttpURLConnection) connection; = (HttpURLConnection) connection;
if (httpConnection.getResponseCode() 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 //not modified so no file download. just return
//instead and trace out something so the user //instead and trace out something so the user
//doesn't think that the download happened when it //doesn't think that the download happened when it
//didn't //didn't
log("Not modified - so not downloaded", logLevel); log("Not modified - so not downloaded", logLevel);
return false; 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) // test for 401 result (HTTP only)
if (httpConnection.getResponseCode() if (httpConnection.getResponseCode()


+ 7
- 6
src/testcases/org/apache/tools/ant/taskdefs/GetTest.java View File

@@ -32,6 +32,10 @@ public class GetTest extends BuildFileTest {
configureProject("src/etc/testcases/taskdefs/get.xml"); configureProject("src/etc/testcases/taskdefs/get.xml");
} }


public void tearDown() {
executeTarget("cleanup");
}

public void test1() { public void test1() {
expectBuildException("test1", "required argument missing"); expectBuildException("test1", "required argument missing");
} }
@@ -54,13 +58,10 @@ public class GetTest extends BuildFileTest {


public void test6() { public void test6() {
executeTarget("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");
} }


} }

Loading…
Cancel
Save