maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dant...@apache.org
Subject git commit: [SCM-747] enhance scm url to support perforce' protocol declaration ( ie ssl, etc )
Date Sun, 04 May 2014 21:16:45 GMT
Repository: maven-scm
Updated Branches:
  refs/heads/master 0e8759c3a -> 84fe9d2f1


[SCM-747] enhance scm url to support perforce' protocol declaration ( ie ssl, etc )


Project: http://git-wip-us.apache.org/repos/asf/maven-scm/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-scm/commit/84fe9d2f
Tree: http://git-wip-us.apache.org/repos/asf/maven-scm/tree/84fe9d2f
Diff: http://git-wip-us.apache.org/repos/asf/maven-scm/diff/84fe9d2f

Branch: refs/heads/master
Commit: 84fe9d2f1928f0813d341fc7c564f2088f3f0b10
Parents: 0e8759c
Author: dantran <dantran@QBServer.(none)>
Authored: Sun May 4 14:09:11 2014 -0700
Committer: dantran <dantran@QBServer.(none)>
Committed: Sun May 4 14:09:11 2014 -0700

----------------------------------------------------------------------
 .../provider/perforce/PerforceScmProvider.java  | 30 ++++++++++++++++++--
 .../PerforceScmProviderRepository.java          | 15 ++++++++++
 .../perforce/PerforceScmProviderTest.java       | 24 +++++++++++++++-
 3 files changed, 66 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-scm/blob/84fe9d2f/maven-scm-providers/maven-scm-provider-perforce/src/main/java/org/apache/maven/scm/provider/perforce/PerforceScmProvider.java
----------------------------------------------------------------------
diff --git a/maven-scm-providers/maven-scm-provider-perforce/src/main/java/org/apache/maven/scm/provider/perforce/PerforceScmProvider.java
b/maven-scm-providers/maven-scm-provider-perforce/src/main/java/org/apache/maven/scm/provider/perforce/PerforceScmProvider.java
index 4109f78..6a3273e 100644
--- a/maven-scm-providers/maven-scm-provider-perforce/src/main/java/org/apache/maven/scm/provider/perforce/PerforceScmProvider.java
+++ b/maven-scm-providers/maven-scm-provider-perforce/src/main/java/org/apache/maven/scm/provider/perforce/PerforceScmProvider.java
@@ -26,6 +26,8 @@ import java.io.IOException;
 import java.io.InputStreamReader;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
+import java.util.Arrays;
+import java.util.HashSet;
 
 import org.apache.maven.scm.CommandParameters;
 import org.apache.maven.scm.ScmException;
@@ -75,6 +77,7 @@ import org.codehaus.plexus.util.cli.Commandline;
 public class PerforceScmProvider
     extends AbstractScmProvider
 {
+    private static final String [] PROTOCOLS = { "tcp", "tcp4", "tcp6", "tcp46", "tcp64",
"ssl", "ssl4", "ssl6", "ssl46", "ssl64" };
     // ----------------------------------------------------------------------
     // ScmProvider Implementation
     // ----------------------------------------------------------------------
@@ -87,10 +90,27 @@ public class PerforceScmProvider
     public ScmProviderRepository makeProviderScmRepository( String scmSpecificUrl, char delimiter
)
         throws ScmRepositoryException
     {
+        String protocol = null;
         String path;
         int port = 0;
         String host = null;
 
+        //minimal logic to support perforce protocols in scm url, and keep the next part
unchange
+        int i0 = scmSpecificUrl.indexOf( delimiter );
+        if ( i0 > 0 )
+        {
+            protocol = scmSpecificUrl.substring( 0, i0 );
+            HashSet<String> protocols = new HashSet<String>( Arrays.asList( PROTOCOLS
));
+            if ( protocols.contains( protocol ) )
+            {
+                scmSpecificUrl = scmSpecificUrl.substring( i0 + 1 );
+            }
+            else
+            {
+                protocol = null;
+            }
+        }
+
         int i1 = scmSpecificUrl.indexOf( delimiter );
         int i2 = scmSpecificUrl.indexOf( delimiter, i1 + 1 );
 
@@ -143,7 +163,7 @@ public class PerforceScmProvider
             path = path.substring( path.indexOf( '@' ) + 1 );
         }
 
-        return new PerforceScmProviderRepository( host, port, path, user, password );
+        return new PerforceScmProviderRepository( protocol, host, port, path, user, password
);
     }
 
     public String getScmType()
@@ -269,10 +289,16 @@ public class PerforceScmProvider
             command.createArg().setValue( workingDir.getAbsolutePath() );
         }
 
+
         if ( repo.getHost() != null )
         {
             command.createArg().setValue( "-p" );
-            String value = repo.getHost();
+            String value = "";
+            if ( ! StringUtils.isBlank( repo.getProtocol() ) )
+            {
+                value += repo.getProtocol() + ":";
+            }
+            value += repo.getHost();
             if ( repo.getPort() != 0 )
             {
                 value += ":" + Integer.toString( repo.getPort() );

http://git-wip-us.apache.org/repos/asf/maven-scm/blob/84fe9d2f/maven-scm-providers/maven-scm-provider-perforce/src/main/java/org/apache/maven/scm/provider/perforce/repository/PerforceScmProviderRepository.java
----------------------------------------------------------------------
diff --git a/maven-scm-providers/maven-scm-provider-perforce/src/main/java/org/apache/maven/scm/provider/perforce/repository/PerforceScmProviderRepository.java
b/maven-scm-providers/maven-scm-provider-perforce/src/main/java/org/apache/maven/scm/provider/perforce/repository/PerforceScmProviderRepository.java
index 09aecfa..3289209 100644
--- a/maven-scm-providers/maven-scm-provider-perforce/src/main/java/org/apache/maven/scm/provider/perforce/repository/PerforceScmProviderRepository.java
+++ b/maven-scm-providers/maven-scm-provider-perforce/src/main/java/org/apache/maven/scm/provider/perforce/repository/PerforceScmProviderRepository.java
@@ -28,6 +28,8 @@ import org.apache.maven.scm.provider.ScmProviderRepositoryWithHost;
 public class PerforceScmProviderRepository
     extends ScmProviderRepositoryWithHost
 {
+    private String protocol;//when empty perforce treats it as 'tcp'
+
     private String path;
 
     public PerforceScmProviderRepository( String host, int port, String path, String user,
String password )
@@ -43,6 +45,14 @@ public class PerforceScmProviderRepository
         setPassword( password );
     }
 
+
+    public PerforceScmProviderRepository( String protocol, String host, int port, String
path, String user, String password )
+    {
+        this( host, port, path, user, password );
+
+        this.protocol = protocol;
+    }
+
     // ----------------------------------------------------------------------
     // ScmProviderRepository Implementation
     // ----------------------------------------------------------------------
@@ -51,4 +61,9 @@ public class PerforceScmProviderRepository
     {
         return path;
     }
+
+    public String getProtocol()
+    {
+        return this.protocol;
+    }
 }

http://git-wip-us.apache.org/repos/asf/maven-scm/blob/84fe9d2f/maven-scm-providers/maven-scm-provider-perforce/src/test/java/org/apache/maven/scm/provider/perforce/PerforceScmProviderTest.java
----------------------------------------------------------------------
diff --git a/maven-scm-providers/maven-scm-provider-perforce/src/test/java/org/apache/maven/scm/provider/perforce/PerforceScmProviderTest.java
b/maven-scm-providers/maven-scm-provider-perforce/src/test/java/org/apache/maven/scm/provider/perforce/PerforceScmProviderTest.java
index dd20ee8..8507edd 100644
--- a/maven-scm-providers/maven-scm-provider-perforce/src/test/java/org/apache/maven/scm/provider/perforce/PerforceScmProviderTest.java
+++ b/maven-scm-providers/maven-scm-provider-perforce/src/test/java/org/apache/maven/scm/provider/perforce/PerforceScmProviderTest.java
@@ -22,10 +22,10 @@ package org.apache.maven.scm.provider.perforce;
 import org.apache.maven.scm.ScmTestCase;
 import org.apache.maven.scm.provider.perforce.repository.PerforceScmProviderRepository;
 import org.apache.maven.scm.repository.ScmRepository;
+import org.codehaus.plexus.util.StringUtils;
 
 /**
  * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
- *
  */
 public class PerforceScmProviderTest
     extends ScmTestCase
@@ -46,6 +46,8 @@ public class PerforceScmProviderTest
         assertNull( p4Repo.getPassword() );
 
         assertEquals( "//depot/projects/pathname", p4Repo.getPath() );
+
+        assertTrue( StringUtils.isBlank( p4Repo.getProtocol() ) );
     }
 
     public void testParseConnectionWithUsername()
@@ -164,4 +166,24 @@ public class PerforceScmProviderTest
 
         assertEquals( "//depot/foo/bar/...", PerforceScmProvider.getCanonicalRepoPath( "//depot/foo/bar/..."
) );
     }
+
+    public void testParseConnectionWithSsl()
+        throws Exception
+    {
+        ScmRepository repo = makeScmRepository( "scm:perforce:ssl:host:1066://depot/projects/pathname"
);
+
+        PerforceScmProviderRepository p4Repo = (PerforceScmProviderRepository) repo.getProviderRepository();
+
+        assertEquals( "host", p4Repo.getHost() );
+
+        assertEquals( 1066, p4Repo.getPort() );
+
+        assertNull( p4Repo.getUser() );
+
+        assertNull( p4Repo.getPassword() );
+
+        assertEquals( "//depot/projects/pathname", p4Repo.getPath() );
+
+        assertEquals( "ssl", p4Repo.getProtocol() );
+    }
 }


Mime
View raw message