You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wagon-commits@maven.apache.org by br...@apache.org on 2006/11/20 07:35:40 UTC
svn commit: r477072 - in /maven/wagon/trunk:
wagon-provider-test/src/main/java/org/apache/maven/wagon/
wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/
wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/provider...
Author: brett
Date: Sun Nov 19 22:35:38 2006
New Revision: 477072
URL: http://svn.apache.org/viewvc?view=rev&rev=477072
Log:
- make ssh tests work again, point at localhost, still disabled by default
- start to refactor jsch specific code into separate methods
Modified:
maven/wagon/trunk/wagon-provider-test/src/main/java/org/apache/maven/wagon/WagonTestCase.java
maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/AbstractSshWagon.java
maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/ScpWagon.java
maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/SftpWagon.java
maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/TestData.java
maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/knownhost/AbstractKnownHostsProviderTest.java
maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/knownhost/SingleKnownHostsProviderTest.java
maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/knownhost/StreamKnownHostsProviderTest.java
Modified: maven/wagon/trunk/wagon-provider-test/src/main/java/org/apache/maven/wagon/WagonTestCase.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-provider-test/src/main/java/org/apache/maven/wagon/WagonTestCase.java?view=diff&rev=477072&r1=477071&r2=477072
==============================================================================
--- maven/wagon/trunk/wagon-provider-test/src/main/java/org/apache/maven/wagon/WagonTestCase.java (original)
+++ maven/wagon/trunk/wagon-provider-test/src/main/java/org/apache/maven/wagon/WagonTestCase.java Sun Nov 19 22:35:38 2006
@@ -16,12 +16,6 @@
* limitations under the License.
*/
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
import org.apache.maven.wagon.authentication.AuthenticationInfo;
import org.apache.maven.wagon.authorization.AuthorizationException;
import org.apache.maven.wagon.observers.ChecksumObserver;
@@ -31,6 +25,12 @@
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.util.FileUtils;
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
@@ -76,7 +76,7 @@
/**
* URL of the repository. For a complete test it should point to a non existing folder so
* we also check for the creation of new folders in the remote site.
- *
+ * <p/>
* return the URL of the repository as specified by Wagon syntax
*/
protected abstract String getTestRepositoryUrl()
@@ -84,7 +84,7 @@
/**
* Protocol id of the Wagon to use, eg. <code>scp</code>, <code>ftp</code>
- *
+ *
* @return the protocol id
*/
protected abstract String getProtocol();
@@ -208,9 +208,9 @@
if ( wagon.supportsDirectoryCopy() )
{
sourceFile = new File( FileTestUtils.getTestOutputDir(), "directory-copy" );
-
+
FileUtils.deleteDirectory( sourceFile );
-
+
writeTestFile( "test-resource-1.txt" );
writeTestFile( "a/test-resource-2.txt" );
writeTestFile( "a/b/test-resource-3.txt" );
@@ -229,79 +229,78 @@
wagon.get( "directory-copy/a/test-resource-2.txt", destFile );
wagon.get( "directory-copy/a/b/test-resource-3.txt", destFile );
wagon.get( "directory-copy/c/test-resource-4.txt", destFile );
- wagon.get( "directory-copy/d/e/f/test-resource-5.txt", destFile);
+ wagon.get( "directory-copy/d/e/f/test-resource-5.txt", destFile );
wagon.disconnect();
}
tearDownWagonTestingFixtures();
}
-
+
/**
* Test for putting a directory with a destination that multiple directories deep,
* all of which haven't been created.
- * @since 1.0-beta-2
+ *
* @throws Exception
+ * @since 1.0-beta-2
*/
public void testWagonPutDirectoryDeepDestination()
throws Exception
{
setupRepositories();
-
+
setupWagonTestingFixtures();
-
+
Wagon wagon = getWagon();
-
+
if ( wagon.supportsDirectoryCopy() )
{
sourceFile = new File( FileTestUtils.getTestOutputDir(), "deep0/deep1/deep2" );
-
+
FileUtils.deleteDirectory( sourceFile );
-
+
writeTestFile( "test-resource-1.txt" );
writeTestFile( "a/test-resource-2.txt" );
writeTestFile( "a/b/test-resource-3.txt" );
writeTestFile( "c/test-resource-4.txt" );
writeTestFile( "d/e/f/test-resource-5.txt" );
-
+
wagon.connect( testRepository, getAuthInfo() );
-
+
wagon.putDirectory( sourceFile, "deep0/deep1/deep2" );
-
+
destFile = FileTestUtils.createUniqueFile( getName(), getName() );
-
+
destFile.deleteOnExit();
-
+
wagon.get( "deep0/deep1/deep2/test-resource-1.txt", destFile );
wagon.get( "deep0/deep1/deep2/a/test-resource-2.txt", destFile );
wagon.get( "deep0/deep1/deep2/a/b/test-resource-3.txt", destFile );
wagon.get( "deep0/deep1/deep2/c/test-resource-4.txt", destFile );
- wagon.get( "deep0/deep1/deep2/d/e/f/test-resource-5.txt", destFile);
-
+ wagon.get( "deep0/deep1/deep2/d/e/f/test-resource-5.txt", destFile );
+
wagon.disconnect();
}
-
+
tearDownWagonTestingFixtures();
}
/**
* Test that when putting a directory that already exists new files get also copied
- * @since 1.0-beta-1
+ *
* @throws Exception
+ * @since 1.0-beta-1
*/
public void testWagonPutDirectoryWhenDirectoryAlreadyExists()
throws Exception
{
-
- final String dirName = "directory-copy-existing";
+
+ final String dirName = "directory-copy-existing";
final String resourceToCreate = "test-resource-1.txt";
- final String[] resources = {
- "a/test-resource-2.txt",
- "a/b/test-resource-3.txt",
- "c/test-resource-4.txt" };
-
+ final String[] resources = {"a/test-resource-2.txt", "a/b/test-resource-3.txt", "c/test-resource-4.txt"};
+
setupRepositories();
setupWagonTestingFixtures();
@@ -314,7 +313,7 @@
FileUtils.deleteDirectory( sourceFile );
- createDirectory( wagon, resourceToCreate , resources, dirName );
+ createDirectory( wagon, resourceToCreate, resources, dirName );
wagon.connect( testRepository, getAuthInfo() );
@@ -344,14 +343,15 @@
}
/**
- * Create a directory with a resource and check that the other ones don't exist
+ * Create a directory with a resource and check that the other ones don't exist
+ *
* @param wagon
* @param resourceToCreate name of the resource to be created
- * @param resourcesNotPresent names of the resources that we'll check don't exist
- * @param dirName directory name to create
+ * @param resourcesPresent names of the resources that we'll check don't exist
+ * @param dirName directory name to create
* @throws Exception
*/
- protected void createDirectory( Wagon wagon, String resourceToCreate, String[] resourcesNotPresent, String dirName )
+ protected void createDirectory( Wagon wagon, String resourceToCreate, String[] resourcesPresent, String dirName )
throws Exception
{
writeTestFile( resourceToCreate );
@@ -360,14 +360,20 @@
wagon.putDirectory( sourceFile, dirName );
- for ( int i = 0; i < resourcesNotPresent.length; i++ )
+ for ( int i = 0; i < resourcesPresent.length; i++ )
{
- assertNotExists( wagon, dirName + "/" + resourcesNotPresent[i] );
+ String resourceName = dirName + "/" + resourcesPresent[i];
+
+ File destFile = FileTestUtils.createUniqueFile( getName(), resourceName );
+
+ destFile.deleteOnExit();
+
+ wagon.get( resourceName, destFile );
}
wagon.disconnect();
}
-
+
protected void assertResourcesAreInRemoteSide( Wagon wagon, List resourceNames )
throws IOException, TransferFailedException, ResourceDoesNotExistException, AuthorizationException
{
@@ -376,7 +382,7 @@
{
String resourceName = (String) iter.next();
- destFile = FileTestUtils.createUniqueFile( getName(), resourceName );
+ File destFile = FileTestUtils.createUniqueFile( getName(), resourceName );
destFile.deleteOnExit();
@@ -386,12 +392,13 @@
/**
* Assert that a resource does not exist in the remote wagon system
- * @since 1.0-beta-1
- * @param wagon wagon to get the resource from
+ *
+ * @param wagon wagon to get the resource from
* @param resourceName name of the resource
- * @throws IOException if a temp file can't be created
- * @throws AuthorizationException
- * @throws TransferFailedException
+ * @throws IOException if a temp file can't be created
+ * @throws AuthorizationException
+ * @throws TransferFailedException
+ * @since 1.0-beta-1
*/
protected void assertNotExists( Wagon wagon, String resourceName )
throws IOException, TransferFailedException, AuthorizationException
@@ -458,12 +465,12 @@
tearDownWagonTestingFixtures();
}
}
-
+
/**
* Test {@link Wagon#getFileList(String)}.
- *
- * @since 1.0-beta-2
+ *
* @throws Exception
+ * @since 1.0-beta-2
*/
public void testWagonGetFileList()
throws Exception
@@ -474,11 +481,8 @@
String dirName = "file-list";
- String filenames[] = new String[] {
- "test-resource.txt",
- "test-resource-b.txt",
- "test-resource.pom",
- "more-resources.dat" };
+ String filenames[] =
+ new String[]{"test-resource.txt", "test-resource-b.txt", "test-resource.pom", "more-resources.dat"};
for ( int i = 0; i < filenames.length; i++ )
{
@@ -503,12 +507,12 @@
tearDownWagonTestingFixtures();
}
-
+
/**
* Test {@link Wagon#getFileList(String)} when the directory does not exist.
- *
- * @since 1.0-beta-2
+ *
* @throws Exception
+ * @since 1.0-beta-2
*/
public void testWagonGetFileListWhenDirectoryDoesNotExist()
throws Exception
@@ -542,9 +546,9 @@
/**
* Test for an existing resource.
- *
- * @since 1.0-beta-2
+ *
* @throws Exception
+ * @since 1.0-beta-2
*/
public void testWagonResourceExists()
throws Exception
@@ -556,7 +560,7 @@
Wagon wagon = getWagon();
putFile();
-
+
wagon.connect( testRepository, getAuthInfo() );
assertTrue( sourceFile.getName() + " does not exist", wagon.resourceExists( sourceFile.getName() ) );
@@ -565,12 +569,12 @@
tearDownWagonTestingFixtures();
}
-
+
/**
* Test for an invalid resource.
- *
- * @since 1.0-beta-2
+ *
* @throws Exception
+ * @since 1.0-beta-2
*/
public void testWagonResourceNotExists()
throws Exception
@@ -589,7 +593,6 @@
tearDownWagonTestingFixtures();
}
-
// ----------------------------------------------------------------------
// File <--> File round trip testing
@@ -597,8 +600,8 @@
// We are testing taking a file, our sourcefile, and placing it into the
// test repository that we have setup.
// ----------------------------------------------------------------------
-
- protected void putFile(String resourceName, String testFileName, String content)
+
+ protected void putFile( String resourceName, String testFileName, String content )
throws Exception
{
message( "Putting test artifact: " + resourceName + " into test repository " + testRepository );
@@ -617,7 +620,7 @@
wagon.removeTransferListener( checksumObserver );
- wagon.disconnect();
+ wagon.disconnect();
}
protected void putFile()
@@ -694,5 +697,5 @@
return repository;
}
-
+
}
Modified: maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/AbstractSshWagon.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/AbstractSshWagon.java?view=diff&rev=477072&r1=477071&r2=477072
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/AbstractSshWagon.java (original)
+++ maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/AbstractSshWagon.java Sun Nov 19 22:35:38 2006
@@ -16,17 +16,15 @@
* limitations under the License.
*/
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.io.StringReader;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Properties;
-
+import com.jcraft.jsch.ChannelExec;
+import com.jcraft.jsch.JSch;
+import com.jcraft.jsch.JSchException;
+import com.jcraft.jsch.Proxy;
+import com.jcraft.jsch.ProxyHTTP;
+import com.jcraft.jsch.ProxySOCKS5;
+import com.jcraft.jsch.Session;
+import com.jcraft.jsch.UIKeyboardInteractive;
+import com.jcraft.jsch.UserInfo;
import org.apache.maven.wagon.AbstractWagon;
import org.apache.maven.wagon.CommandExecutionException;
import org.apache.maven.wagon.CommandExecutor;
@@ -48,15 +46,16 @@
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.StringUtils;
-import com.jcraft.jsch.ChannelExec;
-import com.jcraft.jsch.JSch;
-import com.jcraft.jsch.JSchException;
-import com.jcraft.jsch.Proxy;
-import com.jcraft.jsch.ProxyHTTP;
-import com.jcraft.jsch.ProxySOCKS5;
-import com.jcraft.jsch.Session;
-import com.jcraft.jsch.UIKeyboardInteractive;
-import com.jcraft.jsch.UserInfo;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
/**
* Common SSH operations.
@@ -90,9 +89,10 @@
class Streams
{
String out = "";
+
String err = "";
}
-
+
public void openConnection()
throws AuthenticationException
{
@@ -106,8 +106,6 @@
authenticationInfo.setUserName( System.getProperty( "user.name" ) );
}
- JSch sch = new JSch();
-
int port = getRepository().getPort();
if ( port == WagonConstants.UNKNOWN_PORT )
@@ -117,21 +115,10 @@
String host = getRepository().getHost();
- try
- {
- session = sch.getSession( authenticationInfo.getUserName(), host, port );
- }
- catch ( JSchException e )
- {
- fireSessionError( e );
-
- throw new AuthenticationException( "Cannot connect. Reason: " + e.getMessage(), e );
- }
-
// If user don't define a password, he want to use a private key
+ File privateKey = null;
if ( authenticationInfo.getPassword() == null )
{
- File privateKey;
if ( authenticationInfo.getPrivateKey() != null )
{
@@ -150,20 +137,53 @@
}
fireSessionDebug( "Using private key: " + privateKey );
+ }
+ }
- try
- {
- sch.addIdentity( privateKey.getAbsolutePath(), authenticationInfo.getPassphrase() );
- }
- catch ( JSchException e )
- {
- fireSessionError( e );
+ Properties config = new Properties();
+ config.setProperty( "BatchMode", interactive ? "no" : "yes" );
- throw new AuthenticationException( "Cannot connect. Reason: " + e.getMessage(), e );
- }
+ if ( !interactive )
+ {
+ interactiveUserInfo = new NullInteractiveUserInfo();
+ uIKeyboardInteractive = null;
+ }
+
+ knownHostsProvider.addConfiguration( config );
+
+ initJsch( privateKey, host, port, config );
+ }
+
+ private void initJsch( File privateKey, String host, int port, Properties config )
+ throws AuthenticationException
+ {
+ JSch sch = new JSch();
+
+ if ( privateKey != null && privateKey.exists() )
+ {
+ try
+ {
+ sch.addIdentity( privateKey.getAbsolutePath(), authenticationInfo.getPassphrase() );
+ }
+ catch ( JSchException e )
+ {
+ fireSessionError( e );
+
+ throw new AuthenticationException( "Cannot connect. Reason: " + e.getMessage(), e );
}
}
+ try
+ {
+ session = sch.getSession( authenticationInfo.getUserName(), host, port );
+ }
+ catch ( JSchException e )
+ {
+ fireSessionError( e );
+
+ throw new AuthenticationException( "Cannot connect. Reason: " + e.getMessage(), e );
+ }
+
if ( proxyInfo != null && proxyInfo.getHost() != null )
{
Proxy proxy;
@@ -189,15 +209,6 @@
session.setProxy( null );
}
- Properties config = new Properties();
- config.setProperty( "BatchMode", interactive ? "no" : "yes" );
-
- if ( !interactive )
- {
- interactiveUserInfo = new NullInteractiveUserInfo();
- uIKeyboardInteractive = null;
- }
-
// username and password will be given via UserInfo interface.
UserInfo ui = new WagonUserInfo( authenticationInfo, interactiveUserInfo );
@@ -210,7 +221,6 @@
{
try
{
- knownHostsProvider.addConfiguration( config );
knownHostsProvider.addKnownHosts( sch, ui );
}
catch ( JSchException e )
@@ -259,103 +269,51 @@
return privateKey;
}
-
+
public Streams executeCommand( String command, boolean ignoreFailures )
throws CommandExecutionException
{
- ChannelExec channel = null;
+ fireTransferDebug( "Executing command: " + command );
- InputStream in = null;
- InputStream err = null;
- OutputStream out = null;
+ ChannelExec channel = null;
+ BufferedReader stdoutReader = null;
+ BufferedReader stderrReader = null;
try
{
- fireTransferDebug( "Executing command: " + command );
-
channel = (ChannelExec) session.openChannel( EXEC_CHANNEL );
channel.setCommand( command + "\n" );
- out = channel.getOutputStream();
-
- in = channel.getInputStream();
-
- err = channel.getErrStream();
+ InputStream stdout = channel.getInputStream();
+ InputStream stderr = channel.getErrStream();
channel.connect();
- BufferedReader r = new BufferedReader( new InputStreamReader( err ) );
+ stdoutReader = new BufferedReader( new InputStreamReader( stdout ) );
+ stderrReader = new BufferedReader( new InputStreamReader( stderr ) );
- List output = null;
+ Streams streams = processStreams( stderrReader, stdoutReader );
- Streams streams = new Streams();
-
- while ( true )
+ if ( streams.err.length() > 0 )
{
- String line = r.readLine();
- if ( line == null )
- {
- break;
- }
-
- if ( output == null )
- {
- output = new ArrayList();
- }
-
- // TODO: I think we need to deal with exit codes instead, but IIRC there are some cases of errors that don't have exit codes
- // ignore this error. TODO: output a warning
- if ( !line.startsWith( "Could not chdir to home directory" ) && !line.endsWith( "ttyname: Operation not supported" ) )
- {
- output.add( line );
- streams.err += line + "\n";
- }
+ int exitCode = channel.getExitStatus();
+ throw new CommandExecutionException( "Exit code: " + exitCode + " - " + streams.err );
}
-
- r = new BufferedReader( new InputStreamReader( in ));
- while(true)
- {
- String line = r.readLine();
- if(line == null)
- {
- break;
- }
-
- streams.out += line + "\n";
- }
-
- // drain the output stream.
- // TODO: we'll save this for the 1.0-alpha-8 line, so we can test it more. the -q arg in the
- // unzip command should keep us until then...
-// int avail = in.available();
-// byte[] trashcan = new byte[1024];
-//
-// while( ( avail = in.available() ) > 0 )
-// {
-// in.read( trashcan, 0, avail );
-// }
-
- if ( output != null && !output.isEmpty() )
- {
- throw new CommandExecutionException(
- "Exit code: " + channel.getExitStatus() + " - " + StringUtils.join( output.iterator(), "\n" ) );
- }
-
+
return streams;
}
- catch ( JSchException e )
+ catch ( IOException e )
{
throw new CommandExecutionException( "Cannot execute remote command: " + command, e );
}
- catch ( IOException e )
+ catch ( JSchException e )
{
throw new CommandExecutionException( "Cannot execute remote command: " + command, e );
}
finally
{
- IOUtil.close( out );
- IOUtil.close( in );
- IOUtil.close( err );
+ IOUtil.close( stdoutReader );
+ IOUtil.close( stderrReader );
if ( channel != null )
{
channel.disconnect();
@@ -363,6 +321,53 @@
}
}
+ private Streams processStreams( BufferedReader stderrReader, BufferedReader stdoutReader )
+ throws IOException, CommandExecutionException
+ {
+ Streams streams = new Streams();
+
+ while ( true )
+ {
+ String line = stderrReader.readLine();
+ if ( line == null )
+ {
+ break;
+ }
+
+ // TODO: I think we need to deal with exit codes instead, but IIRC there are some cases of errors that don't have exit codes
+ // ignore this error. TODO: output a warning
+ if ( !line.startsWith( "Could not chdir to home directory" ) &&
+ !line.endsWith( "ttyname: Operation not supported" ) )
+ {
+ streams.err += line + "\n";
+ }
+ }
+
+ while ( true )
+ {
+ String line = stdoutReader.readLine();
+ if ( line == null )
+ {
+ break;
+ }
+
+ streams.out += line + "\n";
+ }
+
+ // drain the output stream.
+ // TODO: we'll save this for the 1.0-alpha-8 line, so we can test it more. the -q arg in the
+ // unzip command should keep us until then...
+// int avail = in.available();
+// byte[] trashcan = new byte[1024];
+//
+// while( ( avail = in.available() ) > 0 )
+// {
+// in.read( trashcan, 0, avail );
+// }
+
+ return streams;
+ }
+
public void executeCommand( String command )
throws CommandExecutionException
{
@@ -613,32 +618,39 @@
{
String path = getPath( getRepository().getBasedir(), destinationDirectory );
Streams streams = executeCommand( "ls -la " + path, true );
-
- BufferedReader br = new BufferedReader(new StringReader(streams.out));
-
+
+ BufferedReader br = new BufferedReader( new StringReader( streams.out ) );
+
List ret = new ArrayList();
String line = br.readLine();
-
- while(line != null)
+
+ while ( line != null )
{
- String parts[] = StringUtils.split( line, " " );
- if(parts.length >= 8)
+ String[] parts = StringUtils.split( line, " " );
+ if ( parts.length >= 8 )
{
- ret.add(parts[8]);
+ ret.add( parts[8] );
}
-
+
line = br.readLine();
}
-
+
return ret;
}
catch ( CommandExecutionException e )
{
- throw new TransferFailedException( "Error performing file listing.", e);
+ if ( e.getMessage().trim().endsWith( "No such file or directory" ) )
+ {
+ throw new ResourceDoesNotExistException( e.getMessage().trim() );
+ }
+ else
+ {
+ throw new TransferFailedException( "Error performing file listing.", e );
+ }
}
catch ( IOException e )
{
- throw new TransferFailedException( "Error parsing file listing.", e);
+ throw new TransferFailedException( "Error parsing file listing.", e );
}
}
Modified: maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/ScpWagon.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/ScpWagon.java?view=diff&rev=477072&r1=477071&r2=477072
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/ScpWagon.java (original)
+++ maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/ScpWagon.java Sun Nov 19 22:35:38 2006
@@ -16,12 +16,8 @@
* limitations under the License.
*/
-import java.io.EOFException;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
+import com.jcraft.jsch.ChannelExec;
+import com.jcraft.jsch.JSchException;
import org.apache.maven.wagon.CommandExecutionException;
import org.apache.maven.wagon.PathUtils;
import org.apache.maven.wagon.PermissionModeUtils;
@@ -33,8 +29,11 @@
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.StringUtils;
-import com.jcraft.jsch.ChannelExec;
-import com.jcraft.jsch.JSchException;
+import java.io.EOFException;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
/**
* A base class for deployers and fetchers using protocols from SSH2 family and
@@ -99,14 +98,33 @@
throw new TransferFailedException( "Error performing commands for file transfer", e );
}
- ChannelExec channel = null;
-
OutputStream out = null;
String path = getPath( basedir, resourceName );
RepositoryPermissions permissions = getRepository().getPermissions();
+ scpJsch( path, out, source, resourceName, resource, getOctalMode( permissions ) );
+
+ try
+ {
+ if ( permissions != null && permissions.getGroup() != null )
+ {
+ executeCommand( "chgrp -f " + permissions.getGroup() + " " + path );
+ }
+ }
+ catch ( CommandExecutionException e )
+ {
+ throw new TransferFailedException( "Error performing commands for file transfer", e );
+ }
+ }
+
+ private void scpJsch( String path, OutputStream out, File source, String resourceName, Resource resource,
+ String mode )
+ throws TransferFailedException
+ {
+ ChannelExec channel = null;
+
try
{
// exec 'scp -t -d rfile' remotely
@@ -130,21 +148,7 @@
// send "C0644 filesize filename", where filename should not include '/'
long filesize = source.length();
- String mode = "644";
- if ( permissions != null && permissions.getFileMode() != null )
- {
- if ( permissions.getFileMode().matches( "[0-9]{3}" ) )
- {
- mode = permissions.getFileMode();
- }
- else
- {
- // TODO: as warning
- fireSessionDebug( "Not using non-octal permissions: " + mode );
- }
- }
-
- command = "C0" + mode + " " + filesize + " ";
+ command = "C" + mode + " " + filesize + " ";
if ( resourceName.lastIndexOf( PATH_SEPARATOR ) > 0 )
{
@@ -196,18 +200,30 @@
channel.disconnect();
}
}
+ }
- try
+ private String getOctalMode( RepositoryPermissions permissions )
+ {
+ String mode = "0644";
+ if ( permissions != null && permissions.getFileMode() != null )
{
- if ( permissions != null && permissions.getGroup() != null )
+ if ( permissions.getFileMode().matches( "[0-9]{3,4}" ) )
{
- executeCommand( "chgrp -f " + permissions.getGroup() + " " + path );
+ mode = permissions.getFileMode();
+
+ if ( mode.length() == 3 )
+ {
+ mode = "0" + mode;
+ }
+ }
+ else
+ {
+ // TODO: calculate?
+ // TODO: as warning
+ fireSessionDebug( "Not using non-octal permissions: " + mode );
}
}
- catch ( CommandExecutionException e )
- {
- throw new TransferFailedException( "Error performing commands for file transfer", e );
- }
+ return mode;
}
private void checkAck( InputStream in )
@@ -241,18 +257,23 @@
fireGetInitiated( resource, destination );
- ChannelExec channel = null;
+ String basedir = getRepository().getBasedir();
+
+ getJsch( basedir, resourceName, resource, destination, getPath( basedir, resourceName ) );
+ }
+ private void getJsch( String basedir, String resourceName, Resource resource, File destination, String path )
+ throws ResourceDoesNotExistException, TransferFailedException
+ {
//I/O streams for remote scp
OutputStream out = null;
InputStream in;
- String basedir = getRepository().getBasedir();
+ ChannelExec channel = null;
try
{
- String path = getPath( basedir, resourceName );
String cmd = "scp -f " + path;
fireTransferDebug( "Executing command: " + cmd );
Modified: maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/SftpWagon.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/SftpWagon.java?view=diff&rev=477072&r1=477071&r2=477072
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/SftpWagon.java (original)
+++ maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/SftpWagon.java Sun Nov 19 22:35:38 2006
@@ -293,14 +293,17 @@
try
{
channel.cd( repository.getBasedir() );
-
- channel.cd( dir );
-
+
+ if ( dir.length() > 0 )
+ {
+ channel.cd( dir );
+ }
+
attrs = channel.stat( filename );
}
catch ( SftpException e )
{
- if ( "No such file".equals( e.toString() ) )
+ if ( e.toString().trim().endsWith( "No such file" ) )
{
throw new ResourceDoesNotExistException( e.toString(), e );
}
Modified: maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/TestData.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/TestData.java?view=diff&rev=477072&r1=477071&r2=477072
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/TestData.java (original)
+++ maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/TestData.java Sun Nov 19 22:35:38 2006
@@ -16,7 +16,10 @@
* limitations under the License.
*/
+import org.codehaus.plexus.util.FileUtils;
+
import java.io.File;
+import java.io.IOException;
/**
* @author <a href="michal@codehaus.org">Michal Maczka</a>
@@ -41,14 +44,18 @@
public static String getHostname()
{
- return System.getProperty( "test.host", "beaver.codehaus.org" );
+ return System.getProperty( "test.host", "localhost" );
}
public static String getHostKey()
{
- // beaver.codehaus.org
- return "AAAAB3NzaC1yc2EAAAABIwAAAIEAwCT2lARY2T3EYjhQW1G4fYDltZgKKdg35esqhqM" +
- "Z3lUV8QTg26aY1HfotUNJ0qaWsa587KP3zRUtHW4oP+hrOq/XQNsn57LKFFceCoy2vf" +
- "/t9/Qin24mCW2QsGdyZ/txEhADbGjPkt4/Z9e/KoZGahWoPTjR26G1i1St9IsZPcU=";
+ try
+ {
+ return FileUtils.fileRead( "/etc/ssh_host_rsa_key.pub" ).substring( "ssh-rsa".length() ).trim();
+ }
+ catch ( IOException e )
+ {
+ return null;
+ }
}
}
Modified: maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/knownhost/AbstractKnownHostsProviderTest.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/knownhost/AbstractKnownHostsProviderTest.java?view=diff&rev=477072&r1=477071&r2=477072
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/knownhost/AbstractKnownHostsProviderTest.java (original)
+++ maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/knownhost/AbstractKnownHostsProviderTest.java Sun Nov 19 22:35:38 2006
@@ -39,7 +39,7 @@
protected final String user = TestData.getUserName();
- protected final String host = TestData.getHostname();
+ protected String host;
/**
* tests what happens if the remote host has a different key than the one
@@ -80,6 +80,13 @@
final Session session = sch.getSession( user, host );
- session.connect();
+ try
+ {
+ session.connect();
+ }
+ catch ( JSchException e )
+ {
+ assertFalse( e.getMessage().indexOf( "UnknownHostKey") >= 0 );
+ }
}
}
Modified: maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/knownhost/SingleKnownHostsProviderTest.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/knownhost/SingleKnownHostsProviderTest.java?view=diff&rev=477072&r1=477071&r2=477072
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/knownhost/SingleKnownHostsProviderTest.java (original)
+++ maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/knownhost/SingleKnownHostsProviderTest.java Sun Nov 19 22:35:38 2006
@@ -37,6 +37,7 @@
{
super.setUp();
+ this.host = TestData.getHostname();
this.okHostsProvider = new SingleKnownHostProvider( host, correctKey );
this.failHostsProvider = new SingleKnownHostProvider( host, incorrectKey );
}
Modified: maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/knownhost/StreamKnownHostsProviderTest.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/knownhost/StreamKnownHostsProviderTest.java?view=diff&rev=477072&r1=477071&r2=477072
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/knownhost/StreamKnownHostsProviderTest.java (original)
+++ maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/knownhost/StreamKnownHostsProviderTest.java Sun Nov 19 22:35:38 2006
@@ -34,6 +34,7 @@
{
super.setUp();
+ host = "beaver.codehaus.org";
okHostsProvider = getProvider( "ok.knownhosts" );
failHostsProvider = getProvider( "fail.knownhosts" );
}
---------------------------------------------------------------------
To unsubscribe, e-mail: wagon-commits-unsubscribe@maven.apache.org
For additional commands, e-mail: wagon-commits-help@maven.apache.org