You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2012/10/23 22:55:24 UTC

svn commit: r1401465 - in /tomcat/sandbox/trunk-resources: java/org/apache/catalina/ java/org/apache/catalina/webresources/ test/org/apache/catalina/webresources/ test/webresources/dir2/ test/webresources/dir2/d1/ test/webresources/dir2/d2/ webapps/doc...

Author: markt
Date: Tue Oct 23 20:55:23 2012
New Revision: 1401465

URL: http://svn.apache.org/viewvc?rev=1401465&view=rev
Log:
Add support for single File resources

Added:
    tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/FileResourceSet.java   (with props)
    tomcat/sandbox/trunk-resources/test/webresources/dir2/
    tomcat/sandbox/trunk-resources/test/webresources/dir2/d1/
    tomcat/sandbox/trunk-resources/test/webresources/dir2/d2/
Modified:
    tomcat/sandbox/trunk-resources/java/org/apache/catalina/WebResourceSet.java
    tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/DirResourceSet.java
    tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/StandardRoot.java
    tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/AbstractTestResourceSet.java
    tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/AbstractTestResourceSetMount.java
    tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestDirResourceSet.java
    tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestDirResourceSetInternal.java
    tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestDirResourceSetMount.java
    tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestJarResourceSet.java
    tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestJarResourceSetInternal.java
    tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestJarResourceSetMount.java
    tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TesterWebResourceRoot.java
    tomcat/sandbox/trunk-resources/webapps/docs/config/resources.xml

Modified: tomcat/sandbox/trunk-resources/java/org/apache/catalina/WebResourceSet.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/java/org/apache/catalina/WebResourceSet.java?rev=1401465&r1=1401464&r2=1401465&view=diff
==============================================================================
--- tomcat/sandbox/trunk-resources/java/org/apache/catalina/WebResourceSet.java (original)
+++ tomcat/sandbox/trunk-resources/java/org/apache/catalina/WebResourceSet.java Tue Oct 23 20:55:23 2012
@@ -73,7 +73,8 @@ public interface WebResourceSet extends 
 
     /**
      * Create a new resource at the requested path using the provided
-     * InputStream.
+     * InputStream. If a resource already exists at the provided path it will
+     * not be overwritten.
      *
      * @param path  The path to be used for the new Resource. It is relative to
      *              the root of the web application and must start with '/'.

Modified: tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/DirResourceSet.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/DirResourceSet.java?rev=1401465&r1=1401464&r2=1401465&view=diff
==============================================================================
--- tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/DirResourceSet.java (original)
+++ tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/DirResourceSet.java Tue Oct 23 20:55:23 2012
@@ -28,25 +28,17 @@ import org.apache.catalina.WebResourceRo
 import org.apache.catalina.WebResourceRoot.ResourceSetType;
 import org.apache.catalina.util.IOTools;
 import org.apache.catalina.util.ResourceSet;
-import org.apache.tomcat.util.http.RequestUtil;
 
 /**
  * Represents a {@link org.apache.catalina.WebResourceSet} based on a directory.
  */
-public class DirResourceSet extends AbstractResourceSet {
-
-    private static final String[] EMPTY_STRING_ARRAY = new String[0];
-
-    private final String internalPath;
-    private File fileBase;
-    private String absoluteBase;
-    private String canonicalBase;
+public class DirResourceSet extends AbstractFileResourceSet {
 
     /**
      * A no argument constructor is required for this to work with the digester.
      */
     public DirResourceSet() {
-        internalPath = "";
+        super("");
     }
 
     /**
@@ -69,10 +61,10 @@ public class DirResourceSet extends Abst
      */
     public DirResourceSet(WebResourceRoot root, String base, String webAppMount,
             String internalPath) {
+        super(internalPath);
         setRoot(root);
         setBase(base);
         setWebAppMount(webAppMount);
-        this.internalPath = internalPath;
 
         if (root.getContext().getAddWebinfClassesResources()) {
             File f = new File(base, internalPath);
@@ -209,89 +201,11 @@ public class DirResourceSet extends Abst
         return true;
     }
 
-    private File file(String name, boolean mustExist) {
-
-        File file = new File(fileBase, name);
-        if (file.exists() && file.canRead() || !mustExist) {
-
-            if (getRoot().getAllowLinking()) {
-                return file;
-            }
-
-            // Check that this file is located under the WebResourceSet's base
-            String canPath = null;
-            try {
-                canPath = file.getCanonicalPath();
-            } catch (IOException e) {
-                // Ignore
-            }
-            if (canPath == null)
-                return null;
-
-            if (!canPath.startsWith(canonicalBase)) {
-                return null;
-            }
-
-            // Case sensitivity check
-            // Note: We know the resource is located somewhere under base at
-            //       point. The purpose of this code is to check in a case
-            //       sensitive manner, the path to the resource under base
-            //       agrees with what was requested
-            String fileAbsPath = file.getAbsolutePath();
-            if (fileAbsPath.endsWith("."))
-                fileAbsPath = fileAbsPath + "/";
-            String absPath = normalize(fileAbsPath);
-            if ((absoluteBase.length() < absPath.length())
-                && (canonicalBase.length() < canPath.length())) {
-                absPath = absPath.substring(absoluteBase.length() + 1);
-                if (absPath.equals(""))
-                    absPath = "/";
-                canPath = canPath.substring(canonicalBase.length() + 1);
-                if (canPath.equals(""))
-                    canPath = "/";
-                if (!canPath.equals(absPath))
-                    return null;
-            }
-
-        } else {
-            return null;
-        }
-        return file;
-    }
-
-    /**
-     * Return a context-relative path, beginning with a "/", that represents
-     * the canonical version of the specified path after ".." and "." elements
-     * are resolved out.  If the specified path attempts to go outside the
-     * boundaries of the current context (i.e. too many ".." path elements
-     * are present), return <code>null</code> instead.
-     *
-     * @param path Path to be normalized
-     */
-    protected String normalize(String path) {
-        return RequestUtil.normalize(path, File.separatorChar == '/');
-    }
-
-    //-------------------------------------------------------- Lifecycle methods
     @Override
-    protected void initInternal() throws LifecycleException {
-
-        fileBase = new File(getBase(), internalPath);
-        if (fileBase.isDirectory() == false) {
+    protected void checkType(File file) {
+        if (file.isDirectory() == false) {
             throw new IllegalArgumentException(
                     "TODO-i18n: base/internalPath is not a directory");
         }
-
-        String absolutePath = fileBase.getAbsolutePath();
-        if (absolutePath.endsWith(".")) {
-            absolutePath = absolutePath + "/";
-        }
-        this.absoluteBase = normalize(absolutePath);
-
-        try {
-            this.canonicalBase = fileBase.getCanonicalPath();
-        } catch (IOException e) {
-            throw new IllegalArgumentException(e);
-        }
     }
 }

Added: tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/FileResourceSet.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/FileResourceSet.java?rev=1401465&view=auto
==============================================================================
--- tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/FileResourceSet.java (added)
+++ tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/FileResourceSet.java Tue Oct 23 20:55:23 2012
@@ -0,0 +1,152 @@
+/*
+ * 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.
+ */
+package org.apache.catalina.webresources;
+
+import java.io.File;
+import java.io.InputStream;
+import java.util.Set;
+
+import org.apache.catalina.LifecycleException;
+import org.apache.catalina.WebResource;
+import org.apache.catalina.WebResourceRoot;
+import org.apache.catalina.util.ResourceSet;
+
+/**
+ * Represents a {@link org.apache.catalina.WebResourceSet} based on a single
+ * file.
+ */
+public class FileResourceSet extends AbstractFileResourceSet {
+
+    /**
+     * A no argument constructor is required for this to work with the digester.
+     */
+    public FileResourceSet() {
+        super("");
+    }
+
+    /**
+     * Creates a new {@link org.apache.catalina.WebResourceSet} based on a
+     * file.
+     *
+     * @param root          The {@link WebResourceRoot} this new
+     *                          {@link org.apache.catalina.WebResourceSet} will
+     *                          be added to.
+     * @param base          The absolute path to the file on the file system
+     *                          from which the resource will be served.
+     * @param webAppMount   The path within the web application at which this
+     *                          {@link org.apache.catalina.WebResourceSet} will
+     *                          be mounted. For example, to add a directory of
+     *                          JARs to a web application, the directory would
+     *                          be mounted at "WEB-INF/lib/"
+     * @param internalPath  The path within this new {@link
+     *                          org.apache.catalina.WebResourceSet} where
+     *                          resources will be served from.
+     */
+    public FileResourceSet(WebResourceRoot root, String base, String webAppMount,
+            String internalPath) {
+        super(internalPath);
+        setRoot(root);
+        setBase(base);
+        setWebAppMount(webAppMount);
+
+        if (getRoot().getState().isAvailable()) {
+            try {
+                start();
+            } catch (LifecycleException e) {
+                throw new IllegalStateException(e);
+            }
+        }
+    }
+
+
+    @Override
+    public WebResource getResource(String path) {
+        checkPath(path);
+
+        String webAppMount = "/" + getWebAppMount();
+        WebResourceRoot root = getRoot();
+        if (path.equals(webAppMount)) {
+            File f = file("", true);
+            if (f == null) {
+                return new EmptyResource(root, path);
+            }
+            return new FileResource(root, f, path);
+        } else {
+            return new EmptyResource(root, path);
+        }
+    }
+
+    @Override
+    public String[] list(String path) {
+        checkPath(path);
+
+        if (path.charAt(path.length() - 1) != '/') {
+            path = path + "/";
+        }
+        String webappMount = "/" + getWebAppMount();
+
+        if (webappMount.startsWith(path)) {
+            webappMount = webappMount.substring(path.length());
+            if (webappMount.equals(fileBase.getName())) {
+                return new String[] {fileBase.getName()};
+            }
+        }
+        return EMPTY_STRING_ARRAY;
+    }
+
+    @Override
+    public Set<String> listWebAppPaths(String path) {
+        checkPath(path);
+
+        ResourceSet<String> result = new ResourceSet<>();
+
+        if (path.charAt(path.length() - 1) != '/') {
+            path = path + "/";
+        }
+        String webappMount = "/" + getWebAppMount();
+
+        if (webappMount.startsWith(path)) {
+            webappMount = webappMount.substring(path.length());
+            if (webappMount.equals(fileBase.getName())) {
+                result.add(path + fileBase.getName());
+            }
+        }
+
+        result.setLocked(true);
+        return result;
+    }
+
+    @Override
+    public boolean mkdir(String path) {
+        checkPath(path);
+        return false;
+    }
+
+    @Override
+    public boolean write(String path, InputStream is) {
+        checkPath(path);
+        return false;
+    }
+
+    @Override
+    protected void checkType(File file) {
+        if (file.isFile() == false) {
+            throw new IllegalArgumentException(
+                    "TODO-i18n: base/internalPath is not a file");
+        }
+    }
+}

Propchange: tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/FileResourceSet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/StandardRoot.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/StandardRoot.java?rev=1401465&r1=1401464&r2=1401465&view=diff
==============================================================================
--- tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/StandardRoot.java (original)
+++ tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/StandardRoot.java Tue Oct 23 20:55:23 2012
@@ -258,8 +258,8 @@ public class StandardRoot extends Lifecy
                 resourceSet = new JarResourceSet(this, base, webAppPath,
                         internalPath);
             } else {
-                throw new UnsupportedOperationException(
-                        sm.getString("standardRoot.createNoFileResourceSet"));
+                resourceSet = new FileResourceSet(this, base, webAppPath,
+                        internalPath);
             }
         } else if (file.isDirectory()) {
             resourceSet =

Modified: tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/AbstractTestResourceSet.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/AbstractTestResourceSet.java?rev=1401465&r1=1401464&r2=1401465&view=diff
==============================================================================
--- tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/AbstractTestResourceSet.java (original)
+++ tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/AbstractTestResourceSet.java Tue Oct 23 20:55:23 2012
@@ -29,41 +29,43 @@ import org.junit.Test;
 
 import org.apache.catalina.LifecycleException;
 import org.apache.catalina.WebResource;
-import org.apache.catalina.WebResourceSet;
+import org.apache.catalina.WebResourceRoot;
 
 public abstract class AbstractTestResourceSet {
 
-    protected WebResourceSet resourceSet;
+    protected WebResourceRoot resourceRoot;
 
-    protected abstract WebResourceSet getWebResourceSet();
+    protected abstract WebResourceRoot getWebResourceRoot();
     protected abstract boolean isWriteable();
 
     public String getMount() {
         return "";
     }
 
+    public abstract String getBaseDir();
+
     @Before
     public final void setup() throws LifecycleException {
-        resourceSet = getWebResourceSet();
-        resourceSet.start();
+        resourceRoot = getWebResourceRoot();
+        resourceRoot.start();
     }
 
     @After
     public final void teardown() throws LifecycleException {
-        resourceSet.stop();
-        resourceSet.destroy();
+        resourceRoot.stop();
+        resourceRoot.destroy();
     }
 
     @Test(expected = IllegalArgumentException.class)
     public final void testGetResourceEmpty() {
-        resourceSet.getResource("");
+        resourceRoot.getResource("");
     }
 
     //------------------------------------------------------------ getResource()
 
     @Test
     public final void testGetResourceRoot() {
-        WebResource webResource = resourceSet.getResource(getMount() + "/");
+        WebResource webResource = resourceRoot.getResource(getMount() + "/");
         Assert.assertTrue(webResource.isDirectory());
         Assert.assertEquals("", webResource.getName());
         Assert.assertEquals(getMount() + "/", webResource.getWebappPath());
@@ -71,7 +73,7 @@ public abstract class AbstractTestResour
 
     @Test
     public final void testGetResourceDirA() {
-        WebResource webResource = resourceSet.getResource(getMount() + "/d1");
+        WebResource webResource = resourceRoot.getResource(getMount() + "/d1");
         Assert.assertTrue(webResource.isDirectory());
         Assert.assertEquals("d1", webResource.getName());
         Assert.assertEquals(getMount() + "/d1/", webResource.getWebappPath());
@@ -79,7 +81,7 @@ public abstract class AbstractTestResour
 
     @Test
     public final void testGetResourceDirB() {
-        WebResource webResource = resourceSet.getResource(getMount() + "/d1/");
+        WebResource webResource = resourceRoot.getResource(getMount() + "/d1/");
         Assert.assertTrue(webResource.isDirectory());
         Assert.assertEquals("d1", webResource.getName());
         Assert.assertEquals(getMount() + "/d1/", webResource.getWebappPath());
@@ -88,7 +90,7 @@ public abstract class AbstractTestResour
     @Test
     public final void testGetResourceFile() {
         WebResource webResource =
-                resourceSet.getResource(getMount() + "/d1/d1-f1.txt");
+                resourceRoot.getResource(getMount() + "/d1/d1-f1.txt");
         Assert.assertTrue(webResource.isFile());
         Assert.assertEquals("d1-f1.txt", webResource.getName());
         Assert.assertEquals(
@@ -99,12 +101,12 @@ public abstract class AbstractTestResour
 
     @Test(expected = IllegalArgumentException.class)
     public final void testListEmpty() {
-        resourceSet.list("");
+        resourceRoot.list("");
     }
 
     @Test
     public final void testListRoot() {
-        String[] results = resourceSet.list(getMount() + "/");
+        String[] results = resourceRoot.list(getMount() + "/");
 
         Set<String> expected = new HashSet<>();
         expected.add("d1");
@@ -120,7 +122,7 @@ public abstract class AbstractTestResour
 
     @Test
     public final void testListDirA() {
-        String[] results = resourceSet.list(getMount() + "/d1");
+        String[] results = resourceRoot.list(getMount() + "/d1");
 
         Set<String> expected = new HashSet<>();
         expected.add("d1-f1.txt");
@@ -133,7 +135,7 @@ public abstract class AbstractTestResour
 
     @Test
     public final void testListDirB() {
-        String[] results = resourceSet.list(getMount() + "/d1/");
+        String[] results = resourceRoot.list(getMount() + "/d1/");
 
         Set<String> expected = new HashSet<>();
         expected.add("d1-f1.txt");
@@ -146,7 +148,7 @@ public abstract class AbstractTestResour
 
     @Test
     public final void testListFile() {
-        String[] results = resourceSet.list(getMount() + "/d1/d1-f1.txt");
+        String[] results = resourceRoot.list(getMount() + "/d1/d1-f1.txt");
 
         Assert.assertNotNull(results);
         Assert.assertEquals(0, results.length);
@@ -156,12 +158,12 @@ public abstract class AbstractTestResour
 
     @Test(expected = IllegalArgumentException.class)
     public final void testListWebAppPathsEmpty() {
-        resourceSet.listWebAppPaths("");
+        resourceRoot.listWebAppPaths("");
     }
 
     @Test
     public final void testListWebAppPathsRoot() {
-        Set<String> results = resourceSet.listWebAppPaths(getMount() + "/");
+        Set<String> results = resourceRoot.listWebAppPaths(getMount() + "/");
 
         Set<String> expected = new HashSet<>();
         expected.add(getMount() + "/d1/");
@@ -177,7 +179,7 @@ public abstract class AbstractTestResour
 
     @Test
     public final void testListWebAppPathsDirA() {
-        Set<String> results = resourceSet.listWebAppPaths(getMount() + "/d1");
+        Set<String> results = resourceRoot.listWebAppPaths(getMount() + "/d1");
 
         Set<String> expected = new HashSet<>();
         expected.add(getMount() + "/d1/d1-f1.txt");
@@ -190,7 +192,7 @@ public abstract class AbstractTestResour
 
     @Test
     public final void testListWebAppPathsDirB() {
-        Set<String> results = resourceSet.listWebAppPaths(getMount() + "/d1/");
+        Set<String> results = resourceRoot.listWebAppPaths(getMount() + "/d1/");
 
         Set<String> expected = new HashSet<>();
         expected.add(getMount() + "/d1/d1-f1.txt");
@@ -204,48 +206,48 @@ public abstract class AbstractTestResour
     @Test
     public final void testListWebAppPathsFile() {
         Set<String> results =
-                resourceSet.listWebAppPaths(getMount() + "/d1/d1-f1.txt");
+                resourceRoot.listWebAppPaths(getMount() + "/d1/d1-f1.txt");
 
-        Assert.assertEquals(0, results.size());
+        Assert.assertNull(results);
     }
 
     //------------------------------------------------------------------ mkdir()
 
     @Test(expected = IllegalArgumentException.class)
     public final void testMkdirEmpty() {
-        resourceSet.mkdir("");
+        resourceRoot.mkdir("");
     }
 
     @Test
     public final void testMkdirRoot() {
-        Assert.assertFalse(resourceSet.mkdir(getMount() + "/"));
+        Assert.assertFalse(resourceRoot.mkdir(getMount() + "/"));
     }
 
     @Test
     public final void testMkdirDirA() {
-        Assert.assertFalse(resourceSet.mkdir(getMount() + "/d1"));
+        Assert.assertFalse(resourceRoot.mkdir(getMount() + "/d1"));
     }
 
     @Test
     public final void testMkdirDirB() {
-        Assert.assertFalse(resourceSet.mkdir(getMount() + "/d1/"));
+        Assert.assertFalse(resourceRoot.mkdir(getMount() + "/d1/"));
     }
 
     @Test
     public final void testMkdirFile() {
-        Assert.assertFalse(resourceSet.mkdir(getMount() + "/d1/d1-f1.txt"));
+        Assert.assertFalse(resourceRoot.mkdir(getMount() + "/d1/d1-f1.txt"));
     }
 
     @Test
     public final void testMkdirNew() {
         if (isWriteable()) {
-            Assert.assertTrue(resourceSet.mkdir(getMount() + "/new-test"));
+            Assert.assertTrue(resourceRoot.mkdir(getMount() + "/new-test"));
 
-            File file = new File("test/webresources/dir1/new-test");
+            File file = new File(getBaseDir(), "new-test");
             Assert.assertTrue(file.isDirectory());
             Assert.assertTrue(file.delete());
         } else {
-            Assert.assertFalse(resourceSet.mkdir(getMount() + "/new-test"));
+            Assert.assertFalse(resourceRoot.mkdir(getMount() + "/new-test"));
         }
     }
 
@@ -254,49 +256,48 @@ public abstract class AbstractTestResour
     @Test(expected = IllegalArgumentException.class)
     public final void testWriteEmpty() {
         InputStream is = new ByteArrayInputStream("test".getBytes());
-        resourceSet.write("", is);
+        resourceRoot.write("", is);
     }
 
     @Test
     public final void testWriteRoot() {
         InputStream is = new ByteArrayInputStream("test".getBytes());
-        Assert.assertFalse(resourceSet.write(getMount() + "/", is));
+        Assert.assertFalse(resourceRoot.write(getMount() + "/", is));
     }
 
     @Test
     public final void testWriteDirA() {
         InputStream is = new ByteArrayInputStream("test".getBytes());
-        Assert.assertFalse(resourceSet.write(getMount() + "/d1", is));
+        Assert.assertFalse(resourceRoot.write(getMount() + "/d1", is));
     }
 
     @Test
     public final void testWriteDirB() {
         InputStream is = new ByteArrayInputStream("test".getBytes());
-        Assert.assertFalse(resourceSet.write(getMount() + "/d1/", is));
+        Assert.assertFalse(resourceRoot.write(getMount() + "/d1/", is));
     }
 
     @Test
     public final void testWriteFile() {
         InputStream is = new ByteArrayInputStream("test".getBytes());
-        Assert.assertFalse(resourceSet.write(getMount() + "/d1/d1-f1.txt", is));
+        Assert.assertFalse(resourceRoot.write(getMount() + "/d1/d1-f1.txt", is));
     }
 
     @Test(expected = NullPointerException.class)
     public final void testWriteNew() {
-        resourceSet.write(getMount() + "/new-test", null);
+        resourceRoot.write(getMount() + "/new-test", null);
     }
 
     @Test
     public final void testWrite() {
         InputStream is = new ByteArrayInputStream("test".getBytes());
         if (isWriteable()) {
-            Assert.assertTrue(resourceSet.write(getMount() + "/new-test", is));
-
-            File file = new File("test/webresources/dir1/new-test");
+            Assert.assertTrue(resourceRoot.write(getMount() + "/new-test", is));
+            File file = new File(getBaseDir(), "new-test");
             Assert.assertTrue(file.exists());
             Assert.assertTrue(file.delete());
         } else {
-            Assert.assertFalse(resourceSet.write(getMount() + "/new-test", is));
+            Assert.assertFalse(resourceRoot.write(getMount() + "/new-test", is));
         }
     }
 }

Modified: tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/AbstractTestResourceSetMount.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/AbstractTestResourceSetMount.java?rev=1401465&r1=1401464&r2=1401465&view=diff
==============================================================================
--- tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/AbstractTestResourceSetMount.java (original)
+++ tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/AbstractTestResourceSetMount.java Tue Oct 23 20:55:23 2012
@@ -35,13 +35,13 @@ public abstract class AbstractTestResour
 
     @Test
     public final void testGetResourceAbove() {
-        WebResource webResource = resourceSet.getResource("/");
+        WebResource webResource = resourceRoot.getResource("/");
         Assert.assertFalse(webResource.exists());
     }
 
     @Test
     public final void testListAbove() {
-        String[] results = resourceSet.list("/");
+        String[] results = resourceRoot.list("/");
 
         Assert.assertNotNull(results);
         Assert.assertEquals(0, results.length);
@@ -49,19 +49,19 @@ public abstract class AbstractTestResour
 
     @Test
     public final void testListWebAppPathsAbove() {
-        Set<String> results = resourceSet.listWebAppPaths("/");
+        Set<String> results = resourceRoot.listWebAppPaths("/");
 
-        Assert.assertEquals(0, results.size());
+        Assert.assertNull(results);
     }
 
     @Test
     public void testMkdirAbove() {
-        Assert.assertFalse(resourceSet.mkdir("/"));
+        Assert.assertFalse(resourceRoot.mkdir("/"));
     }
 
     @Test
     public void testWriteAbove() {
         InputStream is = new ByteArrayInputStream("test".getBytes());
-        Assert.assertFalse(resourceSet.write("/", is));
+        Assert.assertFalse(resourceRoot.write("/", is));
     }
 }

Modified: tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestDirResourceSet.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestDirResourceSet.java?rev=1401465&r1=1401464&r2=1401465&view=diff
==============================================================================
--- tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestDirResourceSet.java (original)
+++ tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestDirResourceSet.java Tue Oct 23 20:55:23 2012
@@ -18,19 +18,29 @@ package org.apache.catalina.webresources
 
 import java.io.File;
 
+import org.apache.catalina.WebResourceRoot;
 import org.apache.catalina.WebResourceSet;
 
 public class TestDirResourceSet extends AbstractTestResourceSet {
 
     @Override
-    public WebResourceSet getWebResourceSet() {
-        File f = new File("test/webresources/dir1");
-        return new DirResourceSet(new TesterWebResourceRoot(),
-                f.getAbsolutePath(), "", "");
+    public WebResourceRoot getWebResourceRoot() {
+        File f = new File(getBaseDir());
+        TesterWebResourceRoot root = new TesterWebResourceRoot();
+        WebResourceSet webResourceSet =
+                new DirResourceSet(new TesterWebResourceRoot(),
+                        f.getAbsolutePath(), "", "");
+        root.setWebResourceSet(webResourceSet);
+        return root;
     }
 
     @Override
     protected boolean isWriteable() {
         return true;
     }
+
+    @Override
+    public String getBaseDir() {
+        return "test/webresources/dir1";
+    }
 }

Modified: tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestDirResourceSetInternal.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestDirResourceSetInternal.java?rev=1401465&r1=1401464&r2=1401465&view=diff
==============================================================================
--- tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestDirResourceSetInternal.java (original)
+++ tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestDirResourceSetInternal.java Tue Oct 23 20:55:23 2012
@@ -18,14 +18,19 @@ package org.apache.catalina.webresources
 
 import java.io.File;
 
+import org.apache.catalina.WebResourceRoot;
 import org.apache.catalina.WebResourceSet;
 
 public class TestDirResourceSetInternal extends TestDirResourceSet {
 
     @Override
-    public WebResourceSet getWebResourceSet() {
+    public WebResourceRoot getWebResourceRoot() {
         File f = new File("test/");
-        return new DirResourceSet(new TesterWebResourceRoot(),
-                f.getAbsolutePath(), "", "webresources/dir1");
+        TesterWebResourceRoot root = new TesterWebResourceRoot();
+        WebResourceSet webResourceSet =
+                new DirResourceSet(new TesterWebResourceRoot(),
+                        f.getAbsolutePath(), "", "webresources/dir1");
+        root.setWebResourceSet(webResourceSet);
+        return root;
     }
 }

Modified: tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestDirResourceSetMount.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestDirResourceSetMount.java?rev=1401465&r1=1401464&r2=1401465&view=diff
==============================================================================
--- tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestDirResourceSetMount.java (original)
+++ tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestDirResourceSetMount.java Tue Oct 23 20:55:23 2012
@@ -18,19 +18,29 @@ package org.apache.catalina.webresources
 
 import java.io.File;
 
+import org.apache.catalina.WebResourceRoot;
 import org.apache.catalina.WebResourceSet;
 
 public class TestDirResourceSetMount extends AbstractTestResourceSetMount {
 
     @Override
-    public WebResourceSet getWebResourceSet() {
-        File f = new File("test/webresources/dir1");
-        return new DirResourceSet(new TesterWebResourceRoot(),
-                f.getAbsolutePath(), "/mount", "");
+    public WebResourceRoot getWebResourceRoot() {
+        File f = new File(getBaseDir());
+        TesterWebResourceRoot root = new TesterWebResourceRoot();
+        WebResourceSet webResourceSet =
+                new DirResourceSet(new TesterWebResourceRoot(),
+                        f.getAbsolutePath(), "/mount", "");
+        root.setWebResourceSet(webResourceSet);
+        return root;
     }
 
     @Override
     protected boolean isWriteable() {
         return true;
     }
+
+    @Override
+    public String getBaseDir() {
+        return "test/webresources/dir1";
+    }
 }

Modified: tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestJarResourceSet.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestJarResourceSet.java?rev=1401465&r1=1401464&r2=1401465&view=diff
==============================================================================
--- tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestJarResourceSet.java (original)
+++ tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestJarResourceSet.java Tue Oct 23 20:55:23 2012
@@ -18,19 +18,28 @@ package org.apache.catalina.webresources
 
 import java.io.File;
 
+import org.apache.catalina.WebResourceRoot;
 import org.apache.catalina.WebResourceSet;
 
 public class TestJarResourceSet extends AbstractTestResourceSet {
 
     @Override
-    public WebResourceSet getWebResourceSet() {
+    public WebResourceRoot getWebResourceRoot() {
         File f = new File("test/webresources/dir1.jar");
-        return new JarResourceSet(
-                new TesterWebResourceRoot(), f.getAbsolutePath(), "", "");
+        TesterWebResourceRoot root = new TesterWebResourceRoot();
+        WebResourceSet webResourceSet =
+                new JarResourceSet(root, f.getAbsolutePath(), "", "");
+        root.setWebResourceSet(webResourceSet);
+        return root;
     }
 
     @Override
     protected boolean isWriteable() {
         return false;
     }
+
+    @Override
+    public String getBaseDir() {
+        return "test/webresources";
+    }
 }

Modified: tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestJarResourceSetInternal.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestJarResourceSetInternal.java?rev=1401465&r1=1401464&r2=1401465&view=diff
==============================================================================
--- tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestJarResourceSetInternal.java (original)
+++ tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestJarResourceSetInternal.java Tue Oct 23 20:55:23 2012
@@ -18,18 +18,28 @@ package org.apache.catalina.webresources
 
 import java.io.File;
 
+import org.apache.catalina.WebResourceRoot;
 import org.apache.catalina.WebResourceSet;
 
 public class TestJarResourceSetInternal extends AbstractTestResourceSet {
+
     @Override
-    public WebResourceSet getWebResourceSet() {
+    public WebResourceRoot getWebResourceRoot() {
         File f = new File("test/webresources/dir1-internal.jar");
-        return new JarResourceSet(
-                new TesterWebResourceRoot(), f.getAbsolutePath(), "", "/dir1");
+        TesterWebResourceRoot root = new TesterWebResourceRoot();
+        WebResourceSet webResourceSet =
+                new JarResourceSet(root, f.getAbsolutePath(), "", "/dir1");
+        root.setWebResourceSet(webResourceSet);
+        return root;
     }
 
     @Override
     protected boolean isWriteable() {
         return false;
     }
+
+    @Override
+    public String getBaseDir() {
+        return "test/webresources";
+    }
 }

Modified: tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestJarResourceSetMount.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestJarResourceSetMount.java?rev=1401465&r1=1401464&r2=1401465&view=diff
==============================================================================
--- tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestJarResourceSetMount.java (original)
+++ tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestJarResourceSetMount.java Tue Oct 23 20:55:23 2012
@@ -18,19 +18,28 @@ package org.apache.catalina.webresources
 
 import java.io.File;
 
+import org.apache.catalina.WebResourceRoot;
 import org.apache.catalina.WebResourceSet;
 
 public class TestJarResourceSetMount extends AbstractTestResourceSetMount {
 
     @Override
-    public WebResourceSet getWebResourceSet() {
+    public WebResourceRoot getWebResourceRoot() {
         File f = new File("test/webresources/dir1.jar");
-        return new JarResourceSet(
-                new TesterWebResourceRoot(), f.getAbsolutePath(), "/mount", "");
+        TesterWebResourceRoot root = new TesterWebResourceRoot();
+        WebResourceSet webResourceSet =
+                new JarResourceSet(root, f.getAbsolutePath(), "/mount", "");
+        root.setWebResourceSet(webResourceSet);
+        return root;
     }
 
     @Override
     protected boolean isWriteable() {
         return false;
     }
+
+    @Override
+    public String getBaseDir() {
+        return "test/webresources";
+    }
 }

Modified: tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TesterWebResourceRoot.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TesterWebResourceRoot.java?rev=1401465&r1=1401464&r2=1401465&view=diff
==============================================================================
--- tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TesterWebResourceRoot.java (original)
+++ tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TesterWebResourceRoot.java Tue Oct 23 20:55:23 2012
@@ -18,6 +18,9 @@ package org.apache.catalina.webresources
 
 import java.io.InputStream;
 import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
 
 import org.apache.catalina.Context;
@@ -30,10 +33,19 @@ import org.apache.catalina.WebResourceSe
 import org.apache.catalina.core.TesterContext;
 
 /**
- * Minimal implementation for use in unit tests.
+ * Minimal implementation for use in unit tests that supports main and pre
+ * resources.
  */
 public class TesterWebResourceRoot implements WebResourceRoot {
 
+    private WebResourceSet main;
+
+    private List<WebResourceSet> resources = new ArrayList<>();
+
+    public void setWebResourceSet(WebResourceSet main) {
+        this.main = main;
+    }
+
     @Override
     public void addLifecycleListener(LifecycleListener listener) {
         // NO-OP
@@ -56,7 +68,7 @@ public class TesterWebResourceRoot imple
 
     @Override
     public void start() throws LifecycleException {
-        // NO-OP
+        resources.add(main);
     }
 
     @Override
@@ -81,7 +93,16 @@ public class TesterWebResourceRoot imple
 
     @Override
     public WebResource getResource(String path) {
-        return null;
+        WebResource result = null;
+        for (WebResourceSet webResourceSet : resources) {
+            result = webResourceSet.getResource(path);
+            if (result.exists()) {
+                return result;
+            }
+        }
+
+        // Default is empty resource in main resources
+        return new EmptyResource(this, path);
     }
 
     @Override
@@ -91,12 +112,28 @@ public class TesterWebResourceRoot imple
 
     @Override
     public String[] list(String path) {
-        return null;
+        // Set because we don't want duplicates
+        HashSet<String> result = new HashSet<>();
+        for (WebResourceSet webResourceSet : resources) {
+            String[] entries = webResourceSet.list(path);
+            for (String entry : entries) {
+                result.add(entry);
+            }
+        }
+        return result.toArray(new String[result.size()]);
     }
 
     @Override
     public Set<String> listWebAppPaths(String path) {
-        return null;
+        // Set because we don't want duplicates
+        HashSet<String> result = new HashSet<>();
+        for (WebResourceSet webResourceSet : resources) {
+            result.addAll(webResourceSet.listWebAppPaths(path));
+        }
+        if (result.size() == 0 && !getResource(path).isDirectory()) {
+            return null;
+        }
+        return result;
     }
 
     @Override
@@ -106,12 +143,20 @@ public class TesterWebResourceRoot imple
 
     @Override
     public boolean mkdir(String path) {
-        return false;
+        if (getResource(path).exists()) {
+            return false;
+        }
+
+        return main.mkdir(path);
     }
 
     @Override
     public boolean write(String path, InputStream is) {
-        return false;
+        if (getResource(path).exists()) {
+            return false;
+        }
+
+        return main.write(path, is);
     }
 
     @Override
@@ -188,7 +233,7 @@ public class TesterWebResourceRoot imple
 
     @Override
     public void addPreResources(WebResourceSet webResourceSet) {
-        // NO-OP
+        resources.add(webResourceSet);
     }
 
     @Override

Modified: tomcat/sandbox/trunk-resources/webapps/docs/config/resources.xml
URL: http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/webapps/docs/config/resources.xml?rev=1401465&r1=1401464&r2=1401465&view=diff
==============================================================================
--- tomcat/sandbox/trunk-resources/webapps/docs/config/resources.xml (original)
+++ tomcat/sandbox/trunk-resources/webapps/docs/config/resources.xml Tue Oct 23 20:55:23 2012
@@ -29,7 +29,7 @@
 <body>
 
 <section name="Table of Contents">
-<toc/>
+<toc />
 </section>
 
 <section name="Introduction">
@@ -111,16 +111,17 @@
       <p>Identifies where the resources to be used are located. This attribute
       is required by the <code>org.apache.catalina.WebResourceSet</code>
       implementations provided by Tomcat and should specify the absolute path to
-      the directory or JAR where the resources are located. Custom
+      the file, directory or JAR where the resources are located. Custom
       implementations may not require it.</p>
     </attribute>
 
     <attribute name="className" required="true">
       <p>Java class name of the implementation to use. This class must
       implement the <code>org.apache.catalina.WebResourceSet</code> interface.
-      Tomcat provides two standard implementations:
-      <code>org.apache.catalina.webresources.DirResourceSet</code> and
-      <code>org.apache.catalina.webresources.JarrResourceSet</code>. Custom
+      Tomcat provides three standard implementations:
+      <code>org.apache.catalina.webresources.DirResourceSet</code>,
+      <code>org.apache.catalina.webresources.FileResourceSet</code> and
+      <code>org.apache.catalina.webresources.JarResourceSet</code>. Custom
       implementations may also be used.
       </p>
     </attribute>



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org