Return-Path: Delivered-To: apmail-maven-wagon-cvs-archive@www.apache.org Received: (qmail 77318 invoked from network); 29 Jun 2004 18:45:54 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 29 Jun 2004 18:45:54 -0000 Received: (qmail 54468 invoked by uid 500); 29 Jun 2004 18:44:59 -0000 Delivered-To: apmail-maven-wagon-cvs-archive@maven.apache.org Received: (qmail 54301 invoked by uid 500); 29 Jun 2004 18:44:58 -0000 Mailing-List: contact wagon-cvs-help@maven.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Delivered-To: mailing list wagon-cvs@maven.apache.org Received: (qmail 54038 invoked by uid 99); 29 Jun 2004 18:44:54 -0000 X-ASF-Spam-Status: No, hits=0.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.27.1) with SMTP; Tue, 29 Jun 2004 11:44:54 -0700 Received: (qmail 75429 invoked by uid 1668); 29 Jun 2004 18:44:41 -0000 Date: 29 Jun 2004 18:44:41 -0000 Message-ID: <20040629184441.75428.qmail@minotaur.apache.org> From: michal@apache.org To: maven-wagon-cvs@apache.org Subject: cvs commit: maven-wagon/wagon-providers/ssh/src/test/java/org/apache/maven/wagon/providers/ssh ScpWagonTest.java ScpWagonWithSshPrivateKeySearchTest.java X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N michal 2004/06/29 11:44:41 Modified: wagon-providers/ssh/src/main/java/org/apache/maven/wagon/providers/ssh ScpWagon.java wagon-providers/ssh/src/test/java/org/apache/maven/wagon/providers/ssh ScpWagonTest.java ScpWagonWithSshPrivateKeySearchTest.java Log: SCP Wagon works now Revision Changes Path 1.11 +128 -62 maven-wagon/wagon-providers/ssh/src/main/java/org/apache/maven/wagon/providers/ssh/ScpWagon.java Index: ScpWagon.java =================================================================== RCS file: /home/cvs/maven-wagon/wagon-providers/ssh/src/main/java/org/apache/maven/wagon/providers/ssh/ScpWagon.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- ScpWagon.java 25 Jun 2004 18:43:27 -0000 1.10 +++ ScpWagon.java 29 Jun 2004 18:44:41 -0000 1.11 @@ -29,6 +29,7 @@ import org.apache.maven.wagon.ResourceDoesNotExistException; import org.apache.maven.wagon.TransferFailedException; import org.apache.maven.wagon.WagonConstants; +import org.apache.maven.wagon.events.TransferEvent; import org.apache.maven.wagon.artifact.Artifact; import org.apache.maven.wagon.authentication.AuthenticationException; import org.apache.maven.wagon.authentication.AuthenticationInfo; @@ -49,12 +50,11 @@ *

* We will first try to use public keys for authentication and if that doesn't * work then we fall back to using the login and password - * - * @version $Id$ * + * @version $Id$ */ public class ScpWagon - extends AbstractWagon implements SshCommandExecutor + extends AbstractWagon implements SshCommandExecutor { public static String EXEC_CHANNEL = "exec"; @@ -69,7 +69,7 @@ // ---------------------------------------------------------------------- public void openConnection() - throws AuthenticationException + throws AuthenticationException { try { @@ -108,7 +108,9 @@ { if ( authInfo.getPassphrase() == null ) { - authInfo.setPassphrase( "" ); + String msg = "Private key provided " + "without passphrase for repo: " + getRepository().getName(); + + throw new AuthenticationException( msg ); } fireSessionDebug( "Using private key: " + privateKey ); @@ -122,7 +124,6 @@ throw new AuthenticationException( msg ); } - ProxyInfo proxyInfo = getRepository().getProxyInfo(); if ( proxyInfo != null && proxyInfo.getHost() != null ) @@ -137,14 +138,14 @@ if ( proxyPort == SOCKS5_PROXY_PORT ) { proxy = new ProxySOCKS5( proxyInfo.getHost() ); - ( (ProxySOCKS5) proxy ).setUserPasswd( proxyInfo.getUserName(), - proxyInfo.getPassword() ); + ( ( ProxySOCKS5 ) proxy ).setUserPasswd( proxyInfo.getUserName(), + proxyInfo.getPassword() ); } else { proxy = new ProxyHTTP( proxyInfo.getHost(), proxyPort ); - ( (ProxyHTTP) proxy ).setUserPasswd( proxyInfo.getUserName(), - proxyInfo.getPassword() ); + ( ( ProxyHTTP ) proxy ).setUserPasswd( proxyInfo.getUserName(), + proxyInfo.getPassword() ); } proxy.connect( session, host, port ); @@ -187,19 +188,21 @@ // // ---------------------------------------------------------------------- - public void closeConnection() + public void closeConnection() { session.disconnect(); } public void executeCommand( String command ) - throws TransferFailedException + throws TransferFailedException { ChannelExec channel = null; try { - channel = (ChannelExec) session.openChannel( EXEC_CHANNEL ); + fireTransferDebug( "Executing command: " + command ); + + channel = ( ChannelExec ) session.openChannel( EXEC_CHANNEL ); channel.setCommand( command ); @@ -217,17 +220,27 @@ public void put( File source, Artifact artifact ) - throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException + throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException { put( source, fullArtifactPath( artifact ) ); } public void put( File source, String resource ) - throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException + throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException { - String mkdirCmd = "mkdir -p " + getRepository().getBasedir() + "/" + PathUtils.dirname( resource ) + "\n"; - executeCommand( mkdirCmd ); + String chdirCmd = "cd " + getRepository().getBasedir() + "\n"; + + executeCommand( chdirCmd ); + + String dir = PathUtils.dirname( resource ); + + if ( dir != null && dir.length() > 0) + { + String mkdirCmd = "mkdir -p " + dir + "\n"; + + executeCommand( mkdirCmd ); + } ChannelExec channel = null; @@ -243,7 +256,7 @@ fireTransferDebug( "Executing command: " + command ); - channel = (ChannelExec) session.openChannel( EXEC_CHANNEL ); + channel = ( ChannelExec ) session.openChannel( EXEC_CHANNEL ); channel.setCommand( command ); @@ -254,7 +267,7 @@ channel.connect(); - byte[] tmp = new byte[1]; + byte[] tmp = new byte[ 1 ]; if ( checkAck( in ) != 0 ) { @@ -286,23 +299,12 @@ // send a content of lfile FileInputStream fis = new FileInputStream( source ); - putTransfer( resource, source, fis, out, false ); + putTransfer( resource, source, fis, out, false ); - byte[] buf = new byte[1024]; -// -// while ( true ) -// { -// int len = fis.read( buf, 0, buf.length ); -// -// if ( len <= 0 ) break; -// -// out.write( buf, 0, len ); -// -// out.flush(); -// } + byte[] buf = new byte[ 1024 ]; // send '\0' - buf[0] = 0; + buf[ 0 ] = 0; out.write( buf, 0, 1 ); @@ -318,7 +320,7 @@ throw new TransferFailedException( msg ); } } - catch ( Exception e ) + catch ( Exception e ) { String msg = "Error occured while deploying '" + resource + "' to remote repository: " + getRepository().getUrl(); @@ -346,13 +348,13 @@ } public void get( Artifact artifact, File destination ) - throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException + throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException { get( fullArtifactPath( artifact ), destination ); } public void get( String resource, File destination ) - throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException + throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException { ChannelExec channel = null; @@ -361,13 +363,16 @@ InputStream in = null; + + LazyFileOutputStream outputStream = new LazyFileOutputStream( destination ); + try { String cmd = "scp -f " + resource; fireTransferDebug( "Executing command: " + cmd ); - channel = (ChannelExec) session.openChannel( EXEC_CHANNEL ); + channel = ( ChannelExec ) session.openChannel( EXEC_CHANNEL ); channel.setCommand( cmd ); @@ -378,10 +383,10 @@ channel.connect(); - byte[] buf = new byte[1024]; + byte[] buf = new byte[ 1024 ]; // send '\0' - buf[0] = 0; + buf[ 0 ] = 0; out.write( buf, 0, 1 ); @@ -405,48 +410,101 @@ { in.read( buf, 0, 1 ); - if ( buf[0] == ' ' ) break; + if ( buf[ 0 ] == ' ' ) + { + break; + } - filesize = filesize * 10 + ( buf[0] - '0' ); + filesize = filesize * 10 + ( buf[ 0 ] - '0' ); } - String file = null; for ( int i = 0; ; i++ ) { in.read( buf, i, 1 ); - if ( buf[i] == (byte) 0x0a ) + if ( buf[ i ] == ( byte ) 0x0a ) { - file = new String( buf, 0, i ); - break; } } // send '\0' - buf[0] = 0; + buf[ 0 ] = 0; out.write( buf, 0, 1 ); out.flush(); - // read a content of lfile - LazyFileOutputStream outputStream = new LazyFileOutputStream( destination ); + fireGetStarted( resource, destination ); - getTransfer( resource, destination, in, outputStream); + TransferEvent transferEvent = new TransferEvent( this, resource, TransferEvent.TRANSFER_PROGRESS, TransferEvent.REQUEST_GET ); + try + { - byte[] tmp = new byte[1]; + while ( true ) + { + int len = Math.min( buf.length, filesize ); + + in.read( buf, 0, len ); + + outputStream.write( buf, 0, len ); + + transferEvent.setData( buf, len ); + + fireTransferProgress( transferEvent ); + + filesize -= len; + + if ( filesize == 0 ) + { + break; + } + } + } + catch ( IOException e ) + { + fireTransferError( resource, e ); + + shutdownStream( outputStream ); + + if ( destination.exists() ) + { + boolean deleted = destination.delete(); + + if ( !deleted ) + { + destination.deleteOnExit(); + } + } + + String msg = "GET request of: " + resource + " from " + source.getName() + "failed"; + + throw new TransferFailedException( msg, e ); + + } + + + fireGetCompleted( resource, destination ); if ( checkAck( in ) != 0 ) { + String msg = "Error occured while deploying '" + + resource + "' to remote repository '" + + getRepository().getUrl() + + "' - Wrong ACK "; + throw new TransferFailedException( msg ); } + else + { + fireTransferDebug( "ACK check: OK" ); + } // send '\0' - buf[0] = 0; + buf[ 0 ] = 0; out.write( buf, 0, 1 ); @@ -461,7 +519,7 @@ { boolean deleted = destination.delete(); - if ( ! deleted ) + if ( !deleted ) { destination.deleteOnExit(); } @@ -473,11 +531,10 @@ throw new TransferFailedException( msg, e ); - } finally { - if ( out != null) + if ( out != null ) { shutdownStream( out ); } @@ -485,6 +542,9 @@ { channel.disconnect(); } + + + shutdownStream( outputStream ); } } @@ -493,7 +553,7 @@ // ---------------------------------------------------------------------- public class WagonUserInfo - implements UserInfo + implements UserInfo { AuthenticationInfo authInfo; @@ -536,22 +596,28 @@ static int checkAck( InputStream in ) throws IOException { int b = in.read(); - // b may be 0 for success, - // 1 for error, - // 2 for fatal error, - // -1 +// b may be 0 for success, +// 1 for error, +// 2 for fatal error, +// -1 + + if ( b == 0 || b == -1 ) + { + return b; + } - if ( b == 0 ) return b; - if ( b == -1 ) return b; if ( b == 1 || b == 2 ) { StringBuffer sb = new StringBuffer(); + int c; + do { c = in.read(); - sb.append( (char) c ); + + sb.append( ( char ) c ); } while ( c != '\n' ); if ( b == 1 ) 1.4 +13 -4 maven-wagon/wagon-providers/ssh/src/test/java/org/apache/maven/wagon/providers/ssh/ScpWagonTest.java Index: ScpWagonTest.java =================================================================== RCS file: /home/cvs/maven-wagon/wagon-providers/ssh/src/test/java/org/apache/maven/wagon/providers/ssh/ScpWagonTest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- ScpWagonTest.java 21 May 2004 16:48:56 -0000 1.3 +++ ScpWagonTest.java 29 Jun 2004 18:44:41 -0000 1.4 @@ -41,14 +41,14 @@ protected String getTestRepositoryUrl() { - return "scp://login.ibiblio.org//public/html/maven"; + return "scp://beaver.codehaus.org//home/users/" + getUserName() + "/public_html"; } protected AuthenticationInfo getAuthInfo() { AuthenticationInfo authInfo = new AuthenticationInfo(); - String userName = System.getProperty( "user.name" ); + String userName = getUserName(); authInfo.setUserName( userName ); @@ -61,8 +61,17 @@ authInfo.setPassphrase( "" ); } - authInfo.setGroup( "maven" ); + authInfo.setGroup( getUserName() ); return authInfo; } + + + private String getUserName() + { + String userName = System.getProperty( "user.name" ); + + return userName; + } + } 1.4 +10 -4 maven-wagon/wagon-providers/ssh/src/test/java/org/apache/maven/wagon/providers/ssh/ScpWagonWithSshPrivateKeySearchTest.java Index: ScpWagonWithSshPrivateKeySearchTest.java =================================================================== RCS file: /home/cvs/maven-wagon/wagon-providers/ssh/src/test/java/org/apache/maven/wagon/providers/ssh/ScpWagonWithSshPrivateKeySearchTest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- ScpWagonWithSshPrivateKeySearchTest.java 21 May 2004 16:48:56 -0000 1.3 +++ ScpWagonWithSshPrivateKeySearchTest.java 29 Jun 2004 18:44:41 -0000 1.4 @@ -39,21 +39,27 @@ protected String getTestRepositoryUrl() { - return "scp://login.ibiblio.org//public/html/maven"; + return "scp://beaver.codehaus.org//home/users/" + getUserName() + "/public_html"; } protected AuthenticationInfo getAuthInfo() { AuthenticationInfo authInfo = new AuthenticationInfo(); - String userName = System.getProperty( "user.name" ); + String userName = getUserName(); authInfo.setUserName( userName ); authInfo.setPassphrase( "" ); - authInfo.setGroup( "maven" ); + authInfo.setGroup( getUserName() ); return authInfo; + } + + private String getUserName() + { + String userName = System.getProperty( "user.name" ); + return userName; } } --------------------------------------------------------------------- To unsubscribe, e-mail: wagon-cvs-unsubscribe@maven.apache.org For additional commands, e-mail: wagon-cvs-help@maven.apache.org