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 ca...@apache.org on 2006/08/12 04:02:22 UTC
svn commit: r430944 [2/2] - in /maven/wagon/trunk: ./
wagon-provider-api/src/main/java/org/apache/maven/wagon/
wagon-provider-api/src/test/java/org/apache/maven/wagon/
wagon-provider-test/src/main/java/org/apache/maven/wagon/ wagon-providers/
wagon-pro...
Modified: maven/wagon/trunk/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/HttpWagon.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/HttpWagon.java?rev=430944&r1=430943&r2=430944&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/HttpWagon.java (original)
+++ maven/wagon/trunk/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/HttpWagon.java Fri Aug 11 19:02:20 2006
@@ -1,7 +1,7 @@
package org.apache.maven.wagon.providers.http;
/*
- * Copyright 2001-2005 The Apache Software Foundation.
+ * Copyright 2001-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,16 @@
* limitations under the License.
*/
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+import java.util.Locale;
+import java.util.TimeZone;
+
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HostConfiguration;
@@ -26,6 +36,7 @@
import org.apache.commons.httpclient.NTCredentials;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.HeadMethod;
import org.apache.commons.httpclient.methods.PutMethod;
import org.apache.commons.httpclient.util.DateParseException;
import org.apache.commons.httpclient.util.DateParser;
@@ -35,18 +46,10 @@
import org.apache.maven.wagon.authorization.AuthorizationException;
import org.apache.maven.wagon.events.TransferEvent;
import org.apache.maven.wagon.resource.Resource;
+import org.apache.maven.wagon.shared.http.HtmlFileListParser;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.StringUtils;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.Locale;
-import java.util.TimeZone;
-
/**
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
* @version $Id$
@@ -199,7 +202,7 @@
"Failed to transfer file: " + url + " after " + attempt + " attempts" );
case HttpStatus.SC_FORBIDDEN:
- throw new AuthorizationException( "Access denided to: " + url );
+ throw new AuthorizationException( "Access denied to: " + url );
case HttpStatus.SC_NOT_FOUND:
throw new ResourceDoesNotExistException( "File: " + url + " does not exist" );
@@ -422,5 +425,159 @@
public void setNumberOfAttempts( int numberOfAttempts )
{
this.numberOfAttempts = numberOfAttempts;
+ }
+
+ public List getFileList( String destinationDirectory )
+ throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
+ {
+ if ( !destinationDirectory.endsWith( "/" ) )
+ {
+ destinationDirectory += "/";
+ }
+
+ String url = getRepository().getUrl() + "/" + destinationDirectory;
+
+ GetMethod getMethod = new GetMethod( url );
+
+ try
+ {
+ // TODO: make these configurable
+
+ getMethod.addRequestHeader( "Cache-control", "no-cache" );
+ getMethod.addRequestHeader( "Cache-store", "no-store" );
+ getMethod.addRequestHeader( "Pragma", "no-cache" );
+ getMethod.addRequestHeader( "Expires", "0" );
+
+ int statusCode = SC_NULL;
+
+ int attempt = 0;
+
+ // We will retry up to NumberOfAttempts times.
+ while ( statusCode == SC_NULL && attempt < getNumberOfAttempts() )
+ {
+ try
+ {
+ // execute the getMethod.
+ statusCode = client.executeMethod( getMethod );
+ }
+ catch ( HttpRecoverableException e )
+ {
+ attempt++;
+ }
+ catch ( IOException e )
+ {
+ throw new TransferFailedException( e.getMessage(), e );
+ }
+ }
+
+ fireTransferDebug( url + " - Status code: " + statusCode );
+
+ // TODO [BP]: according to httpclient docs, really should swallow the output on error. verify if that is required
+ switch ( statusCode )
+ {
+ case HttpStatus.SC_OK:
+ break;
+
+ case SC_NULL:
+ throw new TransferFailedException(
+ "Failed to transfer file: " + url + " after " + attempt + " attempts" );
+
+ case HttpStatus.SC_FORBIDDEN:
+ throw new AuthorizationException( "Access denied to: " + url );
+
+ case HttpStatus.SC_UNAUTHORIZED:
+ throw new AuthorizationException( "Not authorized." );
+
+ case HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED:
+ throw new AuthorizationException( "Not authorized by proxy." );
+
+ case HttpStatus.SC_NOT_FOUND:
+ throw new ResourceDoesNotExistException( "File: " + url + " does not exist" );
+
+ //add more entries here
+ default :
+ throw new TransferFailedException(
+ "Failed to trasfer file: " + url + ". Return code is: " + statusCode );
+ }
+
+ InputStream is = null;
+
+ is = getMethod.getResponseBodyAsStream();
+
+ return HtmlFileListParser.parseFileList( url, is );
+ }
+ catch ( IOException e )
+ {
+ throw new TransferFailedException( "Could not read response body.", e );
+ }
+ finally
+ {
+ getMethod.releaseConnection();
+ }
+ }
+
+ public boolean resourceExists( String resourceName )
+ throws TransferFailedException, AuthorizationException
+ {
+ String url = getRepository().getUrl() + "/" + resourceName;
+
+ HeadMethod headMethod = new HeadMethod( url );
+
+ int statusCode = SC_NULL;
+ int attempt = 0;
+
+ try
+ {
+ while ( statusCode == SC_NULL && attempt < getNumberOfAttempts() )
+ {
+ try
+ {
+ // execute the getMethod.
+ statusCode = client.executeMethod( headMethod );
+ }
+ catch ( HttpRecoverableException e )
+ {
+ attempt++;
+ }
+ catch ( IOException e )
+ {
+ throw new TransferFailedException( e.getMessage(), e );
+ }
+ }
+
+ switch ( statusCode )
+ {
+ case HttpStatus.SC_OK:
+ return true;
+
+ case HttpStatus.SC_NOT_MODIFIED:
+ return true;
+
+ case SC_NULL:
+ throw new TransferFailedException( "Failed to transfer file: " + url + " after " + attempt
+ + " attempts" );
+
+ case HttpStatus.SC_FORBIDDEN:
+ throw new AuthorizationException( "Access denided to: " + url );
+
+ case HttpStatus.SC_UNAUTHORIZED:
+ throw new AuthorizationException( "Not authorized." );
+
+ case HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED:
+ throw new AuthorizationException( "Not authorized by proxy." );
+
+ case HttpStatus.SC_NOT_FOUND:
+ return false;
+
+ //add more entries here
+ default:
+ throw new TransferFailedException( "Failed to trasfer file: " + url + ". Return code is: "
+ + statusCode );
+ }
+ }
+ finally
+ {
+ headMethod.releaseConnection();
+ }
}
}
Modified: maven/wagon/trunk/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpWagonTest.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpWagonTest.java?rev=430944&r1=430943&r2=430944&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpWagonTest.java (original)
+++ maven/wagon/trunk/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpWagonTest.java Fri Aug 11 19:02:20 2006
@@ -1,7 +1,7 @@
package org.apache.maven.wagon.providers.http;
/*
- * Copyright 2001-2005 The Apache Software Foundation.
+ * Copyright 2001-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -71,6 +71,15 @@
FileTestUtils.generateFile( f.getAbsolutePath(), "artifact-dummy" );
httpd = (Httpd) lookup( Httpd.ROLE );
+ }
+
+ public void testWagonGetFileList()
+ throws Exception
+ {
+ File f = new File( FileTestUtils.createDir( "http-repository" ), "file-list" );
+ f.mkdirs();
+
+ super.testWagonGetFileList();
}
protected void tearDownWagonTestingFixtures()
Modified: maven/wagon/trunk/wagon-providers/wagon-ssh-external/pom.xml
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-ssh-external/pom.xml?rev=430944&r1=430943&r2=430944&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ssh-external/pom.xml (original)
+++ maven/wagon/trunk/wagon-providers/wagon-ssh-external/pom.xml Fri Aug 11 19:02:20 2006
@@ -35,4 +35,4 @@
<artifactId>plexus-utils</artifactId>
</dependency>
</dependencies>
-</project>
\ No newline at end of file
+</project>
Modified: maven/wagon/trunk/wagon-providers/wagon-ssh-external/src/main/java/org/apache/maven/wagon/providers/sshext/ScpExternalWagon.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-ssh-external/src/main/java/org/apache/maven/wagon/providers/sshext/ScpExternalWagon.java?rev=430944&r1=430943&r2=430944&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ssh-external/src/main/java/org/apache/maven/wagon/providers/sshext/ScpExternalWagon.java (original)
+++ maven/wagon/trunk/wagon-providers/wagon-ssh-external/src/main/java/org/apache/maven/wagon/providers/sshext/ScpExternalWagon.java Fri Aug 11 19:02:20 2006
@@ -1,7 +1,7 @@
package org.apache.maven.wagon.providers.sshext;
/*
- * Copyright 2001-2005 The Apache Software Foundation.
+ * Copyright 2001-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,15 @@
* limitations under the License.
*/
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
import org.apache.maven.wagon.AbstractWagon;
import org.apache.maven.wagon.CommandExecutionException;
import org.apache.maven.wagon.CommandExecutor;
@@ -36,10 +45,6 @@
import org.codehaus.plexus.util.cli.CommandLineUtils;
import org.codehaus.plexus.util.cli.Commandline;
-import java.io.File;
-import java.io.IOException;
-import java.util.List;
-
/**
* SCP deployer using "external" scp program. To allow for
* ssh-agent type behavior, until we can construct a Java SSH Agent and interface for JSch.
@@ -87,6 +92,12 @@
private String password;
private static final int SSH_FATAL_EXIT_CODE = 255;
+
+ class Streams
+ {
+ String out;
+ String err;
+ }
// ----------------------------------------------------------------------
//
@@ -172,7 +183,7 @@
// nothing to disconnect
}
- public void executeCommand( String command, boolean ignoreFailures )
+ public Streams executeCommand( String command, boolean ignoreFailures )
throws CommandExecutionException
{
boolean putty = sshExecutable.indexOf( "plink" ) >= 0;
@@ -208,8 +219,11 @@
CommandLineUtils.StringStreamConsumer out = new CommandLineUtils.StringStreamConsumer();
CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
int exitCode = CommandLineUtils.executeCommandLine( cl, out, err );
- fireSessionDebug( out.getOutput() );
- fireSessionDebug( err.getOutput() );
+ Streams streams = new Streams();
+ streams.out = out.getOutput();
+ streams.err = err.getOutput();
+ fireSessionDebug( streams.out );
+ fireSessionDebug( streams.err );
if ( exitCode != 0 )
{
if ( !ignoreFailures || exitCode == SSH_FATAL_EXIT_CODE )
@@ -217,6 +231,7 @@
throw new CommandExecutionException( "Exit code " + exitCode + " - " + err.getOutput() );
}
}
+ return streams;
}
catch ( CommandLineException e )
{
@@ -540,5 +555,77 @@
public boolean supportsDirectoryCopy()
{
return true;
+ }
+
+ public List getFileList( String destinationDirectory )
+ throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
+ {
+ try
+ {
+ String path = getPath( getRepository().getBasedir(), destinationDirectory );
+ Streams streams = executeCommand( "ls -la " + path, true );
+
+ BufferedReader br = new BufferedReader(new StringReader(streams.out));
+
+ List ret = new ArrayList();
+ String line = br.readLine();
+
+ while(line != null)
+ {
+ String parts[] = StringUtils.split( line, " " );
+ if(parts.length >= 8)
+ {
+ ret.add(parts[8]);
+ }
+
+ line = br.readLine();
+ }
+
+ return ret;
+ }
+ catch ( CommandExecutionException e )
+ {
+ throw new TransferFailedException( "Error performing file listing.", e);
+ }
+ catch ( IOException e )
+ {
+ throw new TransferFailedException( "Error parsing file listing.", e);
+ }
+ }
+
+ public boolean resourceExists( String resourceName )
+ throws TransferFailedException, AuthorizationException
+ {
+ try
+ {
+ String path = getPath( getRepository().getBasedir(), resourceName );
+ Streams streams = executeCommand( "ls " + path, true );
+
+ BufferedReader br = new BufferedReader(new StringReader(streams.err));
+ Pattern pat = Pattern.compile( "No such file or directory" );
+
+ String line = br.readLine();
+
+ while(line != null)
+ {
+ Matcher mat = pat.matcher( line );
+ if(mat.find())
+ {
+ return false;
+ }
+
+ line = br.readLine();
+ }
+
+ return true;
+ }
+ catch ( CommandExecutionException e )
+ {
+ throw new TransferFailedException( "Error performing file listing.", e);
+ }
+ catch ( IOException 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/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?rev=430944&r1=430943&r2=430944&view=diff
==============================================================================
--- 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 Fri Aug 11 19:02:20 2006
@@ -16,15 +16,17 @@
* limitations under the License.
*/
-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;
+
import org.apache.maven.wagon.AbstractWagon;
import org.apache.maven.wagon.CommandExecutionException;
import org.apache.maven.wagon.CommandExecutor;
@@ -46,15 +48,15 @@
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.StringUtils;
-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.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;
/**
* Common SSH operations.
@@ -85,6 +87,12 @@
private UIKeyboardInteractive uIKeyboardInteractive;
+ class Streams
+ {
+ String out = "";
+ String err = "";
+ }
+
public void openConnection()
throws AuthenticationException
{
@@ -251,8 +259,8 @@
return privateKey;
}
-
- public void executeCommand( String command )
+
+ public Streams executeCommand( String command, boolean ignoreFailures )
throws CommandExecutionException
{
ChannelExec channel = null;
@@ -280,6 +288,8 @@
List output = null;
+ Streams streams = new Streams();
+
while ( true )
{
String line = r.readLine();
@@ -298,9 +308,22 @@
if ( !line.startsWith( "Could not chdir to home directory" ) && !line.endsWith( "ttyname: Operation not supported" ) )
{
output.add( line );
+ streams.err += line + "\n";
}
}
+ 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...
@@ -311,12 +334,14 @@
// {
// 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 )
{
@@ -338,6 +363,12 @@
}
}
+ public void executeCommand( String command )
+ throws CommandExecutionException
+ {
+ executeCommand( command, false );
+ }
+
protected String readLine( InputStream in )
throws IOException
{
@@ -573,5 +604,61 @@
public boolean supportsDirectoryCopy()
{
return true;
+ }
+
+ public List getFileList( String destinationDirectory )
+ throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
+ {
+ try
+ {
+ String path = getPath( getRepository().getBasedir(), destinationDirectory );
+ Streams streams = executeCommand( "ls -la " + path, true );
+
+ BufferedReader br = new BufferedReader(new StringReader(streams.out));
+
+ List ret = new ArrayList();
+ String line = br.readLine();
+
+ while(line != null)
+ {
+ String parts[] = StringUtils.split( line, " " );
+ if(parts.length >= 8)
+ {
+ ret.add(parts[8]);
+ }
+
+ line = br.readLine();
+ }
+
+ return ret;
+ }
+ catch ( CommandExecutionException e )
+ {
+ throw new TransferFailedException( "Error performing file listing.", e);
+ }
+ catch ( IOException e )
+ {
+ throw new TransferFailedException( "Error parsing file listing.", e);
+ }
+ }
+
+ public boolean resourceExists( String resourceName )
+ throws TransferFailedException, AuthorizationException
+ {
+ try
+ {
+ String path = getPath( getRepository().getBasedir(), resourceName );
+ executeCommand( "ls " + path );
+
+ // Parsing of output not really needed. As a failed ls results in a
+ // CommandExectionException on the 'ls' command.
+
+ return true;
+ }
+ catch ( CommandExecutionException e )
+ {
+ // Error? Then the 'ls' command failed. No such file found.
+ return false;
+ }
}
}
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?rev=430944&r1=430943&r2=430944&view=diff
==============================================================================
--- 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 Fri Aug 11 19:02:20 2006
@@ -1,7 +1,7 @@
package org.apache.maven.wagon.providers.ssh;
/*
- * Copyright 2001-2005 The Apache Software Foundation.
+ * Copyright 2001-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,8 +16,12 @@
* limitations under the License.
*/
-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;
+
import org.apache.maven.wagon.CommandExecutionException;
import org.apache.maven.wagon.PathUtils;
import org.apache.maven.wagon.PermissionModeUtils;
@@ -29,15 +33,12 @@
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.StringUtils;
-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;
/**
* A base class for deployers and fetchers using protocols from SSH2 family and
- * JSch library for underlining implmenetation
+ * JSch library for underlying implementation
* <p/>
* This is responsible for authentification stage of the process.
* <p/>
@@ -357,7 +358,8 @@
public boolean getIfNewer( String resourceName, File destination, long timestamp )
throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
{
- throw new UnsupportedOperationException( "getIfNewer is scp wagon must be still implemented" );
+ // TODO Implement ScpWagon.getIfNewer()
+ throw new UnsupportedOperationException( "getIfNewer in scp wagon is not implemented" );
}
}
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?rev=430944&r1=430943&r2=430944&view=diff
==============================================================================
--- 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 Fri Aug 11 19:02:20 2006
@@ -1,7 +1,7 @@
package org.apache.maven.wagon.providers.ssh;
/*
- * Copyright 2001-2005 The Apache Software Foundation.
+ * Copyright 2001-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,10 +16,8 @@
* limitations under the License.
*/
-import com.jcraft.jsch.ChannelSftp;
-import com.jcraft.jsch.JSchException;
-import com.jcraft.jsch.SftpATTRS;
-import com.jcraft.jsch.SftpException;
+import java.io.File;
+
import org.apache.maven.wagon.PathUtils;
import org.apache.maven.wagon.ResourceDoesNotExistException;
import org.apache.maven.wagon.TransferFailedException;
@@ -29,7 +27,10 @@
import org.apache.maven.wagon.resource.Resource;
import org.codehaus.plexus.util.StringUtils;
-import java.io.File;
+import com.jcraft.jsch.ChannelSftp;
+import com.jcraft.jsch.JSchException;
+import com.jcraft.jsch.SftpATTRS;
+import com.jcraft.jsch.SftpException;
/**
* SFTP protocol wagon.
Modified: maven/wagon/trunk/wagon-providers/wagon-webdav/src/main/java/org/apache/maven/wagon/providers/webdav/WebDavWagon.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-webdav/src/main/java/org/apache/maven/wagon/providers/webdav/WebDavWagon.java?rev=430944&r1=430943&r2=430944&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-webdav/src/main/java/org/apache/maven/wagon/providers/webdav/WebDavWagon.java (original)
+++ maven/wagon/trunk/wagon-providers/wagon-webdav/src/main/java/org/apache/maven/wagon/providers/webdav/WebDavWagon.java Fri Aug 11 19:02:20 2006
@@ -24,7 +24,10 @@
import java.net.URL;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Date;
+import java.util.List;
import java.util.Locale;
import java.util.Properties;
import java.util.TimeZone;
@@ -45,6 +48,8 @@
import org.apache.maven.wagon.events.TransferEvent;
import org.apache.maven.wagon.repository.Repository;
import org.apache.maven.wagon.resource.Resource;
+import org.apache.webdav.lib.WebdavResource;
+import org.apache.webdav.lib.methods.DepthSupport;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.StringUtils;
@@ -532,5 +537,101 @@
}
}
+ }
+
+ public List getFileList( String destinationDirectory )
+ throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
+ {
+ webdavResource.addRequestHeader( "X-wagon-provider", "wagon-webdav" );
+ webdavResource.addRequestHeader( "X-wagon-version", wagonVersion );
+
+ webdavResource.addRequestHeader( "Cache-control", "no-cache" );
+ webdavResource.addRequestHeader( "Cache-store", "no-store" );
+ webdavResource.addRequestHeader( "Pragma", "no-cache" );
+ webdavResource.addRequestHeader( "Expires", "0" );
+
+ String basedir = repository.getBasedir();
+
+ if ( !destinationDirectory.endsWith( "/" ) )
+ {
+ destinationDirectory += "/";
+ }
+
+ String cleanDestDir = StringUtils.replace( destinationDirectory, "\\", "/" );
+ String dir = PathUtils.dirname( cleanDestDir );
+ dir = StringUtils.replace( dir, "\\", "/" );
+
+ String oldpath = webdavResource.getPath();
+ String relpath = getPath( basedir, dir );
+
+ try
+ {
+ // Test if dest resource path exist.
+ String cdpath = checkUri( relpath + "/" );
+ webdavResource.setPath( cdpath );
+
+ try
+ {
+ webdavResource.setProperties( WebdavResource.NAME, DepthSupport.DEPTH_0 );
+
+ /* seems this is not needed as Webdav client causes a 404 error in webdavResource.setProperties */
+ if ( !webdavResource.exists() )
+ {
+ throw new ResourceDoesNotExistException( "Destination directory does not exist: " + cdpath );
+ }
+
+ if ( !webdavResource.isCollection() )
+ {
+ throw new ResourceDoesNotExistException( "Destination path exists but is not a "
+ + "WebDAV collection (directory): " + cdpath );
+ }
+
+ String[] entries = webdavResource.list();
+
+ List filelist = new ArrayList();
+ if ( entries != null )
+ {
+ filelist.addAll( Arrays.asList( entries ) );
+ }
+
+ return filelist;
+ }
+ catch ( HttpException e )
+ {
+ if ( e.getReasonCode() == HttpStatus.SC_NOT_FOUND )
+ {
+ throw new ResourceDoesNotExistException( "Destination directory does not exist: " + cdpath, e );
+ }
+ else
+ {
+ throw new TransferFailedException( "Unable to obtain file list from WebDAV collection, "
+ + "HTTP error: " + HttpStatus.getStatusText( e.getReasonCode() ), e );
+ }
+ }
+ finally
+ {
+ webdavResource.setPath( oldpath );
+ }
+
+ }
+ catch ( IOException e )
+ {
+ throw new TransferFailedException( "Unable to obtain file list from WebDAV collection.", e );
+ }
+ }
+
+ public boolean resourceExists( String resourceName )
+ throws TransferFailedException, AuthorizationException
+ {
+ try
+ {
+ String parentDirectory = PathUtils.dirname( resourceName );
+ List entries = getFileList( parentDirectory );
+ return entries.contains( resourceName );
+ }
+ catch ( ResourceDoesNotExistException e )
+ {
+ return false;
+ }
}
}
Modified: maven/wagon/trunk/wagon-providers/wagon-webdav/src/test/java/org/apache/maven/wagon/providers/webdav/PutInputStreamTest.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-webdav/src/test/java/org/apache/maven/wagon/providers/webdav/PutInputStreamTest.java?rev=430944&r1=430943&r2=430944&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-webdav/src/test/java/org/apache/maven/wagon/providers/webdav/PutInputStreamTest.java (original)
+++ maven/wagon/trunk/wagon-providers/wagon-webdav/src/test/java/org/apache/maven/wagon/providers/webdav/PutInputStreamTest.java Fri Aug 11 19:02:20 2006
@@ -23,6 +23,8 @@
import java.io.InputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
+import java.util.Collections;
+import java.util.List;
import junit.framework.TestCase;
@@ -138,6 +140,18 @@
throws ConnectionException, AuthenticationException
{
+ }
+
+ public List getFileList( String destinationDirectory )
+ throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
+ {
+ return Collections.EMPTY_LIST;
+ }
+
+ public boolean resourceExists( String resourceName )
+ throws TransferFailedException, AuthorizationException
+ {
+ return false;
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: wagon-commits-unsubscribe@maven.apache.org
For additional commands, e-mail: wagon-commits-help@maven.apache.org