maven-scm-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eveni...@apache.org
Subject svn commit: r416642 - in /maven/scm/trunk: maven-scm-api/src/main/java/org/apache/maven/scm/provider/ maven-scm-providers/maven-scm-providers-cvs/maven-scm-provider-cvs-commons/src/main/java/org/apache/maven/scm/provider/cvslib/ maven-scm-providers/mav...
Date Fri, 23 Jun 2006 08:56:50 GMT
Author: evenisse
Date: Fri Jun 23 01:56:50 2006
New Revision: 416642

URL: http://svn.apache.org/viewvc?rev=416642&view=rev
Log:
[SCM-215] Add ability to sanitise tag names

Added:
    maven/scm/trunk/maven-scm-providers/maven-scm-providers-cvs/maven-scm-provider-cvs-commons/src/test/java/org/apache/maven/scm/provider/cvslib/CvsScmProviderTest.java
  (with props)
Modified:
    maven/scm/trunk/maven-scm-api/src/main/java/org/apache/maven/scm/provider/AbstractScmProvider.java
    maven/scm/trunk/maven-scm-api/src/main/java/org/apache/maven/scm/provider/ScmProvider.java
    maven/scm/trunk/maven-scm-providers/maven-scm-providers-cvs/maven-scm-provider-cvs-commons/src/main/java/org/apache/maven/scm/provider/cvslib/AbstractCvsScmProvider.java

Modified: maven/scm/trunk/maven-scm-api/src/main/java/org/apache/maven/scm/provider/AbstractScmProvider.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-api/src/main/java/org/apache/maven/scm/provider/AbstractScmProvider.java?rev=416642&r1=416641&r2=416642&view=diff
==============================================================================
--- maven/scm/trunk/maven-scm-api/src/main/java/org/apache/maven/scm/provider/AbstractScmProvider.java
(original)
+++ maven/scm/trunk/maven-scm-api/src/main/java/org/apache/maven/scm/provider/AbstractScmProvider.java
Fri Jun 23 01:56:50 2006
@@ -65,6 +65,24 @@
         return null;
     }
 
+    /* (non-Javadoc)
+    * @see org.apache.maven.scm.provider.ScmProvider#sanitizeTagName(java.lang.String)
+    */
+    public String sanitizeTagName( String tag )
+    {
+        /* by default, we assume all tags are valid. */
+        return tag;
+    }
+
+    /* (non-Javadoc)
+    * @see org.apache.maven.scm.provider.ScmProvider#validateTagName(java.lang.String)
+    */
+    public boolean validateTagName( String tag )
+    {
+        /* by default, we assume all tags are valid. */
+        return true;
+    }
+
     public List validateScmUrl( String scmSpecificUrl, char delimiter )
     {
         List messages = new ArrayList();
@@ -432,7 +450,7 @@
 
     /**
      * List each element (files and directories) of <B>fileSet</B> as they exist
in the repository.
-     * 
+     *
      * @param repository the source control system
      * @param fileSet    the files to list
      * @param parameters
@@ -449,7 +467,7 @@
     /**
      * Calls {@link #list(ScmRepository, ScmFileSet, CommandParameters)} setting the {@link
CommandParameters} with
      * the necessary values from <code>recursive</code> and <code>tag</code>.
-     * 
+     *
      * @see #list(ScmRepository, ScmFileSet, CommandParameters)
      */
     public ListScmResult list( ScmRepository repository, ScmFileSet fileSet, boolean recursive,
String tag )

Modified: maven/scm/trunk/maven-scm-api/src/main/java/org/apache/maven/scm/provider/ScmProvider.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-api/src/main/java/org/apache/maven/scm/provider/ScmProvider.java?rev=416642&r1=416641&r2=416642&view=diff
==============================================================================
--- maven/scm/trunk/maven-scm-api/src/main/java/org/apache/maven/scm/provider/ScmProvider.java
(original)
+++ maven/scm/trunk/maven-scm-api/src/main/java/org/apache/maven/scm/provider/ScmProvider.java
Fri Jun 23 01:56:50 2006
@@ -69,6 +69,22 @@
     String getScmSpecificFilename();
 
     /**
+     * Check if this tag is valid for this SCM provider.
+     *
+     * @param tag tag name to check
+     * @return true if tag is valid
+     */
+    boolean validateTagName( String tag );
+
+    /**
+     * Given a tag name, make it suitable for this SCM provider. For example, CVS converts
"." into "_"
+     *
+     * @param tag input tag name
+     * @return sanitized tag name
+     */
+    String sanitizeTagName( String tag );
+
+    /**
      * Adds the given files to the source control system
      *
      * @param repository the source control system
@@ -295,13 +311,13 @@
 
     /**
      * List each element (files and directories) of <B>fileSet</B> as they exist
in the repository.
-     * 
+     *
      * @param repository the source control system
      * @param fileSet    the files to list
      * @param recursive  descend recursively
      * @param tag        use the version defined by the tag
      * @return the list of files in the repository
      */
-    ListScmResult list(ScmRepository repository, ScmFileSet fileSet, boolean recursive, String
tag)
+    ListScmResult list( ScmRepository repository, ScmFileSet fileSet, boolean recursive,
String tag )
         throws ScmException;
 }

Modified: maven/scm/trunk/maven-scm-providers/maven-scm-providers-cvs/maven-scm-provider-cvs-commons/src/main/java/org/apache/maven/scm/provider/cvslib/AbstractCvsScmProvider.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-providers-cvs/maven-scm-provider-cvs-commons/src/main/java/org/apache/maven/scm/provider/cvslib/AbstractCvsScmProvider.java?rev=416642&r1=416641&r2=416642&view=diff
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-providers-cvs/maven-scm-provider-cvs-commons/src/main/java/org/apache/maven/scm/provider/cvslib/AbstractCvsScmProvider.java
(original)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-providers-cvs/maven-scm-provider-cvs-commons/src/main/java/org/apache/maven/scm/provider/cvslib/AbstractCvsScmProvider.java
Fri Jun 23 01:56:50 2006
@@ -85,6 +85,45 @@
         return "CVS";
     }
 
+    /* From the Cederqvist:
+    *
+    * "Tag names must start with an uppercase or lowercase letter and can
+    * contain uppercase and lowercase letters, digits, `-', and `_'. The
+    * two tag names BASE and HEAD are reserved for use by CVS. It is expected
+    * that future names which are special to CVS will be specially named,
+    * for example by starting with `.', rather than being named analogously
+    * to BASE and HEAD, to avoid conflicts with actual tag names."
+    */
+
+    /* (non-Javadoc)
+    * @see org.apache.maven.scm.provider.AbstractScmProvider#sanitizeTagName(java.lang.String)
+    */
+    public String sanitizeTagName( String arg0 )
+    {
+        if ( validateTagName( arg0 ) )
+        {
+            return arg0;
+        }
+
+        if ( arg0.equals( "HEAD" ) || arg0.equals( "BASE" ) || !arg0.matches( "[A-Za-z].*"
) )
+            /* we don't even bother to sanitize these, they're just silly */
+        {
+            throw new RuntimeException(
+                "Unable to sanitize tag " + arg0 + ": must begin with a letter" + "and not
be HEAD or BASE" );
+        }
+
+        /* swap all illegal characters for a _ */
+        return arg0.replaceAll( "[^A-Za-z0-9_-]", "_" );
+    }
+
+    /* (non-Javadoc)
+    * @see org.apache.maven.scm.provider.AbstractScmProvider#validateTagName(java.lang.String)
+    */
+    public boolean validateTagName( String arg0 )
+    {
+        return ( arg0.matches( "[A-Za-z][A-Za-z0-9_-]*" ) && !arg0.equals( "HEAD"
) && !arg0.equals( "BASE" ) );
+    }
+
     public ScmProviderRepository makeProviderScmRepository( String scmSpecificUrl, char delimiter
)
         throws ScmRepositoryException
     {

Added: maven/scm/trunk/maven-scm-providers/maven-scm-providers-cvs/maven-scm-provider-cvs-commons/src/test/java/org/apache/maven/scm/provider/cvslib/CvsScmProviderTest.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-providers-cvs/maven-scm-provider-cvs-commons/src/test/java/org/apache/maven/scm/provider/cvslib/CvsScmProviderTest.java?rev=416642&view=auto
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-providers-cvs/maven-scm-provider-cvs-commons/src/test/java/org/apache/maven/scm/provider/cvslib/CvsScmProviderTest.java
(added)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-providers-cvs/maven-scm-provider-cvs-commons/src/test/java/org/apache/maven/scm/provider/cvslib/CvsScmProviderTest.java
Fri Jun 23 01:56:50 2006
@@ -0,0 +1,88 @@
+package org.apache.maven.scm.provider.cvslib;
+
+/*
+ * Copyright 2001-2006 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.
+ */
+
+import junit.framework.TestCase;
+import org.apache.maven.scm.provider.ScmProvider;
+import org.apache.maven.scm.provider.cvslib.repository.TestCvsScmProvider;
+
+/**
+ * @author <a href="richardv@mxtelecom.com">Richard van der Hoff</a>
+ * @version $Id$
+ */
+public class CvsScmProviderTest
+    extends TestCase
+{
+    ScmProvider cvsProvider;
+
+    public void setUp()
+    {
+        cvsProvider = new TestCvsScmProvider();
+    }
+
+    public void testGetScmSpecificFilename()
+    {
+        assertEquals( "CVS", cvsProvider.getScmSpecificFilename() );
+    }
+
+    /**
+     * Tests for validateTagName() and sanitizeTagName()
+     */
+    public void testTagValidation()
+    {
+        /* check the two corner-cases fail */
+        testTag( "HEAD", false );
+        testTag( "BASE", false );
+
+        /* check things which start with non-alphanumerics */
+        testTag( "-abcd", false );
+        testTag( "1234abcd", false );
+        testTag( "", false );
+
+        /* check a selection of correctable tags */
+        testCorrectableTag( "abc-1.0.2", "abc-1_0_2" );
+        testCorrectableTag( "abc\0def ghi\u00ff", "abc_def_ghi_" );
+
+        /* check a selection of valid tags */
+        testTag( "ABCD", true );
+        testTag( "a", true );
+        testTag( "abc-1_0_2", true );
+    }
+
+    /**
+     * test a tag verifies correctly
+     *
+     * @param tag   tag to check
+     * @param valid true if this tag should be valid
+     */
+    protected void testTag( String tag, boolean valid )
+    {
+        assertEquals( "Check tag '" + tag + "'", valid, cvsProvider.validateTagName( tag
) );
+    }
+
+    /**
+     * test a tag which is invalid but can be corrected
+     *
+     * @param badtag  tag to test
+     * @param goodtag what tag should be corrected to
+     */
+    protected void testCorrectableTag( String badtag, String goodtag )
+    {
+        testTag( badtag, false );
+        assertEquals( goodtag, cvsProvider.sanitizeTagName( badtag ) );
+    }
+}

Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-providers-cvs/maven-scm-provider-cvs-commons/src/test/java/org/apache/maven/scm/provider/cvslib/CvsScmProviderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-providers-cvs/maven-scm-provider-cvs-commons/src/test/java/org/apache/maven/scm/provider/cvslib/CvsScmProviderTest.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"



Mime
View raw message