brett       2004/01/05 00:54:42

  Modified:    maven-model/src/java/org/apache/maven/model Repository.java
  Log:
  add legacy (now deprecated) functions for compatibility
  
  Revision  Changes    Path
  1.6       +172 -3    
maven-components/maven-model/src/java/org/apache/maven/model/Repository.java
  
  Index: Repository.java
  ===================================================================
  RCS file: 
/home/cvs/maven-components/maven-model/src/java/org/apache/maven/model/Repository.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Repository.java   2 Dec 2003 04:08:25 -0000       1.5
  +++ Repository.java   5 Jan 2004 08:54:42 -0000       1.6
  @@ -26,12 +26,12 @@
    *    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
  + *    "Apache Maven" must not be used to endorse or promote products
    *    derived from this software without prior written permission. For
    *    written permission, please contact [EMAIL PROTECTED]
    *
    * 5. Products derived from this software may not be called "Apache",
  - *    "Apache MavenSession", nor may "Apache" appear in their name, without
  + *    "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
  @@ -57,6 +57,9 @@
    */
   
   import java.io.Serializable;
  +import java.util.ArrayList;
  +import java.util.List;
  +import java.util.StringTokenizer;
   
   /**
    * NOTE: This is very CVS specific, but I would like to try additional SCM
  @@ -130,4 +133,170 @@
       {
           return url;
       }
  +
  +    /**
  +     * Get the SCM type.
  +     * @todo remove usages
  +     * @deprecated use maven-scm RepositoryInfo
  +     * @return SCM type
  +     */
  +    public String getScmType() {
  +        return getConnection().substring( 4, connection.indexOf( ":", 4 ) );
  +    }
  +
  +    /**
  +     * Get the CVS Root.
  +     * @todo remove usages
  +     * @deprecated use maven-scm RepositoryInfo
  +     * @return cvs root
  +     */
  +    public String getCvsRoot() {
  +        return getConnection().substring( 0, connection.lastIndexOf( ":" ) 
).substring( 7 );
  +    }
  +
  +    /**
  +     * Get the CVS module.
  +     * @todo remove usages
  +     * @deprecated use maven-scm RepositoryInfo
  +     * @return cvs module
  +     */
  +    public String getCvsModule() {
  +        return getConnection().substring( connection.lastIndexOf( ":" ) + 1 );
  +    }
  +
  +    /**
  +     * Get the CVS server.
  +     * @todo remove usages
  +     * @deprecated use maven-scm RepositoryInfo
  +     * @return cvs server
  +     */
  +    public String getCvsServer() {
  +        return getConnection().substring( connection.lastIndexOf( ":" ) + 1 );
  +    }
  +
  +    /**
  +     * Get cvs server.
  +     *
  +     * Used in xdocs/src/plugin-resources/templates/cvs-usage.xml
  +     * @todo remove usages
  +     *
  +     * @deprecated use maven-scm RepositoryInfo
  +     * @param conn six token connection string
  +     * @return CVS module.
  +     */
  +    public String getCvsServer(String conn)
  +    {
  +        String[] tokens = splitSCMConnection(conn);
  +        if(tokens[3].indexOf('@') >= 0)
  +        {
  +            return tokens[3].substring(tokens[3].indexOf('@')+1);
  +        }
  +        else
  +        {
  +            return tokens[3];
  +        }
  +    }
  +
  +    /**
  +     * Get cvs root.
  +     *
  +     * Used in xdocs/src/plugin-resources/templates/cvs-usage.xml
  +     * @todo remove usages
  +     *
  +     * @deprecated use maven-scm RepositoryInfo
  +     * @param conn six token connection string
  +     * @param username username override if non-empty.
  +     * @return CVS root.
  +     */
  +    public String getCvsRoot(String conn, String username)
  +    {
  +        String[] tokens = splitSCMConnection(conn);
  +        if(tokens[3].indexOf('@') >= 0)
  +        {
  +            if (username.length() == 0)
  +            {
  +                username = tokens[3].substring(0, tokens[3].indexOf('@'));
  +            }
  +            tokens[3] = username + "@" + tokens[3].substring(tokens[3].indexOf('@') 
+ 1);
  +        }
  +        String result = ":" + tokens[2] + ":" + tokens[3] + ":" + tokens[4];
  +        return result;
  +    }
  +  
  +    /**
  +     * Get cvs module.
  +     *
  +     * Used in xdocs/src/plugin-resources/templates/cvs-usage.xml
  +     * @todo remove usages
  +     *
  +     * @deprecated use maven-scm RepositoryInfo
  +     * @param conn six token connection string
  +     * @return CVS module.
  +     */
  +    public String getCvsModule(String conn)
  +    {
  +        String[] tokens = splitSCMConnection(conn);
  +        return tokens[5];
  +    }    
  +     
  +   
  +    /**
  +     * Splits an SCM string into parts 
  +     * @deprecated use maven-scm RepositoryInfo
  +     * @todo remove usages
  +     * @param connection
  +     * @return
  +     */
  +    public static String[] splitSCMConnection(String connection)
  +    {
  +        if (connection == null)
  +        {
  +            throw new NullPointerException("repository connection is null");
  +        }
  +
  +        if (connection.length() < 4)
  +        {
  +            throw new IllegalArgumentException("repository connection is too 
short");
  +        }
  +
  +        if (!connection.startsWith("scm"))
  +        {
  +            throw new IllegalArgumentException("repository connection must start 
with scm[delim]");
  +        }
  +        
  +        String delimiter = "" + connection.charAt(3);
  +
  +        StringTokenizer tok = new StringTokenizer(connection, delimiter);
  +
  +        String[] tokens = tokenizerToArray(tok);
  +        
  +        if (tokens.length < 6)
  +        {
  +            throw new IllegalArgumentException("repository connection string 
contains less than six tokens");
  +        }
  +
  +        if (tokens.length > 6)
  +        {
  +            throw new IllegalArgumentException("repository connection string 
contains more than six tokens");
  +        }
  +        return tokens;
  +    }
  +
  +    /**
  +     * Converts a tokenizer to an array of strings
  +     * @todo add method to maven-scm EnhancedStringTokenizer
  +     * @deprecated use maven-scm EnhancedStringTokenizer
  +     * @param tok
  +     * @return String[]
  +     */
  +    public static String[] tokenizerToArray(StringTokenizer tok)
  +    {
  +        List l = new ArrayList();
  +        while (tok.hasMoreTokens())
  +        {
  +            l.add(tok.nextToken());
  +        }
  +        return (String[]) l.toArray(new String[l.size()]);
  +    }
   }
  +
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to