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 2014/01/09 14:59:11 UTC

svn commit: r1556807 - in /tomcat/trunk: java/org/apache/catalina/core/ java/org/apache/catalina/ha/deploy/ java/org/apache/catalina/manager/ java/org/apache/catalina/mbeans/ java/org/apache/catalina/startup/ java/org/apache/catalina/storeconfig/ java/...

Author: markt
Date: Thu Jan  9 13:59:10 2014
New Revision: 1556807

URL: http://svn.apache.org/r1556807
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=55958
Differentiate between foo.war the directory and foo.war the file

Modified:
    tomcat/trunk/java/org/apache/catalina/core/ContainerBase.java
    tomcat/trunk/java/org/apache/catalina/ha/deploy/FarmWarDeployer.java
    tomcat/trunk/java/org/apache/catalina/manager/HTMLManagerServlet.java
    tomcat/trunk/java/org/apache/catalina/mbeans/MBeanUtils.java
    tomcat/trunk/java/org/apache/catalina/startup/FailedContext.java
    tomcat/trunk/java/org/apache/catalina/startup/HostConfig.java
    tomcat/trunk/java/org/apache/catalina/storeconfig/StandardContextSF.java
    tomcat/trunk/java/org/apache/catalina/util/ContextName.java
    tomcat/trunk/test/org/apache/catalina/startup/TestHostConfigAutomaticDeployment.java
    tomcat/trunk/test/org/apache/catalina/util/TestContextName.java

Modified: tomcat/trunk/java/org/apache/catalina/core/ContainerBase.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/ContainerBase.java?rev=1556807&r1=1556806&r2=1556807&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/ContainerBase.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/ContainerBase.java Thu Jan  9 13:59:10 2014
@@ -1234,7 +1234,7 @@ public abstract class ContainerBase exte
                 keyProperties.insert(9, c.getName());
             } else if (c instanceof Context) {
                 keyProperties.insert(0, ",context=");
-                ContextName cn = new ContextName(c.getName());
+                ContextName cn = new ContextName(c.getName(), false);
                 keyProperties.insert(9,cn.getDisplayName());
             } else if (c instanceof Host) {
                 keyProperties.insert(0, ",host=");

Modified: tomcat/trunk/java/org/apache/catalina/ha/deploy/FarmWarDeployer.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/ha/deploy/FarmWarDeployer.java?rev=1556807&r1=1556806&r2=1556807&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/ha/deploy/FarmWarDeployer.java (original)
+++ tomcat/trunk/java/org/apache/catalina/ha/deploy/FarmWarDeployer.java Thu Jan  9 13:59:10 2014
@@ -452,7 +452,7 @@ public class FarmWarDeployer extends Clu
     public void fileModified(File newWar) {
         try {
             File deployWar = new File(getDeployDirFile(), newWar.getName());
-            ContextName cn = new ContextName(deployWar.getName());
+            ContextName cn = new ContextName(deployWar.getName(), true);
             if (deployWar.exists() && deployWar.lastModified() > newWar.lastModified()) {
                 if (log.isInfoEnabled())
                     log.info(sm.getString("farmWarDeployer.alreadyDeployed", cn.getName()));
@@ -488,7 +488,7 @@ public class FarmWarDeployer extends Clu
     @Override
     public void fileRemoved(File removeWar) {
         try {
-            ContextName cn = new ContextName(removeWar.getName());
+            ContextName cn = new ContextName(removeWar.getName(), true);
             if (log.isInfoEnabled())
                 log.info(sm.getString("farmWarDeployer.removeLocal",
                         cn.getName()));

Modified: tomcat/trunk/java/org/apache/catalina/manager/HTMLManagerServlet.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/manager/HTMLManagerServlet.java?rev=1556807&r1=1556806&r2=1556807&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/manager/HTMLManagerServlet.java (original)
+++ tomcat/trunk/java/org/apache/catalina/manager/HTMLManagerServlet.java Thu Jan  9 13:59:10 2014
@@ -288,7 +288,7 @@ public final class HTMLManagerServlet ex
                     break;
                 }
 
-                ContextName cn = new ContextName(filename);
+                ContextName cn = new ContextName(filename, true);
                 String name = cn.getName();
 
                 if ((host.findChild(name) != null) && !isDeployed(name)) {

Modified: tomcat/trunk/java/org/apache/catalina/mbeans/MBeanUtils.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/mbeans/MBeanUtils.java?rev=1556807&r1=1556806&r2=1556807&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/mbeans/MBeanUtils.java (original)
+++ tomcat/trunk/java/org/apache/catalina/mbeans/MBeanUtils.java Thu Jan  9 13:59:10 2014
@@ -344,7 +344,7 @@ public class MBeanUtils {
                         ",resourcetype=Global,name=" + environment.getName());
         } else if (container instanceof Context) {
             Context context = ((Context)container);
-            ContextName cn = new ContextName(context.getName());
+            ContextName cn = new ContextName(context.getName(), false);
             Container host = context.getParent();
             name = new ObjectName(domain + ":type=Environment" +
                         ",resourcetype=Context,host=" + host.getName() +
@@ -379,7 +379,7 @@ public class MBeanUtils {
                     ",name=" + quotedResourceName);
         } else if (container instanceof Context) {
             Context context = ((Context)container);
-            ContextName cn = new ContextName(context.getName());
+            ContextName cn = new ContextName(context.getName(), false);
             Container host = context.getParent();
             name = new ObjectName(domain + ":type=Resource" +
                     ",resourcetype=Context,host=" + host.getName() +
@@ -417,7 +417,7 @@ public class MBeanUtils {
                     ",name=" + quotedResourceLinkName);
         } else if (container instanceof Context) {
             Context context = ((Context)container);
-            ContextName cn = new ContextName(context.getName());
+            ContextName cn = new ContextName(context.getName(), false);
             Container host = context.getParent();
             name = new ObjectName(domain + ":type=ResourceLink" +
                     ",resourcetype=Context,host=" + host.getName() +
@@ -467,7 +467,7 @@ public class MBeanUtils {
         ObjectName name = null;
         Context context = loader.getContext();
 
-        ContextName cn = new ContextName(context.getName());
+        ContextName cn = new ContextName(context.getName(), false);
         Container host = context.getParent();
         name = new ObjectName(domain + ":type=Loader,host=" + host.getName() +
                 ",context=" + cn.getDisplayName());

Modified: tomcat/trunk/java/org/apache/catalina/startup/FailedContext.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/FailedContext.java?rev=1556807&r1=1556806&r2=1556807&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/FailedContext.java (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/FailedContext.java Thu Jan  9 13:59:10 2014
@@ -144,7 +144,7 @@ public class FailedContext extends Lifec
         while (!(c instanceof Engine)) {
             if (c instanceof Context) {
                 keyProperties.append(",context=");
-                ContextName cn = new ContextName(c.getName());
+                ContextName cn = new ContextName(c.getName(), false);
                 keyProperties.append(cn.getDisplayName());
             } else if (c instanceof Host) {
                 keyProperties.append(",host=");

Modified: tomcat/trunk/java/org/apache/catalina/startup/HostConfig.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/HostConfig.java?rev=1556807&r1=1556806&r2=1556807&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/HostConfig.java (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/HostConfig.java Thu Jan  9 13:59:10 2014
@@ -443,7 +443,7 @@ public class HostConfig
 
         File appBase = host.getAppBaseFile();
         File configBase = host.getConfigBaseFile();
-        ContextName cn = new ContextName(name);
+        ContextName cn = new ContextName(name, false);
         String baseName = cn.getBaseName();
 
         if (deploymentExists(baseName)) {
@@ -484,7 +484,7 @@ public class HostConfig
             File contextXml = new File(configBase, files[i]);
 
             if (files[i].toLowerCase(Locale.ENGLISH).endsWith(".xml")) {
-                ContextName cn = new ContextName(files[i]);
+                ContextName cn = new ContextName(files[i], true);
 
                 if (isServiced(cn.getName()) || deploymentExists(cn.getName()))
                     continue;
@@ -671,7 +671,7 @@ public class HostConfig
             if (files[i].toLowerCase(Locale.ENGLISH).endsWith(".war") &&
                     war.isFile() && !invalidWars.contains(files[i]) ) {
 
-                ContextName cn = new ContextName(files[i]);
+                ContextName cn = new ContextName(files[i], true);
 
                 if (isServiced(cn.getName())) {
                     continue;
@@ -1025,7 +1025,7 @@ public class HostConfig
                 continue;
             File dir = new File(appBase, files[i]);
             if (dir.isDirectory()) {
-                ContextName cn = new ContextName(files[i]);
+                ContextName cn = new ContextName(files[i], false);
 
                 if (isServiced(cn.getName()) || deploymentExists(cn.getName()))
                     continue;
@@ -1569,9 +1569,9 @@ public class HostConfig
         }
         Iterator<String> iter = sortedAppNames.iterator();
 
-        ContextName previous = new ContextName(iter.next());
+        ContextName previous = new ContextName(iter.next(), false);
         do {
-            ContextName current = new ContextName(iter.next());
+            ContextName current = new ContextName(iter.next(), false);
 
             if (current.getPath().equals(previous.getPath())) {
                 // Current and previous are same path - current will always

Modified: tomcat/trunk/java/org/apache/catalina/storeconfig/StandardContextSF.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/storeconfig/StandardContextSF.java?rev=1556807&r1=1556806&r2=1556807&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/storeconfig/StandardContextSF.java (original)
+++ tomcat/trunk/java/org/apache/catalina/storeconfig/StandardContextSF.java Thu Jan  9 13:59:10 2014
@@ -87,7 +87,7 @@ public class StandardContextSF extends S
                     Context context = ((StandardContext) aContext);
                     Host host = (Host) context.getParent();
                     File configBase = host.getConfigBaseFile();
-                    ContextName cn = new ContextName(context.getName());
+                    ContextName cn = new ContextName(context.getName(), false);
                     String baseName = cn.getBaseName();
                     File xml = new File(configBase, baseName + ".xml");
                     context.setConfigFile(xml.toURI().toURL());

Modified: tomcat/trunk/java/org/apache/catalina/util/ContextName.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/util/ContextName.java?rev=1556807&r1=1556806&r2=1556807&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/util/ContextName.java (original)
+++ tomcat/trunk/java/org/apache/catalina/util/ContextName.java Thu Jan  9 13:59:10 2014
@@ -32,13 +32,17 @@ public final class ContextName {
     private final String version;
     private final String name;
 
+
     /**
      * Creates an instance from a context name, display name, base name,
      * directory name, WAR name or context.xml name.
      *
      * @param name  The name to use as the basis for this object
+     * @param stripFileExtension    If a .war or .xml file extension is present
+     *                              at the end of the provided name should it be
+     *                              removed?
      */
-    public ContextName(String name) {
+    public ContextName(String name, boolean stripFileExtension) {
 
         String tmp1 = name;
 
@@ -58,8 +62,9 @@ public final class ContextName {
         }
 
         // Remove any file extensions
-        if (tmp1.toLowerCase(Locale.ENGLISH).endsWith(".war") ||
-                tmp1.toLowerCase(Locale.ENGLISH).endsWith(".xml")) {
+        if (stripFileExtension &&
+                (tmp1.toLowerCase(Locale.ENGLISH).endsWith(".war") ||
+                        tmp1.toLowerCase(Locale.ENGLISH).endsWith(".xml"))) {
             tmp1 = tmp1.substring(0, tmp1.length() -4);
         }
 

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=1556807&r1=1556806&r2=1556807&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/startup/TestHostConfigAutomaticDeployment.java (original)
+++ tomcat/trunk/test/org/apache/catalina/startup/TestHostConfigAutomaticDeployment.java Thu Jan  9 13:59:10 2014
@@ -45,7 +45,7 @@ import org.apache.catalina.util.ContextN
  */
 public class TestHostConfigAutomaticDeployment extends TomcatBaseTest {
 
-    private static final ContextName  APP_NAME = new ContextName("myapp");
+    private static final ContextName  APP_NAME = new ContextName("myapp", false);
     private static final File XML_SOURCE =
             new File("test/deployment/context.xml");
     private static final File WAR_XML_SOURCE =

Modified: tomcat/trunk/test/org/apache/catalina/util/TestContextName.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/util/TestContextName.java?rev=1556807&r1=1556806&r2=1556807&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/util/TestContextName.java (original)
+++ tomcat/trunk/test/org/apache/catalina/util/TestContextName.java Thu Jan  9 13:59:10 2014
@@ -44,6 +44,8 @@ public class TestContextName {
     private ContextName cn18;
     private ContextName cn19;
     private ContextName cn20;
+    private ContextName cn21;
+    private ContextName cn22;
 
     @Before
     public void setUp() throws Exception {
@@ -57,16 +59,18 @@ public class TestContextName {
         cn8 = new ContextName("/", "C");
         cn9 = new ContextName("/foo", "D");
         cn10 = new ContextName("/foo/bar", "E");
-        cn11 = new ContextName("ROOT");
-        cn12 = new ContextName("foo");
-        cn13 = new ContextName("foo#bar");
-        cn14 = new ContextName("ROOT##A");
-        cn15 = new ContextName("foo##D");
-        cn16 = new ContextName("foo#bar##E");
+        cn11 = new ContextName("ROOT", false);
+        cn12 = new ContextName("foo", false);
+        cn13 = new ContextName("foo#bar", false);
+        cn14 = new ContextName("ROOT##A", false);
+        cn15 = new ContextName("foo##D", false);
+        cn16 = new ContextName("foo#bar##E", false);
         cn17 = new ContextName("/ROOT", null);
-        cn18 = new ContextName("/ROOT#bar");
-        cn19 = new ContextName("/ROOT#bar##A");
-        cn20 = new ContextName("/ROOT##A");
+        cn18 = new ContextName("/ROOT#bar", false);
+        cn19 = new ContextName("/ROOT#bar##A", false);
+        cn20 = new ContextName("/ROOT##A", false);
+        cn21 = new ContextName("foo.war", false);
+        cn22 = new ContextName("foo.war", true);
     }
 
     @Test
@@ -91,6 +95,8 @@ public class TestContextName {
         assertEquals("ROOT#bar", cn18.getBaseName());
         assertEquals("ROOT#bar##A", cn19.getBaseName());
         assertEquals("ROOT##A", cn20.getBaseName());
+        assertEquals("foo.war", cn21.getBaseName());
+        assertEquals("foo", cn22.getBaseName());
     }
 
     @Test
@@ -115,6 +121,8 @@ public class TestContextName {
         assertEquals("/ROOT/bar", cn18.getPath());
         assertEquals("/ROOT/bar", cn19.getPath());
         assertEquals("", cn20.getPath());
+        assertEquals("/foo.war", cn21.getPath());
+        assertEquals("/foo", cn22.getPath());
     }
 
     @Test
@@ -139,6 +147,8 @@ public class TestContextName {
         assertEquals("", cn18.getVersion());
         assertEquals("A", cn19.getVersion());
         assertEquals("A", cn20.getVersion());
+        assertEquals("", cn21.getVersion());
+        assertEquals("", cn22.getVersion());
     }
 
     @Test
@@ -163,6 +173,8 @@ public class TestContextName {
         assertEquals("/ROOT/bar", cn18.getName());
         assertEquals("/ROOT/bar##A", cn19.getName());
         assertEquals("##A", cn20.getName());
+        assertEquals("/foo.war", cn21.getName());
+        assertEquals("/foo", cn22.getName());
     }
 
     @Test
@@ -187,6 +199,8 @@ public class TestContextName {
         assertEquals("/ROOT/bar", cn18.getDisplayName());
         assertEquals("/ROOT/bar##A", cn19.getDisplayName());
         assertEquals("/##A", cn20.getDisplayName());
+        assertEquals("/foo.war", cn21.getDisplayName());
+        assertEquals("/foo", cn22.getDisplayName());
     }
 
     @Test
@@ -211,12 +225,14 @@ public class TestContextName {
         doTestConstructorString(cn18);
         doTestConstructorString(cn19);
         doTestConstructorString(cn20);
+        doTestConstructorString(cn21);
+        doTestConstructorString(cn22);
     }
 
     private void doTestConstructorString(ContextName src) {
-        doCompare(src, new ContextName(src.getBaseName()));
-        doCompare(src, new ContextName(src.getDisplayName()));
-        doCompare(src, new ContextName(src.getName()));
+        doCompare(src, new ContextName(src.getBaseName(), false));
+        doCompare(src, new ContextName(src.getDisplayName(), false));
+        doCompare(src, new ContextName(src.getName(), false));
     }
 
     private void doCompare(ContextName cn1, ContextName cn2) {



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