maven-wagon-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mic...@apache.org
Subject cvs commit: maven-wagon/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http HttpWagon.java
Date Wed, 15 Dec 2004 21:16:07 GMT
michal      2004/12/15 13:16:07

  Modified:    wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh
                        ScpWagon.java
               wagon-provider-api/src/main/java/org/apache/maven/wagon
                        StreamWagon.java Wagon.java
               wagon-provider-api/src/test/java/org/apache/maven/wagon
                        MockWagon.java
               wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http
                        HttpWagon.java
  Log:
  First attempt to implement getIfNewer. I am still experimenting with the API and implementation
of providers and trying to make them simpler.
  
  Revision  Changes    Path
  1.6       +6 -1      maven-wagon/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/ScpWagon.java
  
  Index: ScpWagon.java
  ===================================================================
  RCS file: /home/cvs/maven-wagon/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/ScpWagon.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ScpWagon.java	14 Dec 2004 20:10:38 -0000	1.5
  +++ ScpWagon.java	15 Dec 2004 21:16:06 -0000	1.6
  @@ -528,6 +528,11 @@
           }
       }
   
  +    public boolean getIfNewer( String resourceName, File destination, long timestamp )
  +    {
  +        throw new UnsupportedOperationException( "getIfNewer is scp wagon must be still
implemented" );
  +    }
  +
   // ----------------------------------------------------------------------
   // JSch user info
   // ----------------------------------------------------------------------
  
  
  
  1.15      +39 -1     maven-wagon/wagon-provider-api/src/main/java/org/apache/maven/wagon/StreamWagon.java
  
  Index: StreamWagon.java
  ===================================================================
  RCS file: /home/cvs/maven-wagon/wagon-provider-api/src/main/java/org/apache/maven/wagon/StreamWagon.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- StreamWagon.java	15 Dec 2004 11:46:33 -0000	1.14
  +++ StreamWagon.java	15 Dec 2004 21:16:07 -0000	1.15
  @@ -33,6 +33,7 @@
   public abstract class StreamWagon
       extends AbstractWagon
   {
  +
       // ----------------------------------------------------------------------
       //
       // ----------------------------------------------------------------------
  @@ -75,6 +76,43 @@
   
           getTransfer( inputData.getResource(), destination, is );
       }
  +
  +    public boolean getIfNewer( String resourceName, File destination, long timestamp)
  +            throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
  +    {
  +        boolean retValue = false;
  +
  +        InputData inputData = new InputData( );
  +
  +        Resource resource = new Resource( resourceName );
  +
  +        inputData.setResource( resource );
  +
  +        fillInputData( inputData );
  +
  +        InputStream is = inputData.getInputStream();
  +
  +        if ( resource.getLastModified() > timestamp )
  +        {
  +            retValue = true;
  +
  +            if ( is == null )
  +            {
  +                throw new TransferFailedException( getRepository().getUrl() + " - Could
not open input stream for resource: '" + resource+ "'" );
  +            }
  +
  +            createParentDirectories( destination );
  +
  +            getTransfer( inputData.getResource(), destination, is );
  +        }
  +        else
  +        {
  +            shutdownStream( is );
  +        }
  +
  +        return retValue;
  +    }
  +
   
       // source doesn't exist exception
       public void put( File source, String resourceName )
  
  
  
  1.8       +35 -1     maven-wagon/wagon-provider-api/src/main/java/org/apache/maven/wagon/Wagon.java
  
  Index: Wagon.java
  ===================================================================
  RCS file: /home/cvs/maven-wagon/wagon-provider-api/src/main/java/org/apache/maven/wagon/Wagon.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Wagon.java	31 Jul 2004 15:03:15 -0000	1.7
  +++ Wagon.java	15 Dec 2004 21:16:07 -0000	1.8
  @@ -33,7 +33,41 @@
       // File/File handling
       // ----------------------------------------------------------------------
   
  -    void get( String source, File destination )
  +
  +    /**
  +     * Downloads specified resource from the repository to given file.
  +     *
  +     * @param resourceName
  +     * @param destination
  +     * @throws TransferFailedException
  +     * @throws ResourceDoesNotExistException
  +     * @throws AuthorizationException
  +     */
  +    void get( String resourceName, File destination )
  +        throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException;
  +
  +    /**
  +     * Downloads specified resource from the repository
  +     * if it was modfified since specified date.
  +     * The date is measured in milliseconds, between the current time and midnight, January
1, 1970 UTC
  +     * and aliged to GMT timezone.
  +     *
  +     *
  +     * @param resourceName
  +     * @param destination
  +     * @param timestamp
  +     * @return
  +     * @throws TransferFailedException
  +     * @throws ResourceDoesNotExistException
  +     * @throws AuthorizationException
  +     *
  +     * @return <code>true</code> if newer resource has been downloaded, <code>false</code>
if resource
  +     * in the repository is older or has the same age.
  +     *
  +     * @todo michal: I have to learn more about timezones!
  +     * Specifically how to convert time for UTC to time for GMT and if such conversioin
is needed.
  +     */
  +    boolean getIfNewer( String resourceName, File destination, long timestamp )
           throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException;
   
       void put( File source, String destination )
  
  
  
  1.8       +11 -7     maven-wagon/wagon-provider-api/src/test/java/org/apache/maven/wagon/MockWagon.java
  
  Index: MockWagon.java
  ===================================================================
  RCS file: /home/cvs/maven-wagon/wagon-provider-api/src/test/java/org/apache/maven/wagon/MockWagon.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- MockWagon.java	14 Dec 2004 20:10:38 -0000	1.7
  +++ MockWagon.java	15 Dec 2004 21:16:07 -0000	1.8
  @@ -18,11 +18,9 @@
    */
   
   import org.apache.maven.wagon.resource.Resource;
  +import org.apache.maven.wagon.authorization.AuthorizationException;
   
  -import java.io.ByteArrayInputStream;
  -import java.io.ByteArrayOutputStream;
  -import java.io.InputStream;
  -import java.io.OutputStream;
  +import java.io.*;
   
   /**
    * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
  @@ -52,8 +50,6 @@
   
           if ( errorInputStream )
           {
  -
  -
               MockInputStream mockInputStream = new MockInputStream();
   
               mockInputStream.setForcedError( true );
  @@ -95,6 +91,12 @@
           
       }
   
  +    public boolean getIfNewer( String resourceName, File destination, long timestamp)
  +            throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
  +    {
  +       return false;
  +    }
  +
       public void openConnection()
       {
       }
  @@ -102,4 +104,6 @@
       public void closeConnection()
       {
       }
  +
  +
   }
  
  
  
  1.4       +58 -25    maven-wagon/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/HttpWagon.java
  
  Index: HttpWagon.java
  ===================================================================
  RCS file: /home/cvs/maven-wagon/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/HttpWagon.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- HttpWagon.java	14 Dec 2004 20:10:39 -0000	1.3
  +++ HttpWagon.java	15 Dec 2004 21:16:07 -0000	1.4
  @@ -194,8 +194,35 @@
       }
   
       public void get( String resourceName, File destination )
  +       throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
  +    {
  +        get( resourceName, destination, 0, false );
  +    }
  +
  +    public boolean getIfNewer( String resourceName, File destination, long timestamp )
throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
  +    {
  +        return get( resourceName, destination, timestamp, true );
  +    }
  +
  +    /**
  +     *
  +     * @param resourceName
  +     * @param destination
  +     * @param timestamp
  +     * @param newerRequired
  +     * @return
  +     * @throws TransferFailedException
  +     * @throws ResourceDoesNotExistException
  +     * @throws AuthorizationException
  +     *
  +     * @return <code>true</code> if newer version was downloaded, <code>false</code>
otherwise.
  +     */
  +    public boolean get( String resourceName, File destination, long timestamp, boolean
newerRequired )
           throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
       {
  +
  +        boolean retValue = false;
  +
           String url = getRepository().getUrl() + "/" + resourceName;
   
           GetMethod getMethod = new GetMethod( url );
  @@ -208,7 +235,6 @@
   
           getMethod.addRequestHeader( "Expires", "0" );
   
  -
           int statusCode = SC_NULL;
   
           int attempt = 0;
  @@ -260,10 +286,6 @@
   
           Resource resource = new Resource( resourceName );
   
  -        resource.setLastModified( 0 );
  -
  -        resource.setContentLength( 0 );
  -
           InputStream is = null;
   
           Header contentLengthHeader = getMethod.getResponseHeader( "Content-Length" );
  @@ -301,36 +323,47 @@
   
               fireTransferDebug( "last-modified = " + lastModifiedHeader.getValue() + " ("
+ lastModified + ")" );
           }
  -        try
  -        {
  -            is = getMethod.getResponseBodyAsStream();
   
  -            getTransfer( resource, destination, is );
  -        }
  -        catch ( Exception e )
  +        //@todo have to check how m1 does it
  +        boolean isNewer = timestamp < lastModified;
  +
  +        if(  ( isNewer && newerRequired )  || ( !newerRequired )  )
           {
  -            fireTransferError( resource, e );
  +            retValue = true;
  +
  +            try
  +            {
  +                is = getMethod.getResponseBodyAsStream();
   
  -            if ( destination.exists() )
  +                getTransfer( resource, destination, is );
  +            }
  +            catch ( Exception e )
               {
  -                boolean deleted = destination.delete();
  +                fireTransferError( resource, e );
   
  -                if ( ! deleted )
  +                if ( destination.exists() )
                   {
  -                    destination.deleteOnExit();
  +                    boolean deleted = destination.delete();
  +
  +                    if ( ! deleted )
  +                    {
  +                        destination.deleteOnExit();
  +                    }
                   }
  -            }
   
  -            String msg = "Error occured while deploying to remote repository:" + getRepository();
  +                String msg = "Error occured while deploying to remote repository:" + getRepository();
   
  -            throw new TransferFailedException( msg, e );
  -        }
  -        finally
  -        {
  -            shutdownStream( is );
  -        }
  +                throw new TransferFailedException( msg, e );
  +            }
  +            finally
  +            {
  +                shutdownStream( is );
  +            }
   
  +        }
           getMethod.releaseConnection();
  +
  +        return retValue;
       }
   
       public int getNumberOfAttempts()
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: wagon-cvs-unsubscribe@maven.apache.org
For additional commands, e-mail: wagon-cvs-help@maven.apache.org


Mime
View raw message