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 br...@apache.org on 2005/04/29 05:12:13 UTC

svn commit: r165251 - in /maven/wagon/trunk/wagon-provider-api/src: main/java/org/apache/maven/wagon/PathUtils.java main/java/org/apache/maven/wagon/repository/Repository.java test/java/org/apache/maven/wagon/PathUtilsTest.java

Author: brett
Date: Thu Apr 28 20:12:12 2005
New Revision: 165251

URL: http://svn.apache.org/viewcvs?rev=165251&view=rev
Log:
allow SCM URLs in the repository class

Modified:
    maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/PathUtils.java
    maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/repository/Repository.java
    maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/PathUtilsTest.java

Modified: maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/PathUtils.java
URL: http://svn.apache.org/viewcvs/maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/PathUtils.java?rev=165251&r1=165250&r2=165251&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/PathUtils.java (original)
+++ maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/PathUtils.java Thu Apr 28 20:12:12 2005
@@ -152,7 +152,19 @@
             return "localhost";
         }
 
-        String host = url.substring( url.indexOf( "://" ) + 3 ).trim();
+        String host = url;
+        if ( protocol.equals( "scm" ) )
+        {
+            // skip over type
+            host = host.substring( host.indexOf( ":", 4 ) + 1 ).trim();
+        }
+
+        // skip over protocol
+        host = host.substring( host.indexOf( ":" ) + 1 ).trim();
+        if ( host.startsWith( "//" ) )
+        {
+            host = host.substring( 2 );
+        }
 
         int pos = host.indexOf( "/" );
 
@@ -204,7 +216,7 @@
      * @param url
      * @return
      */
-    public static int port( final String url )
+    public static int port( String url )
     {
 
         final String protocol = PathUtils.protocol( url );
@@ -213,21 +225,39 @@
         {
             return WagonConstants.UNKNOWN_PORT;
         }
-        final String host = PathUtils.host( url );
 
-        if ( host == null )
+        final String authorization = PathUtils.authorization( url );
+
+        if ( authorization == null )
         {
             return WagonConstants.UNKNOWN_PORT;
         }
 
-        final String prefix = protocol + "://" + host;
+        if ( protocol.equals( "scm" ) )
+        {
+            // skip over type
+            url = url.substring( url.indexOf( ":", 4 ) + 1 ).trim();
+        }
+
+        // skip over protocol
+        url = url.substring( url.indexOf( ":" ) + 1 ).trim();
+        if ( url.startsWith( "//" ) )
+        {
+            url = url.substring( 2 );
+        }
 
-        final int start = prefix.length();
+        int start = authorization.length();
 
         if ( url.length() > start && url.charAt( start ) == ':' )
         {
             int end = url.indexOf( '/', start );
 
+            if ( end == start + 1 )
+            {
+                // it is :/
+                return WagonConstants.UNKNOWN_PORT;
+            }
+
             if ( end == -1 )
             {
                 end = url.length();
@@ -247,12 +277,22 @@
      * @return
      * @todo need to URL decode for spaces?
      */
-    public static String basedir( final String url )
+    public static String basedir( String url )
     {
-        final String protocol = PathUtils.protocol( url );
+        String protocol = PathUtils.protocol( url );
 
         String retValue = null;
 
+        if ( protocol.equals( "scm" ) )
+        {
+            // skip over SCM bits
+            if ( url.startsWith( "scm:svn:" ) )
+            {
+                url = url.substring( url.indexOf( ":", 4 ) + 1 );
+                protocol = PathUtils.protocol( url );
+            }
+        }
+
         if ( protocol.equals( "file" ) )
         {
             retValue = url.substring( protocol.length() + 1 );
@@ -296,27 +336,41 @@
         }
         else
         {
-            final String host = PathUtils.authorization( url );
+            final String authorization = PathUtils.authorization( url );
 
             final int port = PathUtils.port( url );
 
-            final int pos;
+            int pos;
 
-            if ( port != WagonConstants.UNKNOWN_PORT )
+            if ( protocol.equals( "scm" ) )
             {
-                pos = ( protocol + "://" + host + ":" + port ).length();
-
+                pos = url.indexOf( ":", 4 ) + 1;
+                pos = url.indexOf( ":", pos ) + 1;
             }
             else
             {
-                pos = ( protocol + "://" + host ).length();
+                pos = url.indexOf( "://" ) + 3;
             }
+
+            pos += authorization.length();
+
+            if ( port != WagonConstants.UNKNOWN_PORT )
+            {
+                pos = pos + Integer.toString( port ).length() + 1;
+            }
+
             if ( url.length() > pos )
             {
                 retValue = url.substring( pos );
+                if ( retValue.startsWith( ":" ) )
+                {
+                    // this is for :/ after the host
+                    retValue = retValue.substring( 1 );
+                }
 
+                // one module may be allowed in the path in CVS
+                retValue = retValue.replace( ':', '/' );
             }
-
         }
 
         if ( retValue == null )

Modified: maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/repository/Repository.java
URL: http://svn.apache.org/viewcvs/maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/repository/Repository.java?rev=165251&r1=165250&r2=165251&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/repository/Repository.java (original)
+++ maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/repository/Repository.java Thu Apr 28 20:12:12 2005
@@ -118,9 +118,9 @@
         //  can't use URL class as is because it won't recognise our protocols, though perhaps we could attempt to
         //  register handlers for scp, etc?
 
-        this.host = PathUtils.host( url );
-
         this.protocol = PathUtils.protocol( url );
+
+        this.host = PathUtils.host( url );
 
         this.port = PathUtils.port( url );
 

Modified: maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/PathUtilsTest.java
URL: http://svn.apache.org/viewcvs/maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/PathUtilsTest.java?rev=165251&r1=165250&r2=165251&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/PathUtilsTest.java (original)
+++ maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/PathUtilsTest.java Thu Apr 28 20:12:12 2005
@@ -67,10 +67,19 @@
 
     }
 
+    public void testScmHostResolving()
+    {
+        assertEquals( "www.codehaus.org", PathUtils.host( "scm:svn:http://www.codehaus.org" ) );
+        assertEquals( "www.codehaus.org", PathUtils.host( "scm:svn:http://www.codehaus.org/repos/module" ) );
+        assertEquals( "www.codehaus.org", PathUtils.host( "scm:cvs:pserver:anoncvs@www.codehaus.org:/root" ) );
+    }
+
     public void testProtocolResolving()
     {
         assertEquals( "http", PathUtils.protocol( "http://www.codehause.org" ) );
         assertEquals( "file", PathUtils.protocol( "file:///c:/temp" ) );
+        assertEquals( "scm", PathUtils.protocol( "scm:svn:http://localhost/repos/module" ) );
+        assertEquals( "scm", PathUtils.protocol( "scm:cvs:pserver:anoncvs@cvs.apache.org:/home/cvspublic" ) );
     }
 
     public void testUserInfo()
@@ -87,6 +96,34 @@
         assertEquals( "/", PathUtils.basedir( urlWithUsernamePassword ) );
     }
 
+    public void testSubversionUserInfo()
+    {
+        String urlWithUsername = "scm:svn:http://brett@www.codehaus.org";
+        assertEquals( "brett", PathUtils.user( urlWithUsername ) );
+        assertNull( PathUtils.password( urlWithUsername ) );
+        assertEquals( "www.codehaus.org", PathUtils.host( urlWithUsername ) );
+        assertEquals( "/", PathUtils.basedir( urlWithUsername ) );
+        String urlWithUsernamePassword = "scm:svn:http://brett:porter@www.codehaus.org";
+        assertEquals( "brett", PathUtils.user( urlWithUsernamePassword ) );
+        assertEquals( "porter", PathUtils.password( urlWithUsernamePassword ) );
+        assertEquals( "www.codehaus.org", PathUtils.host( urlWithUsernamePassword ) );
+        assertEquals( "/", PathUtils.basedir( urlWithUsernamePassword ) );
+    }
+
+    public void testCvsUserInfo()
+    {
+        String urlWithUsername = "scm:cvs:pserver:brett@www.codehaus.org";
+        assertEquals( "brett", PathUtils.user( urlWithUsername ) );
+        assertNull( PathUtils.password( urlWithUsername ) );
+        assertEquals( "www.codehaus.org", PathUtils.host( urlWithUsername ) );
+        assertEquals( "/", PathUtils.basedir( urlWithUsername ) );
+        String urlWithUsernamePassword = "scm:cvs:pserver:brett:porter@www.codehaus.org";
+        assertEquals( "brett", PathUtils.user( urlWithUsernamePassword ) );
+        assertEquals( "porter", PathUtils.password( urlWithUsernamePassword ) );
+        assertEquals( "www.codehaus.org", PathUtils.host( urlWithUsernamePassword ) );
+        assertEquals( "/", PathUtils.basedir( urlWithUsernamePassword ) );
+    }
+
     public void testFileBasedir()
     {
         // see http://www.mozilla.org/quality/networking/testing/filetests.html
@@ -130,6 +167,24 @@
 
         assertEquals( 10, PathUtils.port( "ftp://localhost:10" ) );
 
+    }
+
+    public void testScmPortResolving()
+    {
+        assertEquals( 80, PathUtils.port( "scm:svn:http://www.codehaus.org:80/maven" ) );
+        assertEquals( WagonConstants.UNKNOWN_PORT, PathUtils.port( "scm:cvs:pserver:anoncvs@localhost:/temp:module" ) );
+
+        assertEquals( 2402, PathUtils.port( "scm:cvs:pserver:anoncvs@localhost:2402/temp:module" ) );
+    }
+
+    public void testScmBasedir()
+    {
+        assertEquals( "/maven", PathUtils.basedir( "scm:svn:http://www.codehause.org/maven" ) );
+        assertEquals( "/maven", PathUtils.basedir( "scm:svn:http://www.codehause.org:80/maven" ) );
+        assertEquals( "/maven", PathUtils.basedir( "scm:cvs:pserver:anoncvs@www.codehause.org:80/maven" ) );
+        assertEquals( "/maven", PathUtils.basedir( "scm:cvs:pserver:anoncvs@www.codehause.org:/maven" ) );
+        assertEquals( "/maven/module", PathUtils.basedir( "scm:cvs:pserver:anoncvs@www.codehause.org:80/maven:module" ) );
+        assertEquals( "/maven/module", PathUtils.basedir( "scm:cvs:pserver:anoncvs@www.codehause.org:/maven:module" ) );
     }
 
     public void testPortBasedir()



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