You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm-commits@maven.apache.org by ev...@apache.org on 2003/12/11 20:59:50 UTC

cvs commit: maven-scm/generic-scm-api/src/java/org/apache/maven/genericscm ScmFactory.java

evenisse    2003/12/11 11:59:50

  Modified:    generic-scm-api/src/java/org/apache/maven/genericscm/manager
                        ScmManager.java
  Added:       generic-scm-api/src/java/org/apache/maven/genericscm/manager
                        DefaultScmManager.java
               generic-scm-api/src/java/org/apache/maven/genericscm
                        ScmFactory.java
  Log:
  Refactoring of command creation for simplify it.
  
  Revision  Changes    Path
  1.2       +12 -25    maven-scm/generic-scm-api/src/java/org/apache/maven/genericscm/manager/ScmManager.java
  
  Index: ScmManager.java
  ===================================================================
  RCS file: /home/cvs/maven-scm/generic-scm-api/src/java/org/apache/maven/genericscm/manager/ScmManager.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ScmManager.java	9 Dec 2003 21:28:19 -0000	1.1
  +++ ScmManager.java	11 Dec 2003 19:59:50 -0000	1.2
  @@ -57,7 +57,8 @@
    */
   
   import org.apache.maven.genericscm.ScmException;
  -import org.apache.maven.genericscm.ScmWrapper;
  +import org.apache.maven.genericscm.ScmFactory;
  +import org.apache.maven.genericscm.command.Command;
   import org.apache.maven.genericscm.command.CommandWrapper;
   import org.apache.maven.genericscm.repository.Repository;
   import org.apache.maven.genericscm.repository.RepositoryInfo;
  @@ -68,9 +69,11 @@
    */
   public interface ScmManager
   {
  -    /** The role played in Avalon container */
  -    String ROLE = ScmManager.class.getName();
  -
  +    /**
  +     * @param factory The factory you want to add.
  +     */
  +    void addScmFactory(ScmFactory factory);
  +    
       /**
        * @param repoInfo repository descriptor
        * @return an initialized <code>Repository</code> component
  @@ -79,31 +82,15 @@
   
       /**
        * @param repoInfo repository descriptor
  -     * @return a non-initialized <code>Repository</code> component
  -     */
  -    Repository lookupRepository(RepositoryInfo repoInfo) throws ScmException;
  -    
  -    /**
  -     * @param repoInfo repository descriptor
        * @return an initialized <code>CommandWrapper</code> component
        */
       CommandWrapper getCommandWrapper(RepositoryInfo repoInfo) throws ScmException;
   
       /**
        * @param repoInfo repository descriptor
  -     * @return a non-initialized <code>CommandWrapper</code> component
  -     */
  -    CommandWrapper lookupCommandWrapper(RepositoryInfo repoInfo) throws ScmException;
  -    
  -    /**
  -     * @param repoInfo repository descriptor
  -     * @return an initialized <code>ScmWrapper</code> component
  -     */
  -    ScmWrapper getScmWrapper(RepositoryInfo repoInfo) throws ScmException;
  -    
  -    /**
  -     * @param repoInfo repository descriptor
  -     * @return an non-initialized <code>ScmWrapper</code> component
  +     * @param commandName The command name like <TT>"checkout"</TT>, <TT>"changelog"</TT>
  +     * @return an initialized <code>CommandWrapper</code> component
        */
  -    ScmWrapper lookupScmWrapper() throws ScmException;
  +    Command getCommand(RepositoryInfo repoInfo, String commandName)
  +        throws ScmException;
   }
  
  
  
  1.1                  maven-scm/generic-scm-api/src/java/org/apache/maven/genericscm/manager/DefaultScmManager.java
  
  Index: DefaultScmManager.java
  ===================================================================
  package org.apache.maven.genericscm.manager;
  
  /* ====================================================================
   * 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 java.util.Hashtable;
  
  import org.apache.maven.genericscm.ScmException;
  import org.apache.maven.genericscm.ScmFactory;
  import org.apache.maven.genericscm.command.Command;
  import org.apache.maven.genericscm.command.CommandWrapper;
  import org.apache.maven.genericscm.repository.Repository;
  import org.apache.maven.genericscm.repository.RepositoryInfo;
  
  /**
   * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
   * @version $Id: DefaultScmManager.java,v 1.1 2003/12/11 19:59:50 evenisse Exp $
   */
  public class DefaultScmManager implements ScmManager
  {
      private Hashtable factories;
      /**
       * @param factory The factory you want to add.
       */
      public void addScmFactory(ScmFactory factory)
      {
          if (factories == null)
          {
              factories = new Hashtable();
          }
          factories.put(factory.getSupportedScm(), factory);
      }
      
      /**
       * @param repoInfo repository descriptor
       * @return an initialized <code>Repository</code> component
       */
      public Repository getRepository(RepositoryInfo repoInfo) throws ScmException
      {
          ScmFactory factory = getFactory(repoInfo);
          return factory.createRepository(repoInfo);
      }
  
      /**
       * @param repoInfo repository descriptor
       * @return an initialized <code>CommandWrapper</code> component
       */
      public CommandWrapper getCommandWrapper(RepositoryInfo repoInfo) throws ScmException
      {
          ScmFactory factory = getFactory(repoInfo);
          return factory.createCommandWrapper(repoInfo);
      }
  
      /**
       * @param repoInfo repository descriptor
       * @param commandName The command name like <TT>"checkout"</TT>, <TT>"changelog"</TT>
       * @return an initialized <code>CommandWrapper</code> component
       */
      public Command getCommand(RepositoryInfo repoInfo, String commandName)
          throws ScmException
      {
          ScmFactory factory = getFactory(repoInfo);
          return factory.createCommand(repoInfo, commandName);
      }
      
      private ScmFactory getFactory(RepositoryInfo repoInfo) throws ScmException
      {
          if (repoInfo == null)
          {
              throw new ScmException("RepoInfo cannot be null");
          }
          
          String scmType = repoInfo.getType();
          ScmFactory factory = (ScmFactory)factories.get(scmType);
          
          if (factory == null)
          {
              throw new ScmException(scmType + " factory doesn't exists.");
          }
          return factory;
      }
  }
  
  
  1.1                  maven-scm/generic-scm-api/src/java/org/apache/maven/genericscm/ScmFactory.java
  
  Index: ScmFactory.java
  ===================================================================
  package org.apache.maven.genericscm;
  
  /*
   * ====================================================================
   * 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
   * MavenSession" 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.genericscm.command.Command;
  import org.apache.maven.genericscm.command.CommandWrapper;
  import org.apache.maven.genericscm.repository.Repository;
  import org.apache.maven.genericscm.repository.RepositoryInfo;
  
  /**
   * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
   * @version $Id: ScmFactory.java,v 1.1 2003/12/11 19:59:50 evenisse Exp $
   */
  public interface ScmFactory
  {
      /**
       * Returns the names of supported scm like: <tt>"cvs"</tt>, <tt>"svn"</tt>.
       *
       * @return the name of supported scm
       */
      String getSupportedScm();
      
      /**
       * Creates and returns new instance of CommandWrapper
       * @param repoInfo
       * @return Returns new instance of CommandWrapper
       */
      CommandWrapper createCommandWrapper(RepositoryInfo repoInfo);
      
      /**
       * Creates and returns new instance of Repository
       * @param repoInfo
       * @return Returns new instance of Repository
       */
      Repository createRepository(RepositoryInfo repoInfo);
      
      /**
       * Creates and returns new instance of Command
       * @param repoInfo
       * @param commandName The command name like <tt>"changelog"</tt>, <tt>"checkout"</tt>.
       * @return Returns new instance of Repository
       */
      Command createCommand(RepositoryInfo repoInfo, String commandName);
  }