You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wagon-commits@maven.apache.org by mi...@apache.org on 2003/12/11 22:21:04 UTC

cvs commit: maven-wagon/wagon-api/src/test/java/org/apache/maven/wagon/events MockWagon.java

michal      2003/12/11 13:21:04

  Modified:    wagon-api/src/main/java/org/apache/maven/wagon/managers
                        WagonManager.java DefaultWagonManager.java
                        RepositoryManager.java
               wagon-api/src/main/java/org/apache/maven/wagon Wagon.java
               wagon-api/src/test/java/org/apache/maven/wagon/events
                        MockWagon.java
  Added:       wagon-api/src/test/java/org/apache/maven/wagon/managers
                        DefaultWagonManagerTest.java MockWagonFactory.java
  Log:
  DefaultWagonManager is at 100%
  
  Revision  Changes    Path
  1.1                  maven-wagon/wagon-api/src/test/java/org/apache/maven/wagon/managers/DefaultWagonManagerTest.java
  
  Index: DefaultWagonManagerTest.java
  ===================================================================
  package org.apache.maven.wagon.managers;
  
  /*
   * ==================================================================== The
   * Apache Software License, Version 1.1
   * 
   * Copyright (c) 2001 The Apache Software Foundation. All rights reserved.
   * 
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions are met: 1.
   * Redistributions of source code must retain the above copyright notice, this
   * list of conditions and the following disclaimer. 2. Redistributions in
   * binary form must reproduce the above copyright notice, this list of
   * conditions and the following disclaimer in the documentation and/or other
   * materials provided with the distribution. 3. The end-user documentation
   * included with the redistribution, if any, must include the following
   * acknowledgment: "This product includes software developed by the Apache
   * Software Foundation (http://www.apache.org/)." Alternately, this
   * acknowledgment may appear in the software itself, if and wherever such
   * third-party acknowledgments normally appear. 4. The names "Apache" and
   * "Apache Software Foundation" and "Apache Maven" must not be used to endorse
   * or promote products derived from this software without prior written
   * permission. For written permission, please contact apache@apache.org. 5.
   * Products derived from this software may not be called "Apache", "Apache
   * MavenSession", nor may "Apache" appear in their name, without prior written
   * permission of the Apache Software Foundation.
   * 
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
   * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   * ====================================================================
   * 
   * This software consists of voluntary contributions made by many individuals
   * on behalf of the Apache Software Foundation. For more information on the
   * Apache Software Foundation, please see <http://www.apache.org/> .
   * 
   * ====================================================================
   */
  
  import org.apache.maven.wagon.UnsupportedProtocolException;
  import org.apache.maven.wagon.events.MockWagon;
  import org.apache.maven.wagon.managers.DefaultWagonManager;
  import org.apache.maven.wagon.managers.MockWagonFactory;
  import org.apache.maven.wagon.managers.WagonManager;
  
  import junit.framework.TestCase;
  
  /**
   * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
   * @version $Id: DefaultWagonManagerTest.java,v 1.1 2003/12/11 21:21:03 michal Exp $
   */
  public class DefaultWagonManagerTest extends TestCase
  {
      public void testDefaltWagonManager()
      {
         final MockWagonFactory wagonFactoryA= new MockWagonFactory();
         wagonFactoryA.addProtocol( "a" );
         
         
         final MockWagonFactory wagonFactoryB= new MockWagonFactory();
         
         wagonFactoryB.addProtocol( "b1" );
         wagonFactoryB.addProtocol( "b2" );
         
         final MockWagonFactory wagonFactoryC= new MockWagonFactory();
         
         wagonFactoryC.addProtocol( "c" );
         
         final WagonManager wagonManager = new DefaultWagonManager();
         
         wagonManager.addWagonFactory( wagonFactoryA );
         wagonManager.addWagonFactory( wagonFactoryB );
         wagonManager.addWagonFactory( wagonFactoryC );
         
         
         MockWagon wagon = null;
         
         try
         {
  	       wagon =(MockWagon) wagonManager.getWagon(  "a" );
  	       assertEquals( wagon.getCreatedBy(), wagonFactoryA );
  	       	      
  	       wagon = (MockWagon) wagonManager.getWagon(  "b1" );
  	       assertEquals( wagon.getCreatedBy(), wagonFactoryB );
  	       
  	       wagon = (MockWagon) wagonManager.getWagon(  "b2" );
  	       assertEquals( wagon.getCreatedBy(), wagonFactoryB );
  	       
  	       wagon = (MockWagon) wagonManager.getWagon(  "c" );
  	       assertEquals( wagon.getCreatedBy(), wagonFactoryC );
         }
         catch( Exception e)
         {
             e.printStackTrace();
         	   fail( e.getMessage() );
         }
         
         try
         {
         	   wagon = (MockWagon) wagonManager.getWagon(  "d" );
         	   fail( "Expected :" + UnsupportedProtocolException.class.getName() );
         }
         catch( UnsupportedProtocolException e)
         {
         	   //ok       	  
         }
         
      }
  	
  }
  
  
  
  1.1                  maven-wagon/wagon-api/src/test/java/org/apache/maven/wagon/managers/MockWagonFactory.java
  
  Index: MockWagonFactory.java
  ===================================================================
  package org.apache.maven.wagon.managers;
  
  /*
   * ==================================================================== The
   * Apache Software License, Version 1.1
   * 
   * Copyright (c) 2001 The Apache Software Foundation. All rights reserved.
   * 
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions are met: 1.
   * Redistributions of source code must retain the above copyright notice, this
   * list of conditions and the following disclaimer. 2. Redistributions in
   * binary form must reproduce the above copyright notice, this list of
   * conditions and the following disclaimer in the documentation and/or other
   * materials provided with the distribution. 3. The end-user documentation
   * included with the redistribution, if any, must include the following
   * acknowledgment: "This product includes software developed by the Apache
   * Software Foundation (http://www.apache.org/)." Alternately, this
   * acknowledgment may appear in the software itself, if and wherever such
   * third-party acknowledgments normally appear. 4. The names "Apache" and
   * "Apache Software Foundation" and "Apache Maven" must not be used to endorse
   * or promote products derived from this software without prior written
   * permission. For written permission, please contact apache@apache.org. 5.
   * Products derived from this software may not be called "Apache", "Apache
   * MavenSession", nor may "Apache" appear in their name, without prior written
   * permission of the Apache Software Foundation.
   * 
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
   * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   * ====================================================================
   * 
   * This software consists of voluntary contributions made by many individuals
   * on behalf of the Apache Software Foundation. For more information on the
   * Apache Software Foundation, please see <http://www.apache.org/> .
   * 
   * ====================================================================
   */
  
  import java.util.ArrayList;
  import java.util.List;
  
  import org.apache.maven.wagon.Wagon;
  import org.apache.maven.wagon.WagonFactory;
  import org.apache.maven.wagon.events.MockWagon;
  
  
  /**
   * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
   * @version $Id: MockWagonFactory.java,v 1.1 2003/12/11 21:21:03 michal Exp $
   */
  public class MockWagonFactory implements WagonFactory
  {
  
  	private List protocols = new ArrayList();
  	
  	public void addProtocol( final String protocol )
  	{
  	   protocols.add( protocol );
  	}
  	
  	/**
  	 * @see org.apache.maven.wagon.WagonFactory#getSupportedProtocols()
  	 */
  	public String[] getSupportedProtocols()
  	{			    
  		return ( String[] ) protocols.toArray( new String[ protocols.size() ] ); 
  	}
  
  	/**
  	 * @see org.apache.maven.wagon.WagonFactory#createWagon(java.lang.String)
  	 */
  	public Wagon createWagon( final String protocol )
  	{		
  		final MockWagon retValue = new MockWagon();
  		retValue.setCreatedBy( this );
  		return retValue; 
  	}
  
  }
  
  
  
  1.5       +67 -7     maven-wagon/wagon-api/src/main/java/org/apache/maven/wagon/managers/WagonManager.java
  
  Index: WagonManager.java
  ===================================================================
  RCS file: /home/cvs/maven-wagon/wagon-api/src/main/java/org/apache/maven/wagon/managers/WagonManager.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- WagonManager.java	7 Dec 2003 20:07:45 -0000	1.4
  +++ WagonManager.java	11 Dec 2003 21:21:03 -0000	1.5
  @@ -1,20 +1,80 @@
   package org.apache.maven.wagon.managers;
   
  -import org.apache.maven.wagon.Repository;
  +/*
  + * ====================================================================== 
  + * The Apache Software License, Version 1.1
  + * 
  + * Copyright (c) 2003 The Apache Software Foundation. All rights reserved.
  + * 
  + * Redistribution and use in source and binary forms, with or without
  + * modification, are permitted provided that the following conditions are met: 1.
  + * Redistributions of source code must retain the above copyright notice, this
  + * list of conditions and the following disclaimer. 2. Redistributions in
  + * binary form must reproduce the above copyright notice, this list of
  + * conditions and the following disclaimer in the documentation and/or other
  + * materials provided with the distribution. 3. The end-userName documentation
  + * included with the redistribution, if any, must include the following
  + * acknowledgment: "This product includes software developed by the Apache
  + * Software Foundation (http://www.apache.org/)." Alternately, this
  + * acknowledgment may appear in the software itself, if and wherever such
  + * third-party acknowledgments normally appear. 4. The names "Apache" and
  + * "Apache Software Foundation" and "Apache Maven" must not be used to endorse
  + * or promote products derived from this software without prior written
  + * permission. For written permission, please contact apache@apache.org. 5.
  + * Products derived from this software may not be called "Apache", "Apache
  + * Maven", nor may "Apache" appear in their name, without prior written
  + * permission of the Apache Software Foundation.
  + * 
  + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  + * ====================================================================
  + * 
  + * This software consists of voluntary contributions made by many individuals
  + * on behalf of the Apache Software Foundation. For more information on the
  + * Apache Software Foundation, please see <http://www.apache.org/> .
  + * 
  + * ====================================================================
  + */
  +
   import org.apache.maven.wagon.UnsupportedProtocolException;
   import org.apache.maven.wagon.Wagon;
   import org.apache.maven.wagon.WagonFactory;
   
   /**
  - * @author Michal
  - *         <p/>
  - *         To change the template for this generated type comment go to Window -
  - *         Preferences - Java - Code Generation - Code and Comments
  + * WagonManager eeps the register of known WagonFactory objects
  + * and allows to add new WagonFactory objects to the register.
  + * 
  + * Register of factories is used for finding WagonFactory which is applicable
  + * for given repository (protocol). 
  + * 
  + * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
  + * @version $Id$
  + * @see org.apache.maven.wagon.WagonFactory
    */
   public interface WagonManager
   {
  -    public void addWagonFactory( WagonFactory wagonFactory );
  +    /**
  +     * Registers given WagonFactory and all supported protocols
  +     * 
  +     * 
  +     * @param wagonFactory
  +     */
  +	public void addWagonFactory( WagonFactory wagonFactory );
   
   
  -    public Wagon getWagon( Repository repository ) throws UnsupportedProtocolException;
  +    /**
  +     * Returns Wagon which "understands" given protcol
  +     * @param protocol The protocol used for communictaion with Repoistory
  +     * @return Wagon 
  +     * @throws UnsupportedProtocolException 
  +     */
  +    public Wagon getWagon( String protocol ) throws UnsupportedProtocolException;
   }
  
  
  
  1.5       +21 -37    maven-wagon/wagon-api/src/main/java/org/apache/maven/wagon/managers/DefaultWagonManager.java
  
  Index: DefaultWagonManager.java
  ===================================================================
  RCS file: /home/cvs/maven-wagon/wagon-api/src/main/java/org/apache/maven/wagon/managers/DefaultWagonManager.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DefaultWagonManager.java	10 Dec 2003 18:45:00 -0000	1.4
  +++ DefaultWagonManager.java	11 Dec 2003 21:21:03 -0000	1.5
  @@ -44,22 +44,27 @@
    * ====================================================================
    */
   
  -import org.apache.maven.wagon.Repository;
   import org.apache.maven.wagon.UnsupportedProtocolException;
   import org.apache.maven.wagon.Wagon;
   import org.apache.maven.wagon.WagonFactory;
   
   import java.util.ArrayList;
  -import java.util.Iterator;
   import java.util.List;
  +import java.util.Map;
  +import java.util.HashMap;
  +
   
   /**
  + * Default implementation of WagonFactory interface
  + * 
    * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
    * @version $Id$
    */
   public class DefaultWagonManager implements WagonManager
   {
       private List wagonFactories = null;
  +    
  +    private Map wagonProtocolMap = new HashMap();
   
   
       /**
  @@ -72,49 +77,28 @@
               wagonFactories = new ArrayList();
           }
           wagonFactories.add( wagonFactory );
  -    }
  -
  -    /**
  -     * @param repository 
  -     * 
  -     * @return 
  -     */
  -    public Wagon getWagon( final Repository repository ) throws UnsupportedProtocolException
  -    {
  -        final String protocol = repository.getProtocol();
  -        Wagon retValue = null;
  -        for ( Iterator iterator = wagonFactories.iterator(); iterator.hasNext(); )
  +        final String[] supportedProtocols = wagonFactory.getSupportedProtocols();
  +        for ( int i = 0; i < supportedProtocols.length; i++ )
           {
  -            final WagonFactory wagonFactory = ( WagonFactory ) iterator.next();
  -            if ( supportsProtocol( wagonFactory, protocol ) )
  -            {
  -                retValue = wagonFactory.createWagon( null );
  -                break;
  -            }
  +        	wagonProtocolMap.put( supportedProtocols[i], wagonFactory );
           }
  -        return retValue;
       }
   
       /**
  -     * @param wagonFactory 
  -     * @param protocol     
  +     * @param repository 
        * 
        * @return 
        */
  -    private boolean supportsProtocol( final WagonFactory wagonFactory, final String protocol )
  -    {
  -        boolean retValue = false;
  -        final String[] supportedProtocols = wagonFactory.getSupportedProtocols();
  -        for ( int i = 0; i < supportedProtocols.length; i++ )
  +    public Wagon getWagon( final String protocol ) throws UnsupportedProtocolException
  +    {        
  +        if ( !wagonProtocolMap.containsKey( protocol ) )
           {
  -            if ( protocol.equals( supportedProtocols[i] ) ) ;
  -            {
  -                retValue = true;
  -                break;
  -            }
  -        }
  -        return retValue;
  -
  +          throw new UnsupportedProtocolException( "Cannot find WagonFactory for: " +  protocol );
  +        }         
  +        final WagonFactory wagonFactory = ( WagonFactory ) wagonProtocolMap.get( protocol );
  +        return wagonFactory.createWagon( protocol );
       }
  +
  +    
   
   }
  
  
  
  1.5       +3 -3      maven-wagon/wagon-api/src/main/java/org/apache/maven/wagon/managers/RepositoryManager.java
  
  Index: RepositoryManager.java
  ===================================================================
  RCS file: /home/cvs/maven-wagon/wagon-api/src/main/java/org/apache/maven/wagon/managers/RepositoryManager.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- RepositoryManager.java	7 Dec 2003 20:07:45 -0000	1.4
  +++ RepositoryManager.java	11 Dec 2003 21:21:03 -0000	1.5
  @@ -96,7 +96,7 @@
   
               try
               {
  -                final Wagon wagon = wagonManager.getWagon( repository );
  +                final Wagon wagon = wagonManager.getWagon( repository.getProtocol() );
                   wagon.addSessionListener( sessionListener );
                   wagon.addTransferListener( transferListener );
                   wagon.connect( repository );
  @@ -128,7 +128,7 @@
   
               try
               {
  -                final Wagon wagon = wagonManager.getWagon( repository );
  +                final Wagon wagon = wagonManager.getWagon( repository.getProtocol() );
                   wagon.connect( repository );
                   final GetRequest getRequest = new GetRequest( resource, temp );
                   wagon.transfer( getRequest );
  
  
  
  1.12      +3 -1      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.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- Wagon.java	2 Dec 2003 18:01:30 -0000	1.11
  +++ Wagon.java	11 Dec 2003 21:21:03 -0000	1.12
  @@ -242,4 +242,6 @@
       Repository getRepository();
   
   
  +
  +
   }
  
  
  
  1.10      +22 -2     maven-wagon/wagon-api/src/test/java/org/apache/maven/wagon/events/MockWagon.java
  
  Index: MockWagon.java
  ===================================================================
  RCS file: /home/cvs/maven-wagon/wagon-api/src/test/java/org/apache/maven/wagon/events/MockWagon.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- MockWagon.java	2 Dec 2003 18:01:30 -0000	1.9
  +++ MockWagon.java	11 Dec 2003 21:21:03 -0000	1.10
  @@ -47,6 +47,7 @@
   import org.apache.maven.wagon.AbstractWagon;
   import org.apache.maven.wagon.Repository;
   import org.apache.maven.wagon.TransferFailedException;
  +import org.apache.maven.wagon.WagonFactory;
   import org.apache.maven.wagon.request.GetRequest;
   import org.apache.maven.wagon.request.PutRequest;
   
  @@ -61,7 +62,10 @@
   public class MockWagon extends AbstractWagon
   {
   
  -    /**
  +    /** Used my WagonManagerTest */	
  +	private WagonFactory factory;
  +
  +	/**
        *  
        */
       public MockWagon()
  @@ -181,6 +185,22 @@
               }
           }
   
  +    }
  +    
  +    /**
  +     * @param factory
  +     */
  +    public void setCreatedBy( final WagonFactory factory )
  +    {
  +       this.factory = factory;
  +    }
  +    
  +    /**
  +     * @param factory
  +     */
  +    public WagonFactory getCreatedBy(  )
  +    {
  +    	return factory;
       }
   
   }
  
  
  

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