Author: markt
Date: Wed Jan 20 21:21:35 2016
New Revision: 1725816

URL: http://svn.apache.org/viewvc?rev=1725816&view=rev
Log:
Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=58867
Improve WAR modification checking on Host start

Modified:
    tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java
    
tomcat/trunk/test/org/apache/catalina/startup/TestHostConfigAutomaticDeployment.java
    tomcat/trunk/webapps/docs/changelog.xml

Modified: tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java?rev=1725816&r1=1725815&r2=1725816&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java Wed Jan 20 
21:21:35 2016
@@ -605,8 +605,7 @@ public class ContextConfig implements Li
         file = new File(docBase);
         String origDocBase = docBase;
 
-        ContextName cn = new ContextName(context.getPath(),
-                context.getWebappVersion());
+        ContextName cn = new ContextName(context.getPath(), 
context.getWebappVersion());
         String pathName = cn.getBaseName();
 
         boolean unpackWARs = true;
@@ -631,10 +630,21 @@ public class ContextConfig implements Li
             }
         } else {
             File docDir = new File(docBase);
-            if (!docDir.exists()) {
-                File warFile = new File(docBase + ".war");
-                if (warFile.exists()) {
-                    URL war = new URL("jar:" + warFile.toURI().toURL() + "!/");
+            File warFile = new File(docBase + ".war");
+            URL war = null;
+            if (warFile.exists()) {
+                war = new URL("jar:" + warFile.toURI().toURL() + "!/");
+            }
+            if (docDir.exists()) {
+                if (war != null && unpackWARs) {
+                    // Check if WAR needs to be re-expanded (e.g. if it has
+                    // changed). Note: HostConfig.deployWar() takes care of
+                    // ensuring that the correct XML file is used.
+                    // This will be a NO-OP if the WAR is unchanged.
+                    ExpandWar.expand(host, war, pathName);
+                }
+            } else {
+                if (war != null) {
                     if (unpackWARs) {
                         docBase = ExpandWar.expand(host, war, pathName);
                         file = new File(docBase);

Modified: 
tomcat/trunk/test/org/apache/catalina/startup/TestHostConfigAutomaticDeployment.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/startup/TestHostConfigAutomaticDeployment.java?rev=1725816&r1=1725815&r2=1725816&view=diff
==============================================================================
--- 
tomcat/trunk/test/org/apache/catalina/startup/TestHostConfigAutomaticDeployment.java
 (original)
+++ 
tomcat/trunk/test/org/apache/catalina/startup/TestHostConfigAutomaticDeployment.java
 Wed Jan 20 21:21:35 2016
@@ -1887,4 +1887,84 @@ public class TestHostConfigAutomaticDepl
     public static class TesterContext extends StandardContext {
         // No functional change
     }
+
+
+    @Test
+    public void testUpdateWarOfflineNoContextFF() throws Exception {
+        doTestUpdateWarOffline(WAR_SOURCE, false, false);
+    }
+
+
+    @Test
+    public void testUpdateWarOfflineNoContextTF() throws Exception {
+        doTestUpdateWarOffline(WAR_SOURCE, true, false);
+    }
+
+
+    @Test
+    public void testUpdateWarOfflineNoContextFT() throws Exception {
+        doTestUpdateWarOffline(WAR_SOURCE, false, true);
+    }
+
+
+    @Test
+    public void testUpdateWarOfflineNoContextTT() throws Exception {
+        doTestUpdateWarOffline(WAR_SOURCE, true, true);
+    }
+
+
+    @Test
+    public void testUpdateWarOfflineContextFF() throws Exception {
+        doTestUpdateWarOffline(WAR_XML_SOURCE, false, false);
+    }
+
+
+    @Test
+    public void testUpdateWarOfflineContextTF() throws Exception {
+        doTestUpdateWarOffline(WAR_XML_SOURCE, true, false);
+    }
+
+
+    @Test
+    public void testUpdateWarOfflineContextFT() throws Exception {
+        doTestUpdateWarOffline(WAR_XML_SOURCE, false, true);
+    }
+
+
+    @Test
+    public void testUpdateWarOfflineContextTT() throws Exception {
+        doTestUpdateWarOffline(WAR_XML_SOURCE, true, true);
+    }
+
+
+    private void doTestUpdateWarOffline(File srcWar, boolean deployOnStartUp, 
boolean autoDeploy)
+            throws Exception {
+        Tomcat tomcat = getTomcatInstance();
+        StandardHost host = (StandardHost) tomcat.getHost();
+        host.setDeployOnStartup(deployOnStartUp);
+
+        File war = createWar(srcWar, true);
+        // Make the WAR appear to have been created earlier
+        war.setLastModified(war.lastModified() - 2 * 
HostConfig.FILE_MODIFICATION_RESOLUTION_MS);
+
+        tomcat.addWebapp(APP_NAME.getPath(), war.getAbsolutePath());
+        tomcat.start();
+
+        // Get the last modified timestamp for the expanded dir
+        File dir = new File(host.getAppBase(), APP_NAME.getBaseName());
+        // Make the DIR appear to have been created earlier
+        long lastModified = war.lastModified() - 2 * 
HostConfig.FILE_MODIFICATION_RESOLUTION_MS;
+        dir.setLastModified(lastModified);
+
+        host.stop();
+        war.setLastModified(System.currentTimeMillis());
+        host.start();
+        if (autoDeploy) {
+            host.backgroundProcess();
+        }
+
+        long newLastModified = dir.lastModified();
+
+        Assert.assertNotEquals("Timestamp hasn't changed", lastModified,  
newLastModified);
+    }
 }

Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1725816&r1=1725815&r2=1725816&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Wed Jan 20 21:21:35 2016
@@ -220,6 +220,11 @@
         used. The equivalent attributes from the <code>Context</code> always
         take precedence. (markt)
       </scode>
+      <fix>
+        <bug>58867</bug>: Improve checking on Host start for WAR files that 
have
+        been modified while Tomcat has stopped and re-expand them if
+        <code>unpackWARs</code> is <code>true</code>. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Coyote">



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

Reply via email to