----- Original Message -----
From: "Stefan Bodewig" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, July 13, 2000 00:55
Subject: Re: Time-based dependencies
> >>>>> "SL" == Steve Loughran <[EMAIL PROTECTED]> writes:
>
> SL> [A more powerful variant GET task is something I've debated doing
> SL> in my copious free time; full WebDAV method calls using the Slide
> SL> client side is the ideal goal, but perhaps timestamping would be
> SL> a useful first step].
>
> This will be more than welcome. Don't forget to write the same for the
> FTP part and include a corresponding PUT task 8^).
of course -along with user authentication & stuff, it would let me include
the remote drop as
part of the build file.
> Just kidding - something like this is on my veeeery long TODO list and
> it is far away at the end.
it's kind of far away from mine too.
I have, however, stuck in the tweaks needed for GET to only grab files if
they have changed, which I have tapped in in my spare time today. If you set
UseFiletime to true, then the if-modified-since header is set to the time of
the destination file (if it exists) and then on an HTTP URL the result of
the request is checked for returning not-modified before the content is
downloaded. In that case the task returns (and traces out 'not modified' to
the display)
However it's untested. I need to think of a suitable test matrix (and a
server to generate the test results). If someone wants to try it and let me
know, then great -especially if the test server is beyond the firewall.
There are two design issues which need thinking about too. Both are easy to
implement; it just depends on what people want.
1. non HTTP protocols.
These may include timestamps, so the GET task could choose not to save the
content if it is older. Should it? (Even so, it wont work for FTP and other
protocols that dont include date/time)
2. Touching the file after download. I don't do it -but it would make sense
to steal the code from Touch.java to do exactly that on a post Java1.1 VM.
Comments?
-Steve
cvs diff Get.java (in directory
C:\java\Apps\jakarta-ant\src\main\org\apache\tools\ant\taskdefs\)
Index: Get.java
===================================================================
RCS file:
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Get.java,v
retrieving revision 1.4
diff -r1.4 Get.java
61c61
< * Get a particular source.
---
> * Get a particular file from a URL source.
68a69
> private boolean useFiletime = false; //off by default
87a89,119
> //set the timestamp to the file date.
> long timestamp=0;
> boolean hasTimestamp=false;
> if(destF.exists()) {
> timestamp=destF.lastModified();
> hasTimestamp=true;
> }
>
> //set up the URL connection
> URLConnection connection=url.openConnection();
> //modify the headers
> //NB: things like user authentication could go in here too.
> if(hasTimestamp)
> connection.setIfModifiedSince(timestamp);
> //connect to the remote site (may take some time)
> connection.connect();
> //next test for a 304 result (HTTP only)
> if(connection instanceof HttpURLConnection) {
> HttpURLConnection httpConnection=(HttpURLConnection)connection;
>
> if(httpConnection.getResponseCode()==HttpURLConnection.HTTP_NOT_MODIFIED) {
> //not modified so no file download. just return instead
> //and trace out something so the user doesnt think
> that the
> //download happened
> log("Not modifed");
> return;
> }
> }
> //REVISIT: at this point even non HTTP connections may support
> the if-modified-since
> //behaviour -we just check the date of the content and skip
> the write if it is not
> //newer. Some protocols (FTP) dont include dates, of course.
>
93c125
< is = url.openStream();
---
> is = connection.getInputStream();
156a189,200
>
> /**
> * Use the file time, if set to "<CODE>true</CODE>".
> * In this situation, the if-modified-since header is set so that the
> file is
> * only fetched if it is newer than the local file (or there is no local
> file)
> * This flag is only valid on HTTP connections, it is ignored in other
> cases
> * @param v "true" to enable file time fetching
> */
> public void setUseFiletime(String v) {
> useFiletime = v.equalsIgnoreCase("true");
> }
>