maven-wagon-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject cvs commit: maven-wagon/wagon-provider-api/src/test/java/org/apache/maven/wagon AbstractWagonTest.java LazyFileOutputStreamTest.java
Date Tue, 07 Dec 2004 11:41:37 GMT
brett       2004/12/07 03:41:37

  Modified:    wagon-provider-api/src/main/java/org/apache/maven/wagon/events
                        TransferEvent.java TransferEventSupport.java
                        TransferListener.java
               wagon-provider-api/src/main/java/org/apache/maven/wagon/observers
                        ChecksumObserver.java Debug.java
               wagon-provider-api/src/main/java/org/apache/maven/wagon
                        AbstractWagon.java StreamWagon.java
                        WagonConstants.java
               wagon-provider-api/src/test/java/org/apache/maven/wagon/authentication
                        AuthenticationInfoTest.java
               wagon-provider-api/src/test/java/org/apache/maven/wagon/events
                        MockTransferListener.java
                        TransferEventSupportTest.java
               wagon-provider-api/src/test/java/org/apache/maven/wagon
                        AbstractWagonTest.java
                        LazyFileOutputStreamTest.java
  Log:
  o make transferevent not requiring change mid transfer by moving buffer out of event
  o unify handling of destinationfile in abstractwagon
  
  Revision  Changes    Path
  1.7       +1 -43     maven-wagon/wagon-provider-api/src/main/java/org/apache/maven/wagon/events/TransferEvent.java
  
  Index: TransferEvent.java
  ===================================================================
  RCS file: /home/cvs/maven-wagon/wagon-provider-api/src/main/java/org/apache/maven/wagon/events/TransferEvent.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TransferEvent.java	3 Jun 2004 18:26:58 -0000	1.6
  +++ TransferEvent.java	7 Dec 2004 11:41:35 -0000	1.7
  @@ -55,14 +55,8 @@
       
       private int requestType;
   
  -    private byte[] data;
  -    
  -    private int dataLength;
  -
       private Exception exception;
   
  -    private long progress;
  -    
       private File localFile;
       
   
  @@ -199,42 +193,6 @@
       {
           this.resource = resource;
       }
  -
  -    
  -
  -
  -
  -    /**
  -     *
  -     * @param data
  -     * @param dataLength
  -     */
  -    public void setData( final byte[] data, final int dataLength )
  -    {
  -        this.data = data;
  -        
  -        this.dataLength = dataLength;
  -    }
  -
  -    /**
  -     *
  -     * @return
  -     */
  -    public byte[] getData()
  -    {
  -        return data;
  -    }
  -
  -    /**
  -     *
  -     * @return
  -     */
  -    public int getDataLength()
  -    {
  -        return dataLength;
  -    }
  -    
  -    
   
       /**
        * @return Returns the local file.
  
  
  
  1.3       +5 -3      maven-wagon/wagon-provider-api/src/main/java/org/apache/maven/wagon/events/TransferEventSupport.java
  
  Index: TransferEventSupport.java
  ===================================================================
  RCS file: /home/cvs/maven-wagon/wagon-provider-api/src/main/java/org/apache/maven/wagon/events/TransferEventSupport.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TransferEventSupport.java	3 Jun 2004 18:26:58 -0000	1.2
  +++ TransferEventSupport.java	7 Dec 2004 11:41:35 -0000	1.3
  @@ -110,13 +110,15 @@
        * The Event should be of type {@link TransferEvent#TRANSFER_PROGRESS}.
        *
        * @param transferEvent the TransferEvent which will be dispached to listeners
  +     * @param buffer the buffer containing the additional content
  +     * @param length the length of the content in the buffer
        */
  -    public void fireTransferProgress( final TransferEvent transferEvent )
  +    public void fireTransferProgress( final TransferEvent transferEvent, byte[] buffer,
int length )
       {
           for ( Iterator iter = listeners.iterator(); iter.hasNext(); )
           {
               final TransferListener listener = ( TransferListener ) iter.next();
  -            listener.transferProgress( transferEvent );
  +            listener.transferProgress( transferEvent, buffer, length );
   
           }
       }
  
  
  
  1.3       +3 -3      maven-wagon/wagon-provider-api/src/main/java/org/apache/maven/wagon/events/TransferListener.java
  
  Index: TransferListener.java
  ===================================================================
  RCS file: /home/cvs/maven-wagon/wagon-provider-api/src/main/java/org/apache/maven/wagon/events/TransferListener.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TransferListener.java	3 Jun 2004 18:26:58 -0000	1.2
  +++ TransferListener.java	7 Dec 2004 11:41:35 -0000	1.3
  @@ -32,7 +32,7 @@
       /**
        * @param transferEvent 
        */
  -    void transferProgress( TransferEvent transferEvent );
  +    void transferProgress( TransferEvent transferEvent, byte[] buffer, int length );
   
       /**
        * @param transferEvent 
  @@ -49,4 +49,4 @@
        */
       void debug( String message );
   
  -}
  \ No newline at end of file
  +}
  
  
  
  1.5       +5 -12     maven-wagon/wagon-provider-api/src/main/java/org/apache/maven/wagon/observers/ChecksumObserver.java
  
  Index: ChecksumObserver.java
  ===================================================================
  RCS file: /home/cvs/maven-wagon/wagon-provider-api/src/main/java/org/apache/maven/wagon/observers/ChecksumObserver.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ChecksumObserver.java	10 Aug 2004 20:35:51 -0000	1.4
  +++ ChecksumObserver.java	7 Dec 2004 11:41:35 -0000	1.5
  @@ -108,18 +108,13 @@
       }
   
       /**
  -     * @see org.apache.maven.wagon.events.TransferListener#transferProgress(org.apache.maven.wagon.events.TransferEvent)
  +     * @see org.apache.maven.wagon.events.TransferListener#transferProgress(org.apache.maven.wagon.events.TransferEvent,byte[],int)
        */
  -    public void transferProgress( TransferEvent transferEvent )
  +    public void transferProgress( TransferEvent transferEvent, byte[] buffer, int length
)
       {
           if ( digester != null )
           {
  -            byte[] data = transferEvent.getData();
  -                                
  -            int len = transferEvent.getDataLength();
  -
  -            digester.update( data, 0, len );
  -
  +            digester.update( buffer, 0, length );
           }
           
       }
  @@ -176,9 +171,7 @@
           }
           catch ( Exception e )
           {
  -            //@todo maybe some information should be added to log?
  -            // ignore this
  -            // e.printStackTrace();
  +            // TODO: handle differently!
           }    
           finally
           {
  
  
  
  1.5       +4 -4      maven-wagon/wagon-provider-api/src/main/java/org/apache/maven/wagon/observers/Debug.java
  
  Index: Debug.java
  ===================================================================
  RCS file: /home/cvs/maven-wagon/wagon-provider-api/src/main/java/org/apache/maven/wagon/observers/Debug.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Debug.java	3 Jul 2004 12:52:22 -0000	1.4
  +++ Debug.java	7 Dec 2004 11:41:35 -0000	1.5
  @@ -164,15 +164,15 @@
       }
   
       /**
  -     * @see TransferListener#transferProgress(TransferEvent)
  +     * @see TransferListener#transferProgress(TransferEvent,byte[],int)
        */
  -    public void transferProgress( final TransferEvent transferEvent )
  +    public void transferProgress( final TransferEvent transferEvent, byte[] buffer, int
length )
       {
   
           out.print( "#" );
           //String data = new String( transferEvent.getData(),0, transferEvent.getDataLength());
           //out.println(data);
  -        transfer += transferEvent.getDataLength();
  +        transfer += length;
       }
   
       /**
  
  
  
  1.10      +35 -15    maven-wagon/wagon-provider-api/src/main/java/org/apache/maven/wagon/AbstractWagon.java
  
  Index: AbstractWagon.java
  ===================================================================
  RCS file: /home/cvs/maven-wagon/wagon-provider-api/src/main/java/org/apache/maven/wagon/AbstractWagon.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- AbstractWagon.java	10 Aug 2004 20:35:52 -0000	1.9
  +++ AbstractWagon.java	7 Dec 2004 11:41:35 -0000	1.10
  @@ -22,6 +22,7 @@
   import org.apache.maven.wagon.repository.Repository;
   
   import java.io.File;
  +import java.io.FileInputStream;
   import java.io.IOException;
   import java.io.InputStream;
   import java.io.OutputStream;
  @@ -86,19 +87,38 @@
       
       protected abstract void closeConnection() throws ConnectionException;
   
  +    protected void createParentDirectories( File destination ) 
  +        throws ResourceDoesNotExistException, TransferFailedException
  +    {
  +        if ( destination == null )
  +        {
  +            throw new ResourceDoesNotExistException( "get: Destination cannot be null"
);
  +        }
  +        
  +        File destinationDirectory = destination.getParentFile();
  +        if ( destinationDirectory != null && !destinationDirectory.exists() )
  +        {
  +            if ( !destinationDirectory.mkdirs() )
  +            {
  +                throw new TransferFailedException( "Specified destination directory cannot
be created: " + destinationDirectory );
  +            }
  +        }
  +    }
  +
       // ----------------------------------------------------------------------
       // Stream i/o
       // ----------------------------------------------------------------------
   
  -    protected void getTransfer( String resource, File destination, InputStream input, OutputStream
output )
  +    protected void getTransfer( String resource, File destination, InputStream input )
           throws TransferFailedException
       {
           fireGetStarted( resource, destination );
   
  +        OutputStream output = new LazyFileOutputStream( destination ); 
  +
           try
           {
               transfer( resource, input, output, TransferEvent.REQUEST_GET );
  -
           }
           catch ( IOException e )
           {
  @@ -130,15 +150,22 @@
           fireGetCompleted( resource, destination );
       }
   
  -    protected void putTransfer(String resource, File source, InputStream input, OutputStream
output, boolean closeOutput )
  +    protected void putTransfer(String resource, File source, OutputStream output, boolean
closeOutput )
           throws TransferFailedException
       {
           firePutStarted( resource, source );
   
  +        if ( !source.exists() )
  +        {
  +            throw new TransferFailedException( "Specified source file does not exist: "
+ source );
  +        }
  +
  +        InputStream input = null;
  +
           try
           {
  +            input = new FileInputStream( source );
               transfer( resource, input, output, TransferEvent.REQUEST_PUT );
  -
           }
           catch ( IOException e )
           {
  @@ -178,19 +205,12 @@
               
               // @todo probably new event should be created!!
               
  -            transferEvent.setData( buffer, n );
  -
  -            fireTransferProgress( transferEvent );
  +            fireTransferProgress( transferEvent, buffer, n );
               
               output.write( buffer, 0, n );
  -
  -            
           }
       }
   
  -
  -
  -
       protected void shutdownStream( InputStream inputStream )
       {
           if ( inputStream != null )
  @@ -223,9 +243,9 @@
       //
       // ----------------------------------------------------------------------
   
  -    protected void fireTransferProgress( TransferEvent transferEvent )
  +    protected void fireTransferProgress( TransferEvent transferEvent, byte[] buffer, int
n )
       {
  -        transferEventSupport.fireTransferProgress( transferEvent );
  +        transferEventSupport.fireTransferProgress( transferEvent, buffer, n );
       }
   
       protected void fireGetCompleted( String resource, File localFile )
  
  
  
  1.11      +6 -46     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.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- StreamWagon.java	10 Aug 2004 20:35:52 -0000	1.10
  +++ StreamWagon.java	7 Dec 2004 11:41:36 -0000	1.11
  @@ -50,67 +50,27 @@
       public void get( String resource, File destination )
           throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
       {
  -        
  -        if ( destination == null )
  -        {
  -           throw new ResourceDoesNotExistException( "get: Destination cannot be null" );
  -        }
  -        
  -        
  -        if ( !destination.getParentFile().exists() )
  -        {
  -            if ( !destination.getParentFile().mkdirs() )
  -            {
  -                throw new TransferFailedException( "Specified destination directory cannot
be created: " + destination.getParentFile() );
  -            }
  -        }
  -
  -        LazyFileOutputStream os = null;
  -        
  -        os = new LazyFileOutputStream( destination );
  -        
  -
           InputStream is = getInputStream( resource );
   
  -        if ( os == null )
  +        if ( is == null )
           {
  -            throw new TransferFailedException(  getRepository().getUrl() + " - Could not
open input stream for resource: '" + resource+ "'"  );
  +            throw new TransferFailedException( getRepository().getUrl() + " - Could not
open input stream for resource: '" + resource+ "'" );
           }
   
  -
  -        getTransfer( resource, destination, is, os);
  +        getTransfer( resource, destination, is );
       }
   
       // source doesn't exist exception
       public void put( File source, String resource )
           throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
       {
  -        if ( !source.exists() )
  -        {
  -            throw new TransferFailedException( "Specified source file does not exist: "
+ source );
  -        }
  -
  -        FileInputStream is = null;
  -
  -        try
  -        {           
  -            is = new FileInputStream( source );
  -        }
  -        catch ( FileNotFoundException e )
  -        {
  -            throw new TransferFailedException( "Cannot read from specified source: " +
source.getAbsolutePath() );
  -        }
  -
  -        OutputStream os;
  -
  -
  -        os = getOutputStream( resource );
  +        OutputStream os = getOutputStream( resource );
   
           if ( os == null )
           {
  -                throw new TransferFailedException(  getRepository().getUrl() + " - Could
not open output stream for resource: '" + resource+ "'"  );
  +            throw new TransferFailedException( getRepository().getUrl() + " - Could not
open output stream for resource: '" + resource+ "'" );
           }
   
  -        putTransfer( resource, source, is, os, true);
  +        putTransfer( resource, source, os, true );
       }
   }
  
  
  
  1.3       +4 -4      maven-wagon/wagon-provider-api/src/main/java/org/apache/maven/wagon/WagonConstants.java
  
  Index: WagonConstants.java
  ===================================================================
  RCS file: /home/cvs/maven-wagon/wagon-provider-api/src/main/java/org/apache/maven/wagon/WagonConstants.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- WagonConstants.java	3 Jun 2004 18:27:00 -0000	1.2
  +++ WagonConstants.java	7 Dec 2004 11:41:36 -0000	1.3
  @@ -18,16 +18,16 @@
    */
   
   /**
  - * This class contains constants used in Wagon API
  + * This class contains constants used in Wagon API.
    * 
    * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
    * @version $Id$
    */
   public final class WagonConstants
   {
  -    /** Indicates that port has not been set */
  +    /** Indicates that port has not been set. */
       public final static int UNKNOWN_PORT = -1;
   
  -    /** Indicates that lenght has not been set */
  +    /** Indicates that length has not been set. */
       public final static int UNKNOWN_LENGTH = -1;
   }
  
  
  
  1.3       +10 -1     maven-wagon/wagon-provider-api/src/test/java/org/apache/maven/wagon/authentication/AuthenticationInfoTest.java
  
  Index: AuthenticationInfoTest.java
  ===================================================================
  RCS file: /home/cvs/maven-wagon/wagon-provider-api/src/test/java/org/apache/maven/wagon/authentication/AuthenticationInfoTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AuthenticationInfoTest.java	3 Jun 2004 18:27:00 -0000	1.2
  +++ AuthenticationInfoTest.java	7 Dec 2004 11:41:37 -0000	1.3
  @@ -21,6 +21,7 @@
   import org.apache.maven.wagon.authentication.AuthenticationInfo;
   
   /**
  + * @todo test defaults
    * @author <a href="mailto:jvanzyl@maven.org">Jason van Zyl</a>
    * @version $Id$
    */
  @@ -58,6 +59,14 @@
   
           assertEquals( "password", authenticationInfo.getPassword() );
   
  +
  +        authenticationInfo.setDirectoryMode( "directoryMode" );
  +
  +        assertEquals( "directoryMode", authenticationInfo.getDirectoryMode() );
  +
  +        authenticationInfo.setFileMode( "fileMode" );
  +
  +        assertEquals( "fileMode", authenticationInfo.getFileMode() );
   
           authenticationInfo.setGroup( "group" );
   
  
  
  
  1.3       +2 -2      maven-wagon/wagon-provider-api/src/test/java/org/apache/maven/wagon/events/MockTransferListener.java
  
  Index: MockTransferListener.java
  ===================================================================
  RCS file: /home/cvs/maven-wagon/wagon-provider-api/src/test/java/org/apache/maven/wagon/events/MockTransferListener.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MockTransferListener.java	3 Jun 2004 18:27:00 -0000	1.2
  +++ MockTransferListener.java	7 Dec 2004 11:41:37 -0000	1.3
  @@ -87,7 +87,7 @@
       /**
        * @see org.apache.maven.wagon.events.TransferListener#transferProgress(org.apache.maven.wagon.events.TransferEvent)
        */
  -    public void transferProgress( final TransferEvent transferEvent )
  +    public void transferProgress( final TransferEvent transferEvent, byte[] buffer, int
length )
       {
           this.transferEvent = transferEvent;
           transferProgressCalled = true;
  
  
  
  1.4       +2 -1      maven-wagon/wagon-provider-api/src/test/java/org/apache/maven/wagon/events/TransferEventSupportTest.java
  
  Index: TransferEventSupportTest.java
  ===================================================================
  RCS file: /home/cvs/maven-wagon/wagon-provider-api/src/test/java/org/apache/maven/wagon/events/TransferEventSupportTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TransferEventSupportTest.java	10 Aug 2004 20:35:52 -0000	1.3
  +++ TransferEventSupportTest.java	7 Dec 2004 11:41:37 -0000	1.4
  @@ -100,7 +100,8 @@
   
           final TransferEvent event = getEvent( wagon );
   
  -        eventSupport.fireTransferProgress( event );
  +        // TODO: should be testing the buffer
  +        eventSupport.fireTransferProgress( event, null, 0 );
   
           assertTrue( mock1.isTransferProgressCalled() );
   
  
  
  
  1.7       +5 -15     maven-wagon/wagon-provider-api/src/test/java/org/apache/maven/wagon/AbstractWagonTest.java
  
  Index: AbstractWagonTest.java
  ===================================================================
  RCS file: /home/cvs/maven-wagon/wagon-provider-api/src/test/java/org/apache/maven/wagon/AbstractWagonTest.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- AbstractWagonTest.java	31 Jul 2004 15:03:15 -0000	1.6
  +++ AbstractWagonTest.java	7 Dec 2004 11:41:37 -0000	1.7
  @@ -120,25 +120,15 @@
           assertTrue( sessionListener.isSessionDisconnectedCalled() );
       }
   
  -    public void testGetTransferEvents()
  +    public void testGetTransferEvents() throws Exception
       {
           wagon.fireTransferDebug( "fetch debug message" );
   
  -        try
  -        {
  -            Repository repository = new Repository();
  +        Repository repository = new Repository();
   
  -            wagon.connect( repository );
  +        wagon.connect( repository );
   
  -            wagon.get( artifact, destination );
  -        }
  -
  -        catch ( Exception e )
  -        {
  -            e.printStackTrace();
  -
  -            fail( e.getMessage() );
  -        }
  +        wagon.get( artifact, destination );
   
           assertTrue( transferListener.isTransferStartedCalled() );
   
  
  
  
  1.4       +13 -23    maven-wagon/wagon-provider-api/src/test/java/org/apache/maven/wagon/LazyFileOutputStreamTest.java
  
  Index: LazyFileOutputStreamTest.java
  ===================================================================
  RCS file: /home/cvs/maven-wagon/wagon-provider-api/src/test/java/org/apache/maven/wagon/LazyFileOutputStreamTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- LazyFileOutputStreamTest.java	10 Aug 2004 20:35:53 -0000	1.3
  +++ LazyFileOutputStreamTest.java	7 Dec 2004 11:41:37 -0000	1.4
  @@ -29,40 +29,30 @@
   public class LazyFileOutputStreamTest extends TestCase
   {
   
  -     public void testFileCreation()
  +     public void testFileCreation() throws Exception
        {
  -         try
  -         {
  -             File file = FileTestUtils.createUniqueFile( this );
  +         File file = FileTestUtils.createUniqueFile( this );
                
  -             file.deleteOnExit();
  +         file.deleteOnExit();
   
  -             assertFalse( file.exists() );
  +         assertFalse( file.exists() );
   
  -             LazyFileOutputStream stream = new LazyFileOutputStream( file );
  +         LazyFileOutputStream stream = new LazyFileOutputStream( file );
   
  -             assertFalse( file.exists() );
  +         assertFalse( file.exists() );
   
  -             String exptected = "michal";
  +         String exptected = "michal";
   
  -             stream.write( exptected.getBytes() );
  +         stream.write( exptected.getBytes() );
   
  -             stream.close();
  +         stream.close();
   
  -             assertTrue( file.exists() );
  +         assertTrue( file.exists() );
   
  -             String actual = FileUtils.fileRead( file );
  +         String actual = FileUtils.fileRead( file );
   
  -             assertEquals( exptected, actual );
  +         assertEquals( exptected, actual );
   
  -
  -         }
  -         catch( Exception e )
  -         {
  -             e.printStackTrace();
  -             
  -             fail( e.getMessage() );    
  -         }
        
        }
        
  
  
  

---------------------------------------------------------------------
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