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-api/src/main/java/org/apache/maven/wagon/observers Debug.java Md5SumObserver.java
Date Fri, 21 May 2004 16:48:50 GMT
michal      2004/05/21 09:48:50

  Modified:    wagon-api/src/main/java/org/apache/maven/wagon
                        AbstractWagon.java Wagon.java WagonTestCase.java
                        StreamWagon.java WagonUtils.java
               wagon-api/src/main/java/org/apache/maven/wagon/events
                        TransferEvent.java
               wagon-api/src/main/java/org/apache/maven/wagon/observers
                        Md5SumObserver.java
  Added:       wagon-api/src/main/java/org/apache/maven/wagon/observers
                        Debug.java
  Removed:     wagon-api/src/main/java/org/apache/maven/wagon/events
                        Debug.java
  Log:
  Removing stream based api. I was too quick to introduce it.  Events now contain informatiion
about local file which is ued during put/get transfers
  
  Revision  Changes    Path
  1.3       +20 -11    maven-wagon/wagon-api/src/main/java/org/apache/maven/wagon/AbstractWagon.java
  
  Index: AbstractWagon.java
  ===================================================================
  RCS file: /home/cvs/maven-wagon/wagon-api/src/main/java/org/apache/maven/wagon/AbstractWagon.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AbstractWagon.java	26 Apr 2004 19:23:43 -0000	1.2
  +++ AbstractWagon.java	21 May 2004 16:48:50 -0000	1.3
  @@ -26,6 +26,7 @@
   import org.apache.maven.wagon.events.TransferListener;
   import org.apache.maven.wagon.repository.Repository;
   
  +import java.io.File;
   import java.io.InputStream;
   import java.io.OutputStream;
   import java.io.IOException;
  @@ -94,10 +95,10 @@
       // Stream i/o
       // ----------------------------------------------------------------------
   
  -    protected void getTransfer( String resource, InputStream input, OutputStream output
)
  +    protected void getTransfer( String resource, InputStream input, OutputStream output,
File localFile )
           throws TransferFailedException
       {
  -        fireGetStarted( resource );
  +        fireGetStarted( resource, localFile );
   
           try
           {
  @@ -114,13 +115,13 @@
               throw new TransferFailedException( msg, e );
           }
   
  -        fireGetCompleted( resource );
  +        fireGetCompleted( resource, localFile );
       }
   
  -    protected void putTransfer( String resource, InputStream input, OutputStream output
)
  +    protected void putTransfer( String resource, InputStream input, OutputStream output,
File localFile )
           throws TransferFailedException
       {
  -        firePutStarted( resource );
  +        firePutStarted( resource, localFile );
   
           try
           {
  @@ -137,7 +138,7 @@
               throw new TransferFailedException( msg, e );
           }
   
  -        firePutCompleted( resource );
  +        firePutCompleted( resource, localFile );
       }
   
       protected void transfer( String resource, InputStream input, OutputStream output, int
requestType )
  @@ -236,7 +237,7 @@
           transferEventSupport.fireTransferProgress( transferEvent );
       }
   
  -    protected void fireGetCompleted( String resource )
  +    protected void fireGetCompleted( String resource, File localFile )
       {
           long timestamp = System.currentTimeMillis();
   
  @@ -245,10 +246,12 @@
   
           transferEvent.setTimestamp( timestamp );
   
  +        transferEvent.setLocalFile( localFile );
  +        
           transferEventSupport.fireTransferCompleted( transferEvent );
       }
   
  -    protected void fireGetStarted( String resource )
  +    protected void fireGetStarted( String resource, File localFile )
       {
           long timestamp = System.currentTimeMillis();
   
  @@ -256,11 +259,13 @@
               new TransferEvent( this, resource, TransferEvent.TRANSFER_STARTED, TransferEvent.REQUEST_GET
);
   
           transferEvent.setTimestamp( timestamp );
  +        
  +        transferEvent.setLocalFile( localFile );
   
           transferEventSupport.fireTransferStarted( transferEvent );
       }
   
  -    protected void firePutCompleted( String resource )
  +    protected void firePutCompleted( String resource, File localFile )
       {
           long timestamp = System.currentTimeMillis();
   
  @@ -268,11 +273,13 @@
               new TransferEvent( this, resource, TransferEvent.TRANSFER_COMPLETED, TransferEvent.REQUEST_PUT
);
   
           transferEvent.setTimestamp( timestamp );
  +        
  +        transferEvent.setLocalFile( localFile );
   
           transferEventSupport.fireTransferCompleted( transferEvent );
       }
   
  -    protected void firePutStarted( String resource )
  +    protected void firePutStarted( String resource, File localFile )
       {
           long timestamp = System.currentTimeMillis();
   
  @@ -280,6 +287,8 @@
               new TransferEvent( this, resource, TransferEvent.TRANSFER_STARTED, TransferEvent.REQUEST_PUT
);
   
           transferEvent.setTimestamp( timestamp );
  +        
  +        transferEvent.setLocalFile( localFile );
   
           transferEventSupport.fireTransferStarted( transferEvent );
       }
  
  
  
  1.5       +0 -13     maven-wagon/wagon-api/src/main/java/org/apache/maven/wagon/Wagon.java
  
  Index: Wagon.java
  ===================================================================
  RCS file: /home/cvs/maven-wagon/wagon-api/src/main/java/org/apache/maven/wagon/Wagon.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Wagon.java	20 May 2004 15:41:37 -0000	1.4
  +++ Wagon.java	21 May 2004 16:48:50 -0000	1.5
  @@ -24,8 +24,6 @@
   import org.apache.maven.wagon.repository.Repository;
   
   import java.io.File;
  -import java.io.InputStream;
  -import java.io.OutputStream;
   
   public interface Wagon
   {
  @@ -56,17 +54,6 @@
       // /Stream handling
       // ----------------------------------------------------------------------
   
  -    /**
  -     *  
  -     */
  -    InputStream getInputStream( String source )
  -        throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException;
  -
  -    /**
  -     *  
  -     */
  -    OutputStream getOutputStream( String source )
  -        throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException;
       
   
       Repository getRepository();
  
  
  
  1.6       +2 -2      maven-wagon/wagon-api/src/main/java/org/apache/maven/wagon/WagonTestCase.java
  
  Index: WagonTestCase.java
  ===================================================================
  RCS file: /home/cvs/maven-wagon/wagon-api/src/main/java/org/apache/maven/wagon/WagonTestCase.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- WagonTestCase.java	11 May 2004 19:11:09 -0000	1.5
  +++ WagonTestCase.java	21 May 2004 16:48:50 -0000	1.6
  @@ -2,8 +2,8 @@
   
   import org.apache.maven.wagon.artifact.Artifact;
   import org.apache.maven.wagon.artifact.DefaultArtifact;
  +import org.apache.maven.wagon.observers.Debug;
   import org.apache.maven.wagon.repository.Repository;
  -import org.apache.maven.wagon.events.Debug;
   import org.apache.maven.wagon.authentication.AuthenticationInfo;
   import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
   import org.apache.maven.model.Model;
  
  
  
  1.7       +3 -3      maven-wagon/wagon-api/src/main/java/org/apache/maven/wagon/StreamWagon.java
  
  Index: StreamWagon.java
  ===================================================================
  RCS file: /home/cvs/maven-wagon/wagon-api/src/main/java/org/apache/maven/wagon/StreamWagon.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- StreamWagon.java	11 May 2004 19:11:09 -0000	1.6
  +++ StreamWagon.java	21 May 2004 16:48:50 -0000	1.7
  @@ -117,7 +117,7 @@
               throw new TransferFailedException( msg, e );
           }
   
  -        getTransfer( resource, is, os );
  +        getTransfer( resource, is, os, destination );
       }
   
       // source doesn't exist exception
  @@ -132,7 +132,7 @@
           FileInputStream is = null;
   
           try
  -        {
  +        {           
               is = new FileInputStream( source );
           }
           catch ( FileNotFoundException e )
  @@ -151,6 +151,6 @@
               throw new TransferFailedException( "Cannot create input stream: ", e );
           }
   
  -        putTransfer( resource, is, os );
  +        putTransfer( resource, is, os, source );
       }
   }
  
  
  
  1.2       +46 -46    maven-wagon/wagon-api/src/main/java/org/apache/maven/wagon/WagonUtils.java
  
  Index: WagonUtils.java
  ===================================================================
  RCS file: /home/cvs/maven-wagon/wagon-api/src/main/java/org/apache/maven/wagon/WagonUtils.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- WagonUtils.java	20 May 2004 15:41:37 -0000	1.1
  +++ WagonUtils.java	21 May 2004 16:48:50 -0000	1.2
  @@ -1,11 +1,11 @@
   package org.apache.maven.wagon;
   
  +import org.apache.maven.wagon.authorization.AuthorizationException;
  +import org.codehaus.plexus.util.FileUtils;
  +
  +import java.io.File;
   import java.io.IOException;
  -import java.io.InputStream;
  -import java.io.OutputStream;
   
  -import org.apache.maven.wagon.authorization.AuthorizationException;
  -import org.codehaus.plexus.util.IOUtil;
   
   /**
    * @author <a href="mailto:mmaczka@interia.pl">Michal Maczka</a> 
  @@ -14,70 +14,70 @@
   public class WagonUtils
   {
   
  -    public static byte[] toByteArray( String resource, Wagon wagon  ) throws IOException,
TransferFailedException, ResourceDoesNotExistException, AuthorizationException
  +    
  +    public static String toString( String resource, Wagon wagon  ) throws IOException,
TransferFailedException, ResourceDoesNotExistException, AuthorizationException
       {
  -        InputStream inputStream = null;
  +        
  +        File file = null;
          
           try
  -        {        
  -             inputStream = wagon.getInputStream( resource );
  +        {                     
  +             file = File.createTempFile( "wagon", "tmp" );
  +            
  +             wagon.get( resource, file );
                
  -             byte[] retValue = IOUtil.toByteArray( inputStream );
  +             String retValue = FileUtils.fileRead( file );
                
                return retValue;
           }        
           finally
  -        {
  -             IOUtil.close( inputStream );
  +        {           
  +             
  +             if ( file != null )
  +             {
  +                 boolean deleted = file.delete();
  +                 
  +                 if ( ! deleted )
  +                 {
  +                     file.deleteOnExit();    
  +                 }                
  +             }
           }
           
            
       }
       
  -    public static void fromByteArray( String resource, Wagon wagon, byte[] buffer  ) throws
IOException, TransferFailedException, ResourceDoesNotExistException, AuthorizationException
  +    public static void fromString( String resource, Wagon wagon, String content  ) throws
Exception
       {
  -        OutputStream outputStream = null;
  +        File file = null;
          
           try
  -        {        
  -             outputStream = wagon.getOutputStream( resource );
  -             
  -             IOUtil.copy( buffer, outputStream );
  -             
  -             
  +        {     
  +            file = File.createTempFile( "wagon", "tmp" );
  +            
  +            
  +            //@todo this methos should trow something more sepcific then java.lang.Exception
  +            FileUtils.fileWrite( file.getPath(), content );
  +            
  +            wagon.put( file, resource );
  +                          
           }        
           finally
           {
  -             IOUtil.close( outputStream );
  +            if ( file != null )
  +            {
  +                boolean deleted = file.delete();
  +                
  +                if ( ! deleted )
  +                {
  +                    file.deleteOnExit();    
  +                }
  +                
  +            }
           }
           
            
       }
  -    
  -    
  -    
  -    public static String toString( String resource, Wagon wagon  ) throws IOException,
TransferFailedException, ResourceDoesNotExistException, AuthorizationException
  -    {
  -    
  -        byte[] buffer = toByteArray( resource, wagon );
  -        
  -        String retValue = new String( buffer );
  -        
  -        return retValue;
  -         
  -    }
  -    
  -    public static void fromString( String resource, Wagon wagon, String  str ) throws IOException,
TransferFailedException, ResourceDoesNotExistException, AuthorizationException
  -    {
  -    
  -        byte[] buffer = str.getBytes();
  -        
  -        fromByteArray( resource, wagon, buffer  );
           
  -        
  -         
  -    }
  -    
  -    
       
   }
  
  
  
  1.4       +22 -1     maven-wagon/wagon-api/src/main/java/org/apache/maven/wagon/events/TransferEvent.java
  
  Index: TransferEvent.java
  ===================================================================
  RCS file: /home/cvs/maven-wagon/wagon-api/src/main/java/org/apache/maven/wagon/events/TransferEvent.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TransferEvent.java	20 May 2004 15:41:37 -0000	1.3
  +++ TransferEvent.java	21 May 2004 16:48:50 -0000	1.4
  @@ -18,6 +18,8 @@
   
   import org.apache.maven.wagon.Wagon;
   
  +import java.io.File;
  +
   /***
    * TransferEvent is used to notify TransferListeners about progress
    * in transfer of resources form/to the respository
  @@ -59,6 +61,9 @@
       private Exception exception;
   
       private long progress;
  +    
  +    private File localFile;
  +    
   
       public TransferEvent(
               final Wagon wagon,
  @@ -242,5 +247,21 @@
       {
           return dataLength;
       }
  +    
  +    
   
  +    /**
  +     * @return Returns the local file.
  +     */
  +    public File getLocalFile()
  +    {
  +        return localFile;
  +    }
  +    /**
  +     * @param localFile The local file to set.
  +     */
  +    public void setLocalFile( File localFile )
  +    {
  +        this.localFile = localFile;
  +    }
   }
  
  
  
  1.5       +18 -31    maven-wagon/wagon-api/src/main/java/org/apache/maven/wagon/observers/Md5SumObserver.java
  
  Index: Md5SumObserver.java
  ===================================================================
  RCS file: /home/cvs/maven-wagon/wagon-api/src/main/java/org/apache/maven/wagon/observers/Md5SumObserver.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Md5SumObserver.java	20 May 2004 16:00:57 -0000	1.4
  +++ Md5SumObserver.java	21 May 2004 16:48:50 -0000	1.5
  @@ -82,13 +82,23 @@
               
               if ( type  == TransferEvent.REQUEST_GET )
               {
  -                                            
  -               expectedMd5 = WagonUtils.toString( resource + ".md5 ", wagon ).trim(); 
             
  +                
  +                //we will fetch md5 cheksum from server and
  +                // read its content into memory
  +                File artifactFile = transferEvent.getLocalFile();
  +                
  +                File md5File = new File( artifactFile.getPath() + ".md5" );
  +                
  +                String  md5Resource = resource + ".md5";
  +                
  +                wagon.get( md5Resource, md5File );
  +               
  +                expectedMd5 = FileUtils.fileRead( md5File  );               
               }
               else
               {
  -                //It's PUT put request
  -                
  +                //It's PUT put request we will also put md5 checksum
  +                // which was computed on the fly
                   WagonUtils.fromString( resource + ".md5 ", wagon, actualMd5 );
                   
               }            
  @@ -110,9 +120,8 @@
       }
   
       public void transferError( TransferEvent transferEvent )
  -    {
  -        
  -        
  +    { 
  +        md5Digester = null;  
       }
   
       public void debug( String message )
  @@ -190,29 +199,7 @@
           return retValue;
       }
   
  -    /**
  -     * @param file
  -     */
  -    public void writeToFile( File file )
  -    {
  -        // Here I will write to file the expected md5 sum
  -        //(the one which was donloaded from the server)
  -        if ( expectedMd5 != null )
  -        {
  -            String path = file.getPath();
  -            
  -            try
  -            {                
  -                FileUtils.fileWrite( path , expectedMd5  );
  -            }
  -            catch( Exception e)
  -            {
  -               //getLogger().error( "Could not write the value of md5 checkum to file:
" + path );
  -               
  -            }
  -        }
  -        
  -    }
  +   
       
       
       
  
  
  
  1.1                  maven-wagon/wagon-api/src/main/java/org/apache/maven/wagon/observers/Debug.java
  
  Index: Debug.java
  ===================================================================
  package org.apache.maven.wagon.observers;
  
  import org.apache.maven.wagon.events.SessionEvent;
  import org.apache.maven.wagon.events.SessionListener;
  import org.apache.maven.wagon.events.TransferEvent;
  import org.apache.maven.wagon.events.TransferListener;
  
  import java.io.PrintStream;
  
  /*
   * Copyright 2001-2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  /**
   * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
   * @version $Id: Debug.java,v 1.1 2004/05/21 16:48:50 michal Exp $
   */
  public class Debug
      implements SessionListener, TransferListener
  {
      private PrintStream out;
      
      long timestamp;
      
      long transfer;
      
      
      public Debug()
      {
          this( System.out );    
      }
      
      public Debug( PrintStream out )
      {
         this.out = out;    
      }
  
      /**
       * @see SessionListener#sessionOpening(SessionEvent)
       */
      public void sessionOpening( final SessionEvent sessionEvent )
      {
          //out.println( .getUrl() + " - Session: Opening  ");
      }
  
      /**
       * @see SessionListener#sessionOpened(SessionEvent)
       */
      public void sessionOpened( final SessionEvent sessionEvent )
      {
          out.println(
              sessionEvent.getWagon().getRepository().getUrl() +
              " - Session: Opened  " );
      }
  
      /**
       * @see SessionListener#sessionDisconnecting(SessionEvent)
       */
      public void sessionDisconnecting( final SessionEvent sessionEvent )
      {
          out.println(
              sessionEvent.getWagon().getRepository().getUrl() +
              " - Session: Disconnecting  " );
  
      }
  
      /**
       * @see SessionListener#sessionDisconnected(SessionEvent)
       */
      public void sessionDisconnected( final SessionEvent sessionEvent )
      {
          out.println(
              sessionEvent.getWagon().getRepository().getUrl() +
              " - Session: Disconnected" );
      }
  
      /**
       * @see SessionListener#sessionConnectionRefused(SessionEvent)
       */
      public void sessionConnectionRefused( final SessionEvent sessionEvent )
      {
          out.println(
              sessionEvent.getWagon().getRepository().getUrl() +
              " - Session: Connection refused" );
  
      }
  
      /**
       * @see SessionListener#sessionLoggedIn(SessionEvent)
       */
      public void sessionLoggedIn( final SessionEvent sessionEvent )
      {
          out.println(
              sessionEvent.getWagon().getRepository().getUrl() +
              " - Session: Logged in" );
  
      }
  
      /**
       * @see SessionListener#sessionLoggedOff(SessionEvent)
       */
      public void sessionLoggedOff( final SessionEvent sessionEvent )
      {
          out.println(
              sessionEvent.getWagon().getRepository().getUrl() +
              " - Session: Logged off" );
  
      }
  
      /**
       * @see TransferListener#debug(String)
       */
      public void debug( final String message )
      {
          out.println( message );
  
      }
  
      /**
       * @see TransferListener#transferStarted(TransferEvent)
       */
      public void transferStarted( final TransferEvent transferEvent )
      {
          timestamp = transferEvent.getTimestamp();
          
          transfer = 0;
          
          if( transferEvent.getRequestType() == TransferEvent.REQUEST_GET )
          {
              final String message = "Downloading: " +
                  transferEvent.getResource() +
                  " from " +
                  transferEvent.getWagon().getRepository().getUrl();
              
              out.println( message );
              
              out.println( "" );
          }
          else
          {
              final String message = "Uploading: " +
                  transferEvent.getResource() +
                  " to " +
                  transferEvent.getWagon().getRepository().getUrl();
              
              out.println( message );
              
              out.println( "" );
  
          }
      }
  
      /**
       * @see TransferListener#transferProgress(TransferEvent)
       */
      public void transferProgress( final TransferEvent transferEvent )
      {
  
          out.print( "#" );
          //String data = new String( transferEvent.getData(),0, transferEvent.getDataLength());
          //out.println(data);
          transfer += transferEvent.getProgress();
      }
  
      /**
       * @see TransferListener#transferCompleted(TransferEvent)
       */
      public void transferCompleted( final TransferEvent transferEvent )
      {
          final double duration =
              (double)( transferEvent.getTimestamp() - timestamp ) / 1000;
  
          out.println();
          
          final String message = "Transfer finished. " +
              transfer +
              " bytes copied in " +
              duration +
              " seconds";
          out.println( message );
  
      }
  
      /**
       * @see TransferListener#transferError(TransferEvent)
       */
      public void transferError( final TransferEvent transferEvent )
      {
          out.println( " Transfer error: " + transferEvent.getException() );
  
      }
  
      /**
       * @see SessionListener#sessionError(SessionEvent)
       */
      public void sessionError( final SessionEvent sessionEvent )
      {
          out.println( " Session error: " + sessionEvent.getException() );
  
      }
  
  }
  
  
  

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