continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From och...@apache.org
Subject svn commit: r1126624 - in /continuum/trunk: ./ continuum-base/continuum-scm/ continuum-base/continuum-scm/src/main/java/org/apache/continuum/scm/ continuum-base/continuum-scm/src/test/java/org/apache/continuum/scm/ continuum-buildagent/continuum-builda...
Date Mon, 23 May 2011 18:10:34 GMT
Author: oching
Date: Mon May 23 18:10:33 2011
New Revision: 1126624

URL: http://svn.apache.org/viewvc?rev=1126624&view=rev
Log:
[CONTINUUM-2628]
o use credentials (if) specified in scm url when using ssh protocol for git scm provider,
otherwise use scm credentials specified on project add 
on checkout and update of working copy actions
o added unit tests for setting correct credentials to use in continuum actions

Added:
    continuum/trunk/continuum-base/continuum-scm/src/main/java/org/apache/continuum/scm/ContinuumScmUtils.java
    continuum/trunk/continuum-base/continuum-scm/src/test/java/org/apache/continuum/scm/ContinuumScmUtilsTest.java
Modified:
    continuum/trunk/continuum-base/continuum-scm/pom.xml
    continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/action/CheckoutProjectAction.java
    continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/action/UpdateWorkingDirectoryAction.java
    continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/CheckoutProjectContinuumAction.java
    continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/UpdateWorkingDirectoryFromScmContinuumAction.java
    continuum/trunk/pom.xml

Modified: continuum/trunk/continuum-base/continuum-scm/pom.xml
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-base/continuum-scm/pom.xml?rev=1126624&r1=1126623&r2=1126624&view=diff
==============================================================================
--- continuum/trunk/continuum-base/continuum-scm/pom.xml (original)
+++ continuum/trunk/continuum-base/continuum-scm/pom.xml Mon May 23 18:10:33 2011
@@ -63,6 +63,10 @@ under the License.
     </dependency>
     <dependency>
       <groupId>org.apache.maven.scm</groupId>
+      <artifactId>maven-scm-provider-git-commons</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.scm</groupId>
       <artifactId>maven-scm-provider-svnexe</artifactId>
       <scope>test</scope>
     </dependency>

Added: continuum/trunk/continuum-base/continuum-scm/src/main/java/org/apache/continuum/scm/ContinuumScmUtils.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-base/continuum-scm/src/main/java/org/apache/continuum/scm/ContinuumScmUtils.java?rev=1126624&view=auto
==============================================================================
--- continuum/trunk/continuum-base/continuum-scm/src/main/java/org/apache/continuum/scm/ContinuumScmUtils.java
(added)
+++ continuum/trunk/continuum-base/continuum-scm/src/main/java/org/apache/continuum/scm/ContinuumScmUtils.java
Mon May 23 18:10:33 2011
@@ -0,0 +1,65 @@
+package org.apache.continuum.scm;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.maven.scm.provider.ScmUrlUtils;
+import org.apache.maven.scm.provider.git.repository.GitScmProviderRepository;
+
+/**
+ * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
+ * @version
+ */
+public class ContinuumScmUtils
+{
+    private static final String GIT_SCM_PROVIDERTYPE = "git";
+
+    // CONTINUUM-2628
+    public static ContinuumScmConfiguration setSCMCredentialsforSSH( ContinuumScmConfiguration
config,
+                             String scmUrl, String scmUsername, String scmPassword )
+    {
+        String sshScmUsername = "";
+        String sshScmPassword = "";
+        String providerType = ScmUrlUtils.getProvider( scmUrl );
+
+        String scmSpecificUrl = scmUrl.substring( providerType.length() + 5 );
+
+        if( providerType.contains( GIT_SCM_PROVIDERTYPE ) && scmSpecificUrl.startsWith(
GitScmProviderRepository.PROTOCOL_SSH ) )
+        {
+            scmSpecificUrl = scmSpecificUrl.substring( GitScmProviderRepository.PROTOCOL_SSH.length()
+ 3 );
+
+            // extract user information
+            int indexAt = scmSpecificUrl.indexOf( "@" );
+            if ( indexAt >= 0 )
+            {
+                String userInfo = scmSpecificUrl.substring( 0, indexAt );
+                sshScmUsername = userInfo;
+                int indexPwdSep = userInfo.indexOf( ":" );
+                // password is specified in the url
+                if ( indexPwdSep < 0 )
+                {
+                    sshScmUsername = userInfo.substring( indexPwdSep + 1);
+                }
+                else
+                {
+                    sshScmUsername = userInfo.substring( 0, indexPwdSep );
+                    sshScmPassword = userInfo.substring( indexPwdSep + 1 );
+                }
+            }
+        }
+
+        if( StringUtils.isBlank( sshScmUsername ) )
+        {
+            config.setUsername( scmUsername );
+            config.setPassword( scmPassword );
+        }
+        else
+        {
+            config.setUsername( sshScmUsername );
+            if( !StringUtils.isBlank( sshScmPassword ) )
+            {
+                config.setPassword( sshScmPassword );
+            }
+        }
+
+        return config;
+    }
+}

Added: continuum/trunk/continuum-base/continuum-scm/src/test/java/org/apache/continuum/scm/ContinuumScmUtilsTest.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-base/continuum-scm/src/test/java/org/apache/continuum/scm/ContinuumScmUtilsTest.java?rev=1126624&view=auto
==============================================================================
--- continuum/trunk/continuum-base/continuum-scm/src/test/java/org/apache/continuum/scm/ContinuumScmUtilsTest.java
(added)
+++ continuum/trunk/continuum-base/continuum-scm/src/test/java/org/apache/continuum/scm/ContinuumScmUtilsTest.java
Mon May 23 18:10:33 2011
@@ -0,0 +1,72 @@
+package org.apache.continuum.scm;
+
+import junit.framework.TestCase;
+import org.apache.commons.lang.StringUtils;
+
+/**
+ * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
+ * @version
+ */
+public class ContinuumScmUtilsTest
+    extends TestCase
+{
+    public void testGitProviderWithSSHProtocolUsernameInUrl()
+        throws Exception
+    {
+        ContinuumScmConfiguration scmConfiguration = new ContinuumScmConfiguration();
+
+        scmConfiguration = ContinuumScmUtils.setSCMCredentialsforSSH( scmConfiguration,
+                           "scm:git:ssh://sshUser@gitrepo.com/myproject.git", "dummyuser",
"dummypassword" );
+
+        assertEquals( "sshUser", scmConfiguration.getUsername() );
+        assertTrue( StringUtils.isBlank( scmConfiguration.getPassword() ) );
+    }
+
+    public void testGitProviderWithSSHProtocolUsernameAndPasswordInUrl()
+        throws Exception
+    {
+        ContinuumScmConfiguration scmConfiguration = new ContinuumScmConfiguration();
+
+        scmConfiguration = ContinuumScmUtils.setSCMCredentialsforSSH( scmConfiguration,
+                           "scm:git:ssh://sshUser:sshPassword@gitrepo.com/myproject.git",
"dummyuser", "dummypassword" );
+        
+        assertEquals( "sshUser", scmConfiguration.getUsername() );
+        assertEquals( "sshPassword", scmConfiguration.getPassword() );
+    }
+
+    public void testGitProviderWithSSHProtocolNoCredentialsInUrl()
+        throws Exception
+    {
+        ContinuumScmConfiguration scmConfiguration = new ContinuumScmConfiguration();
+
+        scmConfiguration = ContinuumScmUtils.setSCMCredentialsforSSH( scmConfiguration,
+                           "scm:git:ssh://gitrepo.com/myproject.git", "dummyuser", "dummypassword"
);
+
+        assertEquals( "dummyuser", scmConfiguration.getUsername() );
+        assertEquals( "dummypassword", scmConfiguration.getPassword() );
+    }
+
+    public void testNotGitProvider()
+        throws Exception
+    {
+        ContinuumScmConfiguration scmConfiguration = new ContinuumScmConfiguration();
+
+        scmConfiguration = ContinuumScmUtils.setSCMCredentialsforSSH( scmConfiguration,
+                           "scm:svn:ssh://svnrepo.com/repos/myproject/trunk", "dummyuser",
"dummypassword" );
+
+        assertEquals( "dummyuser", scmConfiguration.getUsername() );
+        assertEquals( "dummypassword", scmConfiguration.getPassword() );
+    }
+
+    public void testNotSSHProtocol()
+        throws Exception
+    {
+        ContinuumScmConfiguration scmConfiguration = new ContinuumScmConfiguration();
+
+        scmConfiguration = ContinuumScmUtils.setSCMCredentialsforSSH( scmConfiguration,
+                           "scm:git:https://gitrepo.com/myproject.git", "dummyuser", "dummypassword"
);
+
+        assertEquals( "dummyuser", scmConfiguration.getUsername() );
+        assertEquals( "dummypassword", scmConfiguration.getPassword() );
+    }
+}

Modified: continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/action/CheckoutProjectAction.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/action/CheckoutProjectAction.java?rev=1126624&r1=1126623&r2=1126624&view=diff
==============================================================================
--- continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/action/CheckoutProjectAction.java
(original)
+++ continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/action/CheckoutProjectAction.java
Mon May 23 18:10:33 2011
@@ -24,15 +24,20 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.continuum.buildagent.configuration.BuildAgentConfigurationService;
 import org.apache.continuum.buildagent.utils.ContinuumBuildAgentUtil;
 import org.apache.continuum.scm.ContinuumScm;
 import org.apache.continuum.scm.ContinuumScmConfiguration;
+import org.apache.continuum.scm.ContinuumScmUtils;
 import org.apache.maven.continuum.model.project.Project;
 import org.apache.maven.continuum.model.scm.ScmResult;
 import org.apache.maven.scm.ScmException;
 import org.apache.maven.scm.command.checkout.CheckOutScmResult;
 import org.apache.maven.scm.manager.NoSuchScmProviderException;
+import org.apache.maven.scm.provider.ScmProvider;
+import org.apache.maven.scm.provider.ScmUrlUtils;
+import org.apache.maven.scm.provider.git.repository.GitScmProviderRepository;
 import org.apache.maven.scm.repository.ScmRepositoryException;
 import org.codehaus.plexus.action.AbstractAction;
 
@@ -158,9 +163,11 @@ public class CheckoutProjectAction
                                                               String scmUserName, String
scmPassword )
     {
         ContinuumScmConfiguration config = new ContinuumScmConfiguration();
+
+        // CONTINUUM-2628
+        config = ContinuumScmUtils.setSCMCredentialsforSSH( config, project.getScmUrl(),
scmUserName, scmPassword );
+        
         config.setUrl( project.getScmUrl() );
-        config.setUsername( scmUserName );
-        config.setPassword( scmPassword );
         config.setUseCredentialsCache( project.isScmUseCache() );
         config.setWorkingDirectory( workingDirectory );
         config.setTag( project.getScmTag() );

Modified: continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/action/UpdateWorkingDirectoryAction.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/action/UpdateWorkingDirectoryAction.java?rev=1126624&r1=1126623&r2=1126624&view=diff
==============================================================================
--- continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/action/UpdateWorkingDirectoryAction.java
(original)
+++ continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/action/UpdateWorkingDirectoryAction.java
Mon May 23 18:10:33 2011
@@ -29,6 +29,7 @@ import org.apache.continuum.buildagent.c
 import org.apache.continuum.buildagent.utils.ContinuumBuildAgentUtil;
 import org.apache.continuum.scm.ContinuumScm;
 import org.apache.continuum.scm.ContinuumScmConfiguration;
+import org.apache.continuum.scm.ContinuumScmUtils;
 import org.apache.maven.continuum.model.project.Project;
 import org.apache.maven.continuum.model.scm.ChangeFile;
 import org.apache.maven.continuum.model.scm.ChangeSet;
@@ -140,8 +141,10 @@ public class UpdateWorkingDirectoryActio
     {
         ContinuumScmConfiguration config = new ContinuumScmConfiguration();
         config.setUrl( project.getScmUrl() );
-        config.setUsername( project.getScmUsername() );
-        config.setPassword( project.getScmPassword() );
+
+        // CONTINUUM-2628
+        config = ContinuumScmUtils.setSCMCredentialsforSSH( config, project.getScmUrl(),
project.getScmUsername(), project.getScmPassword() );
+        
         config.setUseCredentialsCache( project.isScmUseCache() );
         config.setWorkingDirectory( workingDirectory );
         config.setTag( project.getScmTag() );

Modified: continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/CheckoutProjectContinuumAction.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/CheckoutProjectContinuumAction.java?rev=1126624&r1=1126623&r2=1126624&view=diff
==============================================================================
--- continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/CheckoutProjectContinuumAction.java
(original)
+++ continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/CheckoutProjectContinuumAction.java
Mon May 23 18:10:33 2011
@@ -28,6 +28,7 @@ import org.apache.continuum.dao.BuildDef
 import org.apache.continuum.dao.ProjectDao;
 import org.apache.continuum.scm.ContinuumScm;
 import org.apache.continuum.scm.ContinuumScmConfiguration;
+import org.apache.continuum.scm.ContinuumScmUtils;
 import org.apache.continuum.utils.ContinuumUtils;
 import org.apache.maven.continuum.model.project.BuildDefinition;
 import org.apache.maven.continuum.model.project.Project;
@@ -244,8 +245,10 @@ public class CheckoutProjectContinuumAct
         {
             config.setUrl( project.getScmUrl() );
         }
-        config.setUsername( scmUserName );
-        config.setPassword( scmPassword );
+
+        // CONTINUUM-2628
+        config = ContinuumScmUtils.setSCMCredentialsforSSH( config, config.getUrl(), scmUserName,
scmPassword );
+
         config.setUseCredentialsCache( project.isScmUseCache() );
         config.setWorkingDirectory( workingDirectory );
         config.setTag( project.getScmTag() );

Modified: continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/UpdateWorkingDirectoryFromScmContinuumAction.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/UpdateWorkingDirectoryFromScmContinuumAction.java?rev=1126624&r1=1126623&r2=1126624&view=diff
==============================================================================
--- continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/UpdateWorkingDirectoryFromScmContinuumAction.java
(original)
+++ continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/UpdateWorkingDirectoryFromScmContinuumAction.java
Mon May 23 18:10:33 2011
@@ -29,6 +29,7 @@ import org.apache.continuum.dao.BuildRes
 import org.apache.continuum.dao.ProjectDao;
 import org.apache.continuum.scm.ContinuumScm;
 import org.apache.continuum.scm.ContinuumScmConfiguration;
+import org.apache.continuum.scm.ContinuumScmUtils;
 import org.apache.continuum.utils.ContinuumUtils;
 import org.apache.maven.continuum.model.project.BuildDefinition;
 import org.apache.maven.continuum.model.project.BuildResult;
@@ -216,9 +217,10 @@ public class UpdateWorkingDirectoryFromS
         {
             config.setUrl( project.getScmUrl() );
         }
-        
-        config.setUsername( project.getScmUsername() );
-        config.setPassword( project.getScmPassword() );
+
+        // CONTINUUM-2628
+        config = ContinuumScmUtils.setSCMCredentialsforSSH( config, config.getUrl(), project.getScmUsername(),
project.getScmPassword() );
+
         config.setUseCredentialsCache( project.isScmUseCache() );
         config.setWorkingDirectory( workingDirectory );
         config.setTag( project.getScmTag() );

Modified: continuum/trunk/pom.xml
URL: http://svn.apache.org/viewvc/continuum/trunk/pom.xml?rev=1126624&r1=1126623&r2=1126624&view=diff
==============================================================================
--- continuum/trunk/pom.xml (original)
+++ continuum/trunk/pom.xml Mon May 23 18:10:33 2011
@@ -542,6 +542,11 @@ under the License.
         <version>${maven-scm.version}</version>
       </dependency>
       <dependency>
+        <groupId>org.apache.maven.scm</groupId>
+        <artifactId>maven-scm-provider-git-commons</artifactId>
+        <version>${maven-scm.version}</version>
+      </dependency>
+      <dependency>
         <groupId>org.apache.maven.release</groupId>
         <artifactId>maven-release-manager</artifactId>
         <version>2.1</version>



Mime
View raw message