maven-wagon-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r662349 - /maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/jsch/SftpWagon.java
Date Mon, 02 Jun 2008 07:37:20 GMT
Author: brett
Date: Mon Jun  2 00:37:20 2008
New Revision: 662349

URL: http://svn.apache.org/viewvc?rev=662349&view=rev
Log:
[WAGON-215] change sftp to only connect once per wagon connection to improve performace

Modified:
    maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/jsch/SftpWagon.java

Modified: maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/jsch/SftpWagon.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/jsch/SftpWagon.java?rev=662349&r1=662348&r2=662349&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/jsch/SftpWagon.java
(original)
+++ maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/jsch/SftpWagon.java
Mon Jun  2 00:37:20 2008
@@ -28,6 +28,7 @@
 import org.apache.maven.wagon.PathUtils;
 import org.apache.maven.wagon.ResourceDoesNotExistException;
 import org.apache.maven.wagon.TransferFailedException;
+import org.apache.maven.wagon.authentication.AuthenticationException;
 import org.apache.maven.wagon.authorization.AuthorizationException;
 import org.apache.maven.wagon.events.TransferEvent;
 import org.apache.maven.wagon.repository.RepositoryPermissions;
@@ -59,43 +60,43 @@
 
     private static final long MILLIS_PER_SEC = 1000L;
 
-    private void returnToParentDirectory( Resource resource, ChannelSftp channel )
-        throws SftpException
+    private ChannelSftp channel;
+    
+    public void closeConnection()
     {
-        String dir = getResourceDirectory( resource.getName() );
-        String[] dirs = PathUtils.dirnames( dir );
-        for ( int i = 0; i < dirs.length; i++ )
+        if ( channel != null )
         {
-            channel.cd( ".." );
+            channel.disconnect();
         }
+        super.closeConnection();
     }
 
-    private ChannelSftp preparePut( Resource resource, RepositoryPermissions permissions
)
-        throws JSchException, SftpException, TransferFailedException
+    public void openConnectionInternal()
+        throws AuthenticationException
     {
-        ChannelSftp channel;
-        channel = (ChannelSftp) session.openChannel( SFTP_CHANNEL );
-
-        channel.connect();
+        super.openConnectionInternal();
 
-        int directoryMode = getDirectoryMode( permissions );
-
-        channel.cd( "/" );
-        
         try
         {
-            String basedir = getRepository().getBasedir();
-            mkdirs( channel, basedir + "/", directoryMode );
-            
-            mkdirs( channel, resource.getName(), directoryMode );
+            channel = (ChannelSftp) session.openChannel( SFTP_CHANNEL );
+
+            channel.connect();
         }
-        catch ( TransferFailedException e )
+        catch ( JSchException e )
         {
-            fireTransferError( resource, e, TransferEvent.REQUEST_PUT );
+            throw new AuthenticationException( "Error connecting to remote repository: "
+ getRepository().getUrl(), e );
+        }
+    }
 
-            throw e;
+    private void returnToParentDirectory( Resource resource, ChannelSftp channel )
+        throws SftpException
+    {
+        String dir = getResourceDirectory( resource.getName() );
+        String[] dirs = PathUtils.dirnames( dir );
+        for ( int i = 0; i < dirs.length; i++ )
+        {
+            channel.cd( ".." );
         }
-        return channel;
     }
 
     private void putFile( ChannelSftp channel, File source, Resource resource, RepositoryPermissions
permissions )
@@ -109,8 +110,6 @@
 
         firePutStarted( resource, source );
 
-        
-        
         channel.put( source.getAbsolutePath(), filename );
 
         postProcessListeners( resource, source, TransferEvent.REQUEST_PUT );
@@ -240,13 +239,11 @@
 
         firePutInitiated( resource, source );
 
-        ChannelSftp channel = null;
-        
         try
         {
             RepositoryPermissions permissions = getRepository().getPermissions();
         
-            channel = preparePut( resource, permissions );
+            preparePut( resource, permissions );
         
             putFile( channel, source, resource, permissions );
         
@@ -261,21 +258,27 @@
         
             throw new TransferFailedException( msg, e );
         }
-        catch ( JSchException e )
-        {
-            fireTransferError( resource, e, TransferEvent.REQUEST_PUT );
-        
-            String msg = "Error occured while deploying '" + resource.getName() + "' " +
"to remote repository: " +
-                getRepository().getUrl();
+    }
+
+    private void preparePut( Resource resource, RepositoryPermissions permissions )
+        throws SftpException, TransferFailedException
+    {
+        int directoryMode = getDirectoryMode( getRepository().getPermissions() );
+
+        channel.cd( "/" );
         
-            throw new TransferFailedException( msg, e );
+        try
+        {
+            String basedir = getRepository().getBasedir();
+            mkdirs( channel, basedir + "/", directoryMode );
+            
+            mkdirs( channel, resource.getName(), directoryMode );
         }
-        finally
+        catch ( TransferFailedException e )
         {
-            if ( channel != null )
-            {
-                channel.disconnect();
-            }
+            fireTransferError( resource, e, TransferEvent.REQUEST_PUT );
+
+            throw e;
         }
     }
 



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


Mime
View raw message