Index: D:/Development/OSS/mojo-sandbox/tomcat-maven-plugin/src/main/java/org/codehaus/mojo/tomcat/RunEmbeddedMojo.java
===================================================================
--- D:/Development/OSS/mojo-sandbox/tomcat-maven-plugin/src/main/java/org/codehaus/mojo/tomcat/RunEmbeddedMojo.java (revision 0)
+++ D:/Development/OSS/mojo-sandbox/tomcat-maven-plugin/src/main/java/org/codehaus/mojo/tomcat/RunEmbeddedMojo.java (revision 0)
@@ -0,0 +1,270 @@
+package org.codehaus.mojo.tomcat;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.net.URL;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.apache.catalina.Context;
+import org.apache.catalina.Engine;
+import org.apache.catalina.Host;
+import org.apache.catalina.LifecycleException;
+import org.apache.catalina.connector.Connector;
+import org.apache.catalina.loader.WebappLoader;
+import org.apache.catalina.realm.MemoryRealm;
+import org.apache.catalina.startup.Embedded;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.io.SAXReader;
+import org.dom4j.io.XMLWriter;
+
+/**
+ * This mojo runs an embedded Tomcat server, using the webapp sourceDirectory as
+ * context dir, and the project classpath as context classpath.
+ *
+ * @author Jurgen Lust
+ * @author $author$
+ * @version $Revision$
+ *
+ * @goal run
+ * @requiresDependencyResolution runtime
+ * @execute phase="compile"
+ */
+public class RunEmbeddedMojo extends AbstractMojo {
+ /**
+ * the baseDir for the Embedded Tomcat
+ *
+ * @parameter expression="${basedir}"
+ */
+ private String baseDir;
+
+ /**
+ * the classes directory for the webapplication
+ *
+ * @parameter expression="${project.build.outputDirectory}"
+ */
+ private String classesDir;
+
+ /**
+ * The set of dependencies required by the project
+ *
+ * @parameter default-value="${project.artifacts}"
+ * @required
+ * @readonly
+ */
+ private Set dependencies;
+
+ /**
+ * the source directory containing the webapp
+ *
+ * @parameter expression="src/main/webapp"
+ */
+ private String webappSrcDir;
+
+ /**
+ * the work directory for the Embedded Tomcat
+ *
+ * @parameter expression="${project.build.directory}/tomcat"
+ */
+ private String workDir;
+
+ /**
+ *
+ * @see org.apache.maven.plugin.Mojo#execute()
+ */
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ try {
+ initWorkDir();
+ getLog().info("Initializing Embedded Tomcat");
+
+ Embedded server = new Embedded();
+ server.setCatalinaHome(getWorkDir());
+
+ MemoryRealm memoryRealm = new MemoryRealm();
+ server.setRealm(memoryRealm);
+
+ Engine engine = server.createEngine();
+ engine.setName("localEngine");
+ engine.setDefaultHost("localHost");
+
+ Host localHost = server.createHost("localHost", getBaseDir());
+ engine.addChild(localHost);
+
+ Context rootContext = server.createContext("", getWebappSrcDir());
+ localHost.addChild(rootContext);
+ // The classloader for this context should include the classpath
+ // of this plugin, which contains all tomcat jars.
+ WebappLoader loader = new WebappLoader(this.getClass()
+ .getClassLoader());
+
+ // We also need the compiled classes of the project
+ if (classesDir != null) {
+ File classesDirFile = new File(classesDir);
+ loader.addRepository(classesDirFile.toURL().toString());
+ }
+
+ // And of course all project dependencies from the runtime scope
+ if (dependencies != null) {
+ System.out.println("adding dependencies");
+ for (Iterator dit = dependencies.iterator(); dit.hasNext();) {
+ Artifact artifact = (Artifact) dit.next();
+ loader.addRepository(artifact.getFile().toURL().toString());
+ }
+ }
+
+ rootContext.setLoader(loader);
+ rootContext.setReloadable(true);
+ server.addEngine(engine);
+
+ Connector httpConnector = server.createConnector(
+ (java.net.InetAddress) null, 8080, false);
+ server.addConnector(httpConnector);
+ server.start();
+ // now just wait for requests
+ waitInfinitely();
+ } catch (final LifecycleException e) {
+ throw new MojoExecutionException("Could not start tomcat", e);
+ } catch (final DocumentException e) {
+ throw new MojoExecutionException("Could not create config files", e);
+ } catch (final IOException e) {
+ throw new MojoExecutionException("Could not create config files", e);
+ }
+ }
+
+ /**
+ * getter for the baseDir
+ *
+ * @return Returns the baseDir.
+ */
+ public String getBaseDir() {
+ return baseDir;
+ }
+
+ /**
+ * @return Returns the classesDir.
+ */
+ public String getClassesDir() {
+ return classesDir;
+ }
+
+ /**
+ * getter for the webappSrcDir
+ *
+ * @return Returns the webappSrcDir.
+ */
+ public String getWebappSrcDir() {
+ return webappSrcDir;
+ }
+
+ /**
+ * getter for workDir
+ *
+ * @return Returns the workDir.
+ */
+ public String getWorkDir() {
+ return workDir;
+ }
+
+ /**
+ * Create the Tomcat conf directory, and copy the tomcat-users.xml web.xml,
+ * and log4j.xml files into it.
+ *
+ * @throws DocumentException
+ * @throws IOException
+ */
+ private void initWorkDir() throws DocumentException, IOException {
+ getLog().info("Setting up Tomcat work directory: " + getWorkDir());
+
+ File workDirFile = new File(getWorkDir());
+ File confDir = new File(workDirFile, "conf");
+ confDir.mkdirs();
+ writeConfigFile(confDir, "tomcat-users.xml");
+ writeConfigFile(confDir, "web.xml");
+ writeConfigFile(confDir, "log4j.xml");
+ }
+
+ /**
+ * set for the baseDir
+ *
+ * @param webappsDir
+ * The baseDir to set.
+ */
+ public void setBaseDir(final String webappsDir) {
+ this.baseDir = webappsDir;
+ }
+
+ /**
+ * @param classesDir
+ * The classesDir to set.
+ */
+ public void setClassesDir(String classesDir) {
+ this.classesDir = classesDir;
+ }
+
+ /**
+ * setter for the webappSrcDir
+ *
+ * @param webappSrcDir
+ * The webappSrcDir to set.
+ */
+ public void setWebappSrcDir(final String webappSrcDir) {
+ this.webappSrcDir = webappSrcDir;
+ }
+
+ /**
+ * setter for workDir
+ *
+ * @param workDir
+ * The workDir to set.
+ */
+ public void setWorkDir(final String workDir) {
+ this.workDir = workDir;
+ }
+
+ /**
+ * Keep this mojo going
+ */
+ private void waitInfinitely() {
+ Object lock = new Object();
+
+ synchronized (lock) {
+ try {
+ lock.wait();
+ } catch (final InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ /**
+ * Copy the specified config xml file from the classpath to the specified
+ * config directory
+ *
+ * @param confDir
+ * the config directory
+ * @param filename
+ * the name of the xml file
+ *
+ * @throws DocumentException
+ * @throws IOException
+ */
+ private void writeConfigFile(final File confDir, final String filename)
+ throws DocumentException, IOException {
+ getLog().info("Creating " + filename);
+
+ URL sourceUrl = this.getClass().getClassLoader().getResource(filename);
+ SAXReader xmlReader = new SAXReader();
+
+ Document xml = xmlReader.read(sourceUrl);
+ FileOutputStream out = new FileOutputStream(new File(confDir, filename));
+ XMLWriter writer = new XMLWriter(out);
+ writer.write(xml);
+ writer.flush();
+ }
+}
Index: D:/Development/OSS/mojo-sandbox/tomcat-maven-plugin/src/main/resources/tomcat-users.xml
===================================================================
--- D:/Development/OSS/mojo-sandbox/tomcat-maven-plugin/src/main/resources/tomcat-users.xml (revision 0)
+++ D:/Development/OSS/mojo-sandbox/tomcat-maven-plugin/src/main/resources/tomcat-users.xml (revision 0)
@@ -0,0 +1,10 @@
+
+
+
+
+
+
Index: D:/Development/OSS/mojo-sandbox/tomcat-maven-plugin/src/main/resources/web.xml
===================================================================
--- D:/Development/OSS/mojo-sandbox/tomcat-maven-plugin/src/main/resources/web.xml (revision 0)
+++ D:/Development/OSS/mojo-sandbox/tomcat-maven-plugin/src/main/resources/web.xml (revision 0)
@@ -0,0 +1,1094 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ default
+ org.apache.catalina.servlets.DefaultServlet
+
+ debug
+ 0
+
+
+ listings
+ false
+
+ 1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ jsp
+ org.apache.jasper.servlet.JspServlet
+
+ fork
+ false
+
+
+ xpoweredBy
+ false
+
+ 3
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ default
+ /
+
+
+
+
+
+
+
+ jsp
+ *.jsp
+
+
+
+ jsp
+ *.jspx
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 30
+
+
+
+
+
+
+
+
+
+
+
+ abs
+ audio/x-mpeg
+
+
+ ai
+ application/postscript
+
+
+ aif
+ audio/x-aiff
+
+
+ aifc
+ audio/x-aiff
+
+
+ aiff
+ audio/x-aiff
+
+
+ aim
+ application/x-aim
+
+
+ art
+ image/x-jg
+
+
+ asf
+ video/x-ms-asf
+
+
+ asx
+ video/x-ms-asf
+
+
+ au
+ audio/basic
+
+
+ avi
+ video/x-msvideo
+
+
+ avx
+ video/x-rad-screenplay
+
+
+ bcpio
+ application/x-bcpio
+
+
+ bin
+ application/octet-stream
+
+
+ bmp
+ image/bmp
+
+
+ body
+ text/html
+
+
+ cdf
+ application/x-cdf
+
+
+ cer
+ application/x-x509-ca-cert
+
+
+ class
+ application/java
+
+
+ cpio
+ application/x-cpio
+
+
+ csh
+ application/x-csh
+
+
+ css
+ text/css
+
+
+ dib
+ image/bmp
+
+
+ doc
+ application/msword
+
+
+ dtd
+ application/xml-dtd
+
+
+ dv
+ video/x-dv
+
+
+ dvi
+ application/x-dvi
+
+
+ eps
+ application/postscript
+
+
+ etx
+ text/x-setext
+
+
+ exe
+ application/octet-stream
+
+
+ gif
+ image/gif
+
+
+ gtar
+ application/x-gtar
+
+
+ gz
+ application/x-gzip
+
+
+ hdf
+ application/x-hdf
+
+
+ hqx
+ application/mac-binhex40
+
+
+ htc
+ text/x-component
+
+
+ htm
+ text/html
+
+
+ html
+ text/html
+
+
+ hqx
+ application/mac-binhex40
+
+
+ ief
+ image/ief
+
+
+ jad
+ text/vnd.sun.j2me.app-descriptor
+
+
+ jar
+ application/java-archive
+
+
+ java
+ text/plain
+
+
+ jnlp
+ application/x-java-jnlp-file
+
+
+ jpe
+ image/jpeg
+
+
+ jpeg
+ image/jpeg
+
+
+ jpg
+ image/jpeg
+
+
+ js
+ text/javascript
+
+
+ jsf
+ text/plain
+
+
+ jspf
+ text/plain
+
+
+ kar
+ audio/x-midi
+
+
+ latex
+ application/x-latex
+
+
+ m3u
+ audio/x-mpegurl
+
+
+ mac
+ image/x-macpaint
+
+
+ man
+ application/x-troff-man
+
+
+ mathml
+ application/mathml+xml
+
+
+ me
+ application/x-troff-me
+
+
+ mid
+ audio/x-midi
+
+
+ midi
+ audio/x-midi
+
+
+ mif
+ application/x-mif
+
+
+ mov
+ video/quicktime
+
+
+ movie
+ video/x-sgi-movie
+
+
+ mp1
+ audio/x-mpeg
+
+
+ mp2
+ audio/x-mpeg
+
+
+ mp3
+ audio/x-mpeg
+
+
+ mpa
+ audio/x-mpeg
+
+
+ mpe
+ video/mpeg
+
+
+ mpeg
+ video/mpeg
+
+
+ mpega
+ audio/x-mpeg
+
+
+ mpg
+ video/mpeg
+
+
+ mpv2
+ video/mpeg2
+
+
+ ms
+ application/x-wais-source
+
+
+ nc
+ application/x-netcdf
+
+
+ oda
+ application/oda
+
+
+ ogg
+ application/ogg
+
+
+ pbm
+ image/x-portable-bitmap
+
+
+ pct
+ image/pict
+
+
+ pdf
+ application/pdf
+
+
+ pgm
+ image/x-portable-graymap
+
+
+ pic
+ image/pict
+
+
+ pict
+ image/pict
+
+
+ pls
+ audio/x-scpls
+
+
+ png
+ image/png
+
+
+ pnm
+ image/x-portable-anymap
+
+
+ pnt
+ image/x-macpaint
+
+
+ ppm
+ image/x-portable-pixmap
+
+
+ ppt
+ application/powerpoint
+
+
+ ps
+ application/postscript
+
+
+ psd
+ image/x-photoshop
+
+
+ qt
+ video/quicktime
+
+
+ qti
+ image/x-quicktime
+
+
+ qtif
+ image/x-quicktime
+
+
+ ras
+ image/x-cmu-raster
+
+
+ rdf
+ application/rdf+xml
+
+
+ rgb
+ image/x-rgb
+
+
+ rm
+ application/vnd.rn-realmedia
+
+
+ roff
+ application/x-troff
+
+
+ rtf
+ application/rtf
+
+
+ rtx
+ text/richtext
+
+
+ sh
+ application/x-sh
+
+
+ shar
+ application/x-shar
+
+
+ shtml
+ text/x-server-parsed-html
+
+
+ smf
+ audio/x-midi
+
+
+ sit
+ application/x-stuffit
+
+
+ snd
+ audio/basic
+
+
+ src
+ application/x-wais-source
+
+
+ sv4cpio
+ application/x-sv4cpio
+
+
+ sv4crc
+ application/x-sv4crc
+
+
+ svg
+ image/svg+xml
+
+
+ swf
+ application/x-shockwave-flash
+
+
+ t
+ application/x-troff
+
+
+ tar
+ application/x-tar
+
+
+ tcl
+ application/x-tcl
+
+
+ tex
+ application/x-tex
+
+
+ texi
+ application/x-texinfo
+
+
+ texinfo
+ application/x-texinfo
+
+
+ tif
+ image/tiff
+
+
+ tiff
+ image/tiff
+
+
+ tr
+ application/x-troff
+
+
+ tsv
+ text/tab-separated-values
+
+
+ txt
+ text/plain
+
+
+ ulw
+ audio/basic
+
+
+ ustar
+ application/x-ustar
+
+
+ vxml
+ application/voicexml+xml
+
+
+ xbm
+ image/x-xbitmap
+
+
+ xht
+ application/xhtml+xml
+
+
+ xhtml
+ application/xhtml+xml
+
+
+ xml
+ application/xml
+
+
+ xpm
+ image/x-xpixmap
+
+
+ xsl
+ application/xml
+
+
+ xslt
+ application/xslt+xml
+
+
+ xul
+ application/vnd.mozilla.xul+xml
+
+
+ xwd
+ image/x-xwindowdump
+
+
+ wav
+ audio/x-wav
+
+
+ svg
+ image/svg
+
+
+ svgz
+ image/svg
+
+
+ vsd
+ application/x-visio
+
+
+
+ wbmp
+ image/vnd.wap.wbmp
+
+
+
+ wml
+ text/vnd.wap.wml
+
+
+
+ wmlc
+ application/vnd.wap.wmlc
+
+
+
+ wmls
+ text/vnd.wap.wmlscript
+
+
+
+ wmlscriptc
+ application/vnd.wap.wmlscriptc
+
+
+ wrl
+ x-world/x-vrml
+
+
+ Z
+ application/x-compress
+
+
+ z
+ application/x-compress
+
+
+ zip
+ application/zip
+
+
+ xls
+ application/vnd.ms-excel
+
+
+ doc
+ application/vnd.ms-word
+
+
+ ppt
+ application/vnd.ms-powerpoint
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ index.html
+ index.htm
+ index.jsp
+
+
+
Index: D:/Development/OSS/mojo-sandbox/tomcat-maven-plugin/src/main/resources/log4j.xml
===================================================================
--- D:/Development/OSS/mojo-sandbox/tomcat-maven-plugin/src/main/resources/log4j.xml (revision 0)
+++ D:/Development/OSS/mojo-sandbox/tomcat-maven-plugin/src/main/resources/log4j.xml (revision 0)
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Index: D:/Development/OSS/mojo-sandbox/tomcat-maven-plugin/pom.xml
===================================================================
--- D:/Development/OSS/mojo-sandbox/tomcat-maven-plugin/pom.xml (revision 1853)
+++ D:/Development/OSS/mojo-sandbox/tomcat-maven-plugin/pom.xml (working copy)
@@ -1,24 +1,22 @@
-
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
mojo-sandbox
org.codehaus.mojo
2-SNAPSHOT
-
+
4.0.0
-
+
tomcat-maven-plugin
maven-plugin
1.0-SNAPSHOT
-
+
Tomcat Maven Plugin
-
+
Mark Hobson
@@ -29,7 +27,7 @@
0
-
+
org.apache.maven
@@ -41,6 +39,92 @@
commons-codec
1.3
+
+
+ tomcat
+ catalina
+ 5.5.15
+
+
+ tomcat
+ catalina-optional
+ 5.5.15
+
+
+ commons-el
+ commons-el
+ 1.0
+
+
+ commons-logging
+ commons-logging
+ 1.0.4
+
+
+ commons-modeler
+ commons-modeler
+ 1.1
+
+
+ tomcat
+ jasper-compiler
+ 5.5.15
+
+
+ tomcat
+ jasper-compiler-jdt
+ 5.5.15
+
+
+ tomcat
+ jasper-runtime
+ 5.5.15
+
+
+ tomcat
+ jsp-api
+ 5.5.15
+
+
+ tomcat
+ naming-factory
+ 5.5.15
+
+
+ tomcat
+ naming-resources
+ 5.5.15
+
+
+ tomcat
+ servlet-api
+ 5.5.15
+
+
+ tomcat
+ servlets-default
+ 5.5.15
+
+
+ tomcat
+ tomcat-coyote
+ 5.5.15
+
+
+ tomcat
+ tomcat-http
+ 5.5.15
+
+
+ tomcat
+ tomcat-util
+ 5.5.15
+
+
+ dom4j
+ dom4j
+ 1.6.1
+
-
+