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 2008/05/19 05:19:07 UTC
svn commit: r657714 - in /maven/wagon/branches/WAGON-109/wagon-providers:
wagon-http-shared/
wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/
wagon-http-shared/src/test/java/org/apache/maven/wagon/shared/http/
wagon-http/ wagon-http/...
Author: brett
Date: Sun May 18 20:19:07 2008
New Revision: 657714
URL: http://svn.apache.org/viewvc?rev=657714&view=rev
Log:
[WAGON-109] Refactor Wagon HTTP and Wagon WebDav to use a common base and move to jackrabbit
Submitted by: James William Dumay
Added:
maven/wagon/branches/WAGON-109/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java (with props)
maven/wagon/branches/WAGON-109/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/PutInputStream.java
- copied, changed from r646656, maven/wagon/trunk/wagon-providers/wagon-webdav/src/main/java/org/apache/maven/wagon/providers/webdav/PutInputStream.java
maven/wagon/branches/WAGON-109/wagon-providers/wagon-http-shared/src/test/java/org/apache/maven/wagon/shared/http/PutInputStreamTest.java
- copied, changed from r646656, maven/wagon/trunk/wagon-providers/wagon-webdav/src/test/java/org/apache/maven/wagon/providers/webdav/PutInputStreamTest.java
maven/wagon/branches/WAGON-109/wagon-providers/wagon-webdav/src/main/java/org/apache/maven/wagon/providers/webdav/PathNavigator.java (with props)
maven/wagon/branches/WAGON-109/wagon-providers/wagon-webdav/src/main/resources/META-INF/
maven/wagon/branches/WAGON-109/wagon-providers/wagon-webdav/src/main/resources/META-INF/plexus/
maven/wagon/branches/WAGON-109/wagon-providers/wagon-webdav/src/main/resources/META-INF/plexus/components.xml (with props)
maven/wagon/branches/WAGON-109/wagon-providers/wagon-webdav/src/test/java/org/apache/maven/wagon/providers/webdav/PathNavigatorTest.java (with props)
Removed:
maven/wagon/branches/WAGON-109/wagon-providers/wagon-webdav/src/main/java/org/apache/maven/wagon/providers/webdav/CorrectedWebdavResource.java
maven/wagon/branches/WAGON-109/wagon-providers/wagon-webdav/src/main/java/org/apache/maven/wagon/providers/webdav/PutInputStream.java
maven/wagon/branches/WAGON-109/wagon-providers/wagon-webdav/src/test/java/org/apache/maven/wagon/providers/webdav/PutInputStreamTest.java
Modified:
maven/wagon/branches/WAGON-109/wagon-providers/wagon-http-shared/pom.xml
maven/wagon/branches/WAGON-109/wagon-providers/wagon-http/pom.xml
maven/wagon/branches/WAGON-109/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/HttpWagon.java
maven/wagon/branches/WAGON-109/wagon-providers/wagon-webdav/pom.xml
maven/wagon/branches/WAGON-109/wagon-providers/wagon-webdav/src/main/java/org/apache/maven/wagon/providers/webdav/WebDavWagon.java
maven/wagon/branches/WAGON-109/wagon-providers/wagon-webdav/src/test/java/org/apache/maven/wagon/providers/webdav/WebDavWagonGzipTest.java
maven/wagon/branches/WAGON-109/wagon-providers/wagon-webdav/src/test/java/org/apache/maven/wagon/providers/webdav/WebDavWagonTest.java
Modified: maven/wagon/branches/WAGON-109/wagon-providers/wagon-http-shared/pom.xml
URL: http://svn.apache.org/viewvc/maven/wagon/branches/WAGON-109/wagon-providers/wagon-http-shared/pom.xml?rev=657714&r1=657713&r2=657714&view=diff
==============================================================================
--- maven/wagon/branches/WAGON-109/wagon-providers/wagon-http-shared/pom.xml (original)
+++ maven/wagon/branches/WAGON-109/wagon-providers/wagon-http-shared/pom.xml Sun May 18 20:19:07 2008
@@ -17,7 +17,7 @@
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
- -->
+-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -31,19 +31,20 @@
<artifactId>wagon-http-shared</artifactId>
<name>Maven Wagon HTTP Shared Library</name>
<description>
- Shared Library for the wagon-http, and wagon-http-lightweight wagon providers.
+ Shared Library for the wagon-http, and wagon-http-lightweight wagon
+ providers.
</description>
- <issueManagement>
- <system>jira</system>
- <url>http://jira.codehaus.org/browse/WAGONHTTP</url>
- </issueManagement>
-
<dependencies>
<dependency>
<groupId>jtidy</groupId>
<artifactId>jtidy</artifactId>
<version>4aug2000r7-dev</version>
</dependency>
+ <dependency>
+ <groupId>commons-httpclient</groupId>
+ <artifactId>commons-httpclient</artifactId>
+ <version>3.1</version>
+ </dependency>
</dependencies>
</project>
Added: maven/wagon/branches/WAGON-109/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java
URL: http://svn.apache.org/viewvc/maven/wagon/branches/WAGON-109/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java?rev=657714&view=auto
==============================================================================
--- maven/wagon/branches/WAGON-109/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java (added)
+++ maven/wagon/branches/WAGON-109/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java Sun May 18 20:19:07 2008
@@ -0,0 +1,459 @@
+package org.apache.maven.wagon.shared.http;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.wagon.AbstractWagon;
+import org.apache.maven.wagon.TransferFailedException;
+import org.apache.maven.wagon.ResourceDoesNotExistException;
+import org.apache.maven.wagon.repository.Repository;
+import org.apache.maven.wagon.events.TransferEvent;
+import org.apache.maven.wagon.resource.Resource;
+import org.apache.maven.wagon.authorization.AuthorizationException;
+import org.apache.commons.httpclient.*;
+import org.apache.commons.httpclient.util.DateParser;
+import org.apache.commons.httpclient.util.DateParseException;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.HeadMethod;
+import org.apache.commons.httpclient.methods.PutMethod;
+import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.IOUtil;
+
+import java.util.TimeZone;
+import java.util.Locale;
+import java.util.Date;
+import java.util.zip.GZIPInputStream;
+import java.io.File;
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.FileNotFoundException;
+import java.text.SimpleDateFormat;
+
+/**
+ * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
+ * @author <a href="mailto:james@atlassian.com">James William Dumay</a>
+ */
+public abstract class AbstractHttpClientWagon extends AbstractWagon
+{
+ protected static final int SC_NULL = -1;
+
+ protected static final TimeZone GMT_TIME_ZONE = TimeZone.getTimeZone( "GMT" );
+
+ private HttpClient client;
+
+ protected HttpConnectionManager connectionManager;
+
+ public void openConnectionInternal()
+ {
+ repository.setUrl( getURL( repository ) );
+ client = new HttpClient( connectionManager );
+ String username = null;
+ String password = null;
+
+ if ( authenticationInfo != null )
+ {
+ username = authenticationInfo.getUserName();
+
+ password = authenticationInfo.getPassword();
+ }
+
+ String host = getRepository().getHost();
+
+ if ( StringUtils.isNotEmpty( username ) && StringUtils.isNotEmpty( password ) )
+ {
+ Credentials creds = new UsernamePasswordCredentials( username, password );
+
+ client.getState().setCredentials( null, host, creds );
+ client.getState().setAuthenticationPreemptive( true );
+ }
+
+ HostConfiguration hc = new HostConfiguration();
+
+ if ( proxyInfo != null )
+ {
+ String proxyUsername = proxyInfo.getUserName();
+ String proxyPassword = proxyInfo.getPassword();
+ String proxyHost = proxyInfo.getHost();
+ int proxyPort = proxyInfo.getPort();
+ String proxyNtlmHost = proxyInfo.getNtlmHost();
+ String proxyNtlmDomain = proxyInfo.getNtlmDomain();
+ if ( proxyHost != null )
+ {
+ hc.setProxy( proxyHost, proxyPort );
+
+ if ( proxyUsername != null && proxyPassword != null )
+ {
+ Credentials creds;
+ if ( proxyNtlmHost != null || proxyNtlmDomain != null )
+ {
+ creds = new NTCredentials( proxyUsername, proxyPassword, proxyNtlmHost, proxyNtlmDomain );
+ }
+ else
+ {
+ creds = new UsernamePasswordCredentials( proxyUsername, proxyPassword );
+ }
+
+ client.getState().setProxyCredentials( null, proxyHost, creds );
+ client.getState().setAuthenticationPreemptive( true );
+ }
+ }
+ }
+
+ hc.setHost( host );
+
+ //start a session with the webserver
+ client.setHostConfiguration( hc );
+ }
+
+ public void closeConnection()
+ {
+ }
+
+ public void get( String resourceName, File destination )
+ throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
+ {
+ get( resourceName, destination, 0 );
+ }
+
+ public boolean getIfNewer( String resourceName, File destination, long timestamp )
+ throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
+ {
+ return get( resourceName, destination, timestamp );
+ }
+
+ /**
+ * @param resourceName
+ * @param destination
+ * @param timestamp the timestamp to check against, only downloading if newer. If <code>0</code>, always download
+ * @return <code>true</code> if newer version was downloaded, <code>false</code> otherwise.
+ * @throws TransferFailedException
+ * @throws ResourceDoesNotExistException
+ * @throws AuthorizationException
+ */
+ public boolean get( String resourceName, File destination, long timestamp )
+ throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
+ {
+ Resource resource = new Resource( resourceName );
+ fireGetInitiated( resource, destination );
+ boolean retValue = false;
+ String url = getRepository().getUrl() + "/" + resourceName;
+ GetMethod getMethod = new GetMethod( url );;
+
+ try
+ {
+ if ( timestamp > 0 )
+ {
+ SimpleDateFormat fmt = new SimpleDateFormat( "EEE, dd-MMM-yy HH:mm:ss zzz", Locale.US );
+ fmt.setTimeZone( GMT_TIME_ZONE );
+ Header hdr = new Header( "If-Modified-Since", fmt.format( new Date( timestamp ) ) );
+ fireTransferDebug( "sending ==> " + hdr + "(" + timestamp + ")" );
+ getMethod.addRequestHeader( hdr );
+ }
+
+ int statusCode = execute( getMethod );
+
+ 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 HttpStatus.SC_NOT_MODIFIED:
+ return false;
+
+ case SC_NULL:
+ throw new TransferFailedException( "Failed to transfer file: " + url );
+
+ 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 transfer file: " + url + ". Return code is: " + statusCode );
+ }
+
+ InputStream is = null;
+
+ Header contentLengthHeader = getMethod.getResponseHeader( "Content-Length" );
+
+ if ( contentLengthHeader != null )
+ {
+ try
+ {
+ long contentLength = Integer.valueOf( contentLengthHeader.getValue() ).intValue();
+
+ resource.setContentLength( contentLength );
+ }
+ catch ( NumberFormatException e )
+ {
+ fireTransferDebug(
+ "error parsing content length header '" + contentLengthHeader.getValue() + "' " + e );
+ }
+ }
+
+ Header lastModifiedHeader = getMethod.getResponseHeader( "Last-Modified" );
+
+ long lastModified = 0;
+
+ if ( lastModifiedHeader != null )
+ {
+ try
+ {
+ lastModified = DateParser.parseDate( lastModifiedHeader.getValue() ).getTime();
+ }
+ catch ( DateParseException e )
+ {
+ fireTransferDebug( "Unable to parse last modified header" );
+ }
+
+ fireTransferDebug( "last-modified = " + lastModifiedHeader.getValue() + " (" + lastModified + ")" );
+ }
+
+ // always get if timestamp is 0 (ie, target doesn't exist), otherwise only if older than the remote file
+ if ( timestamp == 0 || timestamp < lastModified )
+ {
+ retValue = true;
+
+ Header contentEncoding = getMethod.getResponseHeader( "Content-Encoding" );
+ boolean isGZipped = contentEncoding == null ? false : "gzip".equalsIgnoreCase(contentEncoding.getValue());
+
+ try
+ {
+ is = getMethod.getResponseBodyAsStream();
+ if (isGZipped)
+ {
+ is = new GZIPInputStream( is );
+ }
+
+ getTransfer( resource, destination, is );
+ }
+ catch ( IOException e )
+ {
+ fireTransferError( resource, e, TransferEvent.REQUEST_GET );
+
+ if ( destination.exists() )
+ {
+ boolean deleted = destination.delete();
+
+ if ( !deleted )
+ {
+ destination.deleteOnExit();
+ }
+ }
+
+ String msg = "Error occurred while deploying to remote repository:" + getRepository();
+
+ throw new TransferFailedException( msg, e );
+ }
+ finally
+ {
+ IOUtil.close( is );
+ }
+
+ if ( lastModified > 0 )
+ {
+ resource.setLastModified( lastModified );
+ }
+ }
+ else
+ {
+ fireTransferDebug( "Local file is newer: not downloaded" );
+ }
+
+ return retValue;
+ }
+ finally
+ {
+ getMethod.releaseConnection();
+ }
+ }
+
+ public void put( File source, String resourceName )
+ throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
+ {
+ put(source, resourceName, true);
+ }
+
+ protected void put( File source, String resourceName, boolean firePutInitiated )
+ throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
+ {
+ String url = getRepository().getUrl() + "/" + resourceName;
+ Resource resource = new Resource( resourceName );
+
+ if (firePutInitiated)
+ {
+ firePutInitiated( resource, source );
+ }
+
+ PutMethod putMethod = new PutMethod( url );
+ InputStream is = null;
+ try
+ {
+ is = new PutInputStream( source, resource, this, getTransferEventSupport() );
+ putMethod.setRequestBody( is );
+ }
+ catch ( FileNotFoundException e )
+ {
+ fireTransferError( resource, e, TransferEvent.REQUEST_PUT );
+
+ throw new ResourceDoesNotExistException( "Source file does not exist: " + source, e );
+ }
+
+ try
+ {
+ int statusCode = execute( putMethod );
+
+ fireTransferDebug( url + " - Status code: " + statusCode );
+
+ // Check that we didn't run out of retries.
+ switch ( statusCode )
+ {
+ // Success Codes
+ case HttpStatus.SC_OK: // 200
+ case HttpStatus.SC_CREATED: // 201
+ case HttpStatus.SC_ACCEPTED: // 202
+ case HttpStatus.SC_NO_CONTENT: // 204
+ break;
+
+ case SC_NULL:
+ throw new TransferFailedException( "Failed to transfer file: " + url );
+
+ case HttpStatus.SC_FORBIDDEN:
+ throw new AuthorizationException( "Access denied to: " + url );
+
+ case HttpStatus.SC_NOT_FOUND:
+ throw new ResourceDoesNotExistException( "File: " + url + " does not exist" );
+
+ //add more entries here
+ default :
+ throw new TransferFailedException(
+ "Failed to transfer file: " + url + ". Return code is: " + statusCode );
+ }
+
+ putMethod.releaseConnection();
+
+ firePutCompleted( resource, source );
+ }
+ finally
+ {
+ IOUtil.close(is);
+ }
+ }
+
+ public boolean resourceExists( String resourceName )
+ throws TransferFailedException, AuthorizationException
+ {
+ String url = getRepository().getUrl() + "/" + resourceName;
+ HeadMethod headMethod = new HeadMethod( url );
+ int statusCode = execute( headMethod );
+ try
+ {
+ 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);
+
+ 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:
+ return false;
+
+ //add more entries here
+ default:
+ throw new TransferFailedException( "Failed to transfer file: " + url + ". Return code is: "
+ + statusCode );
+ }
+ }
+ finally
+ {
+ headMethod.releaseConnection();
+ }
+ }
+
+ protected int execute(HttpMethod httpMethod)
+ throws TransferFailedException
+ {
+ int statusCode = SC_NULL;
+ httpMethod.getParams().setSoTimeout( getTimeout() );
+ setHeaders(httpMethod);
+ try
+ {
+ // execute the method.
+ statusCode = client.executeMethod( httpMethod );
+ }
+ catch ( IOException e )
+ {
+ throw new TransferFailedException( e.getMessage(), e );
+ }
+ return statusCode;
+ }
+
+ protected void setHeaders(HttpMethod method)
+ {
+ method.addRequestHeader( "Cache-control", "no-cache" );
+ method.addRequestHeader( "Cache-store", "no-store" );
+ method.addRequestHeader( "Pragma", "no-cache" );
+ method.addRequestHeader( "Expires", "0" );
+ method.addRequestHeader( "Accept-Encoding", "gzip" );
+ }
+
+ /**
+ * getUrl
+ * Implementors can override this to remove unwanted parts of the url such as role-hints
+ * @param repository
+ * @return
+ */
+ protected String getURL( Repository repository )
+ {
+ return repository.getUrl();
+ }
+
+ protected HttpClient getClient() {
+ return client;
+ }
+
+ public void setConnectionManager(HttpConnectionManager connectionManager) {
+ this.connectionManager = connectionManager;
+ }
+}
Propchange: maven/wagon/branches/WAGON-109/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java
------------------------------------------------------------------------------
svn:eol-style = native
Copied: maven/wagon/branches/WAGON-109/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/PutInputStream.java (from r646656, maven/wagon/trunk/wagon-providers/wagon-webdav/src/main/java/org/apache/maven/wagon/providers/webdav/PutInputStream.java)
URL: http://svn.apache.org/viewvc/maven/wagon/branches/WAGON-109/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/PutInputStream.java?p2=maven/wagon/branches/WAGON-109/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/PutInputStream.java&p1=maven/wagon/trunk/wagon-providers/wagon-webdav/src/main/java/org/apache/maven/wagon/providers/webdav/PutInputStream.java&r1=646656&r2=657714&rev=657714&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-webdav/src/main/java/org/apache/maven/wagon/providers/webdav/PutInputStream.java (original)
+++ maven/wagon/branches/WAGON-109/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/PutInputStream.java Sun May 18 20:19:07 2008
@@ -1,4 +1,4 @@
-package org.apache.maven.wagon.providers.webdav;
+package org.apache.maven.wagon.shared.http;
/*
* Licensed to the Apache Software Foundation (ASF) under one
Copied: maven/wagon/branches/WAGON-109/wagon-providers/wagon-http-shared/src/test/java/org/apache/maven/wagon/shared/http/PutInputStreamTest.java (from r646656, 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/branches/WAGON-109/wagon-providers/wagon-http-shared/src/test/java/org/apache/maven/wagon/shared/http/PutInputStreamTest.java?p2=maven/wagon/branches/WAGON-109/wagon-providers/wagon-http-shared/src/test/java/org/apache/maven/wagon/shared/http/PutInputStreamTest.java&p1=maven/wagon/trunk/wagon-providers/wagon-webdav/src/test/java/org/apache/maven/wagon/providers/webdav/PutInputStreamTest.java&r1=646656&r2=657714&rev=657714&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-webdav/src/test/java/org/apache/maven/wagon/providers/webdav/PutInputStreamTest.java (original)
+++ maven/wagon/branches/WAGON-109/wagon-providers/wagon-http-shared/src/test/java/org/apache/maven/wagon/shared/http/PutInputStreamTest.java Sun May 18 20:19:07 2008
@@ -1,4 +1,4 @@
-package org.apache.maven.wagon.providers.webdav;
+package org.apache.maven.wagon.shared.http;
/*
* Licensed to the Apache Software Foundation (ASF) under one
@@ -139,7 +139,7 @@
}
- public void openConnection()
+ public void openConnectionInternal()
throws ConnectionException, AuthenticationException
{
Modified: maven/wagon/branches/WAGON-109/wagon-providers/wagon-http/pom.xml
URL: http://svn.apache.org/viewvc/maven/wagon/branches/WAGON-109/wagon-providers/wagon-http/pom.xml?rev=657714&r1=657713&r2=657714&view=diff
==============================================================================
--- maven/wagon/branches/WAGON-109/wagon-providers/wagon-http/pom.xml (original)
+++ maven/wagon/branches/WAGON-109/wagon-providers/wagon-http/pom.xml Sun May 18 20:19:07 2008
@@ -34,11 +34,6 @@
Wagon that gets and puts artifacts through http using Apache commons-httpclient
</description>
- <issueManagement>
- <system>jira</system>
- <url>http://jira.codehaus.org/browse/WAGONHTTP</url>
- </issueManagement>
-
<dependencies>
<dependency>
<groupId>${pom.groupId}</groupId>
@@ -58,17 +53,19 @@
</exclusions>
</dependency>
<dependency>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- <version>1.0.4</version>
- <scope>runtime</scope>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.3</version>
+ <scope>test</scope>
</dependency>
<dependency>
- <groupId>commons-httpclient</groupId>
- <artifactId>commons-httpclient</artifactId>
- <version>3.1</version>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty</artifactId>
+ <version>4.2.12</version>
+ <scope>test</scope>
</dependency>
</dependencies>
+ <!-- I believe we can shade this in Maven itself
<build>
<plugins>
<plugin>
@@ -111,4 +108,5 @@
</plugin>
</plugins>
</build>
+ -->
</project>
Modified: maven/wagon/branches/WAGON-109/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/HttpWagon.java
URL: http://svn.apache.org/viewvc/maven/wagon/branches/WAGON-109/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/HttpWagon.java?rev=657714&r1=657713&r2=657714&view=diff
==============================================================================
--- maven/wagon/branches/WAGON-109/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/HttpWagon.java (original)
+++ maven/wagon/branches/WAGON-109/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/HttpWagon.java Sun May 18 20:19:07 2008
@@ -19,372 +19,25 @@
* 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 java.util.zip.GZIPInputStream;
-
-import org.apache.commons.httpclient.Credentials;
-import org.apache.commons.httpclient.Header;
-import org.apache.commons.httpclient.HostConfiguration;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.HttpConnectionManager;
-import org.apache.commons.httpclient.HttpMethod;
+
import org.apache.commons.httpclient.HttpStatus;
-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;
-import org.apache.maven.wagon.AbstractWagon;
import org.apache.maven.wagon.ResourceDoesNotExistException;
import org.apache.maven.wagon.TransferFailedException;
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.AbstractHttpClientWagon;
import org.apache.maven.wagon.shared.http.HtmlFileListParser;
-import org.codehaus.plexus.util.IOUtil;
-import org.codehaus.plexus.util.StringUtils;
/**
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
* @version $Id$
*/
public class HttpWagon
- extends AbstractWagon
-{
- private static final int SC_NULL = -1;
-
- private HttpClient client;
-
- private static final TimeZone GMT_TIME_ZONE = TimeZone.getTimeZone( "GMT" );
-
- private HttpConnectionManager connectionManager;
-
- protected void openConnectionInternal()
- {
- client = new HttpClient( connectionManager );
-
- String username = null;
-
- String password = null;
-
- if ( authenticationInfo != null )
- {
- username = authenticationInfo.getUserName();
-
- password = authenticationInfo.getPassword();
- }
-
- String host = getRepository().getHost();
-
- if ( StringUtils.isNotEmpty( username ) && StringUtils.isNotEmpty( password ) )
- {
- Credentials creds = new UsernamePasswordCredentials( username, password );
-
- client.getState().setCredentials( null, host, creds );
- client.getState().setAuthenticationPreemptive( true );
- }
-
- HostConfiguration hc = new HostConfiguration();
-
- if ( proxyInfo != null )
- {
- String proxyUsername = proxyInfo.getUserName();
-
- String proxyPassword = proxyInfo.getPassword();
-
- String proxyHost = proxyInfo.getHost();
-
- int proxyPort = proxyInfo.getPort();
-
- String proxyNtlmHost = proxyInfo.getNtlmHost();
-
- String proxyNtlmDomain = proxyInfo.getNtlmDomain();
-
- if ( proxyHost != null )
- {
- hc.setProxy( proxyHost, proxyPort );
-
- if ( proxyUsername != null && proxyPassword != null )
- {
- Credentials creds;
- if ( proxyNtlmHost != null || proxyNtlmDomain != null )
- {
- creds = new NTCredentials( proxyUsername, proxyPassword, proxyNtlmHost, proxyNtlmDomain );
- }
- else
- {
- creds = new UsernamePasswordCredentials( proxyUsername, proxyPassword );
- }
-
- client.getState().setProxyCredentials( null, proxyHost, creds );
- client.getState().setAuthenticationPreemptive( true );
- }
- }
- }
-
- hc.setHost( host );
-
- //start a session with the webserver
- client.setHostConfiguration( hc );
- }
-
- // put
- public void put( File source, String resourceName )
- throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
- {
- String url = getRepository().getUrl() + "/" + resourceName;
-
- Resource resource = new Resource( resourceName );
-
- firePutInitiated( resource, source );
-
- PutMethod putMethod = new PutMethod( url );
- putMethod.getParams().setSoTimeout( getTimeout() );
-
- try
- {
- InputStream is = new PutInputStream( source, resource, this, getTransferEventSupport() );
- putMethod.setRequestBody( is );
- }
- catch ( FileNotFoundException e )
- {
- fireTransferError( resource, e, TransferEvent.REQUEST_PUT );
-
- throw new ResourceDoesNotExistException( "Source file does not exist: " + source, e );
- }
-
- int statusCode = execute( putMethod );
-
- fireTransferDebug( url + " - Status code: " + statusCode );
-
- // Check that we didn't run out of retries.
- switch ( statusCode )
- {
- // Success Codes
- case HttpStatus.SC_OK: // 200
- case HttpStatus.SC_CREATED: // 201
- case HttpStatus.SC_ACCEPTED: // 202
- case HttpStatus.SC_NO_CONTENT: // 204
- break;
-
- case SC_NULL:
- throw new TransferFailedException( "Failed to transfer file: " + url );
-
- case HttpStatus.SC_FORBIDDEN:
- throw new AuthorizationException( "Access denied to: " + url );
-
- case HttpStatus.SC_NOT_FOUND:
- throw new ResourceDoesNotExistException( "File: " + url + " does not exist" );
-
- //add more entries here
- default :
- throw new TransferFailedException(
- "Failed to transfer file: " + url + ". Return code is: " + statusCode );
- }
-
- putMethod.releaseConnection();
-
- firePutCompleted( resource, source );
- }
-
- public void closeConnection()
- {
- }
-
- public void get( String resourceName, File destination )
- throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
- {
- get( resourceName, destination, 0 );
- }
-
- public boolean getIfNewer( String resourceName, File destination, long timestamp )
- throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
- {
- return get( resourceName, destination, timestamp );
- }
-
- /**
- * @param resourceName
- * @param destination
- * @param timestamp the timestamp to check against, only downloading if newer. If <code>0</code>, always download
- * @return <code>true</code> if newer version was downloaded, <code>false</code> otherwise.
- * @throws TransferFailedException
- * @throws ResourceDoesNotExistException
- * @throws AuthorizationException
- */
- public boolean get( String resourceName, File destination, long timestamp )
- throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
- {
- Resource resource = new Resource( resourceName );
-
- fireGetInitiated( resource, destination );
-
- boolean retValue = false;
-
- String url = getRepository().getUrl() + "/" + resourceName;
-
- GetMethod getMethod = new GetMethod( url );
- getMethod.getParams().setSoTimeout( getTimeout() );
-
- 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" );
- getMethod.addRequestHeader( "Accept-Encoding", "gzip" );
-
- if ( timestamp > 0 )
- {
- SimpleDateFormat fmt = new SimpleDateFormat( "EEE, dd-MMM-yy HH:mm:ss zzz", Locale.US );
- fmt.setTimeZone( GMT_TIME_ZONE );
- Header hdr = new Header( "If-Modified-Since", fmt.format( new Date( timestamp ) ) );
- fireTransferDebug( "sending ==> " + hdr + "(" + timestamp + ")" );
- getMethod.addRequestHeader( hdr );
- }
-
- int statusCode = execute( getMethod );
-
- 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 HttpStatus.SC_NOT_MODIFIED:
- return false;
-
- case SC_NULL:
- throw new TransferFailedException( "Failed to transfer file: " + url );
-
- 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 transfer file: " + url + ". Return code is: " + statusCode );
- }
-
- InputStream is = null;
-
- Header contentLengthHeader = getMethod.getResponseHeader( "Content-Length" );
-
- if ( contentLengthHeader != null )
- {
- try
- {
- long contentLength = Integer.valueOf( contentLengthHeader.getValue() ).intValue();
-
- resource.setContentLength( contentLength );
- }
- catch ( NumberFormatException e )
- {
- fireTransferDebug(
- "error parsing content length header '" + contentLengthHeader.getValue() + "' " + e );
- }
- }
-
- Header lastModifiedHeader = getMethod.getResponseHeader( "Last-Modified" );
-
- long lastModified = 0;
-
- if ( lastModifiedHeader != null )
- {
- try
- {
- lastModified = DateParser.parseDate( lastModifiedHeader.getValue() ).getTime();
- }
- catch ( DateParseException e )
- {
- fireTransferDebug( "Unable to parse last modified header" );
- }
-
- fireTransferDebug( "last-modified = " + lastModifiedHeader.getValue() + " (" + lastModified + ")" );
- }
-
- // always get if timestamp is 0 (ie, target doesn't exist), otherwise only if older than the remote file
- if ( timestamp == 0 || timestamp < lastModified )
- {
- retValue = true;
-
- Header contentEncoding = getMethod.getResponseHeader( "Content-Encoding" );
- boolean isGZipped = contentEncoding == null ? false : "gzip".equalsIgnoreCase(contentEncoding.getValue());
-
- try
- {
- is = getMethod.getResponseBodyAsStream();
- if (isGZipped)
- {
- is = new GZIPInputStream( is );
- }
-
- getTransfer( resource, destination, is );
- }
- catch ( IOException e )
- {
- fireTransferError( resource, e, TransferEvent.REQUEST_GET );
-
- if ( destination.exists() )
- {
- boolean deleted = destination.delete();
-
- if ( !deleted )
- {
- destination.deleteOnExit();
- }
- }
-
- String msg = "Error occurred while deploying to remote repository:" + getRepository();
-
- throw new TransferFailedException( msg, e );
- }
- finally
- {
- IOUtil.close( is );
- }
-
- if ( lastModified > 0 )
- {
- resource.setLastModified( lastModified );
- }
- }
- else
- {
- fireTransferDebug( "Local file is newer: not downloaded" );
- }
-
- return retValue;
- }
- finally
- {
- getMethod.releaseConnection();
- }
- }
-
+ extends AbstractHttpClientWagon
+{
public List getFileList( String destinationDirectory )
throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
{
@@ -396,17 +49,9 @@
String url = getRepository().getUrl() + "/" + destinationDirectory;
GetMethod getMethod = new GetMethod( url );
- getMethod.getParams().setSoTimeout( getTimeout() );
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 = execute( getMethod );
fireTransferDebug( url + " - Status code: " + statusCode );
@@ -453,71 +98,4 @@
getMethod.releaseConnection();
}
}
-
- public boolean resourceExists( String resourceName )
- throws TransferFailedException, AuthorizationException
- {
- String url = getRepository().getUrl() + "/" + resourceName;
-
- HeadMethod headMethod = new HeadMethod( url );
- headMethod.getParams().setSoTimeout( getTimeout() );
-
- int statusCode = execute( headMethod );
-
- try
- {
- 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);
-
- 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:
- return false;
-
- //add more entries here
- default:
- throw new TransferFailedException( "Failed to transfer file: " + url + ". Return code is: "
- + statusCode );
- }
- }
- finally
- {
- headMethod.releaseConnection();
- }
- }
-
- private int execute(HttpMethod httpMethod)
- throws TransferFailedException
- {
- int statusCode = SC_NULL;
- try
- {
- // execute the method.
- statusCode = client.executeMethod( httpMethod );
- }
- catch ( IOException e )
- {
- throw new TransferFailedException( e.getMessage(), e );
- }
- return statusCode;
- }
-
- public void setConnectionManager(HttpConnectionManager connectionManager) {
- this.connectionManager = connectionManager;
- }
}
Modified: maven/wagon/branches/WAGON-109/wagon-providers/wagon-webdav/pom.xml
URL: http://svn.apache.org/viewvc/maven/wagon/branches/WAGON-109/wagon-providers/wagon-webdav/pom.xml?rev=657714&r1=657713&r2=657714&view=diff
==============================================================================
--- maven/wagon/branches/WAGON-109/wagon-providers/wagon-webdav/pom.xml (original)
+++ maven/wagon/branches/WAGON-109/wagon-providers/wagon-webdav/pom.xml Sun May 18 20:19:07 2008
@@ -17,7 +17,7 @@
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
- -->
+-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -39,24 +39,36 @@
<name>Henry Isidro</name>
<email>hisidro@exist.com</email>
</contributor>
+ <contributor>
+ <name>James William Dumay</name>
+ <email>james@atlassian.com</email>
+ </contributor>
</contributors>
<dependencies>
<dependency>
- <groupId>slide</groupId>
- <artifactId>slide-webdavlib</artifactId>
- <version>2.1</version>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>wagon-http-shared</artifactId>
+ <version>1.0-rc1-SNAPSHOT</version>
</dependency>
<dependency>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- <version>1.0.4</version>
- <scope>runtime</scope>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>jackrabbit-webdav</artifactId>
+ <version>1.4</version>
</dependency>
+
+ <!-- Test dependencies -->
<dependency>
- <groupId>org.codehaus.plexus</groupId>
- <artifactId>plexus-utils</artifactId>
- <version>1.4.2</version>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.5.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.3</version>
+ <scope>test</scope>
</dependency>
<dependency>
<groupId>it.could</groupId>
Added: maven/wagon/branches/WAGON-109/wagon-providers/wagon-webdav/src/main/java/org/apache/maven/wagon/providers/webdav/PathNavigator.java
URL: http://svn.apache.org/viewvc/maven/wagon/branches/WAGON-109/wagon-providers/wagon-webdav/src/main/java/org/apache/maven/wagon/providers/webdav/PathNavigator.java?rev=657714&view=auto
==============================================================================
--- maven/wagon/branches/WAGON-109/wagon-providers/wagon-webdav/src/main/java/org/apache/maven/wagon/providers/webdav/PathNavigator.java (added)
+++ maven/wagon/branches/WAGON-109/wagon-providers/wagon-webdav/src/main/java/org/apache/maven/wagon/providers/webdav/PathNavigator.java Sun May 18 20:19:07 2008
@@ -0,0 +1,73 @@
+package org.apache.maven.wagon.providers.webdav;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.codehaus.plexus.util.StringUtils;
+
+import java.util.List;
+import java.util.Arrays;
+
+/**
+ * @author <a href="mailto:james@atlassian.com">James William Dumay</a>
+ */
+public class PathNavigator
+{
+ final private List list;
+
+ private int currentPosition;
+
+ public PathNavigator(String path)
+ {
+ list = Arrays.asList(StringUtils.split(path, "/"));
+ currentPosition = list.size() + 1;
+ }
+
+ public String getPath()
+ {
+ List currentPathList = list.subList(0, currentPosition);
+ StringBuffer sb = new StringBuffer();
+ for (int i = 0; i < currentPathList.size(); i++)
+ {
+ sb.append(currentPathList.get(i));
+ sb.append('/');
+ }
+ return sb.toString();
+ }
+
+ public boolean backward()
+ {
+ if (currentPosition - 1 == 0)
+ {
+ return false;
+ }
+ currentPosition--;
+ return true;
+ }
+
+ public boolean forward()
+ {
+ if (currentPosition + 1 > list.size())
+ {
+ return false;
+ }
+ currentPosition++;
+ return true;
+ }
+}
Propchange: maven/wagon/branches/WAGON-109/wagon-providers/wagon-webdav/src/main/java/org/apache/maven/wagon/providers/webdav/PathNavigator.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: maven/wagon/branches/WAGON-109/wagon-providers/wagon-webdav/src/main/java/org/apache/maven/wagon/providers/webdav/WebDavWagon.java
URL: http://svn.apache.org/viewvc/maven/wagon/branches/WAGON-109/wagon-providers/wagon-webdav/src/main/java/org/apache/maven/wagon/providers/webdav/WebDavWagon.java?rev=657714&r1=657713&r2=657714&view=diff
==============================================================================
--- maven/wagon/branches/WAGON-109/wagon-providers/wagon-webdav/src/main/java/org/apache/maven/wagon/providers/webdav/WebDavWagon.java (original)
+++ maven/wagon/branches/WAGON-109/wagon-providers/wagon-webdav/src/main/java/org/apache/maven/wagon/providers/webdav/WebDavWagon.java Sun May 18 20:19:07 2008
@@ -19,45 +19,32 @@
* under the License.
*/
-import org.apache.commons.httpclient.HttpException;
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
import org.apache.commons.httpclient.HttpStatus;
-import org.apache.commons.httpclient.HttpURL;
-import org.apache.commons.httpclient.HttpsURL;
-import org.apache.commons.httpclient.URIException;
-import org.apache.commons.httpclient.UsernamePasswordCredentials;
-import org.apache.maven.wagon.AbstractWagon;
-import org.apache.maven.wagon.ConnectionException;
-import org.apache.maven.wagon.LazyFileOutputStream;
+import org.apache.jackrabbit.webdav.DavConstants;
+import org.apache.jackrabbit.webdav.DavException;
+import org.apache.jackrabbit.webdav.MultiStatus;
+import org.apache.jackrabbit.webdav.MultiStatusResponse;
+import org.apache.jackrabbit.webdav.client.methods.MkColMethod;
+import org.apache.jackrabbit.webdav.client.methods.PropFindMethod;
+import org.apache.jackrabbit.webdav.property.DavProperty;
+import org.apache.jackrabbit.webdav.property.DavPropertyName;
+import org.apache.jackrabbit.webdav.property.DavPropertyNameSet;
+import org.apache.jackrabbit.webdav.property.DavPropertySet;
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.Repository;
import org.apache.maven.wagon.resource.Resource;
-import org.apache.webdav.lib.WebdavResource;
-import org.apache.webdav.lib.methods.DepthSupport;
+import org.apache.maven.wagon.shared.http.AbstractHttpClientWagon;
import org.codehaus.plexus.util.FileUtils;
-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.io.OutputStream;
-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.Stack;
-import java.util.TimeZone;
+import org.w3c.dom.Node;
/**
* <p>WebDavWagon</p>
@@ -67,138 +54,11 @@
* @author <a href="mailto:hisidro@exist.com">Henry Isidro</a>
* @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
* @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
- * @plexus.component role="org.apache.maven.wagon.Wagon"
- * role-hint="dav"
- * instantiation-strategy="per-lookup"
+ * @author <a href="mailto:james@atlassian.com>James William Dumay</a>
*/
public class WebDavWagon
- extends AbstractWagon
+ extends AbstractHttpClientWagon
{
- private static final TimeZone TIMESTAMP_TIME_ZONE = TimeZone.getTimeZone( "GMT" );
-
- private static String wagonVersion;
-
- private DateFormat dateFormat = new SimpleDateFormat( "EEE, dd-MMM-yy HH:mm:ss zzz", Locale.US );
-
- private CorrectedWebdavResource webdavResource;
-
- public WebDavWagon()
- {
- dateFormat.setTimeZone( TIMESTAMP_TIME_ZONE );
-
- if ( wagonVersion == null )
- {
- URL pomUrl = this.getClass()
- .getResource( "/META-INF/maven/org.apache.maven.wagon/wagon-webdav/pom.properties" );
- if ( pomUrl == null )
- {
- wagonVersion = "";
- }
- else
- {
- Properties props = new Properties();
- try
- {
- props.load( pomUrl.openStream() );
- wagonVersion = props.getProperty( "version" );
- }
- catch ( IOException e )
- {
- wagonVersion = "";
- }
- }
- }
- }
-
- /**
- * Opens a connection via web-dav resource
- *
- * @throws AuthenticationException
- * @throws ConnectionException
- */
- public void openConnectionInternal()
- throws AuthenticationException, ConnectionException
- {
- final boolean hasProxy = ( proxyInfo != null && proxyInfo.getUserName() != null );
- final boolean hasAuthentication = ( authenticationInfo != null && authenticationInfo.getUserName() != null );
-
- String url = getURL( repository );
-
- repository.setUrl( url );
-
- HttpURL httpURL = null;
-
- try
- {
- httpURL = urlToHttpURL( url );
-
- if ( hasAuthentication )
- {
- String userName = authenticationInfo.getUserName();
- String password = authenticationInfo.getPassword();
-
- if ( userName != null && password != null )
- {
- httpURL.setUserinfo( userName, password );
- }
- }
-
- CorrectedWebdavResource.setDefaultAction( CorrectedWebdavResource.NOACTION );
- webdavResource = new CorrectedWebdavResource( httpURL );
- webdavResource.setConnectionTimeout(getTimeout());
-
- if ( hasProxy )
- {
- webdavResource.setProxy( proxyInfo.getHost(), proxyInfo.getPort() );
- if ( !StringUtils.isEmpty( proxyInfo.getUserName() ) )
- {
- UsernamePasswordCredentials proxyCredentials = new UsernamePasswordCredentials();
- proxyCredentials.setUserName( proxyInfo.getUserName() );
- proxyCredentials.setPassword( proxyInfo.getPassword() );
- webdavResource.setProxyCredentials( proxyCredentials );
- }
- }
- }
- catch ( HttpException he )
- {
- throw new ConnectionException( "Connection Exception: " + url + " " + he.getReasonCode() + " " +
- HttpStatus.getStatusText( he.getReasonCode() ), he );
- }
- catch ( URIException urie )
- {
- throw new ConnectionException( "Connection Exception: " + urie.getReason(), urie );
- }
- catch ( IOException ioe )
- {
- throw new ConnectionException( "Connection Exception: " + ioe.getMessage(), ioe );
- }
- }
-
- /**
- * Closes the connection
- *
- * @throws ConnectionException
- */
- public void closeConnection()
- throws ConnectionException
- {
- try
- {
- if ( webdavResource != null )
- {
- webdavResource.close();
- }
- }
- catch ( IOException ioe )
- {
- throw new ConnectionException( "Connection Exception: " + ioe.getMessage(), ioe );
- }
- finally
- {
- webdavResource = null;
- }
- }
-
/**
* Puts a file into the remote repository
*
@@ -231,57 +91,20 @@
firePutInitiated( resource, source );
+ //Parent directories need to be created before posting
mkdirs( dir );
- try
- {
- // Put source into destination path.
- firePutStarted( resource, source );
-
- InputStream is = new PutInputStream( source, resource, this, getTransferEventSupport() );
- boolean success = webdavResource.putMethod( dest, is, (int) source.length() );
- int statusCode = webdavResource.getStatusCode();
-
- switch ( statusCode )
- {
- case HttpStatus.SC_OK:
- break;
-
- case HttpStatus.SC_CREATED:
- break;
-
- case HttpStatus.SC_FORBIDDEN:
- throw new AuthorizationException( "Access denied to: " + dest );
-
- case HttpStatus.SC_NOT_FOUND:
- // should never happen as the destination is created before or fail
- throw new TransferFailedException( "Destination folder could not be created: " + dest );
-
- case HttpStatus.SC_LENGTH_REQUIRED:
- throw new TransferFailedException( "Transfer failed, server requires Content-Length." );
-
- //add more entries here
- default:
- if ( !success )
- {
- throw new TransferFailedException( "Failed to transfer file: " + dest + ". Return code is: " +
- statusCode + " " + HttpStatus.getStatusText( statusCode ) );
- }
- }
- }
- catch ( FileNotFoundException e )
- {
- throw new TransferFailedException( "Specified source file does not exist: " + source, e );
- }
- catch ( IOException e )
- {
- fireTransferError( resource, e, TransferEvent.REQUEST_PUT );
-
- String msg = "PUT request for: " + resource + " to " + source.getName() + " failed";
+ super.put(source, resourceName, false);
+ }
- throw new TransferFailedException( msg, e );
- }
- firePutCompleted( resource, source );
+ /**
+ * This wagon supports directory copying
+ *
+ * @return <code>true</code> always
+ */
+ public boolean supportsDirectoryCopy()
+ {
+ return true;
}
/**
@@ -296,289 +119,50 @@
{
Repository repository = getRepository();
String basedir = repository.getBasedir();
- String destinationPath = webdavResource.getPath();
String relpath = FileUtils.normalize( getPath( basedir, dir ) + "/" );
- String currentPath = relpath;
- Stack directoriesToBeCreated = new Stack();
-
- try
+ PathNavigator navigator = new PathNavigator(relpath);
+ while (navigator.backward())
{
- while ( currentPath != null )
- {
- webdavResource.setPath( currentPath );
+ int status = SC_NULL;
+ String url = getUrl(navigator);
+ status = doMkCol(url);
- /* needed to call webdavResource.exists() later */
- try
- {
- webdavResource.setProperties( WebdavResource.NAME, DepthSupport.DEPTH_0 );
- }
- catch ( HttpException e )
- {
- // ignore exceptions thrown when the path does not exist ( 404 errors )
- }
-
- if ( webdavResource.exists() )
- {
- if ( webdavResource.isCollection() )
- {
- /* path exists and it's a directory */
- break;
- }
- else
- {
- throw new TransferFailedException(
- "Destination path exists and is not a WebDAV collection (directory): " +
- webdavResource.toString() );
- }
- }
-
- /* if dest resource path does not exist, create it later */
- directoriesToBeCreated.push( currentPath );
-
- /* go down a folder */
- currentPath += "/../";
- currentPath = FileUtils.normalize( currentPath );
- }
-
- // mkcolMethod() cannot create a directory hierarchy at once,
- // it has to create each directory one at a time
- while ( !directoriesToBeCreated.empty() )
+ //If collection has been created or exists
+ if (status == HttpStatus.SC_OK
+ || status == HttpStatus.SC_CREATED
+ || status == HttpStatus.SC_METHOD_NOT_ALLOWED)
{
- currentPath = (String) directoriesToBeCreated.pop();
- if ( currentPath.equals( "/" ) )
+ while (navigator.forward())
{
- /* Impossible to create root directory, skip */
- continue;
- }
- webdavResource.setPath( currentPath );
-
- try
- {
- boolean destinationCreated = webdavResource.mkcolMethod( currentPath );
- if ( !destinationCreated )
- {
- throw new TransferFailedException( "Destination folder [" + currentPath +
- "] could not be created: " + webdavResource.toString() + " - Server returned error: " +
- webdavResource.getStatusCode() + ": " +
- HttpStatus.getStatusText( webdavResource.getStatusCode() ) );
- }
- }
- catch ( IOException e )
- {
- throw new TransferFailedException( "Failed to create destination WebDAV collection (directory) [" +
- currentPath + "]: " + webdavResource.toString(), e );
+ status = SC_NULL;
+ url = getUrl(navigator);
+ status = doMkCol(url);
}
+ break;
}
-
- webdavResource.setPath( destinationPath );
- }
- catch ( HttpException e )
- {
- throw new TransferFailedException( "Unknown error creating destination WebDAV collection (directory): " +
- webdavResource.toString() + ". Server returned error: " + HttpStatus.getStatusText( e.getReasonCode() ),
- e );
- }
- catch ( IOException e )
- {
- throw new TransferFailedException(
- "Unknown error creating destination WebDAV collection (directory): " + webdavResource.toString(), e );
}
}
- /**
- * Converts a String url to an HttpURL
- *
- * @param url String url to convert to an HttpURL
- * @return an HttpURL object created from the String url
- * @throws URIException
- */
- private HttpURL urlToHttpURL( String url )
- throws URIException
+ private int doMkCol(String url) throws TransferFailedException
{
- if ( url.startsWith( "https" ) )
- {
- return new HttpsURL( url );
- }
- else
- {
- return new HttpURL( url );
- }
- }
-
- /**
- * Determine which URI to use at the prompt.
- *
- * @param uri the path to be set.
- * @return the normalized path.
- * @see FileUtils#normalize(String)
- */
- private String checkUri( String uri )
- throws IOException
- {
-
- if ( webdavResource == null )
- {
- throw new IOException( "Not connected yet." );
- }
-
- if ( uri == null )
- {
- uri = webdavResource.getPath();
- }
-
- return FileUtils.normalize( uri );
- }
-
- public void get( String resourceName, File destination )
- throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
- {
- get( resourceName, destination, 0 );
-
- }
-
- public boolean getIfNewer( String resourceName, File destination, long timestamp )
- throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
- {
- return get( resourceName, destination, timestamp );
- }
-
- /**
- * Get a file from remote server
- *
- * @param resourceName
- * @param destination
- * @param timestamp the timestamp to check against, only downloading if newer. If <code>0</code>, always download
- * @return <code>true</code> if newer version was downloaded, <code>false</code> otherwise.
- * @throws TransferFailedException
- * @throws ResourceDoesNotExistException
- * @throws AuthorizationException
- */
- public boolean get( String resourceName, File destination, long timestamp )
- throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
- {
- Resource resource = new Resource( resourceName );
-
- fireGetInitiated( resource, destination );
-
- String url = getRepository().getUrl() + "/" + resourceName;
-
- addRequestHeaders();
- webdavResource.addRequestHeader( "Accept-Encoding", "gzip" );
-
- if ( timestamp > 0 )
- {
- webdavResource.addRequestHeader( "If-Modified-Since", dateFormat.format( new Date( timestamp ) ) );
- }
-
- InputStream is = null;
- OutputStream output = new LazyFileOutputStream( destination );
+ MkColMethod method = null;
try
{
- is = webdavResource.getMethodData( url );
- getTransfer( resource, destination, is );
- }
- catch ( HttpException e )
- {
- fireTransferError( resource, e, TransferEvent.REQUEST_GET );
- throw new TransferFailedException(
- "Failed to transfer file: " + url + ". Return code is: " + e.getReasonCode(), e );
- }
- catch ( IOException e )
- {
- fireTransferError( resource, e, TransferEvent.REQUEST_GET );
-
- if ( destination.exists() )
- {
- boolean deleted = destination.delete();
-
- if ( !deleted )
- {
- destination.deleteOnExit();
- }
- }
-
- int statusCode = webdavResource.getStatusCode();
- switch ( statusCode )
- {
- case HttpStatus.SC_NOT_MODIFIED:
- return false;
-
- 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" );
-
- default:
- throw new TransferFailedException(
- "Failed to transfer file: " + url + ". Return code is: " + statusCode, e );
- }
+ method = new MkColMethod(url);
+ return execute(method);
}
finally
{
- IOUtil.close( is );
- IOUtil.close( output );
- }
-
- int statusCode = webdavResource.getStatusCode();
-
- switch ( statusCode )
- {
- case HttpStatus.SC_OK:
- return true;
-
- case HttpStatus.SC_NOT_MODIFIED:
- return false;
-
- 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" );
-
- default:
- throw new TransferFailedException(
- "Failed to transfer file: " + url + ". Return code is: " + statusCode );
- }
-
- }
-
- private String getURL( Repository repository )
- {
- String url = repository.getUrl();
- String s = "dav:";
- if ( url.startsWith( s ) )
- {
- return url.substring( s.length() );
- }
- else
- {
- return url;
+ if (method != null) method.releaseConnection();
}
}
- /**
- * This wagon supports directory copying
- *
- * @return <code>true</code> always
- */
- public boolean supportsDirectoryCopy()
+ private String getUrl(PathNavigator navigator)
{
- return true;
+ String url = getRepository().getUrl().replaceAll(getRepository().getBasedir(), "");
+ return url + '/' + navigator.getPath();
}
/**
@@ -611,104 +195,107 @@
}
- public List getFileList( String destinationDirectory )
- throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
+ private boolean isDirectory(String url) throws TransferFailedException
{
- addRequestHeaders();
-
- String basedir = repository.getBasedir();
+ DavPropertyNameSet nameSet = new DavPropertyNameSet();
+ nameSet.add(DavPropertyName.create(DavConstants.PROPERTY_RESOURCETYPE));
- if ( !destinationDirectory.endsWith( "/" ) )
+ PropFindMethod method = null;
+ try
{
- destinationDirectory += "/";
+ method = new PropFindMethod(url, nameSet, DavConstants.DEPTH_0);
+ execute(method);
+ if (method.succeeded())
+ {
+ MultiStatus multiStatus = method.getResponseBodyAsMultiStatus();
+ MultiStatusResponse response = multiStatus.getResponses()[0];
+ DavPropertySet propertySet = response.getProperties(HttpStatus.SC_OK);
+ DavProperty property = propertySet.get(DavConstants.PROPERTY_RESOURCETYPE);
+ if (property != null)
+ {
+ Node node = (Node)property.getValue();
+ return node.getLocalName().equals(DavConstants.XML_COLLECTION);
+ }
+ }
+ return false;
}
-
- String cleanDestDir = StringUtils.replace( destinationDirectory, "\\", "/" );
- String dir = PathUtils.dirname( cleanDestDir );
- dir = StringUtils.replace( dir, "\\", "/" );
-
- String oldpath = webdavResource.getPath();
- String relpath = getPath( basedir, dir );
-
- try
+ catch (DavException e)
+ {
+ throw new TransferFailedException(e.getMessage(), e);
+ }
+ catch (IOException e)
+ {
+ throw new TransferFailedException(e.getMessage(), e);
+ }
+ finally
{
- // Test if dest resource path exist.
- String cdpath = checkUri( relpath + "/" );
- webdavResource.setPath( cdpath );
+ if (method != null) method.releaseConnection();
+ }
+ }
+ public List getFileList( String destinationDirectory )
+ throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
+ {
+ final String url = getRepository().getUrl() + '/' + destinationDirectory;
+ if (isDirectory(url))
+ {
+ PropFindMethod method = null;
try
{
- webdavResource.setProperties( WebdavResource.NAME, DepthSupport.DEPTH_0 );
+ DavPropertyNameSet nameSet = new DavPropertyNameSet();
+ nameSet.add(DavPropertyName.create(DavConstants.PROPERTY_DISPLAYNAME));
- /* seems this is not needed as Webdav client causes a 404 error in webdavResource.setProperties */
- if ( !webdavResource.exists() )
+ method = new PropFindMethod(url, nameSet, DavConstants.DEPTH_1);
+ int status = execute(method);
+ if (method.succeeded())
{
- throw new ResourceDoesNotExistException( "Destination directory does not exist: " + cdpath );
- }
+ ArrayList dirs = new ArrayList();
+ MultiStatus multiStatus = method.getResponseBodyAsMultiStatus();
- if ( !webdavResource.isCollection() )
- {
- throw new ResourceDoesNotExistException(
- "Destination path exists but is not a " + "WebDAV collection (directory): " + cdpath );
+ for (int i = 0; i < multiStatus.getResponses().length; i++)
+ {
+ MultiStatusResponse response = multiStatus.getResponses()[i];
+ String fileName = PathUtils.filename(response.getHref());
+ if (!StringUtils.isEmpty(fileName))
+ {
+ dirs.add(fileName);
+ }
+ }
+ return dirs;
}
-
- String[] entries = webdavResource.list();
-
- List filelist = new ArrayList();
- if ( entries != null )
+
+ if (status == HttpStatus.SC_NOT_FOUND)
{
- filelist.addAll( Arrays.asList( entries ) );
+ throw new ResourceDoesNotExistException( "Destination directory does not exist: " + url );
}
-
- return filelist;
}
- catch ( HttpException e )
+ catch (DavException 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 );
- }
+ throw new TransferFailedException(e.getMessage(), e);
+ }
+ catch (IOException e)
+ {
+ throw new TransferFailedException(e.getMessage(), e);
}
finally
{
- webdavResource.setPath( oldpath );
+ if (method != null) method.releaseConnection();
}
-
- }
- catch ( IOException e )
- {
- throw new TransferFailedException( "Unable to obtain file list from WebDAV collection.", e );
}
+ throw new ResourceDoesNotExistException("Destination path exists but is not a " + "WebDAV collection (directory): " + url );
}
-
- private void addRequestHeaders()
- {
- 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" );
- }
-
- public boolean resourceExists( String resourceName )
- throws TransferFailedException, AuthorizationException
+
+ protected String getURL( Repository repository )
{
- try
+ String url = repository.getUrl();
+ String s = "dav:";
+ if ( url.startsWith( s ) )
{
- String parentDirectory = PathUtils.dirname( resourceName );
- List entries = getFileList( parentDirectory );
- return entries.contains( resourceName );
+ return url.substring( s.length() );
}
- catch ( ResourceDoesNotExistException e )
+ else
{
- return false;
+ return url;
}
}
}
Added: maven/wagon/branches/WAGON-109/wagon-providers/wagon-webdav/src/main/resources/META-INF/plexus/components.xml
URL: http://svn.apache.org/viewvc/maven/wagon/branches/WAGON-109/wagon-providers/wagon-webdav/src/main/resources/META-INF/plexus/components.xml?rev=657714&view=auto
==============================================================================
--- maven/wagon/branches/WAGON-109/wagon-providers/wagon-webdav/src/main/resources/META-INF/plexus/components.xml (added)
+++ maven/wagon/branches/WAGON-109/wagon-providers/wagon-webdav/src/main/resources/META-INF/plexus/components.xml Sun May 18 20:19:07 2008
@@ -0,0 +1,38 @@
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+
+<component-set>
+ <components>
+ <component>
+ <role>org.apache.commons.httpclient.HttpConnectionManager</role>
+ <implementation>org.apache.commons.httpclient.MultiThreadedHttpConnectionManager</implementation>
+ </component>
+ <component>
+ <role>org.apache.maven.wagon.Wagon</role>
+ <role-hint>dav</role-hint>
+ <implementation>org.apache.maven.wagon.providers.webdav.WebDavWagon</implementation>
+ <instantiation-strategy>per-lookup</instantiation-strategy>
+ <requirements>
+ <requirement>
+ <role>org.apache.commons.httpclient.HttpConnectionManager</role>
+ </requirement>
+ </requirements>
+ </component>
+ </components>
+</component-set>
Propchange: maven/wagon/branches/WAGON-109/wagon-providers/wagon-webdav/src/main/resources/META-INF/plexus/components.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: maven/wagon/branches/WAGON-109/wagon-providers/wagon-webdav/src/test/java/org/apache/maven/wagon/providers/webdav/PathNavigatorTest.java
URL: http://svn.apache.org/viewvc/maven/wagon/branches/WAGON-109/wagon-providers/wagon-webdav/src/test/java/org/apache/maven/wagon/providers/webdav/PathNavigatorTest.java?rev=657714&view=auto
==============================================================================
--- maven/wagon/branches/WAGON-109/wagon-providers/wagon-webdav/src/test/java/org/apache/maven/wagon/providers/webdav/PathNavigatorTest.java (added)
+++ maven/wagon/branches/WAGON-109/wagon-providers/wagon-webdav/src/test/java/org/apache/maven/wagon/providers/webdav/PathNavigatorTest.java Sun May 18 20:19:07 2008
@@ -0,0 +1,59 @@
+package org.apache.maven.wagon.providers.webdav;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import junit.framework.TestCase;
+
+/**
+ * @author <a href="mailto:james@atlassian.com">James William Dumay</a>
+ */
+public class PathNavigatorTest extends TestCase
+{
+ private static final String TEST_PATH = "the/quick/brown/fox/jumps/over/the/lazy/maven/developer";
+
+ public void testBackForwardBack()
+ {
+ PathNavigator navigator = new PathNavigator(TEST_PATH);
+
+ //Nav backward
+ assertTrue(navigator.backward());
+ assertEquals("the/quick/brown/fox/jumps/over/the/lazy/maven/developer/", navigator.getPath());
+
+ assertTrue(navigator.backward());
+ assertEquals("the/quick/brown/fox/jumps/over/the/lazy/maven/", navigator.getPath());
+
+ assertTrue(navigator.backward());
+ assertEquals("the/quick/brown/fox/jumps/over/the/lazy/", navigator.getPath());
+
+ assertTrue(navigator.backward());
+ assertEquals("the/quick/brown/fox/jumps/over/the/", navigator.getPath());
+
+ //Nav forward
+ assertTrue(navigator.forward());
+ assertEquals("the/quick/brown/fox/jumps/over/the/lazy/", navigator.getPath());
+
+ assertTrue(navigator.forward());
+ assertEquals("the/quick/brown/fox/jumps/over/the/lazy/maven/", navigator.getPath());
+
+ //Nav backward
+ assertTrue(navigator.backward());
+ assertEquals("the/quick/brown/fox/jumps/over/the/lazy/", navigator.getPath());
+ }
+}
Propchange: maven/wagon/branches/WAGON-109/wagon-providers/wagon-webdav/src/test/java/org/apache/maven/wagon/providers/webdav/PathNavigatorTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: maven/wagon/branches/WAGON-109/wagon-providers/wagon-webdav/src/test/java/org/apache/maven/wagon/providers/webdav/WebDavWagonGzipTest.java
URL: http://svn.apache.org/viewvc/maven/wagon/branches/WAGON-109/wagon-providers/wagon-webdav/src/test/java/org/apache/maven/wagon/providers/webdav/WebDavWagonGzipTest.java?rev=657714&r1=657713&r2=657714&view=diff
==============================================================================
--- maven/wagon/branches/WAGON-109/wagon-providers/wagon-webdav/src/test/java/org/apache/maven/wagon/providers/webdav/WebDavWagonGzipTest.java (original)
+++ maven/wagon/branches/WAGON-109/wagon-providers/wagon-webdav/src/test/java/org/apache/maven/wagon/providers/webdav/WebDavWagonGzipTest.java Sun May 18 20:19:07 2008
@@ -28,15 +28,14 @@
import org.apache.maven.wagon.FileTestUtils;
import org.apache.maven.wagon.Wagon;
import org.apache.maven.wagon.repository.Repository;
+import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.util.FileUtils;
import org.mortbay.http.HttpContext;
import org.mortbay.http.HttpServer;
import org.mortbay.http.SocketListener;
import org.mortbay.http.handler.ResourceHandler;
-import junit.framework.TestCase;
-
-public class WebDavWagonGzipTest extends TestCase
+public class WebDavWagonGzipTest extends PlexusTestCase
{
public void testGzipGet() throws Exception
{
@@ -57,7 +56,7 @@
try
{
- Wagon wagon = new WebDavWagon();
+ Wagon wagon = (Wagon)lookup("org.apache.maven.wagon.Wagon", "dav");
Repository testRepository = new Repository();
Modified: maven/wagon/branches/WAGON-109/wagon-providers/wagon-webdav/src/test/java/org/apache/maven/wagon/providers/webdav/WebDavWagonTest.java
URL: http://svn.apache.org/viewvc/maven/wagon/branches/WAGON-109/wagon-providers/wagon-webdav/src/test/java/org/apache/maven/wagon/providers/webdav/WebDavWagonTest.java?rev=657714&r1=657713&r2=657714&view=diff
==============================================================================
--- maven/wagon/branches/WAGON-109/wagon-providers/wagon-webdav/src/test/java/org/apache/maven/wagon/providers/webdav/WebDavWagonTest.java (original)
+++ maven/wagon/branches/WAGON-109/wagon-providers/wagon-webdav/src/test/java/org/apache/maven/wagon/providers/webdav/WebDavWagonTest.java Sun May 18 20:19:07 2008
@@ -19,16 +19,12 @@
* under the License.
*/
-import org.apache.maven.wagon.FileTestUtils;
-import org.apache.maven.wagon.TransferFailedException;
-import org.apache.maven.wagon.Wagon;
-import org.apache.maven.wagon.WagonTestCase;
-import org.apache.maven.wagon.authentication.AuthenticationInfo;
-import org.codehaus.plexus.util.FileUtils;
-
import java.io.File;
import java.io.IOException;
+import org.apache.maven.wagon.FileTestUtils;
+import org.apache.maven.wagon.WagonTestCase;
+
/**
* WebDAV Wagon Test
*
@@ -74,31 +70,4 @@
{
release( server );
}
-
- public void testWagonPutToNonWebdav()
- throws Exception
- {
- setupRepositories();
-
- String url = "http://localhost:10007";
-
- testRepository.setUrl( "dav:" + url );
-
- setupWagonTestingFixtures();
-
- try
- {
- putFile();
- fail( "Expected and not thrown " + TransferFailedException.class.getName() );
- }
- catch ( TransferFailedException e )
- {
- assertEquals( "Exception message doesn't match expected",
- "Destination folder could not be created: " + url + "/test-resource", e.getMessage() );
- }
-
- testRepository.setUrl( getTestRepositoryUrl() );
-
- tearDownWagonTestingFixtures();
- }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: wagon-commits-unsubscribe@maven.apache.org
For additional commands, e-mail: wagon-commits-help@maven.apache.org