You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ol...@apache.org on 2011/10/18 18:32:24 UTC

svn commit: r1185743 - /tomcat/maven-plugin/trunk/tomcat7-war-runner/src/main/java/org/apache/tomcat/maven/runner/Tomcat7Runner.java

Author: olamy
Date: Tue Oct 18 16:32:23 2011
New Revision: 1185743

URL: http://svn.apache.org/viewvc?rev=1185743&view=rev
Log:
[MTOMCAT-102] if there a context.xml in the war META-INF/context.xml use it for the context.

Modified:
    tomcat/maven-plugin/trunk/tomcat7-war-runner/src/main/java/org/apache/tomcat/maven/runner/Tomcat7Runner.java

Modified: tomcat/maven-plugin/trunk/tomcat7-war-runner/src/main/java/org/apache/tomcat/maven/runner/Tomcat7Runner.java
URL: http://svn.apache.org/viewvc/tomcat/maven-plugin/trunk/tomcat7-war-runner/src/main/java/org/apache/tomcat/maven/runner/Tomcat7Runner.java?rev=1185743&r1=1185742&r2=1185743&view=diff
==============================================================================
--- tomcat/maven-plugin/trunk/tomcat7-war-runner/src/main/java/org/apache/tomcat/maven/runner/Tomcat7Runner.java (original)
+++ tomcat/maven-plugin/trunk/tomcat7-war-runner/src/main/java/org/apache/tomcat/maven/runner/Tomcat7Runner.java Tue Oct 18 16:32:23 2011
@@ -18,17 +18,20 @@ package org.apache.tomcat.maven.runner;
  * under the License.
  */
 
+import org.apache.catalina.Context;
 import org.apache.catalina.connector.Connector;
 import org.apache.catalina.startup.Catalina;
 import org.apache.catalina.startup.Tomcat;
 import org.apache.catalina.valves.AccessLogValve;
 import org.apache.tomcat.util.http.fileupload.FileUtils;
+import org.apache.tomcat.util.http.fileupload.IOUtils;
 
 import java.io.BufferedOutputStream;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.URL;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Properties;
@@ -133,6 +136,7 @@ public class Tomcat7Runner
 
             if ( this.enableNaming() )
             {
+                System.setProperty( "catalina.useNaming", "true" );
                 tomcat.enableNaming();
             }
 
@@ -190,17 +194,21 @@ public class Tomcat7Runner
             // add webapps
             for ( Map.Entry<String, String> entry : this.webappWarPerContext.entrySet() )
             {
+                String baseDir = null;
                 if ( entry.getKey().equals( "/" ) )
                 {
-                    tomcat.addWebapp( entry.getKey(),
-                                      new File( extractDirectory, "webapps/ROOT.war" ).getAbsolutePath() );
+                    baseDir = new File( extractDirectory, "webapps/ROOT.war" ).getAbsolutePath();
                 }
                 else
                 {
-                    tomcat.addWebapp( entry.getKey(),
-                                      new File( extractDirectory, "webapps/" + entry.getValue() ).getAbsolutePath() );
+                    baseDir = new File( extractDirectory, "webapps/" + entry.getValue() ).getAbsolutePath();
+                }
+                Context context = tomcat.addWebapp( entry.getKey(), baseDir );
+                URL contextFileUrl = getContextXml( baseDir );
+                if ( contextFileUrl != null )
+                {
+                    context.setConfigFile( contextFileUrl );
                 }
-
             }
 
             tomcat.start();
@@ -210,6 +218,28 @@ public class Tomcat7Runner
 
     }
 
+    private URL getContextXml( String warPath )
+        throws IOException
+    {
+        InputStream inputStream = null;
+        try
+        {
+            URL url = new URL( "jar:file:" + warPath + "!/META-INF/context.xml" );
+            inputStream = url.openConnection().getInputStream();
+            if ( inputStream != null )
+            {
+                return url;
+            }
+        }
+        finally
+        {
+            IOUtils.closeQuietly( inputStream );
+        }
+        return null;
+    }
+
+    //protected WebappLoader createWebappLoader()
+
     private void waitIndefinitely()
     {
         Object lock = new Object();
@@ -250,7 +280,6 @@ public class Tomcat7Runner
         }
         extractDirectory.mkdirs();
 
-
         // ensure webapp dir is here
         new File( extractDirectory, "webapps" ).mkdirs();
 



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