Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: tomcat6-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat6/AbstractRunMojo.java
- ===================================================================
- --- tomcat6-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat6/AbstractRunMojo.java (revision 1345248)
- +++ tomcat6-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat6/AbstractRunMojo.java (working copy)
- @@ -60,13 +60,14 @@
- import java.net.InetAddress;
- import java.net.MalformedURLException;
- import java.net.URL;
- -import java.security.Principal;
- import java.util.ArrayList;
- import java.util.Collection;
- +import java.util.Hashtable;
- import java.util.Iterator;
- import java.util.List;
- import java.util.Map;
- import java.util.Set;
- +import org.apache.naming.resources.FileDirContext;
- /**
- * Abstract goal that provides common configuration for embedded Tomcat goals.
- @@ -433,6 +434,7 @@
- *
- * @return the webapp context path
- */
- + @Override
- protected String getPath()
- {
- return path;
- @@ -465,6 +467,12 @@
- webappLoader.setLoaderClass( classLoaderClass );
- }
- + MultipleDirContext dc = this.getFileDirContext();
- + if (dc != null)
- + {
- + context.setResources(dc);
- + }
- +
- context.setLoader( webappLoader );
- File contextFile = getContextFile();
- if ( contextFile != null )
- @@ -615,7 +623,7 @@
- {
- throw new MojoExecutionException( " tomcatWebXml " + tomcatWebXml.getPath() + " not exists" );
- }
- - //MTOMCAT-42 here it's a real file resources not a one coming with the mojo
- + //MTOMCAT-42 here it's a real file resources not a one coming with the mojo
- FileUtils.copyFile( tomcatWebXml, new File( confDir, "web.xml" ) );
- //copyFile( tomcatWebXml.getPath(), new File( confDir, "web.xml" ) );
- }
- @@ -1003,4 +1011,122 @@
- host.addChild( staticContext );
- }
- }
- +
- + /**
- + * Scan ${project.build.dir}/apache-tomcat-maven-plugin for directories. Every directory found
- + * is assumed to be a WAR overlay and is added to a MultipleDirContext
- + *
- + * @return
- + */
- + private MultipleDirContext getFileDirContext()
- + {
- + MultipleDirContext ret = null;
- +
- + File f = new File(project.getBuild().getDirectory(), "apache-tomcat-maven-plugin");
- + if (f.isDirectory())
- + {
- + ret = new MultipleDirContext();
- + for (final File overlayRoot : f.listFiles())
- + {
- + if (overlayRoot.isDirectory())
- + {
- + ret.addVirtualDocBase(overlayRoot.getPath());
- + }
- + }
- + }
- +
- + return ret;
- + }
- +
- + /**
- + * WAR overlays can contain other resources besides classes. This class overlays the extracted
- + * WAR overlay directory over the docBase; if a file is not found in the docBase then the WAR
- + * overlays are searched
- + *
- + * See http://blog.bazoud.com/post/2009-05-12-multiples-docbases-avec-tomcat.html
- + */
- + private static class MultipleDirContext extends FileDirContext
- + {
- + private final ArrayList<FileDirContextAdapter> virtualContexts = new ArrayList<FileDirContextAdapter>();
- +
- + public MultipleDirContext()
- + {
- + super();
- + }
- +
- + public MultipleDirContext(Hashtable env)
- + {
- + super(env);
- + }
- +
- + public void addVirtualDocBase(final String virtualDocBase)
- + {
- + FileDirContextAdapter x = new FileDirContextAdapter();
- + x.setDocBase(virtualDocBase);
- + virtualContexts.add(x);
- + }
- +
- + @Override
- + public void allocate()
- + {
- + super.allocate();
- +
- + for (final FileDirContextAdapter x : virtualContexts)
- + {
- + x.allocate();
- + }
- + }
- +
- + @Override
- + public void release()
- + {
- + super.release();
- + for (final FileDirContextAdapter x : virtualContexts)
- + {
- + x.release();
- + }
- + }
- +
- + @Override
- + protected File file(String name)
- + {
- + File ret = super.file(name);
- +
- + if (ret == null)
- + {
- + for (final FileDirContextAdapter x : virtualContexts)
- + {
- + ret = x.file(name);
- + if (ret != null)
- + {
- + break;
- + }
- + }
- + }
- +
- + return ret;
- + }
- + }
- +
- + /**
- + * Used to make {@link FileDirContext#file(java.lang.String)} accessible from this context
- + */
- + private static class FileDirContextAdapter extends FileDirContext
- + {
- + FileDirContextAdapter()
- + {
- + super();
- + }
- +
- + FileDirContextAdapter(Hashtable env)
- + {
- + super(env);
- + }
- +
- + @Override
- + protected File file(String name)
- + {
- + return super.file(name);
- + }
- + }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement