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 2013/11/05 00:54:37 UTC

svn commit: r1538809 - in /tomcat/trunk/java/org/apache/catalina: WebResourceRoot.java loader/WebappClassLoader.java webresources/StandardRoot.java

Author: markt
Date: Mon Nov  4 23:54:37 2013
New Revision: 1538809

URL: http://svn.apache.org/r1538809
Log:
Add getClassLoaderResources() support

Modified:
    tomcat/trunk/java/org/apache/catalina/WebResourceRoot.java
    tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java
    tomcat/trunk/java/org/apache/catalina/webresources/StandardRoot.java

Modified: tomcat/trunk/java/org/apache/catalina/WebResourceRoot.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/WebResourceRoot.java?rev=1538809&r1=1538808&r2=1538809&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/WebResourceRoot.java (original)
+++ tomcat/trunk/java/org/apache/catalina/WebResourceRoot.java Mon Nov  4 23:54:37 2013
@@ -96,7 +96,7 @@ public interface WebResourceRoot extends
     WebResource getResource(String path);
 
     /**
-     * Obtain the object(s) that represent the resource at the given path. Note
+     * Obtain the objects that represent the resource at the given path. Note
      * that the resource at that path may not exist. If the path does not
      * exist, the WebResource returned will be associated with the main
      * WebResourceSet. This will include all matches even if the resource would
@@ -106,7 +106,7 @@ public interface WebResourceRoot extends
      * @param path  The path for the resource of interest relative to the root
      *              of the web application. It must start with '/'.
      *
-     * @return  The object that represents the resource at the given path
+     * @return  The objects that represents the resource at the given path
      */
     WebResource[] getResources(String path);
 
@@ -127,6 +127,23 @@ public interface WebResourceRoot extends
     WebResource getClassLoaderResource(String path);
 
     /**
+     * Obtain the objects that represent the class loader resource at the given
+     * path. Note that the resource at that path may not exist. If the path does
+     * not exist, the WebResource returned will be associated with the main
+     * WebResourceSet. This will include all matches even if the resource would
+     * not normally be accessible (e.g. because it was overridden by another
+     * resource)
+     *
+     * @param path  The path for the class loader resource of interest relative
+     *              to the root of the class loader resources for the web
+     *              application. It must start with '/'.
+     *
+     * @return  The objects that represents the class loader resources at the
+     *          given path
+     */
+    WebResource[] getClassLoaderResources(String path);
+
+    /**
      * Obtain the list of the names of all of the files and directories located
      * in the specified directory.
      *

Modified: tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java?rev=1538809&r1=1538808&r2=1538809&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java (original)
+++ tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java Mon Nov  4 23:54:37 2013
@@ -1163,36 +1163,13 @@ public class WebappClassLoader extends U
 
         LinkedHashSet<URL> result = new LinkedHashSet<>();
 
-        int jarFilesLength = jarFiles.length;
-
-        // Looking at the repository
-        // TODO Add support to WebResourceRoot for looking up class loader
-        //      resoucres
-        WebResource[] webResources = resources.getResources("/WEB-INF/classes/" + name);
+        WebResource[] webResources = resources.getClassLoaderResources("/" + name);
         for (WebResource webResource : webResources) {
             if (webResource.exists()) {
                 result.add(webResource.getURL());
             }
         }
 
-        // Looking at the JAR files
-        synchronized (jarFiles) {
-            if (openJARs()) {
-                for (int i = 0; i < jarFilesLength; i++) {
-                    JarEntry jarEntry = jarFiles[i].getJarEntry(name);
-                    if (jarEntry != null) {
-                        try {
-                            String jarFakeUrl = getURI(jarRealFiles[i]).toString();
-                            jarFakeUrl = "jar:" + jarFakeUrl + "!/" + name;
-                            result.add(new URL(jarFakeUrl));
-                        } catch (MalformedURLException e) {
-                            // Ignore
-                        }
-                    }
-                }
-            }
-        }
-
         return Collections.enumeration(result);
     }
 
@@ -2832,17 +2809,18 @@ public class WebappClassLoader extends U
         if ((entry == null) && (notFoundResources.containsKey(name)))
             return null;
 
+        if (entry == null) {
+            synchronized (notFoundResources) {
+                notFoundResources.put(name, name);
+            }
+            return null;
+        }
+
         JarEntry jarEntry = null;
 
         synchronized (jarFiles) {
 
             try {
-                if (entry == null) {
-                    synchronized (notFoundResources) {
-                        notFoundResources.put(name, name);
-                    }
-                    return null;
-                }
 
                 /* Only cache the binary content if there is some content
                  * available and either:

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=1538809&r1=1538808&r2=1538809&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/webresources/StandardRoot.java (original)
+++ tomcat/trunk/java/org/apache/catalina/webresources/StandardRoot.java Mon Nov  4 23:54:37 2013
@@ -197,6 +197,15 @@ public class StandardRoot extends Lifecy
     }
 
 
+    @Override
+    public WebResource[] getClassLoaderResources(String path) {
+        if (path == null || path.length() == 0 || !path.startsWith("/")) {
+            throw new IllegalArgumentException();
+        }
+        return getResources("/WEB-INF/classes" + path, true);
+    }
+
+
     protected WebResource getResourceInternal(String path,
             boolean useClassLoaderResources) {
         WebResource result = null;
@@ -226,12 +235,17 @@ public class StandardRoot extends Lifecy
 
     @Override
     public WebResource[] getResources(String path) {
+        return getResources(path, false);
+    }
+
+    private WebResource[] getResources(String path,
+            boolean useClassLoaderResources) {
         checkState();
 
         ArrayList<WebResource> result = new ArrayList<>();
         for (ArrayList<WebResourceSet> list : allResources) {
             for (WebResourceSet webResourceSet : list) {
-                if (!webResourceSet.getClassLoaderOnly()) {
+                if (useClassLoaderResources || !webResourceSet.getClassLoaderOnly()) {
                     WebResource webResource = webResourceSet.getResource(path);
                     if (webResource.exists()) {
                         result.add(webResource);



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