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/12/12 22:49:19 UTC

svn commit: r1550545 - in /tomcat/tc7.0.x/trunk: ./ java/org/apache/catalina/startup/HostConfig.java test/org/apache/catalina/startup/TestHostConfigAutomaticDeployment.java webapps/docs/changelog.xml webapps/docs/config/automatic-deployment.xml

Author: markt
Date: Thu Dec 12 21:49:19 2013
New Revision: 1550545

URL: http://svn.apache.org/r1550545
Log:
Fix an edge case spotted while testing other functionality.
If a context.xml file is added to a DIR it was always ignored. It will now trigger a redeploy.

Modified:
    tomcat/tc7.0.x/trunk/   (props changed)
    tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/HostConfig.java
    tomcat/tc7.0.x/trunk/test/org/apache/catalina/startup/TestHostConfigAutomaticDeployment.java
    tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
    tomcat/tc7.0.x/trunk/webapps/docs/config/automatic-deployment.xml

Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
  Merged /tomcat/trunk:r1550541

Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/HostConfig.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/HostConfig.java?rev=1550545&r1=1550544&r2=1550545&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/HostConfig.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/HostConfig.java Thu Dec 12 21:49:19 2013
@@ -1263,6 +1263,11 @@ public class HostConfig
                 deployedApp.redeployResources.put(
                         xmlCopy.getAbsolutePath(),
                         Long.valueOf(0));
+                if (!xml.exists()) {
+                    deployedApp.redeployResources.put(
+                            xml.getAbsolutePath(),
+                            Long.valueOf(0));
+                }
             }
             addWatchedResources(deployedApp, dir.getAbsolutePath(), context);
             // Add the global redeploy resources (which are never deleted) at

Modified: tomcat/tc7.0.x/trunk/test/org/apache/catalina/startup/TestHostConfigAutomaticDeployment.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/catalina/startup/TestHostConfigAutomaticDeployment.java?rev=1550545&r1=1550544&r2=1550545&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/test/org/apache/catalina/startup/TestHostConfigAutomaticDeployment.java (original)
+++ tomcat/tc7.0.x/trunk/test/org/apache/catalina/startup/TestHostConfigAutomaticDeployment.java Thu Dec 12 21:49:19 2013
@@ -64,6 +64,8 @@ public class TestHostConfigAutomaticDepl
             new File("test/deployment/broken.war");
     private static final File DIR_XML_SOURCE =
             new File("test/deployment/dirContext");
+    private static final File DIR_XML_SOURCE_META_INF =
+            new File("test/deployment/dirContext/META-INF");
     private static final File DIR_SOURCE =
             new File("test/deployment/dirNoContext");
 
@@ -71,6 +73,7 @@ public class TestHostConfigAutomaticDepl
     private static final int EXT = 2;
     private static final int WAR = 3;
     private static final int DIR = 4;
+    private static final int DIR_XML = 5;
 
     private static final int NONE = 1;
     private static final int RELOAD = 2;
@@ -1228,21 +1231,25 @@ public class TestHostConfigAutomaticDepl
     /*
      * Expected behaviour for the addition of files.
      *
-     * Artifacts present     Artifact   Artifacts remaining
-     * XML  WAR  EXT  DIR     Added      XML  WAR  EXT DIR   Action
-     *  N    Y    N    N       DIR        -    Y    -   A     None
-     *  N    N    N    Y       WAR        -    A    -   R   Redeploy
-     *  Y    N    N    N       DIR        Y    -    -   A     None
-     *  N    N    N    Y       XML        A    -    -   Y   Redeploy
-     *  Y    N    N    N       WAR        Y    A    -   -    Reload
-     *  N    Y    N    N       XML        A    Y    -   -   Redeploy
-     *  Y    Y    N    N       DIR        Y    Y    -   A     None
-     *  Y    N    N    Y       WAR        Y    A    -   N    Reload
-     *  N    Y    N    Y       XML        A    Y    -   Y   Redeploy
-     *  Y    N    Y    N       DIR        Y    -    Y   A     None
-     *  Y    N    Y    N       WAR        Y    A    Y   -     None
-     *  N    N    N    Y       EXT        A    -    A   R   Redeploy
-     *  N    Y    N    N       EXT        A    Y    A   -   Redeploy
+     * Artifacts present   copyXML  deployXML  Artifact   Artifacts remaining
+     * XML  WAR  EXT  DIR                       Added      XML  WAR  EXT DIR   Action
+     *  N    Y    N    N      N        Y         DIR        -    Y    -   A     None
+     *  N    N    N    Y      N        Y         WAR        -    A    -   R   Redeploy
+     *  Y    N    N    N      N        Y         DIR        Y    -    -   A     None
+     *  N    N    N    Y      N        Y         XML        A    -    -   Y   Redeploy
+     *  Y    N    N    N      N        Y         WAR        Y    A    -   -    Reload
+     *  N    Y    N    N      N        Y         XML        A    Y    -   -   Redeploy
+     *  Y    Y    N    N      N        Y         DIR        Y    Y    -   A     None
+     *  Y    N    N    Y      N        Y         WAR        Y    A    -   N    Reload
+     *  N    Y    N    Y      N        Y         XML        A    Y    -   Y   Redeploy
+     *  Y    N    Y    N      N        Y         DIR        Y    -    Y   A     None
+     *  Y    N    Y    N      N        Y         WAR        Y    A    Y   -     None
+     *  N    N    N    Y      N        Y         EXT        A    -    A   R   Redeploy
+     *  N    Y    N    N      N        Y         EXT        A    Y    A   -   Redeploy
+     *
+     *  N    N    N    Y     Y/N       N       DIR+XML      -    -    -   Y   Redeploy (failed)
+     *  N    N    N    Y      Y        Y       DIR+XML      A    -    -   Y   Redeploy
+     *  N    N    N    Y      N        Y       DIR+XML      -    -    -   Y   Redeploy
      *
      * Addition of a file  is treated as if the added file has been modified
      * with the following additional actions:
@@ -1349,12 +1356,50 @@ public class TestHostConfigAutomaticDepl
                 true, true, false, XML_COOKIE_NAME, REDEPLOY);
     }
 
+    @Test
+    public void testAdditionDirAddDirXmlTF() throws Exception {
+        doTestAddition(false, false, false, false, true, true, false, DIR_XML,
+                false, false, true, null, REDEPLOY, LifecycleState.FAILED);
+    }
+
+    @Test
+    public void testAdditionDirAddDirXmlFF() throws Exception {
+        doTestAddition(false, false, false, false, true, false, false, DIR_XML,
+                false, false, true, null, REDEPLOY, LifecycleState.FAILED);
+    }
+
+    @Test
+    public void testAdditionDirAddDirXmlTT() throws Exception {
+        doTestAddition(false, false, false, false, true, true, true, DIR_XML,
+                true, false, true, DIR_COOKIE_NAME, REDEPLOY,
+                LifecycleState.STARTED);
+    }
+
+    @Test
+    public void testAdditionDirAddDirXmlFT() throws Exception {
+        doTestAddition(false, false, false, false, true, false, true, DIR_XML,
+                false, false, true, DIR_COOKIE_NAME, REDEPLOY,
+                LifecycleState.STARTED);
+    }
+
     private void doTestAddition(boolean startXml, boolean startExternalWar,
             boolean startExternalDir, boolean startWar, boolean startDir,
             int toAdd, boolean resultXml, boolean resultWar,
             boolean resultDir, String resultCookieName, int resultAction)
             throws Exception {
 
+        doTestAddition(startXml, startExternalWar, startExternalDir, startWar,
+                startDir, false, true, toAdd, resultXml, resultWar, resultDir,
+                resultCookieName, resultAction, LifecycleState.STARTED);
+    }
+
+    private void doTestAddition(boolean startXml, boolean startExternalWar,
+            boolean startExternalDir, boolean startWar, boolean startDir,
+            boolean copyXML, boolean deployXML, int toAdd, boolean resultXml,
+            boolean resultWar, boolean resultDir, String resultCookieName,
+            int resultAction, LifecycleState state)
+            throws Exception {
+
         Tomcat tomcat = getTomcatInstance();
         StandardHost host = (StandardHost) tomcat.getHost();
 
@@ -1379,13 +1424,16 @@ public class TestHostConfigAutomaticDepl
             war = createWar(WAR_XML_SOURCE, true);
         }
         if (startDir) {
-            dir = createDirInAppbase(true);
+            dir = createDirInAppbase(toAdd != DIR_XML);
         }
 
         if ((startWar || startExternalWar) && !startDir) {
             host.setUnpackWARs(false);
         }
 
+        host.setCopyXML(copyXML);
+        host.setDeployXML(deployXML);
+
         // Deploy the files we copied
         tomcat.start();
         host.backgroundProcess();
@@ -1421,6 +1469,10 @@ public class TestHostConfigAutomaticDepl
                     Assert.fail();
                 }
                 break;
+            case DIR_XML:
+                dir = createDirXmlInAppbase();
+                xml = getXmlInConfigBaseForAppbase();
+                break;
             default:
                 Assert.fail();
         }
@@ -1489,8 +1541,7 @@ public class TestHostConfigAutomaticDepl
             if (newContext == null) {
                 Assert.fail();
             } else {
-                Assert.assertEquals(
-                        LifecycleState.STARTED, newContext.getState());
+                Assert.assertEquals(state, newContext.getState());
             }
             Assert.assertNotSame(oldContext, newContext);
             // No init or start as that will be in a new context object
@@ -1619,6 +1670,13 @@ public class TestHostConfigAutomaticDepl
         return dir;
     }
 
+    private File createDirXmlInAppbase() throws IOException {
+        File dir = new File(getAppBaseFile(getTomcatInstance().getHost()),
+                APP_NAME.getBaseName() + "/META-INF");
+        recurrsiveCopy(DIR_XML_SOURCE_META_INF, dir);
+        return dir;
+    }
+
     private File createDirInExternal(boolean withXml) throws IOException {
         File ext = new File(external, "external" + ".war");
         if (withXml) {
@@ -1642,8 +1700,7 @@ public class TestHostConfigAutomaticDepl
     }
 
     private File createXmlInConfigBaseForAppbase() throws IOException {
-        Host host = getTomcatInstance().getHost();
-        File xml = new File(getConfigBaseFile(host), APP_NAME + ".xml");
+        File xml = getXmlInConfigBaseForAppbase();
         File parent = xml.getParentFile();
         if (!parent.isDirectory()) {
             Assert.assertTrue(parent.mkdirs());
@@ -1652,6 +1709,11 @@ public class TestHostConfigAutomaticDepl
         return xml;
     }
 
+    private File getXmlInConfigBaseForAppbase() {
+        Host host = getTomcatInstance().getHost();
+        return new File(getConfigBaseFile(host), APP_NAME + ".xml");
+    }
+
     private File createXmlInConfigBaseForExternal(File ext) throws IOException {
         return createXmlInConfigBaseForExternal(ext, false);
     }

Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1550545&r1=1550544&r2=1550545&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Thu Dec 12 21:49:19 2013
@@ -66,6 +66,12 @@
         added to member map again by ping at heartbeat thread in the node that
         received the <code>MapMessage.MSG_STOP</code>. (kfujino)
       </fix>
+      <fix>
+        Handle the case where a <code>context.xml</code> file is added to a
+        web application deployed from a directory. Previously the file was
+        ignored until Tomcat was restarted. Now (assuming automatic deployment
+        is enabled)it will trigger a redploy of the web application. (markt)
+      </fix>
     </changelog>
   </subsection>
 </section>

Modified: tomcat/tc7.0.x/trunk/webapps/docs/config/automatic-deployment.xml
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/config/automatic-deployment.xml?rev=1550545&r1=1550544&r2=1550545&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/config/automatic-deployment.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/config/automatic-deployment.xml Thu Dec 12 21:49:19 2013
@@ -514,6 +514,9 @@
         will be logged when the WAR in the <em>appBase</em> is first detected.
         If the external WAR is removed, the WAR in the <em>appBaase</em> will be
         left and may be deployed via automatic deployment.</li>
+    <li>If an XML file is added to the META-INF directory of an application
+        deployed from that DIR, the application will always be redeployed. The
+        result will be the same as for a new deployment.</li>
   </ul>
 
 </section>



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