wagon-commits@maven.apache.org
[Top] [All Lists]

svn commit: r515353 [2/2] - in /maven/wagon/branches/wagon-1.x: ./ wagon

Subject: svn commit: r515353 [2/2] - in /maven/wagon/branches/wagon-1.x: ./ wagon-provider-api/ wagon-provider-test/ wagon-providers/wagon-file/ wagon-providers/wagon-file/src/main/java/org/apache/maven/wagon/providers/file/ wagon-providers/wagon-file/src/main/...
From:
Date: Tue, 06 Mar 2007 23:23:35 -0000
Modified: 
maven/wagon/branches/wagon-1.x/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-1.x/wagon-providers/wagon-webdav/src/main/java/org/apache/maven/wagon/providers/webdav/WebDavWagon.java?view=diff&rev=515353&r1=515352&r2=515353
==============================================================================
--- 
maven/wagon/branches/wagon-1.x/wagon-providers/wagon-webdav/src/main/java/org/apache/maven/wagon/providers/webdav/WebDavWagon.java
 (original)
+++ 
maven/wagon/branches/wagon-1.x/wagon-providers/wagon-webdav/src/main/java/org/apache/maven/wagon/providers/webdav/WebDavWagon.java
 Tue Mar  6 15:23:30 2007
@@ -1,19 +1,22 @@
 package org.apache.maven.wagon.providers.webdav;
 
 /*
- * Copyright 2001-2006 The Apache Software Foundation.
+ * 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
  *
- * Licensed 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
  *
- *      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.
+ * 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.commons.httpclient.HttpException;
@@ -53,6 +56,7 @@
 import java.util.List;
 import java.util.Locale;
 import java.util.Properties;
+import java.util.Stack;
 import java.util.TimeZone;
 
 /**
@@ -60,11 +64,13 @@
  * 
  * <p>Allows using a webdav remote repository for downloads and deployments</p>
  * 
- * <p>TODO: webdav https server is not tested</p>
- * 
  * @author <a href="mailto:hisidro@xxxxxxxxx";>Henry Isidro</a>
- * @author <a href="mailto:joakim@xxxxxxxxxxx";>Joakim Erdfelt</a>
+ * @author <a href="mailto:joakime@xxxxxxxxxx";>Joakim Erdfelt</a>
  * @author <a href="mailto:carlos@xxxxxxxxxx";>Carlos Sanchez</a>
+ * 
+ * @plexus.component role="org.apache.maven.wagon.Wagon" 
+ *   role-hint="dav"
+ *   instantiation-strategy="per-lookup"
  */
 public class WebDavWagon
     extends AbstractWagon
@@ -96,7 +102,6 @@
                 {
                     props.load( pomUrl.openStream() );
                     wagonVersion = props.getProperty( "version" );
-                    System.out.println( "WAGON_VERSION: " + wagonVersion );
                 }
                 catch ( IOException e )
                 {
@@ -210,8 +215,6 @@
     {
         Repository repository = getRepository();
 
-        String basedir = repository.getBasedir();
-
         resourceName = StringUtils.replace( resourceName, "\\", "/" );
         String dir = PathUtils.dirname( resourceName );
         dir = StringUtils.replace( dir, "\\", "/" );
@@ -229,54 +232,8 @@
         }
 
         firePutInitiated( resource, source );
-        String oldpath = webdavResource.getPath();
-
-        String relpath = getPath( basedir, dir );
-
-        try
-        {
-            // Test if dest resource path exist.
-            String cdpath = checkUri( relpath + "/" );
-            webdavResource.setPath( cdpath );
-
-            if ( webdavResource.exists() && !webdavResource.isCollection() )
-            {
-                throw new TransferFailedException(
-                    "Destination path exists and is not a WebDAV collection 
(directory): " + cdpath );
-            }
-
-            webdavResource.setPath( oldpath );
-
-            // if dest resource path does not exist, create it
-            if ( !webdavResource.exists() )
-            {
-                // mkcolMethod() cannot create a directory hierarchy at once,
-                // it has to create each directory one at a time
-                try
-                {
-                    String[] dirs = relpath.split( "/" );
-                    String createDir = "/";
 
-                    // start at 1 because first element of dirs[] from split() 
is ""
-                    for ( int count = 1; count < dirs.length; count++ )
-                    {
-                        createDir = createDir + dirs[count] + "/";
-                        webdavResource.mkcolMethod( createDir );
-                    }
-                    webdavResource.setPath( oldpath );
-                }
-                catch ( IOException ioe )
-                {
-                    throw new TransferFailedException( "Failed to create 
destination WebDAV collection (directory): "
-                        + relpath, ioe );
-                }
-            }
-        }
-        catch ( IOException e )
-        {
-            throw new TransferFailedException(
-                "Failed to create destination WebDAV collection (directory): " 
+ relpath, e );
-        }
+        mkdirs( dir );
 
         try
         {
@@ -299,10 +256,11 @@
                     throw new AuthorizationException( "Access denied to: " + 
dest );
 
                 case HttpStatus.SC_NOT_FOUND:
-                    throw new ResourceDoesNotExistException( "File: " + dest + 
" does not exist" );
+                    // should never happen as the destination is created 
before or fail
+                    throw new TransferFailedException( "Destination does not 
exist: " + repository.getUrl() );
 
                 case HttpStatus.SC_LENGTH_REQUIRED:
-                    throw new ResourceDoesNotExistException( "Transfer failed, 
server requires Content-Length." );
+                    throw new TransferFailedException( "Transfer failed, 
server requires Content-Length." );
 
                     //add more entries here
                 default:
@@ -329,6 +287,103 @@
     }
 
     /**
+     * Create directories in server as needed.
+     * They are created one at a time until the whole path exists.
+     *
+     * @param dir path to be created in server from repository basedir
+     * @throws TransferFailedException
+     */
+    private void mkdirs( String dir )
+        throws TransferFailedException
+    {
+        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
+        {
+            while ( currentPath != null )
+            {
+                webdavResource.setPath( currentPath );
+
+                /* 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() )
+            {
+                currentPath = (String) directoriesToBeCreated.pop();
+                webdavResource.setPath( currentPath );
+
+                try
+                {
+                    boolean destinationCreated = webdavResource.mkcolMethod( 
currentPath );
+                    if ( !destinationCreated )
+                    {
+                        throw new TransferFailedException( "Destination folder 
could not be created: "
+                            + webdavResource.toString() );
+                    }
+                }
+                catch ( IOException e )
+                {
+                    throw new TransferFailedException( "Failed to create 
destination WebDAV collection (directory): "
+                        + webdavResource.toString(), e );
+                }
+            }
+
+            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
@@ -350,9 +405,10 @@
 
     /**
      * Determine which URI to use at the prompt.
+     * @see FileUtils#normalize(String)
      *
      * @param uri the path to be set.
-     * @return the absolute path.
+     * @return the normalized path.
      */
     private String checkUri( String uri )
         throws IOException

Modified: 
maven/wagon/branches/wagon-1.x/wagon-providers/wagon-webdav/src/test/java/org/apache/maven/wagon/providers/webdav/ServletServer.java
URL: 
http://svn.apache.org/viewvc/maven/wagon/branches/wagon-1.x/wagon-providers/wagon-webdav/src/test/java/org/apache/maven/wagon/providers/webdav/ServletServer.java?view=diff&rev=515353&r1=515352&r2=515353
==============================================================================
--- 
maven/wagon/branches/wagon-1.x/wagon-providers/wagon-webdav/src/test/java/org/apache/maven/wagon/providers/webdav/ServletServer.java
 (original)
+++ 
maven/wagon/branches/wagon-1.x/wagon-providers/wagon-webdav/src/test/java/org/apache/maven/wagon/providers/webdav/ServletServer.java
 Tue Mar  6 15:23:30 2007
@@ -100,11 +100,15 @@
             context.addHandler( new SecurityHandler() );
         }
 
-        Iterator itpaths = wdc.getServlets().iterator();
-        while ( itpaths.hasNext() )
+        List servlets = wdc.getServlets();
+        if ( servlets != null )
         {
-            Servlet servlet = (Servlet) itpaths.next();
-            initServlet( context, servlet );
+            Iterator itpaths = servlets.iterator();
+            while ( itpaths.hasNext() )
+            {
+                Servlet servlet = (Servlet) itpaths.next();
+                initServlet( context, servlet );
+            }
         }
     }
 

Modified: 
maven/wagon/branches/wagon-1.x/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-1.x/wagon-providers/wagon-webdav/src/test/java/org/apache/maven/wagon/providers/webdav/WebDavWagonTest.java?view=diff&rev=515353&r1=515352&r2=515353
==============================================================================
--- 
maven/wagon/branches/wagon-1.x/wagon-providers/wagon-webdav/src/test/java/org/apache/maven/wagon/providers/webdav/WebDavWagonTest.java
 (original)
+++ 
maven/wagon/branches/wagon-1.x/wagon-providers/wagon-webdav/src/test/java/org/apache/maven/wagon/providers/webdav/WebDavWagonTest.java
 Tue Mar  6 15:23:30 2007
@@ -20,12 +20,14 @@
 import java.io.IOException;
 
 import org.apache.maven.wagon.FileTestUtils;
+import org.apache.maven.wagon.TransferFailedException;
 import org.apache.maven.wagon.WagonTestCase;
 
 /**
  * WebDAV Wagon Test 
  * 
  * @author <a href="mailto:joakim@xxxxxxxxxxx";>Joakim Erdfelt</a>
+ * @author <a href="mailto:carlos@xxxxxxxxxx";>Carlos Sanchez</a>
  */
 public class WebDavWagonTest
     extends WagonTestCase
@@ -66,4 +68,32 @@
     {
         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
+                + "/", e.getMessage() );
+        }
+
+        testRepository.setUrl( getTestRepositoryUrl() );
+
+        tearDownWagonTestingFixtures();
+    }
+
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: wagon-commits-unsubscribe@xxxxxxxxxxxxxxxx
For additional commands, e-mail: wagon-commits-help@xxxxxxxxxxxxxxxx

<Prev in Thread] Current Thread [Next in Thread>
  • svn commit: r515353 [2/2] - in /maven/wagon/branches/wagon-1.x: ./ wagon-provider-api/ wagon-provider-test/ wagon-providers/wagon-file/ wagon-providers/wagon-file/src/main/java/org/apache/maven/wagon/providers/file/ wagon-providers/wagon-file/src/main/..., joakime <=