You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2013/01/15 01:31:02 UTC

svn commit: r1433240 - /tomee/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java

Author: rmannibucau
Date: Tue Jan 15 00:31:02 2013
New Revision: 1433240

URL: http://svn.apache.org/viewvc?rev=1433240&view=rev
Log:
TOMEE-733 rework realWarPath algorithm

Modified:
    tomee/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java

Modified: tomee/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java
URL: http://svn.apache.org/viewvc/tomee/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java?rev=1433240&r1=1433239&r2=1433240&view=diff
==============================================================================
--- tomee/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java (original)
+++ tomee/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java Tue Jan 15 00:31:02 2013
@@ -19,6 +19,7 @@ package org.apache.tomee.catalina;
 import org.apache.catalina.Cluster;
 import org.apache.catalina.Container;
 import org.apache.catalina.Engine;
+import org.apache.catalina.Globals;
 import org.apache.catalina.Host;
 import org.apache.catalina.LifecycleException;
 import org.apache.catalina.LifecycleListener;
@@ -33,6 +34,7 @@ import org.apache.catalina.Wrapper;
 import org.apache.catalina.core.ContainerBase;
 import org.apache.catalina.core.NamingContextListener;
 import org.apache.catalina.core.StandardContext;
+import org.apache.catalina.core.StandardEngine;
 import org.apache.catalina.core.StandardHost;
 import org.apache.catalina.core.StandardServer;
 import org.apache.catalina.core.StandardWrapper;
@@ -840,6 +842,57 @@ public class TomcatWebAppBuilder impleme
     }
 
     private static File realWarPath(final StandardContext standardContext) {
+        File docBase;
+        Container container = standardContext;
+        while (container != null) {
+            if (container instanceof Host) {
+                break;
+            }
+            container = container.getParent();
+        }
+
+        File file = new File(standardContext.getDocBase());
+        if (!file.isAbsolute()) {
+            if (container == null) {
+                docBase = new File(engineBase(standardContext), standardContext.getDocBase());
+            } else {
+                final String appBase = ((Host) container).getAppBase();
+                file = new File(appBase);
+                if (!file.isAbsolute()) {
+                    file = new File(engineBase(standardContext), appBase);
+                }
+                docBase = new File(file, standardContext.getDocBase());
+            }
+        } else {
+            docBase = file;
+        }
+
+        if (!docBase.exists()) { // for old compatibility, will be removed soon
+            return oldRealWarPath(standardContext);
+        }
+
+        final String name = docBase.getName();
+        if (name.endsWith(".war")) {
+            final File extracted = new File(docBase.getParentFile(), name.substring(0, name.length() - ".war".length()));
+            if (extracted.exists()) {
+                return extracted;
+            }
+        }
+
+        return docBase;
+    }
+
+    private static File engineBase(final StandardContext standardContext) {
+        String base=System.getProperty(Globals.CATALINA_BASE_PROP);
+        if( base == null ) {
+            final StandardEngine eng = (StandardEngine) standardContext.getParent().getParent();
+            base = eng.getBaseDir();
+        }
+        return new File(base);
+    }
+
+    @Deprecated
+    private static File oldRealWarPath(final StandardContext standardContext) {
         String doc = standardContext.getDocBase();
         // handle ROOT case
         if (doc == null || doc.length() == 0) {
@@ -850,12 +903,14 @@ public class TomcatWebAppBuilder impleme
         if (war.exists()) {
             return war;
         }
+
         final StandardHost host = (StandardHost) standardContext.getParent();
         final String base = host.getAppBase();
         war = new File(base, doc);
         if (war.exists()) {
             return war;
         }
+
         war = new File(new File(System.getProperty("catalina.home"), base), doc);
         if (war.exists()) {
             return war;