maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hbout...@apache.org
Subject maven-wagon git commit: [WAGON-427] added support for IPv6 Submitted by: genadi-hp Applied with little style modifications
Date Sun, 22 Mar 2015 13:38:41 GMT
Repository: maven-wagon
Updated Branches:
  refs/heads/master 327947eb0 -> 479f7bea6


[WAGON-427] added support for IPv6
Submitted by: genadi-hp
Applied with little style modifications

Project: http://git-wip-us.apache.org/repos/asf/maven-wagon/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-wagon/commit/479f7bea
Tree: http://git-wip-us.apache.org/repos/asf/maven-wagon/tree/479f7bea
Diff: http://git-wip-us.apache.org/repos/asf/maven-wagon/diff/479f7bea

Branch: refs/heads/master
Commit: 479f7bea6ff1f315bf3372e3f9eb7a9ef88e3e52
Parents: 327947e
Author: Hervé Boutemy <hboutemy@apache.org>
Authored: Sun Mar 22 14:38:37 2015 +0100
Committer: Hervé Boutemy <hboutemy@apache.org>
Committed: Sun Mar 22 14:38:37 2015 +0100

----------------------------------------------------------------------
 .../java/org/apache/maven/wagon/PathUtils.java  | 33 +++++-----
 .../maven/wagon/repository/Repository.java      | 21 +++++-
 .../org/apache/maven/wagon/PathUtilsTest.java   | 69 ++++++++++++++------
 .../maven/wagon/repository/RepositoryTest.java  | 56 ++++++++++++++++
 4 files changed, 140 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-wagon/blob/479f7bea/wagon-provider-api/src/main/java/org/apache/maven/wagon/PathUtils.java
----------------------------------------------------------------------
diff --git a/wagon-provider-api/src/main/java/org/apache/maven/wagon/PathUtils.java b/wagon-provider-api/src/main/java/org/apache/maven/wagon/PathUtils.java
index 32180ce..e77e03a 100644
--- a/wagon-provider-api/src/main/java/org/apache/maven/wagon/PathUtils.java
+++ b/wagon-provider-api/src/main/java/org/apache/maven/wagon/PathUtils.java
@@ -33,7 +33,7 @@ public final class PathUtils
     private PathUtils()
     {
     }
-    
+
     /**
      * Returns the directory path portion of a file specification string.
      * Matches the equally named unix command.
@@ -135,14 +135,12 @@ public final class PathUtils
     {
         String authorization = authorization( url );
         int index = authorization.indexOf( '@' );
-        if ( index >= 0 )
-        {
-            return authorization.substring( index + 1 );
-        }
-        else
-        {
-            return authorization;
-        }
+        String host = ( index >= 0 ) ? authorization.substring( index + 1 ) : authorization;
+        // In case we have IPv6 in the host portion of url
+        // we have to remove brackets '[' and ']'
+        return ( ( host.charAt( 0 ) == '[' ) && ( host.charAt( host.length() - 1
) == ']' ) )
+                        ? host.substring( 1, host.length() - 1 )
+                        : host;
     }
 
     /**
@@ -185,14 +183,7 @@ public final class PathUtils
 
         pos = host.indexOf( '@' );
 
-        if ( pos > 0 )
-        {
-            pos = host.indexOf( ':', pos );
-        }
-        else
-        {
-            pos = host.indexOf( ":" );
-        }
+        pos = ( pos > 0 ) ? endOfHostPosition( host, pos ) : endOfHostPosition( host,
0 );
 
         if ( pos > 0 )
         {
@@ -201,6 +192,14 @@ public final class PathUtils
         return host;
     }
 
+    private static int endOfHostPosition( String host, int pos )
+    {
+        // if this is IPv6 then it will be in IPv6 Literal Addresses in URL's format
+        // see: http://www.ietf.org/rfc/rfc2732.txt
+        int endOfIPv6Pos = host.indexOf( ']', pos );
+        return ( endOfIPv6Pos > 0 ) ? endOfIPv6Pos + 1 : host.indexOf( ":", pos );
+    }
+
     /**
      * /**
      * Return the protocol name.

http://git-wip-us.apache.org/repos/asf/maven-wagon/blob/479f7bea/wagon-provider-api/src/main/java/org/apache/maven/wagon/repository/Repository.java
----------------------------------------------------------------------
diff --git a/wagon-provider-api/src/main/java/org/apache/maven/wagon/repository/Repository.java
b/wagon-provider-api/src/main/java/org/apache/maven/wagon/repository/Repository.java
index 6c9ce8d..b28dd1a 100644
--- a/wagon-provider-api/src/main/java/org/apache/maven/wagon/repository/Repository.java
+++ b/wagon-provider-api/src/main/java/org/apache/maven/wagon/repository/Repository.java
@@ -182,7 +182,16 @@ public class Repository
 
         sb.append( "://" );
 
-        sb.append( host );
+        if ( isIPv6Address() )
+        {
+            // If this is IPv6 then we have to surround it
+            // with brackets '[' and ']'
+            sb.append( "[" ).append( getHost() ).append( "]" );
+        }
+        else
+        {
+            sb.append( getHost() );
+        }
 
         if ( port != WagonConstants.UNKNOWN_PORT )
         {
@@ -196,6 +205,16 @@ public class Repository
         return sb.toString();
     }
 
+    /**
+     * Checks whtther provided url contains IPv6 format in host portion
+     * 
+     * @return true if provide host part is of IPv6 format
+     */
+    private boolean isIPv6Address()
+    {
+        return getHost().contains( ":" );
+    }
+
     public String getHost()
     {
         if ( host == null )

http://git-wip-us.apache.org/repos/asf/maven-wagon/blob/479f7bea/wagon-provider-api/src/test/java/org/apache/maven/wagon/PathUtilsTest.java
----------------------------------------------------------------------
diff --git a/wagon-provider-api/src/test/java/org/apache/maven/wagon/PathUtilsTest.java b/wagon-provider-api/src/test/java/org/apache/maven/wagon/PathUtilsTest.java
index 48c5bd4..0f09202 100644
--- a/wagon-provider-api/src/test/java/org/apache/maven/wagon/PathUtilsTest.java
+++ b/wagon-provider-api/src/test/java/org/apache/maven/wagon/PathUtilsTest.java
@@ -154,7 +154,7 @@ public class PathUtilsTest
     public void testFileBasedir()
     {
         // see http://www.mozilla.org/quality/networking/testing/filetests.html
-        
+
         // strict forms
         assertEquals( "c:/temp", PathUtils.basedir( "file:///c|/temp" ) );
         assertEquals( "localhost", PathUtils.host( "file:///c|/temp" ) );
@@ -255,26 +255,53 @@ public class PathUtilsTest
 
     public void testIpV4()
     {
-        assertUrl( "http://127.0.0.1",
-                   "http", null, null, "127.0.0.1", -1, "/" );
-        assertUrl( "http://127.0.0.1:8080",
-                   "http", null, null, "127.0.0.1", 8080, "/" );
-        assertUrl( "http://127.0.0.1/oo/rest/users",
-                   "http", null, null, "127.0.0.1", -1, "/oo/rest/users" );
-        assertUrl( "http://127.0.0.1:8080/oo/rest/users",
-                   "http", null, null, "127.0.0.1", 8080, "/oo/rest/users" );
-
-        assertUrl( "http://user:password@127.0.0.1",
-                   "http", "user", "password", "127.0.0.1", -1, "/" );
-        assertUrl( "http://user:password@127.0.0.1:8080",
-                   "http", "user", "password", "127.0.0.1", 8080, "/" );
-        assertUrl( "http://user:password@127.0.0.1/oo/rest/users",
-                   "http", "user", "password", "127.0.0.1", -1, "/oo/rest/users" );
-        assertUrl( "http://user:password@127.0.0.1:8080/oo/rest/users",
-                   "http", "user", "password", "127.0.0.1", 8080, "/oo/rest/users" );
-
-        assertUrl( "scm:svn:http://user:password@127.0.0.1:8080/oo/rest/users",
-                   "scm", "user", "password", "127.0.0.1", 8080, "/oo/rest/users" );
+        assertUrl( "http://127.0.0.1", "http", null, null, "127.0.0.1", -1, "/" );
+        assertUrl( "http://127.0.0.1:8080", "http", null, null, "127.0.0.1", 8080, "/" );
+        assertUrl( "http://127.0.0.1/oo/rest/users", "http", null, null, "127.0.0.1", -1,
"/oo/rest/users" );
+        assertUrl( "http://127.0.0.1:8080/oo/rest/users", "http", null, null, "127.0.0.1",
8080, "/oo/rest/users" );
+
+        assertUrl( "http://user:password@127.0.0.1", "http", "user", "password", "127.0.0.1",
-1, "/" );
+        assertUrl( "http://user:password@127.0.0.1:8080", "http", "user", "password", "127.0.0.1",
8080, "/" );
+        assertUrl( "http://user:password@127.0.0.1/oo/rest/users", "http", "user", "password",
"127.0.0.1", -1,
+                   "/oo/rest/users" );
+        assertUrl( "http://user:password@127.0.0.1:8080/oo/rest/users", "http", "user", "password",
"127.0.0.1", 8080,
+                   "/oo/rest/users" );
+
+        assertUrl( "scm:svn:http://user:password@127.0.0.1:8080/oo/rest/users", "scm", "user",
"password", "127.0.0.1",
+                   8080, "/oo/rest/users" );
+    }
+
+    public void testIPv6()
+    {
+        assertUrl( "http://user:password@[fff:::1]:7891/oo/rest/users", "http", "user", "password",
"fff:::1", 7891,
+                   "/oo/rest/users" );
+        assertUrl( "http://[fff:::1]:7891/oo/rest/users", "http", null, null, "fff:::1",
7891, "/oo/rest/users" );
+        assertUrl( "http://user:password@[fff:::1]/oo/rest/users", "http", "user", "password",
"fff:::1", -1,
+                   "/oo/rest/users" );
+        assertUrl( "http://user:password@[fff:::1]:7891", "http", "user", "password", "fff:::1",
7891, "/" );
+
+        assertUrl( "http://user:password@[fff:000::222:1111]:7891/oo/rest/users", "http",
"user", "password",
+                   "fff:000::222:1111", 7891, "/oo/rest/users" );
+        assertUrl( "http://[fff:000::222:1111]:7891/oo/rest/users", "http", null, null, "fff:000::222:1111",
7891,
+                   "/oo/rest/users" );
+        assertUrl( "http://user:password@[fff:000::222:1111]/oo/rest/users", "http", "user",
"password",
+                   "fff:000::222:1111", -1, "/oo/rest/users" );
+        assertUrl( "http://user:password@[fff:000::222:1111]:7891", "http", "user", "password",
"fff:000::222:1111",
+                   7891, "/" );
+
+        assertUrl( "http://user:password@16.60.56.58:7891/oo/rest/users", "http", "user",
"password", "16.60.56.58",
+                   7891, "/oo/rest/users" );
+        assertUrl( "http://16.60.56.58:7891/oo/rest/users", "http", null, null, "16.60.56.58",
7891, "/oo/rest/users" );
+        assertUrl( "http://user:password@16.60.56.58/oo/rest/users", "http", "user", "password",
"16.60.56.58", -1,
+                   "/oo/rest/users" );
+        assertUrl( "http://user:password@16.60.56.58:7891", "http", "user", "password", "16.60.56.58",
7891, "/" );
+
+        assertUrl( "http://user:password@16.60.56.58:7891/oo/rest/users", "http", "user",
"password", "16.60.56.58",
+                   7891, "/oo/rest/users" );
+        assertUrl( "http://16.60.56.58:7891/oo/rest/users", "http", null, null, "16.60.56.58",
7891, "/oo/rest/users" );
+        assertUrl( "http://user:password@16.60.56.58/oo/rest/users", "http", "user", "password",
"16.60.56.58", -1,
+                   "/oo/rest/users" );
+        assertUrl( "http://user:password@16.60.56.58:7891", "http", "user", "password", "16.60.56.58",
7891, "/" );
     }
 
     private void assertUrl( String url, String protocol, String user, String password, String
host, int port,

http://git-wip-us.apache.org/repos/asf/maven-wagon/blob/479f7bea/wagon-provider-api/src/test/java/org/apache/maven/wagon/repository/RepositoryTest.java
----------------------------------------------------------------------
diff --git a/wagon-provider-api/src/test/java/org/apache/maven/wagon/repository/RepositoryTest.java
b/wagon-provider-api/src/test/java/org/apache/maven/wagon/repository/RepositoryTest.java
index 2495728..bb85df0 100644
--- a/wagon-provider-api/src/test/java/org/apache/maven/wagon/repository/RepositoryTest.java
+++ b/wagon-provider-api/src/test/java/org/apache/maven/wagon/repository/RepositoryTest.java
@@ -105,4 +105,60 @@ public class RepositoryTest
         assertEquals( "http://www.ibiblio.org", repository.getUrl() );
 
     }
+
+    public void testIPv6()
+    {
+        assertRepository( "http://user:password@[fff:::1]:7891/oo/rest/users", "http://[fff:::1]:7891/oo/rest/users",
+                          "/oo/rest/users", "user", "password", "fff:::1", 7891 );
+        assertRepository( "http://[fff:::1]:7891/oo/rest/users", "http://[fff:::1]:7891/oo/rest/users",
+                          "/oo/rest/users", null, null, "fff:::1", 7891 );
+        assertRepository( "http://user:password@[fff:::1]/oo/rest/users", "http://[fff:::1]/oo/rest/users",
+                          "/oo/rest/users", "user", "password", "fff:::1", -1 );
+        assertRepository( "http://user:password@[fff:::1]:7891", "http://[fff:::1]:7891",
"/", "user", "password",
+                          "fff:::1", 7891 );
+
+        assertRepository( "http://user:password@[fff:000::222:1111]:7891/oo/rest/users",
+                          "http://[fff:000::222:1111]:7891/oo/rest/users", "/oo/rest/users",
"user", "password",
+                          "fff:000::222:1111", 7891 );
+        assertRepository( "http://[fff:000::222:1111]:7891/oo/rest/users",
+                          "http://[fff:000::222:1111]:7891/oo/rest/users", "/oo/rest/users",
null, null,
+                          "fff:000::222:1111", 7891 );
+        assertRepository( "http://user:password@[fff:000::222:1111]/oo/rest/users",
+                          "http://[fff:000::222:1111]/oo/rest/users", "/oo/rest/users", "user",
"password",
+                          "fff:000::222:1111", -1 );
+        assertRepository( "http://user:password@[fff:000::222:1111]:7891", "http://[fff:000::222:1111]:7891",
"/",
+                          "user", "password", "fff:000::222:1111", 7891 );
+
+        assertRepository( "http://user:password@16.60.56.58:7891/oo/rest/users",
+                          "http://16.60.56.58:7891/oo/rest/users", "/oo/rest/users", "user",
"password", "16.60.56.58",
+                          7891 );
+        assertRepository( "http://16.60.56.58:7891/oo/rest/users", "http://16.60.56.58:7891/oo/rest/users",
+                          "/oo/rest/users", null, null, "16.60.56.58", 7891 );
+        assertRepository( "http://user:password@16.60.56.58/oo/rest/users", "http://16.60.56.58/oo/rest/users",
+                          "/oo/rest/users", "user", "password", "16.60.56.58", -1 );
+        assertRepository( "http://user:password@16.60.56.58:7891", "http://16.60.56.58:7891",
"/", "user", "password",
+                          "16.60.56.58", 7891 );
+
+        assertRepository( "http://user:password@16.60.56.58:7891/oo/rest/users",
+                          "http://16.60.56.58:7891/oo/rest/users", "/oo/rest/users", "user",
"password", "16.60.56.58",
+                          7891 );
+        assertRepository( "http://16.60.56.58:7891/oo/rest/users", "http://16.60.56.58:7891/oo/rest/users",
+                          "/oo/rest/users", null, null, "16.60.56.58", 7891 );
+        assertRepository( "http://user:password@16.60.56.58/oo/rest/users", "http://16.60.56.58/oo/rest/users",
+                          "/oo/rest/users", "user", "password", "16.60.56.58", -1 );
+        assertRepository( "http://user:password@16.60.56.58:7891", "http://16.60.56.58:7891",
"/", "user", "password",
+                          "16.60.56.58", 7891 );
+    }
+
+    private void assertRepository( String url, String repoUrl, String baseDir, String user,
String password,
+                                   String host, int port )
+    {
+        Repository repo = new Repository( String.valueOf( System.currentTimeMillis() ), url
);
+        assertEquals( repoUrl, repo.getUrl() );
+        assertEquals( baseDir, repo.getBasedir() );
+        assertEquals( host, repo.getHost() );
+        assertEquals( user, repo.getUsername() );
+        assertEquals( password, repo.getPassword() );
+        assertEquals( port, repo.getPort() );
+    }
 }


Mime
View raw message