evenisse    2004/04/21 06:53:53

  Modified:    src/java/org/apache/maven/util Tag: MAVEN-1_0-BRANCH
                        HttpUtils.java
  Log:
  Fix MAVEN-1226. Snapshot is download only if the remote version is more recent than 
local version.
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.28.4.6  +13 -8     maven/src/java/org/apache/maven/util/HttpUtils.java
  
  Index: HttpUtils.java
  ===================================================================
  RCS file: /home/cvs/maven/src/java/org/apache/maven/util/HttpUtils.java,v
  retrieving revision 1.28.4.5
  retrieving revision 1.28.4.6
  diff -u -r1.28.4.5 -r1.28.4.6
  --- HttpUtils.java    15 Apr 2004 06:05:51 -0000      1.28.4.5
  +++ HttpUtils.java    21 Apr 2004 13:53:53 -0000      1.28.4.6
  @@ -28,7 +28,6 @@
   import java.net.PasswordAuthentication;
   import java.net.URL;
   import java.net.URLConnection;
  -import java.util.Date;
   
   /**
    * Http utils for retrieving files.
  @@ -170,10 +169,10 @@
           throws IOException
       {
           //set the timestamp to the file date.
  -        Date timestamp = null;
  +        long timestamp = -1;
           if ( useTimestamp && destinationFile.exists() )
           {
  -            timestamp = new Date( destinationFile.lastModified() );
  +            timestamp = destinationFile.lastModified();
           }
   
           try
  @@ -201,7 +200,7 @@
        * @param url the URL of the file to retrieve
        * @param destinationFile where to store it
        * @param timestamp if provided, the remote URL is only retrieved if it was
  -     * modified more recently than timestamp. Otherwise, null indicates that
  +     * modified more recently than timestamp. Otherwise, negative value indicates 
that
        * the remote URL should be retrieved unconditionally.
        * @param proxyHost Proxy Host (if proxy is required), or null
        * @param proxyPort Proxy Port (if proxy is required), or null
  @@ -213,7 +212,7 @@
        */
       public static void getFile( String url,
                                   File destinationFile,
  -                                Date timestamp,
  +                                long timestamp,
                                   String proxyHost,
                                   String proxyPort,
                                   String proxyUserName,
  @@ -234,9 +233,9 @@
           URLConnection connection = source.openConnection();
   
           //modify the headers
  -        if ( timestamp != null )
  +        if ( timestamp >= 0 )
           {
  -            connection.setIfModifiedSince( timestamp.getTime() );
  +            connection.setIfModifiedSince( timestamp );
           }
           // prepare Java 1.1 style credentials
           if ( username != null || password != null )
  @@ -315,6 +314,12 @@
               throw isException;
           }
   
  +        if ( connection.getLastModified() <= timestamp &&
  +             connection.getLastModified() != 0 )
  +        {
  +            return;
  +        }
  +        
           FileOutputStream fos = new FileOutputStream( destinationFile );
   
           byte[] buffer = new byte[100 * 1024];
  @@ -333,7 +338,7 @@
           // if (and only if) the use file time option is set, then the
           // saved file now has its timestamp set to that of the downloaded
           // file
  -        if ( timestamp != null )
  +        if ( timestamp >= 0 )
           {
               long remoteTimestamp = connection.getLastModified();
               if ( remoteTimestamp != 0 )
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to