From 5a3192b85dc89b48f30ac088ddfce9774f6b49e7 Mon Sep 17 00:00:00 2001 From: James William Dumay Date: Tue, 3 Jun 2008 08:23:06 +0000 Subject: [PATCH] MRM-781 - Removal of Archiva-Webdav implementation in favor of Jackrabbit-webdav * Implementing litmus compatible removeMember() (DELETE) * Unit tests git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@662691 13f79535-47bb-0310-9956-ffa450edef68 --- .../archiva/webdav/ArchivaDavResource.java | 37 ++++++---------- .../maven/archiva/webdav/DavResourceTest.java | 44 ++++++++++++++++++- 2 files changed, 57 insertions(+), 24 deletions(-) diff --git a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResource.java b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResource.java index 7d0efa9f4..78c1b0c8f 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResource.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResource.java @@ -307,37 +307,28 @@ public class ArchivaDavResource throws DavException { File resource = checkDavResourceIsArchivaDavResource( member ).getLocalResource(); - - if ( !resource.exists() ) - { - throw new DavException( HttpServletResponse.SC_NOT_FOUND, member.getResourcePath() ); - } - - boolean suceeded = false; - - if ( resource.isDirectory() ) + + if ( resource.exists() ) { try { - FileUtils.deleteDirectory( resource ); - suceeded = true; + if ( resource.isDirectory() ) + { + FileUtils.deleteDirectory(resource); + } + else + { + if (!resource.delete()) + { + throw new IOException("Could not remove file"); + } + } } catch ( IOException e ) { - throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e ); + throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR ); } } - - if ( !suceeded && resource.isFile() ) - { - suceeded = resource.delete(); - } - - if ( !suceeded ) - { - throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Could not delete resource " + - member.getResourcePath() ); - } } public void move( DavResource destination ) diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/DavResourceTest.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/DavResourceTest.java index 483aab675..46cd3af72 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/DavResourceTest.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/DavResourceTest.java @@ -23,6 +23,9 @@ import java.io.File; import org.apache.commons.io.FileUtils; import org.apache.jackrabbit.webdav.DavException; import org.apache.jackrabbit.webdav.DavResource; +import org.apache.jackrabbit.webdav.DavResourceFactory; +import org.apache.jackrabbit.webdav.DavResourceLocator; +import org.apache.jackrabbit.webdav.DavServletRequest; import org.apache.jackrabbit.webdav.DavServletResponse; import org.apache.jackrabbit.webdav.DavSession; import org.apache.jackrabbit.webdav.lock.ActiveLock; @@ -43,6 +46,8 @@ public class DavResourceTest extends PlexusInSpringTestCase private ArchivaDavResourceLocator resourceLocator; + private DavResourceFactory resourceFactory; + private File baseDir; private final String REPOPATH = "myresource.jar"; @@ -64,6 +69,7 @@ public class DavResourceTest extends PlexusInSpringTestCase baseDir.mkdirs(); myResource = new File(baseDir, "myresource.jar"); assertTrue("Could not create " + myResource.getAbsolutePath(), myResource.createNewFile()); + resourceFactory = new RootContextDavResourceFactory(); resourceLocator = (ArchivaDavResourceLocator)new ArchivaDavLocatorFactory().createResourceLocator("/", REPOPATH); resource = getDavResource(resourceLocator.getHref(false), myResource); lockManager = new SimpleLockManager(); @@ -81,7 +87,32 @@ public class DavResourceTest extends PlexusInSpringTestCase private DavResource getDavResource(String logicalPath, File file) { - return new ArchivaDavResource(file.getAbsolutePath(), logicalPath, mimeTypes, session, resourceLocator, null); + return new ArchivaDavResource(file.getAbsolutePath(), logicalPath, mimeTypes, session, resourceLocator, resourceFactory); + } + + public void testDeleteCollection() + throws Exception + { + File dir = new File(baseDir, "testdir"); + try + { + assertTrue(dir.mkdir()); + DavResource directoryResource = getDavResource("/testdir", dir); + directoryResource.getCollection().removeMember(directoryResource); + assertFalse(dir.exists()); + } + finally + { + FileUtils.deleteDirectory(dir); + } + } + + public void testDeleteResource() + throws Exception + { + assertTrue(myResource.exists()); + resource.getCollection().removeMember(resource); + assertFalse(myResource.exists()); } public void testIsLockable() @@ -232,4 +263,15 @@ public class DavResourceTest extends PlexusInSpringTestCase assertEquals(0, resource.getLocks().length); } + + private class RootContextDavResourceFactory implements DavResourceFactory + { + public DavResource createResource(DavResourceLocator locator, DavServletRequest request, DavServletResponse response) throws DavException { + throw new UnsupportedOperationException("Not supported yet."); + } + + public DavResource createResource(DavResourceLocator locator, DavSession session) throws DavException { + return new ArchivaDavResource(baseDir.getAbsolutePath(), "/", mimeTypes, session, resourceLocator, resourceFactory); + } + } } -- 2.39.5