Author: ecki Date: Mon Jan 19 00:09:10 2015 New Revision: 1652881 URL: http://svn.apache.org/r1652881 Log: [VFS-557][webdav] avoid temp and empty directories after test
Added: commons/proper/vfs/trunk/core/src/test/resources/jcrweb.xml Modified: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/webdav/test/JackrabbitMain.java commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/webdav/test/WebdavProviderTestCase.java commons/proper/vfs/trunk/src/changes/changes.xml Modified: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/webdav/test/JackrabbitMain.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/webdav/test/JackrabbitMain.java?rev=1652881&r1=1652880&r2=1652881&view=diff ============================================================================== --- commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/webdav/test/JackrabbitMain.java (original) +++ commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/webdav/test/JackrabbitMain.java Mon Jan 19 00:09:10 2015 @@ -21,6 +21,8 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.net.URL; +import java.util.Collections; +import java.util.Enumeration; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.GnuParser; @@ -30,10 +32,14 @@ import org.apache.commons.cli.ParseExcep import org.apache.commons.io.IOUtils; import org.apache.jackrabbit.servlet.jackrabbit.JackrabbitRepositoryServlet; import org.apache.jackrabbit.standalone.Main; +import org.apache.log4j.AppenderSkeleton; +import org.apache.log4j.ConsoleAppender; import org.apache.log4j.FileAppender; import org.apache.log4j.Layout; +import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.apache.log4j.PatternLayout; +import org.apache.log4j.Priority; import org.mortbay.jetty.Connector; import org.mortbay.jetty.NCSARequestLog; import org.mortbay.jetty.Server; @@ -72,6 +78,10 @@ class JackrabbitMain private final Server server = new Server(); + private FileAppender jackrabbitAppender; + private FileAppender jettyAppender; + + public JackrabbitMain(final String[] args) throws ParseException { options.addOption("?", "help", false, "print this message"); @@ -133,22 +143,16 @@ class JackrabbitMain final Layout layout = new PatternLayout("%d{dd.MM.yyyy HH:mm:ss} *%-5p* %c{1}: %m%n"); final Logger jackrabbitLog = Logger.getRootLogger(); - jackrabbitLog.addAppender(new FileAppender(layout, new File(log, "jackrabbit.log").getPath())); + jackrabbitAppender = new FileAppender(layout, new File(log, "jackrabbit.log").getPath()); + jackrabbitAppender.setThreshold(Level.ALL); + jackrabbitLog.addAppender(jackrabbitAppender); final Logger jettyLog = Logger.getLogger("org.mortbay.log"); - jettyLog.addAppender(new FileAppender(layout, new File(log, "jetty.log").getPath())); + jettyAppender = new FileAppender(layout, new File(log, "jetty.log").getPath()); + jettyAppender.setThreshold(Level.ALL); + jettyLog.addAppender(jettyAppender); jettyLog.setAdditivity(false); - // if (command.hasOption("debug")) - // { - // jackrabbitLog.setLevel(Level.DEBUG); - // jettyLog.setLevel(Level.DEBUG); - // } else - // { - // jackrabbitLog.setLevel(Level.INFO); - // jettyLog.setLevel(Level.INFO); - // } - // System.setProperty("derby.stream.error.file", new File(log, "derby.log").getPath()); } @@ -175,12 +179,17 @@ class JackrabbitMain { webapp.setContextPath("/"); webapp.setWar(file.getPath()); + webapp.setClassLoader(JackrabbitMain.class.getClassLoader()); + // we use a modified web.xml which has some servlets remove (which produce random empty directories) + URL res = getResource("/jcrweb.xml"); + if (res != null) + webapp.setDescriptor(res.toString()); webapp.setExtractWAR(false); webapp.setTempDirectory(tmp); final ServletHolder servlet = new ServletHolder(JackrabbitRepositoryServlet.class); servlet.setInitOrder(1); - servlet.setInitParameter("repository.home", repository.getPath()); + servlet.setInitParameter("repository.home", repository.getAbsolutePath()); final String conf = command.getOptionValue("conf"); if (conf != null) { @@ -189,6 +198,17 @@ class JackrabbitMain webapp.addServlet(servlet, "/repository.properties"); } + /** Try to load a resource with various classloaders. */ + private URL getResource(String name) + { + URL res = Thread.currentThread().getContextClassLoader().getResource(name); + if (res == null) + { + res = getClass().getResource(name); + } + return res; // might be null + } + public void run() throws Exception { String defaultFile = "jackrabbit-standalone.jar"; @@ -218,7 +238,7 @@ class JackrabbitMain message("Welcome to Apache Jackrabbit!"); message("-------------------------------"); - final File repository = new File(command.getOptionValue("repo", "jackrabbit")); + final File repository = new File(command.getOptionValue("repo", "target/test/jackrabbit")); message("Using repository directory " + repository); repository.mkdirs(); final File tmp = new File(repository, "tmp"); @@ -234,6 +254,7 @@ class JackrabbitMain accessLog.setHandler(webapp); prepareAccessLog(log); server.setHandler(accessLog); + prepareConnector(); server.addConnector(connector); prepareShutdown(); @@ -259,7 +280,12 @@ class JackrabbitMain public void shutdown() throws Exception, InterruptedException { message("Shutting down the server..."); + server.setGracefulShutdown(5); server.stop(); + Logger.getRootLogger().removeAppender(jackrabbitAppender); + Logger.getLogger("org.mortbay.log").removeAppender(jettyAppender); + jackrabbitAppender.close(); + jettyAppender.close(); server.join(); message("-------------------------------"); message("Goodbye from Apache Jackrabbit!"); Modified: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/webdav/test/WebdavProviderTestCase.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/webdav/test/WebdavProviderTestCase.java?rev=1652881&r1=1652880&r2=1652881&view=diff ============================================================================== --- commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/webdav/test/WebdavProviderTestCase.java (original) +++ commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/webdav/test/WebdavProviderTestCase.java Mon Jan 19 00:09:10 2015 @@ -73,11 +73,13 @@ public class WebdavProviderTestCase exte private static boolean DEBUG = Boolean.getBoolean("WebdavProviderTestCase.Debug"); - public static File createTempDirectory() throws IOException + static File createTempDirectory() throws IOException { - final File tempFile; + // create base folder + final File base = new File("./target/test").getCanonicalFile(); + base.mkdirs(); - tempFile = File.createTempFile("WebdavProviderTestCase_", Long.toString(System.nanoTime())); + final File tempFile = File.createTempFile("WebdavProviderTestCase_", ".tmp", base); if (!tempFile.delete()) { @@ -89,6 +91,9 @@ public class WebdavProviderTestCase exte throw new IOException("Could not create temp directory: " + tempFile.getAbsolutePath()); } + if (DEBUG) + System.out.println("Working in " + tempFile); + return tempFile; } @@ -306,6 +311,13 @@ public class WebdavProviderTestCase exte JrMain.shutdown(); // WARN logged because one thread is still there, so clean up explicitly. MultiThreadedHttpConnectionManager.shutdownAll(); + + if (DEBUG) + { + message("Skipping cleanup of " + RepoDirectory); + return; + } + // Remove repo dir try { Added: commons/proper/vfs/trunk/core/src/test/resources/jcrweb.xml URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/resources/jcrweb.xml?rev=1652881&view=auto ============================================================================== --- commons/proper/vfs/trunk/core/src/test/resources/jcrweb.xml (added) +++ commons/proper/vfs/trunk/core/src/test/resources/jcrweb.xml Mon Jan 19 00:09:10 2015 @@ -0,0 +1,186 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. + --> + +<!-- Apache Commons VFS Note: + This file is from jackrabbit-standalone-1.6.5!WEB-INF/web.xml + Some servlets are removed or reconfigured to avoid cluttering directories. +--> + +<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd"> +<web-app> + <display-name>Apache Jackrabbit</display-name> + + <!-- ====================================================================== --> + <!-- R E P O S I T O R Y S E R V L E T --> + <!-- ====================================================================== --> + <servlet> + <servlet-name>Repository</servlet-name> + <servlet-class>org.apache.jackrabbit.j2ee.RepositoryAccessServlet</servlet-class> + + <init-param> + <param-name>repository.context.attribute.name</param-name> + <param-value>javax.jcr.Repository</param-value> + </init-param> + + <load-on-startup>2</load-on-startup> + </servlet> + + <!-- ====================================================================== --> + <!-- W E B D A V S E R V L E T --> + <!-- ====================================================================== --> + <servlet> + <servlet-name>Webdav</servlet-name> + <description> + The webdav servlet that connects HTTP request to the repository. + </description> + <servlet-class>org.apache.jackrabbit.j2ee.SimpleWebdavServlet</servlet-class> + + <init-param> + <param-name>resource-path-prefix</param-name> + <param-value>/repository</param-value> + <description> + defines the prefix for spooling resources out of the repository. + </description> + </init-param> + <init-param> + <param-name>resource-config</param-name> + <param-value>/WEB-INF/config.xml</param-value> + <description> + Defines various dav-resource configuration parameters. + </description> + </init-param> + <load-on-startup>3</load-on-startup> + </servlet> + + <!-- ====================================================================== --> + <!-- W E B D A V S E R V E R S E R V L E T --> + <!-- ====================================================================== --> + <servlet> + <servlet-name>JCRWebdavServer</servlet-name> + <description> + The servlet used to remote JCR calls over HTTP. + </description> + <servlet-class>org.apache.jackrabbit.j2ee.JcrRemotingServlet</servlet-class> + <init-param> + <param-name>missing-auth-mapping</param-name> + <param-value></param-value> + <description> + Defines how a missing authorization header should be handled. + 1) If this init-param is missing, a 401 response is generated. + This is suiteable for clients (eg. webdav clients) for which + sending a proper authorization header is not possible if the + server never sent a 401. + 2) If this init-param is present with an empty value, + null-credentials are returned, thus forcing an null login + on the repository. + 3) If this init-param has a 'user:password' value, the respective + simple credentials are generated. + </description> + </init-param> + <!-- + Optional parameter to define the value of the 'WWW-Authenticate' header + --> + <!-- + <init-param> + <param-name>authenticate-header</param-name> + <param-value>Basic realm="Jackrabbit Webdav Server"</param-value> + <description> + Defines the value of the 'WWW-Authenticate' header. + </description> + </init-param> + --> + <init-param> + <param-name>resource-path-prefix</param-name> + <param-value>/server</param-value> + <description> + defines the prefix for spooling resources out of the repository. + </description> + </init-param> + <!-- + Init parameters specific for JcrRemotingServlet + --> + <init-param> + <param-name>home</param-name> + <param-value>target/test/jackrabbit</param-value> + <description>JcrRemotingServlet: Optional home directory for JcrRemotingServlet temporary files (default: "jackrabbit")</description> + </init-param> + <init-param> + <param-name>rmi.enabled</param-name> + <param-value>false</param-value> + </init-param> + <!-- + <init-param> + <param-name>temp-directory</param-name> + <param-value></param-value> + <description>JcrRemotingServlet: Optional temporary directory name (under home, default: "tmp")</description> + </init-param> + <init-param> + <param-name>batchread-config</param-name> + <param-value>/WEB-INF/batchread.properties</param-value> + <description>JcrRemotingServlet: Optional mapping from node type names to default depth.</description> + </init-param> + --> + <load-on-startup>5</load-on-startup> + </servlet> + + <!-- ====================================================================== --> + <!-- R M I B I N D I N G S E R V L E T S --> + <!-- ====================================================================== --> +<!-- <servlet> + <servlet-name>RMI</servlet-name> + <servlet-class>org.apache.jackrabbit.servlet.remote.RMIRemoteBindingServlet</servlet-class> + <init-param> + <param-name>url</param-name> + <param-value>//localhost/jackrabbit.repository</param-value> + </init-param> + <load-on-startup>6</load-on-startup> + </servlet> +--> + <!-- ====================================================================== --> + <!-- S E R V L E T M A P P I N G --> + <!-- ====================================================================== --> + <servlet-mapping> + <servlet-name>Webdav</servlet-name> + <url-pattern>/repository/*</url-pattern> + </servlet-mapping> + <servlet-mapping> + <servlet-name>JCRWebdavServer</servlet-name> + <url-pattern>/server/*</url-pattern> + </servlet-mapping> +<!-- <servlet-mapping> + <servlet-name>RMI</servlet-name> + <url-pattern>/rmi</url-pattern> + </servlet-mapping>--> + + <!-- ====================================================================== --> + <!-- W E L C O M E F I L E S --> + <!-- ====================================================================== --> + <welcome-file-list> + <welcome-file>index.jsp</welcome-file> + </welcome-file-list> + + <error-page> + <exception-type>org.apache.jackrabbit.j2ee.JcrApiNotFoundException</exception-type> + <location>/error/classpath.jsp</location> + </error-page> + <error-page> + <exception-type>javax.jcr.RepositoryException</exception-type> + <location>/error/repository.jsp</location> + </error-page> + +</web-app> Modified: commons/proper/vfs/trunk/src/changes/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/src/changes/changes.xml?rev=1652881&r1=1652880&r2=1652881&view=diff ============================================================================== --- commons/proper/vfs/trunk/src/changes/changes.xml (original) +++ commons/proper/vfs/trunk/src/changes/changes.xml Mon Jan 19 00:09:10 2015 @@ -26,9 +26,14 @@ <!-- <action issue="VFS-443" dev="ggregory" type="update" due-to="nickallen"> --> <!-- [Local] Need an easy way to convert from a FileObject to a File. --> <!-- </action> --> + <action issue="VFS-557" dev="ecki" type="fix"> + [webdav][test] Create WebDav test directory in target/test. Avoid creating core/jackrabbit/tmp. + Logfiles of Jackrabbit are preserved when -DWebdavProviderTestCase.Debug=true is specified. + </action> <action issue="VFS-558" dev="ecki" type="fix"> Make moveTo() and getParent() work with CacheStrategy.ON_CALL. In case of FTP Provider it would lead otherwise to an UnsupportedOperationException. + </action> <action dev="ecki" type="fix"> [sandbox] RACRandomAccessFile is now in org.apache.commons.vfs2.util package (so sandbox has only one overlapping package). </action>