tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1312036 - in /tomcat/maven-plugin/trunk: tomcat6-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat6/AbstractRunMojo.java tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/AbstractRunMojo.java
Date Tue, 10 Apr 2012 23:18:35 GMT
Author: olamy
Date: Tue Apr 10 23:18:34 2012
New Revision: 1312036

URL: http://svn.apache.org/viewvc?rev=1312036&view=rev
Log:
[MTOMCAT-137] Adding a static context to tomcat for static files like images, js, html etc.
Submitted by Gaurav Vishnoi
feature added for tomcat7 mojo too.

Modified:
    tomcat/maven-plugin/trunk/tomcat6-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat6/AbstractRunMojo.java
    tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/AbstractRunMojo.java

Modified: tomcat/maven-plugin/trunk/tomcat6-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat6/AbstractRunMojo.java
URL: http://svn.apache.org/viewvc/tomcat/maven-plugin/trunk/tomcat6-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat6/AbstractRunMojo.java?rev=1312036&r1=1312035&r2=1312036&view=diff
==============================================================================
--- tomcat/maven-plugin/trunk/tomcat6-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat6/AbstractRunMojo.java
(original)
+++ tomcat/maven-plugin/trunk/tomcat6-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat6/AbstractRunMojo.java
Tue Apr 10 23:18:34 2012
@@ -24,9 +24,11 @@ import org.apache.catalina.Context;
 import org.apache.catalina.Engine;
 import org.apache.catalina.Host;
 import org.apache.catalina.LifecycleException;
+import org.apache.catalina.Wrapper;
 import org.apache.catalina.connector.Connector;
 import org.apache.catalina.loader.WebappLoader;
 import org.apache.catalina.realm.MemoryRealm;
+import org.apache.catalina.servlets.DefaultServlet;
 import org.apache.catalina.startup.Catalina;
 import org.apache.catalina.startup.Embedded;
 import org.apache.maven.artifact.Artifact;
@@ -253,7 +255,7 @@ public abstract class AbstractRunMojo
      * @since 1.1
      */
     private String keystorePass;
-    
+
     /**
      * Override the type of keystore file to be used for the server certificate. If not specified,
the default value is "JKS".
      *
@@ -341,6 +343,23 @@ public abstract class AbstractRunMojo
      */
     private ClassRealm tomcatRealm;
 
+    /**
+     * The static context
+     *
+     * @parameter expression="${maven.tomcat.staticContextPath}" default-value="/"
+     * @since 2.0
+     */
+    private String staticContextPath;
+
+    /**
+     * The static context docroot base fully qualified path.
+     * if <code>null</code> static context won't be added
+     *
+     * @parameter expression="${maven.tomcat.staticContextPath}"
+     * @since 2.0
+     */
+    private String staticContextDocbase;
+
     // ----------------------------------------------------------------------
     // Mojo Implementation
     // ----------------------------------------------------------------------
@@ -730,7 +749,7 @@ public abstract class AbstractRunMojo
                 Host host = container.createHost( "localHost", appBase );
 
                 host.addChild( context );
-
+                createStaticContext( container, context, host );
                 if ( addContextWarDependencies )
                 {
                     Collection<Context> dependecyContexts = createDependencyContexts(
container );
@@ -958,4 +977,20 @@ public abstract class AbstractRunMojo
         }
         return contexts;
     }
+
+
+    private void createStaticContext( final Embedded container, Context context, Host host
)
+    {
+        if ( staticContextDocbase != null )
+        {
+            Context staticContext = container.createContext( staticContextPath, staticContextDocbase
);
+            staticContext.setPrivileged( true );
+            Wrapper servlet = context.createWrapper();
+            servlet.setServletClass( DefaultServlet.class.getName() );
+            servlet.setName( "staticContent" );
+            staticContext.addChild( servlet );
+            staticContext.addServletMapping( "/", "staticContent" );
+            host.addChild( staticContext );
+        }
+    }
 }

Modified: tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/AbstractRunMojo.java
URL: http://svn.apache.org/viewvc/tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/AbstractRunMojo.java?rev=1312036&r1=1312035&r2=1312036&view=diff
==============================================================================
--- tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/AbstractRunMojo.java
(original)
+++ tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/AbstractRunMojo.java
Tue Apr 10 23:18:34 2012
@@ -19,10 +19,13 @@ package org.apache.tomcat.maven.plugin.t
  */
 
 import org.apache.catalina.Context;
+import org.apache.catalina.Host;
 import org.apache.catalina.LifecycleException;
+import org.apache.catalina.Wrapper;
 import org.apache.catalina.connector.Connector;
 import org.apache.catalina.loader.WebappLoader;
 import org.apache.catalina.realm.MemoryRealm;
+import org.apache.catalina.servlets.DefaultServlet;
 import org.apache.catalina.startup.Catalina;
 import org.apache.catalina.startup.CatalinaProperties;
 import org.apache.catalina.startup.Tomcat;
@@ -334,6 +337,23 @@ public abstract class AbstractRunMojo
      */
     protected boolean skip;
 
+    /**
+     * The static context
+     *
+     * @parameter expression="${maven.tomcat.staticContextPath}" default-value="/"
+     * @since 2.0
+     */
+    private String staticContextPath;
+
+    /**
+     * The static context docroot base fully qualified path
+     * if <code>null</code> static context won't be added
+     *
+     * @parameter expression="${maven.tomcat.staticContextPath}"
+     * @since 2.0
+     */
+    private String staticContextDocbase;
+
     // ----------------------------------------------------------------------
     // Fields
     // ----------------------------------------------------------------------
@@ -760,6 +780,8 @@ public abstract class AbstractRunMojo
 
                 embeddedTomcat.getHost().setAppBase( new File( configurationDir, "webapps"
).getAbsolutePath() );
 
+                createStaticContext( embeddedTomcat, ctx, embeddedTomcat.getHost() );
+
                 Connector connector = new Connector( protocol );
                 connector.setPort( port );
 
@@ -999,4 +1021,19 @@ public abstract class AbstractRunMojo
         }
         return contexts;
     }
+
+    private void createStaticContext( final Tomcat container, Context context, Host host
)
+    {
+        if ( staticContextDocbase != null )
+        {
+            Context staticContext = container.addContext( staticContextPath, staticContextDocbase
);
+            staticContext.setPrivileged( true );
+            Wrapper servlet = context.createWrapper();
+            servlet.setServletClass( DefaultServlet.class.getName() );
+            servlet.setName( "staticContent" );
+            staticContext.addChild( servlet );
+            staticContext.addServletMapping( "/", "staticContent" );
+            host.addChild( staticContext );
+        }
+    }
 }



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


Mime
View raw message