Author: markt
Date: Thu Jul  2 19:42:30 2015
New Revision: 1688896

URL: http://svn.apache.org/r1688896
Log:
Make the manifest of the exploded WAR available to resources extracted from 
that WAR.

Added:
    tomcat/trunk/test/webresources/dir1/META-INF/
    tomcat/trunk/test/webresources/dir1/META-INF/MANIFEST.MF   (with props)
Modified:
    tomcat/trunk/java/org/apache/catalina/webresources/DirResourceSet.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/LocalStrings.properties
    
tomcat/trunk/test/org/apache/catalina/webresources/AbstractTestResourceSet.java

Modified: tomcat/trunk/java/org/apache/catalina/webresources/DirResourceSet.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/webresources/DirResourceSet.java?rev=1688896&r1=1688895&r2=1688896&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/webresources/DirResourceSet.java 
(original)
+++ tomcat/trunk/java/org/apache/catalina/webresources/DirResourceSet.java Thu 
Jul  2 19:42:30 2015
@@ -17,10 +17,12 @@
 package org.apache.catalina.webresources;
 
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Set;
+import java.util.jar.Manifest;
 
 import org.apache.catalina.LifecycleException;
 import org.apache.catalina.WebResource;
@@ -28,12 +30,16 @@ 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.juli.logging.Log;
+import org.apache.juli.logging.LogFactory;
 
 /**
  * Represents a {@link org.apache.catalina.WebResourceSet} based on a 
directory.
  */
 public class DirResourceSet extends AbstractFileResourceSet {
 
+    private static final Log log = LogFactory.getLog(DirResourceSet.class);
+
     /**
      * A no argument constructor is required for this to work with the 
digester.
      */
@@ -102,7 +108,7 @@ public class DirResourceSet extends Abst
             if (f.isDirectory() && path.charAt(path.length() - 1) != '/') {
                 path = path + '/';
             }
-            return new FileResource(root, path, f, isReadOnly());
+            return new FileResource(root, path, f, isReadOnly(), 
getManifest());
         } else {
             return new EmptyResource(root, path);
         }
@@ -248,4 +254,22 @@ public class DirResourceSet extends Abst
                     getBase(), File.separator, getInternalPath()));
         }
     }
+
+    //-------------------------------------------------------- Lifecycle 
methods
+    @Override
+    protected void initInternal() throws LifecycleException {
+        super.initInternal();
+        // Is this an exploded web application?
+        if (getWebAppMount().equals("")) {
+            // Look for a manifest
+            File mf = file("META-INF/MANIFEST.MF", true);
+            if (mf != null && mf.isFile()) {
+                try (FileInputStream fis = new FileInputStream(mf)) {
+                    setManifest(new Manifest(fis));
+                } catch (IOException e) {
+                    log.warn(sm.getString("dirResourceSet.manifestFail", 
mf.getAbsolutePath()), e);
+                }
+            }
+        }
+    }
 }

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=1688896&r1=1688895&r2=1688896&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/webresources/FileResource.java 
(original)
+++ tomcat/trunk/java/org/apache/catalina/webresources/FileResource.java Thu 
Jul  2 19:42:30 2015
@@ -43,9 +43,10 @@ public class FileResource extends Abstra
     private final File resource;
     private final String name;
     private final boolean readOnly;
+    private final Manifest manifest;
 
     public FileResource(WebResourceRoot root, String webAppPath,
-            File resource, boolean readOnly) {
+            File resource, boolean readOnly, Manifest manifest) {
         super(root,webAppPath);
         this.resource = resource;
 
@@ -67,6 +68,7 @@ public class FileResource extends Abstra
         }
 
         this.readOnly = readOnly;
+        this.manifest = manifest;
     }
 
     @Override
@@ -218,7 +220,7 @@ public class FileResource extends Abstra
 
     @Override
     public Manifest getManifest() {
-        return null;
+        return manifest;
     }
 
     @Override

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=1688896&r1=1688895&r2=1688896&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/webresources/FileResourceSet.java 
(original)
+++ tomcat/trunk/java/org/apache/catalina/webresources/FileResourceSet.java Thu 
Jul  2 19:42:30 2015
@@ -84,7 +84,7 @@ public class FileResourceSet extends Abs
             if (f == null) {
                 return new EmptyResource(root, path);
             }
-            return new FileResource(root, path, f, isReadOnly());
+            return new FileResource(root, path, f, isReadOnly(), null);
         }
 
         if (path.charAt(path.length() - 1) != '/') {

Modified: 
tomcat/trunk/java/org/apache/catalina/webresources/LocalStrings.properties
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/webresources/LocalStrings.properties?rev=1688896&r1=1688895&r2=1688896&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/webresources/LocalStrings.properties 
(original)
+++ tomcat/trunk/java/org/apache/catalina/webresources/LocalStrings.properties 
Thu Jul  2 19:42:30 2015
@@ -25,6 +25,7 @@ cache.backgroundEvictFail=The background
 cache.objectMaxSizeTooBig=The value of [{0}]kB for objectMaxSize is larger 
than the limit of maxSize/20 so has been reduced to [{1}]kB
 cache.objectMaxSizeTooBigBytes=The value specified for the maximum object size 
to cache [{0}]kB is greater than Integer.MAX_VALUE bytes which is the maximum 
size that can be cached. The limit will be set to Integer.MAX_VALUE bytes.
 
+dirResourceSet.manifestFail=Failed to read manifest from [{0}]
 dirResourceSet.notDirectory=The directory specified by base and internal path 
[{0}]{1}[{2}] does not exist.
 dirResourceSet.writeExists=The target of the write already exists
 dirResourceSet.writeNpe=The input stream may not be null

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=1688896&r1=1688895&r2=1688896&view=diff
==============================================================================
--- 
tomcat/trunk/test/org/apache/catalina/webresources/AbstractTestResourceSet.java 
(original)
+++ 
tomcat/trunk/test/org/apache/catalina/webresources/AbstractTestResourceSet.java 
Thu Jul  2 19:42:30 2015
@@ -22,6 +22,7 @@ import java.io.InputStream;
 import java.net.URL;
 import java.util.HashSet;
 import java.util.Set;
+import java.util.jar.Manifest;
 
 import org.junit.After;
 import org.junit.Assert;
@@ -180,6 +181,7 @@ public abstract class AbstractTestResour
         optional.add(".svn");
         // Files visible in some tests only
         optional.add(getMount() + ".ignore-me.txt");
+        optional.add("META-INF");
 
         for (String result : results) {
             Assert.assertTrue(result,
@@ -273,6 +275,8 @@ public abstract class AbstractTestResour
         optional.add(getMount() + "/.svn/");
         // Files visible in some tests only
         optional.add(getMount() + "/.ignore-me.txt");
+        // Files visible in some configurations only
+        optional.add(getMount() + "/META-INF/");
 
         for (String result : results) {
             Assert.assertTrue(result,
@@ -500,6 +504,21 @@ public abstract class AbstractTestResour
         }
     }
 
+
+    // ----------------------------------------------------------- 
getManifest()
+
+    @Test
+    public final void testGetManifest() {
+        WebResource exists = resourceRoot.getResource(getMount() + 
"/d1/d1-f1.txt");
+        boolean manifestExists = 
resourceRoot.getResource("/META-INF/MANIFEST.MF").exists();
+        Manifest m = exists.getManifest();
+        if (getMount().equals("") && manifestExists) {
+            Assert.assertNotNull(m);
+        } else {
+            Assert.assertNull(m);
+        }
+    }
+
 
     // ------------------------------------------------------------ 
constructors
 

Added: tomcat/trunk/test/webresources/dir1/META-INF/MANIFEST.MF
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/webresources/dir1/META-INF/MANIFEST.MF?rev=1688896&view=auto
==============================================================================
--- tomcat/trunk/test/webresources/dir1/META-INF/MANIFEST.MF (added)
+++ tomcat/trunk/test/webresources/dir1/META-INF/MANIFEST.MF Thu Jul  2 
19:42:30 2015
@@ -0,0 +1,2 @@
+Manifest-Version: 1.0
+

Propchange: tomcat/trunk/test/webresources/dir1/META-INF/MANIFEST.MF
------------------------------------------------------------------------------
    svn:eol-style = native



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

Reply via email to