Author: markt
Date: Tue Jan  8 16:18:22 2013
New Revision: 1430353

URL: http://svn.apache.org/viewvc?rev=1430353&view=rev
Log:
Adds support for Virtual resources to the FileResourceSet (it still needs to be 
added for the DirResourceSet). This will allow an application to full traverse 
the resource hierarchy including any non-main resources mounted under a 
directory structure that does not exist in the main resources.

Added:
    tomcat/trunk/java/org/apache/catalina/webresources/VirtualResource.java   
(with props)
    
tomcat/trunk/test/org/apache/catalina/webresources/TestFileResourceSetVirtual.java
   (with props)
    tomcat/trunk/test/webresources/dir3/
Modified:
    tomcat/trunk/java/org/apache/catalina/WebResource.java
    tomcat/trunk/java/org/apache/catalina/webresources/CachedResource.java
    tomcat/trunk/java/org/apache/catalina/webresources/EmptyResource.java
    tomcat/trunk/java/org/apache/catalina/webresources/FileResource.java
    tomcat/trunk/java/org/apache/catalina/webresources/FileResourceSet.java
    tomcat/trunk/java/org/apache/catalina/webresources/JarResource.java
    tomcat/trunk/java/org/apache/catalina/webresources/JarResourceRoot.java
    tomcat/trunk/java/org/apache/catalina/webresources/StandardRoot.java
    
tomcat/trunk/test/org/apache/catalina/webresources/AbstractTestResourceSet.java
    tomcat/trunk/test/org/apache/catalina/webresources/TestDirResourceSet.java
    
tomcat/trunk/test/org/apache/catalina/webresources/TestDirResourceSetInternal.java
    
tomcat/trunk/test/org/apache/catalina/webresources/TestDirResourceSetMount.java
    tomcat/trunk/test/org/apache/catalina/webresources/TestFileResourceSet.java
    tomcat/trunk/test/org/apache/catalina/webresources/TestJarResourceSet.java
    
tomcat/trunk/test/org/apache/catalina/webresources/TestJarResourceSetInternal.java
    
tomcat/trunk/test/org/apache/catalina/webresources/TestJarResourceSetMount.java
    
tomcat/trunk/test/org/apache/catalina/webresources/TesterWebResourceRoot.java

Modified: tomcat/trunk/java/org/apache/catalina/WebResource.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/WebResource.java?rev=1430353&r1=1430352&r2=1430353&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/WebResource.java (original)
+++ tomcat/trunk/java/org/apache/catalina/WebResource.java Tue Jan  8 16:18:22 
2013
@@ -41,6 +41,15 @@ public interface WebResource {
     boolean exists();
 
     /**
+     * Indicates if this resource is required for applications to correctly 
scan
+     * the file structure but that does not exist in either the main or any
+     * additional {@link WebResourceSet}. For example, if an external
+     * directory is mapped to /WEB-INF/lib in an otherwise empty web
+     * application, /WEB-INF will be represented as a virtual resource.
+     */
+    boolean isVirtual();
+
+    /**
      * See {@link java.io.File#isDirectory()}.
      */
     boolean isDirectory();

Modified: tomcat/trunk/java/org/apache/catalina/webresources/CachedResource.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/webresources/CachedResource.java?rev=1430353&r1=1430352&r2=1430353&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/webresources/CachedResource.java 
(original)
+++ tomcat/trunk/java/org/apache/catalina/webresources/CachedResource.java Tue 
Jan  8 16:18:22 2013
@@ -43,6 +43,7 @@ public class CachedResource implements W
     private volatile Boolean cachedIsFile = null;
     private volatile Boolean cachedIsDirectory = null;
     private volatile Boolean cachedExists = null;
+    private volatile Boolean cachedIsVirtual = null;
     private volatile Long cachedContentLength = null;
 
 
@@ -118,6 +119,16 @@ public class CachedResource implements W
     }
 
     @Override
+    public boolean isVirtual() {
+        Boolean cachedIsVirtual = this.cachedIsVirtual;
+        if (cachedIsVirtual == null) {
+            cachedIsVirtual = Boolean.valueOf(webResource.isVirtual());
+            this.cachedIsVirtual = cachedIsVirtual;
+        }
+        return cachedIsVirtual.booleanValue();
+    }
+
+    @Override
     public boolean isDirectory() {
         Boolean cachedIsDirectory = this.cachedIsDirectory;
         if (cachedIsDirectory == null) {

Modified: tomcat/trunk/java/org/apache/catalina/webresources/EmptyResource.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/webresources/EmptyResource.java?rev=1430353&r1=1430352&r2=1430353&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/webresources/EmptyResource.java 
(original)
+++ tomcat/trunk/java/org/apache/catalina/webresources/EmptyResource.java Tue 
Jan  8 16:18:22 2013
@@ -48,6 +48,11 @@ public class EmptyResource implements We
     }
 
     @Override
+    public boolean isVirtual() {
+        return false;
+    }
+
+    @Override
     public boolean isDirectory() {
         return false;
     }

Modified: tomcat/trunk/java/org/apache/catalina/webresources/FileResource.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/webresources/FileResource.java?rev=1430353&r1=1430352&r2=1430353&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/webresources/FileResource.java 
(original)
+++ tomcat/trunk/java/org/apache/catalina/webresources/FileResource.java Tue 
Jan  8 16:18:22 2013
@@ -75,6 +75,11 @@ public class FileResource extends Abstra
     }
 
     @Override
+    public boolean isVirtual() {
+        return false;
+    }
+
+    @Override
     public boolean isDirectory() {
         return resource.isDirectory();
     }

Modified: 
tomcat/trunk/java/org/apache/catalina/webresources/FileResourceSet.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/webresources/FileResourceSet.java?rev=1430353&r1=1430352&r2=1430353&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/webresources/FileResourceSet.java 
(original)
+++ tomcat/trunk/java/org/apache/catalina/webresources/FileResourceSet.java Tue 
Jan  8 16:18:22 2013
@@ -85,9 +85,20 @@ public class FileResourceSet extends Abs
                 return new EmptyResource(root, path);
             }
             return new FileResource(root, f, path);
-        } else {
-            return new EmptyResource(root, path);
         }
+
+        if (path.charAt(path.length() - 1) != '/') {
+            path = path + '/';
+        }
+
+        if (webAppMount.startsWith(path)) {
+            String name = path.substring(0, path.length() - 1);
+            name = name.substring(name.lastIndexOf('/') + 1);
+            if (name.length() > 0) {
+                return new VirtualResource(root, path, name);
+            }
+        }
+        return new EmptyResource(root, path);
     }
 
     @Override
@@ -97,14 +108,21 @@ public class FileResourceSet extends Abs
         if (path.charAt(path.length() - 1) != '/') {
             path = path + '/';
         }
-        String webappMount = getWebAppMount();
+        String webAppMount = getWebAppMount();
 
-        if (webappMount.startsWith(path)) {
-            webappMount = webappMount.substring(path.length());
-            if (webappMount.equals(fileBase.getName())) {
+        if (webAppMount.startsWith(path)) {
+            webAppMount = webAppMount.substring(path.length());
+            if (webAppMount.equals(fileBase.getName())) {
                 return new String[] {fileBase.getName()};
+            } else {
+                // Virtual directory
+                int i = webAppMount.indexOf('/');
+                if (i > 0) {
+                    return new String[] {webAppMount.substring(0, i)};
+                }
             }
         }
+
         return EMPTY_STRING_ARRAY;
     }
 
@@ -117,12 +135,18 @@ public class FileResourceSet extends Abs
         if (path.charAt(path.length() - 1) != '/') {
             path = path + '/';
         }
-        String webappMount = getWebAppMount();
+        String webAppMount = getWebAppMount();
 
-        if (webappMount.startsWith(path)) {
-            webappMount = webappMount.substring(path.length());
-            if (webappMount.equals(fileBase.getName())) {
+        if (webAppMount.startsWith(path)) {
+            webAppMount = webAppMount.substring(path.length());
+            if (webAppMount.equals(fileBase.getName())) {
                 result.add(path + fileBase.getName());
+            } else {
+                // Virtual directory
+                int i = webAppMount.indexOf('/');
+                if (i > 0) {
+                    result.add(path + webAppMount.substring(0, i + 1));
+                }
             }
         }
 

Modified: tomcat/trunk/java/org/apache/catalina/webresources/JarResource.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/webresources/JarResource.java?rev=1430353&r1=1430352&r2=1430353&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/webresources/JarResource.java 
(original)
+++ tomcat/trunk/java/org/apache/catalina/webresources/JarResource.java Tue Jan 
 8 16:18:22 2013
@@ -75,6 +75,11 @@ public class JarResource extends Abstrac
     }
 
     @Override
+    public boolean isVirtual() {
+        return false;
+    }
+
+    @Override
     public boolean isDirectory() {
         return resource.isDirectory();
     }

Modified: 
tomcat/trunk/java/org/apache/catalina/webresources/JarResourceRoot.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/webresources/JarResourceRoot.java?rev=1430353&r1=1430352&r2=1430353&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/webresources/JarResourceRoot.java 
(original)
+++ tomcat/trunk/java/org/apache/catalina/webresources/JarResourceRoot.java Tue 
Jan  8 16:18:22 2013
@@ -50,6 +50,11 @@ public class JarResourceRoot extends Abs
     }
 
     @Override
+    public boolean isVirtual() {
+        return false;
+    }
+
+    @Override
     public boolean isDirectory() {
         return true;
     }

Modified: tomcat/trunk/java/org/apache/catalina/webresources/StandardRoot.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/webresources/StandardRoot.java?rev=1430353&r1=1430352&r2=1430353&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/webresources/StandardRoot.java 
(original)
+++ tomcat/trunk/java/org/apache/catalina/webresources/StandardRoot.java Tue 
Jan  8 16:18:22 2013
@@ -170,15 +170,24 @@ public class StandardRoot extends Lifecy
         checkState();
 
         WebResource result = null;
+        WebResource virtual = null;
         for (ArrayList<WebResourceSet> list : allResources) {
             for (WebResourceSet webResourceSet : list) {
                 result = webResourceSet.getResource(path);
                 if (result.exists()) {
                     return result;
                 }
+                if (virtual == null && result.isVirtual()) {
+                    virtual = result;
+                }
             }
         }
 
+        // Use the first virtual result if no real result was found
+        if (virtual != null) {
+            return virtual;
+        }
+
         // Default is empty resource in main resources
         return new EmptyResource(this, path);
     }
@@ -378,6 +387,15 @@ public class StandardRoot extends Lifecy
         return f.getAbsolutePath();
     }
 
+    /**
+     * For unit testing
+     */
+    protected void setMainResources(WebResourceSet main) {
+        this.main = main;
+        mainResources.clear();
+        mainResources.add(main);
+    }
+
     @Override
     public void backgroundProcess() {
         cache.backgroundProcess();

Added: tomcat/trunk/java/org/apache/catalina/webresources/VirtualResource.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/webresources/VirtualResource.java?rev=1430353&view=auto
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/webresources/VirtualResource.java 
(added)
+++ tomcat/trunk/java/org/apache/catalina/webresources/VirtualResource.java Tue 
Jan  8 16:18:22 2013
@@ -0,0 +1,45 @@
+/*
+ * 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 org.apache.catalina.WebResourceRoot;
+
+public class VirtualResource extends EmptyResource {
+
+    private final String name;
+
+    public VirtualResource(WebResourceRoot root, String webAppPath,
+            String name) {
+        super(root, webAppPath);
+        this.name = name;
+    }
+
+    @Override
+    public boolean isVirtual() {
+        return true;
+    }
+
+    @Override
+    public boolean isDirectory() {
+        return true;
+    }
+
+    @Override
+    public String getName() {
+        return name;
+    }
+}

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

Modified: 
tomcat/trunk/test/org/apache/catalina/webresources/AbstractTestResourceSet.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/webresources/AbstractTestResourceSet.java?rev=1430353&r1=1430352&r2=1430353&view=diff
==============================================================================
--- 
tomcat/trunk/test/org/apache/catalina/webresources/AbstractTestResourceSet.java 
(original)
+++ 
tomcat/trunk/test/org/apache/catalina/webresources/AbstractTestResourceSet.java 
Tue Jan  8 16:18:22 2013
@@ -225,12 +225,32 @@ public abstract class AbstractTestResour
 
     @Test
     public final void testMkdirDirA() {
-        Assert.assertFalse(resourceRoot.mkdir(getMount() + "/d1"));
+        WebResource d1 = resourceRoot.getResource(getMount() + "/d1");
+        if (d1.exists()) {
+            Assert.assertFalse(resourceRoot.mkdir(getMount() + "/d1"));
+        } else if (d1.isVirtual()) {
+            Assert.assertTrue(resourceRoot.mkdir(getMount() + "/d1"));
+            File file = new File(getBaseDir(), "d1");
+            Assert.assertTrue(file.isDirectory());
+            Assert.assertTrue(file.delete());
+        } else {
+            Assert.fail("Unhandled condition in unit test");
+        }
     }
 
     @Test
     public final void testMkdirDirB() {
-        Assert.assertFalse(resourceRoot.mkdir(getMount() + "/d1/"));
+        WebResource d1 = resourceRoot.getResource(getMount() + "/d1/");
+        if (d1.exists()) {
+            Assert.assertFalse(resourceRoot.mkdir(getMount() + "/d1/"));
+        } else if (d1.isVirtual()) {
+            Assert.assertTrue(resourceRoot.mkdir(getMount() + "/d1/"));
+            File file = new File(getBaseDir(), "d1");
+            Assert.assertTrue(file.isDirectory());
+            Assert.assertTrue(file.delete());
+        } else {
+            Assert.fail("Unhandled condition in unit test");
+        }
     }
 
     @Test
@@ -267,14 +287,36 @@ public abstract class AbstractTestResour
 
     @Test
     public final void testWriteDirA() {
+        WebResource d1 = resourceRoot.getResource(getMount() + "/d1");
         InputStream is = new ByteArrayInputStream("test".getBytes());
-        Assert.assertFalse(resourceRoot.write(getMount() + "/d1", is, false));
+        if (d1.exists()) {
+            Assert.assertFalse(resourceRoot.write(getMount() + "/d1", is, 
false));
+        } else if (d1.isVirtual()) {
+            Assert.assertTrue(resourceRoot.write(
+                    getMount() + "/d1", is, false));
+            File file = new File(getBaseDir(), "d1");
+            Assert.assertTrue(file.exists());
+            Assert.assertTrue(file.delete());
+        } else {
+            Assert.fail("Unhandled condition in unit test");
+        }
     }
 
     @Test
     public final void testWriteDirB() {
+        WebResource d1 = resourceRoot.getResource(getMount() + "/d1/");
         InputStream is = new ByteArrayInputStream("test".getBytes());
-        Assert.assertFalse(resourceRoot.write(getMount() + "/d1/", is, false));
+        if (d1.exists()) {
+            Assert.assertFalse(resourceRoot.write(getMount() + "/d1/", is, 
false));
+        } else if (d1.isVirtual()) {
+            Assert.assertTrue(resourceRoot.write(
+                    getMount() + "/d1/", is, false));
+            File file = new File(getBaseDir(), "d1");
+            Assert.assertTrue(file.exists());
+            Assert.assertTrue(file.delete());
+        } else {
+            Assert.fail("Unhandled condition in unit test");
+        }
     }
 
     @Test

Modified: 
tomcat/trunk/test/org/apache/catalina/webresources/TestDirResourceSet.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/webresources/TestDirResourceSet.java?rev=1430353&r1=1430352&r2=1430353&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/webresources/TestDirResourceSet.java 
(original)
+++ tomcat/trunk/test/org/apache/catalina/webresources/TestDirResourceSet.java 
Tue Jan  8 16:18:22 2013
@@ -30,7 +30,7 @@ public class TestDirResourceSet extends 
         WebResourceSet webResourceSet =
                 new DirResourceSet(new TesterWebResourceRoot(),
                         f.getAbsolutePath(), "/", "/");
-        root.setWebResourceSet(webResourceSet);
+        root.setMainResources(webResourceSet);
         return root;
     }
 

Modified: 
tomcat/trunk/test/org/apache/catalina/webresources/TestDirResourceSetInternal.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/webresources/TestDirResourceSetInternal.java?rev=1430353&r1=1430352&r2=1430353&view=diff
==============================================================================
--- 
tomcat/trunk/test/org/apache/catalina/webresources/TestDirResourceSetInternal.java
 (original)
+++ 
tomcat/trunk/test/org/apache/catalina/webresources/TestDirResourceSetInternal.java
 Tue Jan  8 16:18:22 2013
@@ -30,7 +30,7 @@ public class TestDirResourceSetInternal 
         WebResourceSet webResourceSet =
                 new DirResourceSet(new TesterWebResourceRoot(),
                         f.getAbsolutePath(), "/", "/webresources/dir1");
-        root.setWebResourceSet(webResourceSet);
+        root.setMainResources(webResourceSet);
         return root;
     }
 }

Modified: 
tomcat/trunk/test/org/apache/catalina/webresources/TestDirResourceSetMount.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/webresources/TestDirResourceSetMount.java?rev=1430353&r1=1430352&r2=1430353&view=diff
==============================================================================
--- 
tomcat/trunk/test/org/apache/catalina/webresources/TestDirResourceSetMount.java 
(original)
+++ 
tomcat/trunk/test/org/apache/catalina/webresources/TestDirResourceSetMount.java 
Tue Jan  8 16:18:22 2013
@@ -30,7 +30,7 @@ public class TestDirResourceSetMount ext
         WebResourceSet webResourceSet =
                 new DirResourceSet(new TesterWebResourceRoot(),
                         f.getAbsolutePath(), "/mount", "/");
-        root.setWebResourceSet(webResourceSet);
+        root.setMainResources(webResourceSet);
         return root;
     }
 

Modified: 
tomcat/trunk/test/org/apache/catalina/webresources/TestFileResourceSet.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/webresources/TestFileResourceSet.java?rev=1430353&r1=1430352&r2=1430353&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/webresources/TestFileResourceSet.java 
(original)
+++ tomcat/trunk/test/org/apache/catalina/webresources/TestFileResourceSet.java 
Tue Jan  8 16:18:22 2013
@@ -30,7 +30,7 @@ public class TestFileResourceSet extends
         WebResourceSet webResourceSet =
                 new DirResourceSet(new TesterWebResourceRoot(),
                         f.getAbsolutePath(), "/", "/");
-        root.setWebResourceSet(webResourceSet);
+        root.setMainResources(webResourceSet);
 
         WebResourceSet f1 = new FileResourceSet(root,
                 "test/webresources/dir1/f1.txt", "/f1.txt", "/");

Added: 
tomcat/trunk/test/org/apache/catalina/webresources/TestFileResourceSetVirtual.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/webresources/TestFileResourceSetVirtual.java?rev=1430353&view=auto
==============================================================================
--- 
tomcat/trunk/test/org/apache/catalina/webresources/TestFileResourceSetVirtual.java
 (added)
+++ 
tomcat/trunk/test/org/apache/catalina/webresources/TestFileResourceSetVirtual.java
 Tue Jan  8 16:18:22 2013
@@ -0,0 +1,30 @@
+/*
+ * 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;
+
+/**
+ * Mounts file resources in sub directories that do not exist in the main
+ * resoucres.
+ */
+public class TestFileResourceSetVirtual extends TestFileResourceSet {
+
+    @Override
+    public String getBaseDir() {
+        return "test/webresources/dir3";
+    }
+
+}

Propchange: 
tomcat/trunk/test/org/apache/catalina/webresources/TestFileResourceSetVirtual.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
tomcat/trunk/test/org/apache/catalina/webresources/TestJarResourceSet.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/webresources/TestJarResourceSet.java?rev=1430353&r1=1430352&r2=1430353&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/webresources/TestJarResourceSet.java 
(original)
+++ tomcat/trunk/test/org/apache/catalina/webresources/TestJarResourceSet.java 
Tue Jan  8 16:18:22 2013
@@ -29,7 +29,7 @@ public class TestJarResourceSet extends 
         TesterWebResourceRoot root = new TesterWebResourceRoot();
         WebResourceSet webResourceSet =
                 new JarResourceSet(root, f.getAbsolutePath(), "/", "/");
-        root.setWebResourceSet(webResourceSet);
+        root.setMainResources(webResourceSet);
         return root;
     }
 

Modified: 
tomcat/trunk/test/org/apache/catalina/webresources/TestJarResourceSetInternal.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/webresources/TestJarResourceSetInternal.java?rev=1430353&r1=1430352&r2=1430353&view=diff
==============================================================================
--- 
tomcat/trunk/test/org/apache/catalina/webresources/TestJarResourceSetInternal.java
 (original)
+++ 
tomcat/trunk/test/org/apache/catalina/webresources/TestJarResourceSetInternal.java
 Tue Jan  8 16:18:22 2013
@@ -29,7 +29,7 @@ public class TestJarResourceSetInternal 
         TesterWebResourceRoot root = new TesterWebResourceRoot();
         WebResourceSet webResourceSet =
                 new JarResourceSet(root, f.getAbsolutePath(), "/", "/dir1");
-        root.setWebResourceSet(webResourceSet);
+        root.setMainResources(webResourceSet);
         return root;
     }
 

Modified: 
tomcat/trunk/test/org/apache/catalina/webresources/TestJarResourceSetMount.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/webresources/TestJarResourceSetMount.java?rev=1430353&r1=1430352&r2=1430353&view=diff
==============================================================================
--- 
tomcat/trunk/test/org/apache/catalina/webresources/TestJarResourceSetMount.java 
(original)
+++ 
tomcat/trunk/test/org/apache/catalina/webresources/TestJarResourceSetMount.java 
Tue Jan  8 16:18:22 2013
@@ -29,7 +29,7 @@ public class TestJarResourceSetMount ext
         TesterWebResourceRoot root = new TesterWebResourceRoot();
         WebResourceSet webResourceSet =
                 new JarResourceSet(root, f.getAbsolutePath(), "/mount", "/");
-        root.setWebResourceSet(webResourceSet);
+        root.setMainResources(webResourceSet);
         return root;
     }
 

Modified: 
tomcat/trunk/test/org/apache/catalina/webresources/TesterWebResourceRoot.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/webresources/TesterWebResourceRoot.java?rev=1430353&r1=1430352&r2=1430353&view=diff
==============================================================================
--- 
tomcat/trunk/test/org/apache/catalina/webresources/TesterWebResourceRoot.java 
(original)
+++ 
tomcat/trunk/test/org/apache/catalina/webresources/TesterWebResourceRoot.java 
Tue Jan  8 16:18:22 2013
@@ -16,34 +16,23 @@
  */
 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;
 import org.apache.catalina.LifecycleException;
 import org.apache.catalina.LifecycleListener;
 import org.apache.catalina.LifecycleState;
-import org.apache.catalina.WebResource;
-import org.apache.catalina.WebResourceRoot;
-import org.apache.catalina.WebResourceSet;
 import org.apache.catalina.core.TesterContext;
 
 /**
  * Minimal implementation for use in unit tests that supports main and pre
  * resources.
  */
-public class TesterWebResourceRoot implements WebResourceRoot {
+public class TesterWebResourceRoot extends StandardRoot {
 
-    private WebResourceSet main;
-
-    private List<WebResourceSet> resources = new ArrayList<>();
-
-    public void setWebResourceSet(WebResourceSet main) {
-        this.main = main;
+    public TesterWebResourceRoot() {
+        super();
+        setCachingAllowed(false);
     }
 
     @Override
@@ -62,22 +51,22 @@ public class TesterWebResourceRoot imple
     }
 
     @Override
-    public void init() throws LifecycleException {
+    public void initInternal() throws LifecycleException {
         // NO-OP
     }
 
     @Override
-    public void start() throws LifecycleException {
-        resources.add(main);
+    public void startInternal() throws LifecycleException {
+        setState(LifecycleState.STARTING);
     }
 
     @Override
-    public void stop() throws LifecycleException {
-        // NO-OP
+    public void stopInternal() throws LifecycleException {
+        setState(LifecycleState.STOPPING);
     }
 
     @Override
-    public void destroy() throws LifecycleException {
+    public void destroyInternal() throws LifecycleException {
         // NO-OP
     }
 
@@ -92,74 +81,6 @@ public class TesterWebResourceRoot imple
     }
 
     @Override
-    public WebResource getResource(String path) {
-        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
-    public WebResource[] getResources(String path) {
-        return null;
-    }
-
-    @Override
-    public String[] list(String path) {
-        // 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) {
-        // 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
-    public WebResource[] listResources(String path) {
-        return null;
-    }
-
-    @Override
-    public boolean mkdir(String path) {
-        if (getResource(path).exists()) {
-            return false;
-        }
-
-        return main.mkdir(path);
-    }
-
-    @Override
-    public boolean write(String path, InputStream is, boolean overwrite) {
-        if (getResource(path).exists()) {
-            return false;
-        }
-
-        return main.write(path, is, false);
-    }
-
-    @Override
     public Context getContext() {
         return new TesterContext();
     }
@@ -232,21 +153,6 @@ public class TesterWebResourceRoot imple
     }
 
     @Override
-    public void addPreResources(WebResourceSet webResourceSet) {
-        resources.add(webResourceSet);
-    }
-
-    @Override
-    public void addJarResources(WebResourceSet webResourceSet) {
-        // NO-OP
-    }
-
-    @Override
-    public void addPostResources(WebResourceSet webResourceSet) {
-        // NO-OP
-    }
-
-    @Override
     public void backgroundProcess() {
         // NO-OP
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to