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/artifact/verify MD5Verfier.java
Date Mon, 26 Apr 2004 19:23:43 GMT
michal      2004/04/26 12:23:43

  Modified:    wagon-api/src/main/java/org/apache/maven/wagon
                        Conductor.java ConnectionException.java
                        AbstractWagon.java Wagon.java StreamWagon.java
               wagon-api/src/main/java/org/apache/maven/wagon/manager
                        DefaultWagonManager.java WagonManager.java
               wagon-api/src/main/java/org/apache/maven/wagon/events
                        TransferEvent.java
               wagon-api/src/main/java/org/apache/maven/wagon/repository
                        Repository.java
               wagon-api/src/main/java/org/apache/maven/wagon/providers/file
                        FileWagon.java
               wagon-api/src/test/java/org/apache/maven/wagon
                        MockWagon.java
               wagon-api/src/main/java/org/apache/maven/wagon/artifact/verify
                        MD5Verfier.java
  Added:       wagon-api/src/main/java/org/apache/maven/wagon/observers
                        Md5SumObserver.java
  Log:
  Minor API clean up and leaving the comments for the future work.
  
  Some comments:
  - I started to use the convention when only first name of the class is upper case. So I
have Md5Observer not MD5Observer.
  - We need to have clear guidline regarding the usage of plexusContainer.release() method.
It was not used at  the moment and I used it where ever it was possible.
  
  Revision  Changes    Path
  1.3       +7 -2      maven-wagon/wagon-api/src/main/java/org/apache/maven/wagon/Conductor.java
  
  Index: Conductor.java
  ===================================================================
  RCS file: /home/cvs/maven-wagon/wagon-api/src/main/java/org/apache/maven/wagon/Conductor.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Conductor.java	21 Apr 2004 17:33:49 -0000	1.2
  +++ Conductor.java	26 Apr 2004 19:23:43 -0000	1.3
  @@ -4,7 +4,6 @@
   import org.apache.maven.wagon.manager.WagonManager;
   import org.apache.maven.wagon.repository.Repository;
   
  -import java.util.Locale;
   
   /**
    * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
  @@ -40,6 +39,12 @@
       {
           return wagonManager.getWagon( protocol );
       }
  +    
  +    public void releaseWagon( Wagon wagon ) throws Exception
  +    {
  +       wagonManager.releaseWagon( wagon );    
  +    }
  +    
   
       public void addRepository( Repository repository )
       {
  
  
  
  1.2       +3 -2      maven-wagon/wagon-api/src/main/java/org/apache/maven/wagon/ConnectionException.java
  
  Index: ConnectionException.java
  ===================================================================
  RCS file: /home/cvs/maven-wagon/wagon-api/src/main/java/org/apache/maven/wagon/ConnectionException.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ConnectionException.java	30 Mar 2004 14:43:00 -0000	1.1
  +++ ConnectionException.java	26 Apr 2004 19:23:43 -0000	1.2
  @@ -17,7 +17,8 @@
    */
   
   /**
  - * The exception is thrown when a connection to repository cannot be estblished.
  + * The exception is thrown when a connection 
  + * to repository cannot be estblished or open connection cannot be closed.
    * 
    * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
    * @version $Id$
  
  
  
  1.2       +8 -4      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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractWagon.java	30 Mar 2004 14:43:00 -0000	1.1
  +++ AbstractWagon.java	26 Apr 2004 19:23:43 -0000	1.2
  @@ -17,6 +17,7 @@
    */
   
   import org.apache.maven.wagon.artifact.Artifact;
  +import org.apache.maven.wagon.authentication.AuthenticationException;
   import org.apache.maven.wagon.events.SessionEvent;
   import org.apache.maven.wagon.events.SessionEventSupport;
   import org.apache.maven.wagon.events.SessionListener;
  @@ -29,6 +30,7 @@
   import java.io.OutputStream;
   import java.io.IOException;
   
  +
   /**
    * Implementation of common facilties for Wagon providers.
    *
  @@ -59,8 +61,8 @@
       // Connection
       // ----------------------------------------------------------------------
   
  -    public void connect( Repository source )
  -        throws Exception
  +    public void connect( Repository source ) throws 
  +      ConnectionException, AuthenticationException
       {
           if ( source == null )
           {
  @@ -77,7 +79,7 @@
       }
   
       public void disconnect()
  -        throws Exception
  +        throws ConnectionException
       {
           fireSessionDisconnecting();
   
  @@ -85,6 +87,8 @@
   
           fireSessionDisconnected();
       }
  +    
  +    protected abstract void closeConnection() throws ConnectionException;
   
       // ----------------------------------------------------------------------
       // Stream i/o
  
  
  
  1.3       +5 -7      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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Wagon.java	24 Apr 2004 15:51:25 -0000	1.2
  +++ Wagon.java	26 Apr 2004 19:23:43 -0000	1.3
  @@ -17,6 +17,7 @@
    */
   
   import org.apache.maven.wagon.artifact.Artifact;
  +import org.apache.maven.wagon.authentication.AuthenticationException;
   import org.apache.maven.wagon.authorization.AuthorizationException;
   import org.apache.maven.wagon.events.SessionListener;
   import org.apache.maven.wagon.events.TransferListener;
  @@ -48,8 +49,6 @@
       void put( File source, Artifact artifact )
           throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException;
   
  -    String[] getSupportedProtocols();
  -
       Repository getRepository();
   
       // ----------------------------------------------------------------------
  @@ -57,16 +56,15 @@
       // ----------------------------------------------------------------------
   
       void connect( Repository source )
  -        throws Exception;
  +        throws ConnectionException, AuthenticationException;
   
       void openConnection()
  -        throws Exception;
  +        throws ConnectionException, AuthenticationException;
   
       void disconnect()
  -        throws Exception;
  +        throws ConnectionException;
   
  -    void closeConnection()
  -        throws Exception;
  +   
   
       // ----------------------------------------------------------------------
       //  Session listener
  
  
  
  1.3       +4 -4      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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- StreamWagon.java	24 Apr 2004 15:51:25 -0000	1.2
  +++ StreamWagon.java	26 Apr 2004 19:23:43 -0000	1.3
  @@ -34,16 +34,16 @@
       // ----------------------------------------------------------------------
   
       public abstract InputStream getInputStream( String resource )
  -        throws Exception;
  +        throws TransferFailedException;
   
       public abstract OutputStream getOutputStream( String resource )
  -        throws Exception;
  +        throws TransferFailedException;
   
       public abstract void openConnection()
  -        throws Exception;
  +        throws ConnectionException;
   
       public abstract void closeConnection()
  -        throws Exception;
  +        throws ConnectionException;
   
       // ----------------------------------------------------------------------
       // We take the artifact and create the resource from that so we can
  
  
  
  1.4       +46 -2     maven-wagon/wagon-api/src/main/java/org/apache/maven/wagon/manager/DefaultWagonManager.java
  
  Index: DefaultWagonManager.java
  ===================================================================
  RCS file: /home/cvs/maven-wagon/wagon-api/src/main/java/org/apache/maven/wagon/manager/DefaultWagonManager.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DefaultWagonManager.java	21 Apr 2004 19:25:56 -0000	1.3
  +++ DefaultWagonManager.java	26 Apr 2004 19:23:43 -0000	1.4
  @@ -19,7 +19,6 @@
   import org.apache.maven.wagon.TransferFailedException;
   import org.apache.maven.wagon.UnsupportedProtocolException;
   import org.apache.maven.wagon.Wagon;
  -import org.apache.maven.wagon.WagonException;
   import org.apache.maven.wagon.artifact.Artifact;
   import org.apache.maven.wagon.repository.Repository;
   import org.codehaus.plexus.PlexusConstants;
  @@ -47,6 +46,7 @@
   
       private PlexusContainer container;
   
  +    
       public Wagon getWagon( String protocol ) throws UnsupportedProtocolException
       {
           Wagon wagon;
  @@ -62,6 +62,23 @@
   
           return wagon;
       }
  +    
  +    /**
  +     * 
  +     * @param wagon
  +     * @throws Exception
  +     * 
  +     * @todo how we can handle exception here? Maybe we should just swallow it?
  +     * Plexus exception handling is not very precise here (it sucks in short words:) )
  +     * Maybe plexus should not throw any exception here as this is internal problem of
plexus
  +     * and any ingeration from outside or intelligent error handlig are rather excluded.

  +     */
  +    public void releaseWagon( Wagon wagon ) throws Exception 
  +    {
  +       container.release( wagon );       
  +    }
  +    
  +    
   
       public void addRepository( Repository repository )
       {
  @@ -87,6 +104,11 @@
                   wagon.connect( repository );
   
                   wagon.put( source, artifact );
  +                
  +                wagon.disconnect();
  +                
  +                releaseWagon( wagon );
  +                
               }
               catch ( UnsupportedProtocolException e )
               {
  @@ -100,6 +122,23 @@
           }
       }
   
  +    /**
  +     * 
  +     * @param artifact
  +     * @param destination
  +     * @return
  +     * @throws TransferFailedException
  +     * 
  +     * @todo I want to somehow plug artifact validators at such low level. 
  +     *       Simply if artifact was downloaded but it was rejected by validator(s)
  +     *       the loop should continue. Some of the validators can be feeded directly using
events
  +     *       so number of i/o operation could be limited. 
  +     *       
  +     *       If we won't plug validation process here the question is what we can do afterwards?
  +     *       We don't know from which repository artifact was fetched and where we should
restart.
  +     *       We should be also fetching md5 sums and such from the same exact directory
then artifacts
  +     * 
  +     */
       public boolean get( Artifact artifact, File destination )  throws TransferFailedException
   
       {
           boolean transfered = false;
  @@ -128,6 +167,11 @@
                   wagon.get( artifact, temp );
   
                   transfered = true;
  +                
  +                wagon.disconnect();
  +                
  +                releaseWagon( wagon );
  +                                
               }
               catch ( Exception e )
               {
  
  
  
  1.4       +13 -9     maven-wagon/wagon-api/src/main/java/org/apache/maven/wagon/manager/WagonManager.java
  
  Index: WagonManager.java
  ===================================================================
  RCS file: /home/cvs/maven-wagon/wagon-api/src/main/java/org/apache/maven/wagon/manager/WagonManager.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- WagonManager.java	21 Apr 2004 17:33:49 -0000	1.3
  +++ WagonManager.java	26 Apr 2004 19:23:43 -0000	1.4
  @@ -18,22 +18,26 @@
   
   import org.apache.maven.wagon.UnsupportedProtocolException;
   import org.apache.maven.wagon.Wagon;
  -import org.apache.maven.wagon.TransferFailedException;
  -import org.apache.maven.wagon.ResourceDoesNotExistException;
  -import org.apache.maven.wagon.authorization.AuthorizationException;
  +
   import org.apache.maven.wagon.repository.Repository;
  -import org.apache.maven.wagon.artifact.Artifact;
   
  -import java.io.File;
   
  +/**
  + * 
  + * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a> 
  + * @version $Id$
  + */
   public interface WagonManager
   {
       String ROLE = WagonManager.class.getName();
   
  -   Wagon getWagon( String protocol )
  +    Wagon getWagon( String protocol )
           throws UnsupportedProtocolException;
   
  -    void addRepository( Repository repository );
  -
  -    void removeRepository( Repository repository );
  +   void releaseWagon( Wagon wagon ) throws Exception; 
  +   
  +   void addRepository( Repository repository );
  +   
  +   void removeRepository( Repository repository );
  +    
   }
  
  
  
  1.2       +1 -2      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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TransferEvent.java	30 Mar 2004 14:43:02 -0000	1.1
  +++ TransferEvent.java	26 Apr 2004 19:23:43 -0000	1.2
  @@ -16,7 +16,6 @@
    * limitations under the License.
    */
   
  -import org.apache.maven.wagon.repository.Repository;
   import org.apache.maven.wagon.Wagon;
   
   /***
  
  
  
  1.2       +2 -3      maven-wagon/wagon-api/src/main/java/org/apache/maven/wagon/repository/Repository.java
  
  Index: Repository.java
  ===================================================================
  RCS file: /home/cvs/maven-wagon/wagon-api/src/main/java/org/apache/maven/wagon/repository/Repository.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Repository.java	30 Mar 2004 14:43:02 -0000	1.1
  +++ Repository.java	26 Apr 2004 19:23:43 -0000	1.2
  @@ -24,8 +24,7 @@
   import org.codehaus.plexus.util.StringUtils;
   
   import java.io.Serializable;
  -import java.net.URL;
  -import java.util.Properties;
  +
   
   /**
    * This class is an abstraction of the location from/to resources
  
  
  
  1.1                  maven-wagon/wagon-api/src/main/java/org/apache/maven/wagon/observers/Md5SumObserver.java
  
  Index: Md5SumObserver.java
  ===================================================================
  package org.apache.maven.wagon.observers;
  
  import java.security.MessageDigest;
  import java.security.NoSuchAlgorithmException;
  
  import org.apache.maven.wagon.events.TransferEvent;
  import org.apache.maven.wagon.events.TransferListener;
  
  /**
   * 
   * TransferListeners which computes MD5 checksum on the fly when files are transfered.
   * 
   * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a> 
   * @version $Id: Md5SumObserver.java,v 1.1 2004/04/26 19:23:43 michal Exp $ 
   */
  public class Md5SumObserver implements TransferListener
  {
      private MessageDigest md5Digester;
      
      /**
       * @see org.apache.maven.wagon.events.TransferListener#transferStarted(org.apache.maven.wagon.events.TransferEvent)
       */
      public void transferStarted( TransferEvent transferEvent )
      {
          try
          {
              md5Digester = MessageDigest.getInstance( "MD5" );
          }
          catch ( NoSuchAlgorithmException e)
          {
             // ignore
          }
          
      }
  
      /**
       * @see org.apache.maven.wagon.events.TransferListener#transferProgress(org.apache.maven.wagon.events.TransferEvent)
       */
      public void transferProgress( TransferEvent transferEvent )
      {
          if ( md5Digester != null )
          {
             byte[] data = transferEvent.getData();
             
             md5Digester.update( data );
             
          }                
          
      }
  
      public void transferCompleted( TransferEvent transferEvent )
      {
          // here we can do we need to have possibility to transfer to memory:
          //Wagon wagon = transferEvent.getWagon();
          //
          //String resource transferEvent.getResource();
          //
          //String md5 = wagon.getToString( resource + ".md5" );
      }
  
      public void transferError( TransferEvent transferEvent )
      {
          // TODO Auto-generated method stub
          
      }
  
      public void debug( String message )
      {
         
          
      }
      
      public String getMd5Sum() 
      {
         String retValue = null;
         
         if ( md5Digester != null )
         {
             retValue = new String ( md5Digester.digest() );
         }
         
         return retValue;
         
      }
      
  }
  
  
  
  1.3       +29 -14    maven-wagon/wagon-api/src/main/java/org/apache/maven/wagon/providers/file/FileWagon.java
  
  Index: FileWagon.java
  ===================================================================
  RCS file: /home/cvs/maven-wagon/wagon-api/src/main/java/org/apache/maven/wagon/providers/file/FileWagon.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- FileWagon.java	24 Apr 2004 15:51:25 -0000	1.2
  +++ FileWagon.java	26 Apr 2004 19:23:43 -0000	1.3
  @@ -17,9 +17,11 @@
    */
   
   import org.apache.maven.wagon.StreamWagon;
  +import org.apache.maven.wagon.TransferFailedException;
   
   import java.io.File;
   import java.io.FileInputStream;
  +import java.io.FileNotFoundException;
   import java.io.FileOutputStream;
   import java.io.InputStream;
   import java.io.OutputStream;
  @@ -33,37 +35,50 @@
   public class FileWagon
       extends StreamWagon
   {
  -    public String[] getSupportedProtocols()
  -    {
  -        return new String[] {"file"};
  -    }
  -
  + 
       // get
       public InputStream getInputStream( String resource )
  -        throws Exception
  +        throws TransferFailedException
       {
  -        System.out.println( "resource = " + resource );
   
  -        return new FileInputStream( new File( getRepository().getBasedir(), resource )
);
  +        File f = new File( getRepository().getBasedir(), resource );
  +        
  +        try
  +        {
  +            return new FileInputStream( f );
  +        }
  +        catch ( FileNotFoundException e)
  +        {
  +            throw new TransferFailedException( "Could not read from file: " + f.getAbsolutePath(),
e );
  +        }
       }
   
       // put
       public OutputStream getOutputStream( String resource )
  -        throws Exception
  +        throws TransferFailedException
       {
  -        System.out.println( "resource = " + resource );
  -
  +       
           File f = new File( getRepository().getBasedir(), resource );
   
           if ( f.getParentFile() != null && !f.getParentFile().exists() )
           {
               if ( !f.getParentFile().mkdirs() )
               {
  -                //!! need to throw an exception
  +                String msg = "Some of the requied directories do not exist and could not
be create. " +
  +                		"Requested path:  "  + f.getAbsolutePath();
  +                
  +                throw new TransferFailedException( msg );
               }
           }
   
  -        return new FileOutputStream( f );
  +        try
  +        {
  +            return new FileOutputStream( f );
  +        }
  +        catch ( FileNotFoundException e)
  +        {
  +            throw new TransferFailedException( "Could not write to file: " + f.getAbsolutePath(),
e );
  +        }
       }
   
       public void openConnection()
  
  
  
  1.3       +3 -3      maven-wagon/wagon-api/src/test/java/org/apache/maven/wagon/MockWagon.java
  
  Index: MockWagon.java
  ===================================================================
  RCS file: /home/cvs/maven-wagon/wagon-api/src/test/java/org/apache/maven/wagon/MockWagon.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MockWagon.java	24 Apr 2004 15:51:25 -0000	1.2
  +++ MockWagon.java	26 Apr 2004 19:23:43 -0000	1.3
  @@ -29,7 +29,7 @@
       }
   
       public InputStream getInputStream( String resource )
  -        throws Exception
  +        throws TransferFailedException
       {
           if ( errorInputStream )
           {
  @@ -48,7 +48,7 @@
       }
   
       public OutputStream getOutputStream( String resource )
  -        throws Exception
  +        throws TransferFailedException
       {
           if ( errorInputStream )
           {
  
  
  
  1.2       +2 -2      maven-wagon/wagon-api/src/main/java/org/apache/maven/wagon/artifact/verify/MD5Verfier.java
  
  Index: MD5Verfier.java
  ===================================================================
  RCS file: /home/cvs/maven-wagon/wagon-api/src/main/java/org/apache/maven/wagon/artifact/verify/MD5Verfier.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MD5Verfier.java	30 Mar 2004 14:43:02 -0000	1.1
  +++ MD5Verfier.java	26 Apr 2004 19:23:43 -0000	1.2
  @@ -1,4 +1,4 @@
  -package org.apache.maven.artifact.verifier;
  +package org.apache.maven.wagon.artifact.verify;
   
   import java.io.File;
   import java.io.FileInputStream;
  
  
  

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