./0000700000175000017500000000000011474402266007333 5ustar neoneo./tomcat-maven-plugin-1.1/0000700000175000017500000000000011453106444013513 5ustar neoneo./tomcat-maven-plugin-1.1/pom.xml0000600000175000017500000002051611453106432015033 0ustar neoneo org.codehaus.mojo mojo-parent 27 ../mojo-parent/pom.xml 4.0.0 tomcat-maven-plugin maven-plugin Tomcat Maven Plugin 1.1 The Tomcat Maven Plugin provides goals to manipulate WAR projects within the Tomcat servlet container. 6.0.29 1.5 1.5 2.0.8 ${mavenVersion} 2005 Mark Hobson markhobson@gmail.com Lead Developer 0 olamy Olivier Lamy olamy@apache.org Jurgen Lust Spike Washburn The Apache Software License, Version 2.0 http://www.apache.org/licenses/LICENSE-2.0.txt repo scm:svn:http://svn.codehaus.org/mojo/tags/tomcat-maven-plugin-1.1 scm:svn:https://svn.codehaus.org/mojo/tags/tomcat-maven-plugin-1.1 http://fisheye.codehaus.org/browse/mojo/tags/tomcat-maven-plugin-1.1 jira http://jira.codehaus.org/browse/MTOMCAT org.apache.maven maven-plugin-api ${mavenVersion} org.apache.maven maven-artifact-manager ${mavenVersion} org.apache.maven.wagon wagon-provider-api 1.0-alpha-5 org.apache.maven maven-artifact ${mavenVersion} org.apache.maven maven-project ${mavenVersion} org.apache.maven maven-archiver 2.2 org.codehaus.plexus plexus-utils 1.0.4 commons-codec commons-codec 1.3 org.codehaus.plexus plexus-classworlds 2.2.2 org.apache.tomcat catalina ${tomcat.version} org.apache.tomcat catalina-ha ${tomcat.version} runtime org.apache.tomcat tribes ${tomcat.version} runtime org.apache.tomcat el-api ${tomcat.version} runtime org.apache.tomcat jasper ${tomcat.version} runtime org.apache.tomcat jasper-el ${tomcat.version} runtime org.apache.tomcat jasper-jdt ${tomcat.version} runtime org.apache.tomcat jsp-api ${tomcat.version} runtime org.apache.tomcat servlet-api ${tomcat.version} runtime org.apache.tomcat coyote ${tomcat.version} runtime org.apache.tomcat dbcp ${tomcat.version} runtime maven-compiler-plugin ${compileSource} ${compileTarget} org.codehaus.plexus plexus-component-metadata 1.5.1 generate-metadata maven-pmd-plugin 2.4 ${compileSource} org.apache.maven.plugins maven-plugin-plugin 2.5 ${maven.compiler.target} maven-3 ${basedir} org.apache.maven.plugins maven-site-plugin 3.0-beta-2 org.apache.maven.plugins maven-javadoc-plugin 2.7 org.apache.maven.plugins maven-javadoc-plugin 2.7 org.apache.maven.plugins maven-project-info-reports-plugin 2.2 true false ./tomcat-maven-plugin-1.1/src/0000700000175000017500000000000011453106426014302 5ustar neoneo./tomcat-maven-plugin-1.1/src/main/0000700000175000017500000000000011453106424015224 5ustar neoneo./tomcat-maven-plugin-1.1/src/main/resources/0000700000175000017500000000000011453106424017236 5ustar neoneo./tomcat-maven-plugin-1.1/src/main/resources/conf/0000700000175000017500000000000011453106424020163 5ustar neoneo./tomcat-maven-plugin-1.1/src/main/resources/conf/web.xml0000600000175000017500000014403211453106424021470 0ustar neoneo 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 mp4 video/mp4 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 odb application/vnd.oasis.opendocument.database odc application/vnd.oasis.opendocument.chart odf application/vnd.oasis.opendocument.formula odg application/vnd.oasis.opendocument.graphics odi application/vnd.oasis.opendocument.image odm application/vnd.oasis.opendocument.text-master odp application/vnd.oasis.opendocument.presentation ods application/vnd.oasis.opendocument.spreadsheet odt application/vnd.oasis.opendocument.text ogg application/ogg otg application/vnd.oasis.opendocument.graphics-template oth application/vnd.oasis.opendocument.text-web otp application/vnd.oasis.opendocument.presentation-template ots application/vnd.oasis.opendocument.spreadsheet-template ott application/vnd.oasis.opendocument.text-template 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 smf audio/x-midi sit application/x-stuffit snd audio/basic src application/x-wais-source sv4cpio application/x-sv4cpio sv4crc application/x-sv4crc 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+xml svgz image/svg+xml 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 wmv video/x-ms-wmv wrl x-world/x-vrml wspolicy application/wspolicy+xml 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 ./tomcat-maven-plugin-1.1/src/main/resources/conf/tomcat-users.xml0000600000175000017500000000212311453106424023333 0ustar neoneo ./tomcat-maven-plugin-1.1/src/main/resources/org/0000700000175000017500000000000011453106424020025 5ustar neoneo./tomcat-maven-plugin-1.1/src/main/resources/org/codehaus/0000700000175000017500000000000011453106424021620 5ustar neoneo./tomcat-maven-plugin-1.1/src/main/resources/org/codehaus/mojo/0000700000175000017500000000000011453106424022564 5ustar neoneo./tomcat-maven-plugin-1.1/src/main/resources/org/codehaus/mojo/tomcat/0000700000175000017500000000000011453106424024053 5ustar neoneo./tomcat-maven-plugin-1.1/src/main/resources/org/codehaus/mojo/tomcat/messages.properties0000600000175000017500000000527711453106424030015 0ustar neoneo# AbstractCatalinaMojo AbstractCatalinaMojo.managerError = Cannot invoke Tomcat manager: {0} AbstractCatalinaMojo.managerIOError = Cannot invoke Tomcat manager AbstractCatalinaMojo.defaultAuth = No server specified for authentication - using defaults AbstractCatalinaMojo.unknownServer = Server not defined in settings.xml: {0} AbstractCatalinaMojo.defaultUserName = No server username specified - using default AbstractCatalinaMojo.defaultPassword = No server password specified - using default # AbstractWarCatalinaMojo AbstractWarCatalinaMojo.nonWar = Skipping non-war project # AbstractDeployMojo AbstractDeployMojo.unknownMode = Unknown deployment mode: {0} AbstractDeployMojo.missingContext = Cannot find context file: {0} AbstractDeployMojo.deployingWar = Deploying war to {0} AbstractDeployMojo.deployingContext = Deploying context to {0} AbstractDeployMojo.deployingWarContext = Deploying war and context to {0} # AbstractRunMojo AbstractRunMojo.nonWar = Skipping non-war project AbstractRunMojo.runningWar = Running war on {0} AbstractRunMojo.cannotStart = Could not start Tomcat AbstractRunMojo.cannotCreateConfiguration = Could not create Tomcat configuration AbstractRunMojo.creatingConfiguration = Creating Tomcat server configuration at {0} AbstractRunMojo.usingConfiguration = Using existing Tomcat server configuration at {0} AbstractRunMojo.interrupted = Tomcat server interrupted AbstractRunMojo.cannotStop = Could not stop Tomcat # DeployMojo DeployMojo.missingWar = Cannot find war file: {0} DeployMojo.invalidMode = Cannot deploy war and context using tomcat:deploy - use tomcat:exploded or tomcat:inplace instead # ExplodedMojo ExplodedMojo.missingWar = Cannot find exploded war: {0} # InplaceMojo InplaceMojo.missingWar = Cannot find inplace war: {0} # ListMojo ListMojo.listApps = Listing applications at {0} # RedeployMojo RedeployMojo.redeployApp = Redeploying application at {0} # ResourcesMojo ResourcesMojo.listAllResources = Listing all resources at {0} ResourcesMojo.listTypedResources = Listing resources of type {0} at {1} # RolesMojo RolesMojo.listRoles = Listing security roles at {0} # ServerInfoMojo ServerInfoMojo.listInfo = Listing server information at {0} # SessionsMojo SessionsMojo.listSessions = Listing session information for application at {0} # ShutdownMojo ShutdownMojo.shutdownError = Error while shutting down embedded tomcats. # StartMojo StartMojo.startingApp = Starting application at {0} # StopMojo StopMojo.stoppingApp = Stopping application at {0} # UndeployMojo UndeployMojo.undeployingApp = Undeploying application at {0} UndeployMojo.undeployError = Cannot undeploy application: {0} # ReloadMojo ReloadMojo.reloadingApp = Reloading application at {0} ./tomcat-maven-plugin-1.1/src/main/java/0000700000175000017500000000000011453106422016143 5ustar neoneo./tomcat-maven-plugin-1.1/src/main/java/org/0000700000175000017500000000000011453106422016732 5ustar neoneo./tomcat-maven-plugin-1.1/src/main/java/org/codehaus/0000700000175000017500000000000011453106422020525 5ustar neoneo./tomcat-maven-plugin-1.1/src/main/java/org/codehaus/mojo/0000700000175000017500000000000011453106422021471 5ustar neoneo./tomcat-maven-plugin-1.1/src/main/java/org/codehaus/mojo/tomcat/0000700000175000017500000000000011453106424022762 5ustar neoneo./tomcat-maven-plugin-1.1/src/main/java/org/codehaus/mojo/tomcat/EmbeddedRegistry.java0000600000175000017500000001121111453106424027045 0ustar neoneopackage org.codehaus.mojo.tomcat; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import org.apache.catalina.LifecycleException; import org.apache.catalina.startup.Embedded; import org.apache.maven.plugin.logging.Log; import java.util.HashSet; import java.util.Iterator; import java.util.Set; /** * Registry which collects all embedded Tomcat Servers so that they will be shutdown * through a shutdown hook when the JVM terminates or you can ask the registry to * shutdown all started servers. * @author Mark Michaelis * @since 1.1 */ public final class EmbeddedRegistry { private static EmbeddedRegistry instance; private Set containers = new HashSet( 1 ); /** * Don't instantiate - use the instance through {@link #getInstance()}. */ private EmbeddedRegistry() { // no op } /** * Retrieve the lazily initialized instance of the registry. * * @return singleton instance of the registry */ public static EmbeddedRegistry getInstance() { if ( instance == null ) { instance = new EmbeddedRegistry(); Runtime.getRuntime().addShutdownHook( new Thread() { @Override public void run() { try { getInstance().shutdownAll( null ); } catch ( LifecycleException e ) { // ignore, the exception should already have been reported } } } ); } return instance; } /** * Adds the given container to the registry which automatically registers it for the shutdown * hook. * * @param container the container to register * @return true if it got added; false if not */ public synchronized boolean register( final Embedded container ) { return containers.add( container ); } /** * Shuts down all registered embedded tomcats. All tomcats which successfully shut down will be * removed from the registry. * * @param log the log to write possible shutdown exceptions to * @throws LifecycleException the first exception which occurred will be rethrown */ public synchronized void shutdownAll( final Log log ) throws LifecycleException { LifecycleException firstException = null; for ( Iterator iterator = containers.iterator(); iterator.hasNext(); ) { Embedded embedded = iterator.next(); try { embedded.stop(); iterator.remove(); } catch ( LifecycleException e ) { if ( firstException == null ) { firstException = e; error( log, e, "Error while shutting down embedded Tomcat. Will be rethrown." ); } else { error( log, e, "Error while shutting down embedded Tomcat." ); } } } if ( firstException != null ) { throw firstException; } } /** * Reports the exception. If a log is given (typically when called from within a Mojo) the * message will be printed to the log. Otherwise it will be printed to StdErr. * * @param log the log to write the message to; null to write to stderr * @param e exception which shall be reported * @param message message which shall be reported */ private void error( final Log log, final LifecycleException e, final String message ) { if ( log == null ) { System.err.println( "ERROR: " + message ); e.printStackTrace(); } else { log.error( message, e ); } } } ./tomcat-maven-plugin-1.1/src/main/java/org/codehaus/mojo/tomcat/AbstractRunWarMojo.java0000600000175000017500000000443211453106424027361 0ustar neoneopackage org.codehaus.mojo.tomcat; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.io.File; /** * Runs the current project as a packaged web application using an embedded Tomcat server. * * @requiresDependencyResolution runtime * @author Mark Hobson * @version $Id: AbstractRunWarMojo.java 12065 2010-04-05 17:15:53Z olamy $ * @todo depend on war:exploded when MNG-1649 resolved */ public abstract class AbstractRunWarMojo extends AbstractRunMojo { // ---------------------------------------------------------------------- // Mojo Parameters // ---------------------------------------------------------------------- /** * The path of the exploded WAR directory to run. * * @parameter expression = "${project.build.directory}/${project.build.finalName}" * @required */ private File warDirectory; /** * The path of the Tomcat context XML file. * * @parameter expression = * "${project.build.directory}/${project.build.finalName}/META-INF/context.xml" */ private File contextFile; // ---------------------------------------------------------------------- // AbstractRunMojo Implementation // ---------------------------------------------------------------------- /** * {@inheritDoc} */ @Override protected File getDocBase() { return warDirectory; } /** * {@inheritDoc} */ @Override protected File getContextFile() { return contextFile; } } ./tomcat-maven-plugin-1.1/src/main/java/org/codehaus/mojo/tomcat/RunWarMojo.java0000600000175000017500000000243011453106424025671 0ustar neoneopackage org.codehaus.mojo.tomcat; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ /** * Runs the current project as a packaged web application using an embedded Tomcat server. * * @goal run-war * @execute phase="package" * @requiresDependencyResolution runtime * @author Mark Hobson * @version $Id: RunWarMojo.java 12065 2010-04-05 17:15:53Z olamy $ * @todo depend on war:exploded when MNG-1649 resolved */ public class RunWarMojo extends AbstractRunWarMojo { // no-op : only mojo metadata overriding } ./tomcat-maven-plugin-1.1/src/main/java/org/codehaus/mojo/tomcat/ListMojo.java0000600000175000017500000000316311453106424025372 0ustar neoneopackage org.codehaus.mojo.tomcat; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import org.apache.maven.plugin.MojoExecutionException; import java.io.IOException; /** * Lists all the currently deployed web applications in Tomcat. * * @goal list * @author Mark Hobson * @version $Id: ListMojo.java 8855 2009-01-21 11:23:04Z olamy $ */ public class ListMojo extends AbstractCatalinaMojo { // ---------------------------------------------------------------------- // Protected Methods // ---------------------------------------------------------------------- /** * {@inheritDoc} */ @Override protected void invokeManager() throws MojoExecutionException, TomcatManagerException, IOException { getLog().info( getMessage( "ListMojo.listApps", getURL() ) ); log( getManager().list() ); } } ./tomcat-maven-plugin-1.1/src/main/java/org/codehaus/mojo/tomcat/DeployMojo.java0000600000175000017500000000217311453106424025713 0ustar neoneopackage org.codehaus.mojo.tomcat; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ /** * Deploy a WAR to Tomcat. * * @goal deploy * @execute phase="package" * @author Mark Hobson * @version $Id: DeployMojo.java 8857 2009-01-21 11:35:26Z olamy $ */ public class DeployMojo extends AbstractDeployWarMojo { // no-op : only mojo metadata overriding } ./tomcat-maven-plugin-1.1/src/main/java/org/codehaus/mojo/tomcat/SessionsMojo.java0000600000175000017500000000322611453106424026265 0ustar neoneopackage org.codehaus.mojo.tomcat; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import org.apache.maven.plugin.MojoExecutionException; import java.io.IOException; /** * Lists session information for a WAR in Tomcat. * * @goal sessions * @author Mark Hobson * @version $Id: SessionsMojo.java 8855 2009-01-21 11:23:04Z olamy $ */ public class SessionsMojo extends AbstractWarCatalinaMojo { // ---------------------------------------------------------------------- // Protected Methods // ---------------------------------------------------------------------- /** * {@inheritDoc} */ @Override protected void invokeManager() throws MojoExecutionException, TomcatManagerException, IOException { getLog().info( getMessage( "SessionsMojo.listSessions", getDeployedURL() ) ); log( getManager().getSessions( getPath() ) ); } } ./tomcat-maven-plugin-1.1/src/main/java/org/codehaus/mojo/tomcat/RolesMojo.java0000600000175000017500000000313711453106424025544 0ustar neoneopackage org.codehaus.mojo.tomcat; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import org.apache.maven.plugin.MojoExecutionException; import java.io.IOException; /** * Lists security roles in Tomcat. * * @goal roles * @author Mark Hobson * @version $Id: RolesMojo.java 8855 2009-01-21 11:23:04Z olamy $ */ public class RolesMojo extends AbstractCatalinaMojo { // ---------------------------------------------------------------------- // Protected Methods // ---------------------------------------------------------------------- /** * {@inheritDoc} */ @Override protected void invokeManager() throws MojoExecutionException, TomcatManagerException, IOException { getLog().info( getMessage( "RolesMojo.listRoles", getURL() ) ); log( getManager().getRoles() ); } } ./tomcat-maven-plugin-1.1/src/main/java/org/codehaus/mojo/tomcat/StartMojo.java0000600000175000017500000000315311453106424025553 0ustar neoneopackage org.codehaus.mojo.tomcat; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import org.apache.maven.plugin.MojoExecutionException; import java.io.IOException; /** * Start a WAR in Tomcat. * * @goal start * @author Mark Hobson * @version $Id: StartMojo.java 8855 2009-01-21 11:23:04Z olamy $ */ public class StartMojo extends AbstractWarCatalinaMojo { // ---------------------------------------------------------------------- // Protected Methods // ---------------------------------------------------------------------- /** * {@inheritDoc} */ @Override protected void invokeManager() throws MojoExecutionException, TomcatManagerException, IOException { getLog().info( getMessage( "StartMojo.startingApp", getDeployedURL() ) ); log( getManager().start( getPath() ) ); } } ./tomcat-maven-plugin-1.1/src/main/java/org/codehaus/mojo/tomcat/StopMojo.java0000600000175000017500000000314511453106424025404 0ustar neoneopackage org.codehaus.mojo.tomcat; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import org.apache.maven.plugin.MojoExecutionException; import java.io.IOException; /** * Stop a WAR in Tomcat. * * @goal stop * @author Mark Hobson * @version $Id: StopMojo.java 8855 2009-01-21 11:23:04Z olamy $ */ public class StopMojo extends AbstractWarCatalinaMojo { // ---------------------------------------------------------------------- // Protected Methods // ---------------------------------------------------------------------- /** * {@inheritDoc} */ @Override protected void invokeManager() throws MojoExecutionException, TomcatManagerException, IOException { getLog().info( getMessage( "StopMojo.stoppingApp", getDeployedURL() ) ); log( getManager().stop( getPath() ) ); } } ./tomcat-maven-plugin-1.1/src/main/java/org/codehaus/mojo/tomcat/ServerInfoMojo.java0000600000175000017500000000322511453106424026540 0ustar neoneopackage org.codehaus.mojo.tomcat; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import org.apache.maven.plugin.MojoExecutionException; import java.io.IOException; /** * Lists information about the Tomcat version, OS, and JVM properties. * * @goal info * @author Mark Hobson * @version $Id: ServerInfoMojo.java 8855 2009-01-21 11:23:04Z olamy $ */ public class ServerInfoMojo extends AbstractCatalinaMojo { // ---------------------------------------------------------------------- // Protected Methods // ---------------------------------------------------------------------- /** * {@inheritDoc} */ @Override protected void invokeManager() throws MojoExecutionException, TomcatManagerException, IOException { getLog().info( getMessage( "ServerInfoMojo.listInfo", getURL() ) ); log( getManager().getServerInfo() ); } } ./tomcat-maven-plugin-1.1/src/main/java/org/codehaus/mojo/tomcat/TomcatManager.java0000600000175000017500000006255611453106424026367 0ustar neoneopackage org.codehaus.mojo.tomcat; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import org.apache.commons.codec.binary.Base64; import java.io.BufferedOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; /** * A Tomcat manager webapp invocation wrapper. * * @author Mark Hobson * @version $Id: TomcatManager.java 8855 2009-01-21 11:23:04Z olamy $ */ public class TomcatManager { // ---------------------------------------------------------------------- // Constants // ---------------------------------------------------------------------- /** * The charset to use when decoding Tomcat manager responses. */ private static final String MANAGER_CHARSET = "UTF-8"; // ---------------------------------------------------------------------- // Fields // ---------------------------------------------------------------------- /** * The full URL of the Tomcat manager instance to use. */ private URL url; /** * The username to use when authenticating with Tomcat manager. */ private String username; /** * The password to use when authenticating with Tomcat manager. */ private String password; /** * The URL encoding charset to use when communicating with Tomcat manager. */ private String charset; /** * The user agent name to use when communicating with Tomcat manager. */ private String userAgent; // ---------------------------------------------------------------------- // Constructors // ---------------------------------------------------------------------- /** * Creates a Tomcat manager wrapper for the specified URL that uses a username of admin, an empty * password and ISO-8859-1 URL encoding. * * @param url the full URL of the Tomcat manager instance to use */ public TomcatManager( URL url ) { this( url, "admin" ); } /** * Creates a Tomcat manager wrapper for the specified URL and username that uses an empty password and ISO-8859-1 * URL encoding. * * @param url the full URL of the Tomcat manager instance to use * @param username the username to use when authenticating with Tomcat manager */ public TomcatManager( URL url, String username ) { this( url, username, "" ); } /** * Creates a Tomcat manager wrapper for the specified URL, username and password that uses ISO-8859-1 URL encoding. * * @param url the full URL of the Tomcat manager instance to use * @param username the username to use when authenticating with Tomcat manager * @param password the password to use when authenticating with Tomcat manager */ public TomcatManager( URL url, String username, String password ) { this( url, username, password, "ISO-8859-1" ); } /** * Creates a Tomcat manager wrapper for the specified URL, username, password and URL encoding. * * @param url the full URL of the Tomcat manager instance to use * @param username the username to use when authenticating with Tomcat manager * @param password the password to use when authenticating with Tomcat manager * @param charset the URL encoding charset to use when communicating with Tomcat manager */ public TomcatManager( URL url, String username, String password, String charset ) { this.url = url; this.username = username; this.password = password; this.charset = charset; } // ---------------------------------------------------------------------- // Public Methods // ---------------------------------------------------------------------- /** * Gets the full URL of the Tomcat manager instance. * * @return the full URL of the Tomcat manager instance */ public URL getURL() { return url; } /** * Gets the username to use when authenticating with Tomcat manager. * * @return the username to use when authenticating with Tomcat manager */ public String getUserName() { return username; } /** * Gets the password to use when authenticating with Tomcat manager. * * @return the password to use when authenticating with Tomcat manager */ public String getPassword() { return password; } /** * Gets the URL encoding charset to use when communicating with Tomcat manager. * * @return the URL encoding charset to use when communicating with Tomcat manager */ public String getCharset() { return charset; } /** * Gets the user agent name to use when communicating with Tomcat manager. * * @return the user agent name to use when communicating with Tomcat manager */ public String getUserAgent() { return userAgent; } /** * Sets the user agent name to use when communicating with Tomcat manager. * * @param userAgent the user agent name to use when communicating with Tomcat manager */ public void setUserAgent( String userAgent ) { this.userAgent = userAgent; } /** * Deploys the specified WAR as a URL to the specified context path. * * @param path the webapp context path to deploy to * @param war the URL of the WAR to deploy * @return the Tomcat manager response * @throws TomcatManagerException if the Tomcat manager request fails * @throws IOException if an i/o error occurs */ public String deploy( String path, URL war ) throws TomcatManagerException, IOException { return deploy( path, war, false ); } /** * Deploys the specified WAR as a URL to the specified context path, optionally undeploying the webapp if it already * exists. * * @param path the webapp context path to deploy to * @param war the URL of the WAR to deploy * @param update whether to first undeploy the webapp if it already exists * @return the Tomcat manager response * @throws TomcatManagerException if the Tomcat manager request fails * @throws IOException if an i/o error occurs */ public String deploy( String path, URL war, boolean update ) throws TomcatManagerException, IOException { return deploy( path, war, update, null ); } /** * Deploys the specified WAR as a URL to the specified context path, optionally undeploying the webapp if it already * exists and using the specified tag name. * * @param path the webapp context path to deploy to * @param war the URL of the WAR to deploy * @param update whether to first undeploy the webapp if it already exists * @param tag the tag name to use * @return the Tomcat manager response * @throws TomcatManagerException if the Tomcat manager request fails * @throws IOException if an i/o error occurs */ public String deploy( String path, URL war, boolean update, String tag ) throws TomcatManagerException, IOException { return deployImpl( path, null, war, null, update, tag ); } /** * Deploys the specified WAR as a HTTP PUT to the specified context path. * * @param path the webapp context path to deploy to * @param war an input stream to the WAR to deploy * @return the Tomcat manager response * @throws TomcatManagerException if the Tomcat manager request fails * @throws IOException if an i/o error occurs */ public String deploy( String path, InputStream war ) throws TomcatManagerException, IOException { return deploy( path, war, false ); } /** * Deploys the specified WAR as a HTTP PUT to the specified context path, optionally undeploying the webapp if it * already exists. * * @param path the webapp context path to deploy to * @param war an input stream to the WAR to deploy * @param update whether to first undeploy the webapp if it already exists * @return the Tomcat manager response * @throws TomcatManagerException if the Tomcat manager request fails * @throws IOException if an i/o error occurs */ public String deploy( String path, InputStream war, boolean update ) throws TomcatManagerException, IOException { return deploy( path, war, update, null ); } /** * Deploys the specified WAR as a HTTP PUT to the specified context path, optionally undeploying the webapp if it * already exists and using the specified tag name. * * @param path the webapp context path to deploy to * @param war an input stream to the WAR to deploy * @param update whether to first undeploy the webapp if it already exists * @param tag the tag name to use * @return the Tomcat manager response * @throws TomcatManagerException if the Tomcat manager request fails * @throws IOException if an i/o error occurs */ public String deploy( String path, InputStream war, boolean update, String tag ) throws TomcatManagerException, IOException { return deployImpl( path, null, null, war, update, tag ); } /** * Deploys the specified context XML configuration to the specified context path. * * @param path the webapp context path to deploy to * @param config the URL of the context XML configuration to deploy * @return the Tomcat manager response * @throws TomcatManagerException if the Tomcat manager request fails * @throws IOException if an i/o error occurs */ public String deployContext( String path, URL config ) throws TomcatManagerException, IOException { return deployContext( path, config, false ); } /** * Deploys the specified context XML configuration to the specified context path, optionally undeploying the webapp * if it already exists. * * @param path the webapp context path to deploy to * @param config the URL of the context XML configuration to deploy * @param update whether to first undeploy the webapp if it already exists * @return the Tomcat manager response * @throws TomcatManagerException if the Tomcat manager request fails * @throws IOException if an i/o error occurs */ public String deployContext( String path, URL config, boolean update ) throws TomcatManagerException, IOException { return deployContext( path, config, update, null ); } /** * Deploys the specified context XML configuration to the specified context path, optionally undeploying the webapp * if it already exists and using the specified tag name. * * @param path the webapp context path to deploy to * @param config the URL of the context XML configuration to deploy * @param update whether to first undeploy the webapp if it already exists * @param tag the tag name to use * @return the Tomcat manager response * @throws TomcatManagerException if the Tomcat manager request fails * @throws IOException if an i/o error occurs */ public String deployContext( String path, URL config, boolean update, String tag ) throws TomcatManagerException, IOException { return deployContext( path, config, null, update, tag ); } /** * Deploys the specified context XML configuration and WAR as a URL to the specified context path. * * @param path the webapp context path to deploy to * @param config the URL of the context XML configuration to deploy * @param war the URL of the WAR to deploy * @return the Tomcat manager response * @throws TomcatManagerException if the Tomcat manager request fails * @throws IOException if an i/o error occurs */ public String deployContext( String path, URL config, URL war ) throws TomcatManagerException, IOException { return deployContext( path, config, war, false ); } /** * Deploys the specified context XML configuration and WAR as a URL to the specified context path, optionally * undeploying the webapp if it already exists. * * @param path the webapp context path to deploy to * @param config the URL of the context XML configuration to deploy * @param war the URL of the WAR to deploy * @param update whether to first undeploy the webapp if it already exists * @return the Tomcat manager response * @throws TomcatManagerException if the Tomcat manager request fails * @throws IOException if an i/o error occurs */ public String deployContext( String path, URL config, URL war, boolean update ) throws TomcatManagerException, IOException { return deployContext( path, config, war, update, null ); } /** * Deploys the specified context XML configuration and WAR as a URL to the specified context path, optionally * undeploying the webapp if it already exists and using the specified tag name. * * @param path the webapp context path to deploy to * @param config the URL of the context XML configuration to deploy * @param war the URL of the WAR to deploy * @param update whether to first undeploy the webapp if it already exists * @param tag the tag name to use * @return the Tomcat manager response * @throws TomcatManagerException if the Tomcat manager request fails * @throws IOException if an i/o error occurs */ public String deployContext( String path, URL config, URL war, boolean update, String tag ) throws TomcatManagerException, IOException { return deployImpl( path, config, war, null, update, tag ); } /** * Undeploys the webapp at the specified context path. * * @param path the webapp context path to undeploy * @return the Tomcat manager response * @throws TomcatManagerException if the Tomcat manager request fails * @throws IOException if an i/o error occurs */ public String undeploy( String path ) throws TomcatManagerException, IOException { return invoke( "/undeploy?path=" + URLEncoder.encode( path, charset ) ); } /** * Reloads the webapp at the specified context path. * * @param path the webapp context path to reload * @return the Tomcat manager response * @throws TomcatManagerException if the Tomcat manager request fails * @throws IOException if an i/o error occurs */ public String reload( String path ) throws TomcatManagerException, IOException { return invoke( "/reload?path=" + URLEncoder.encode( path, charset ) ); } /** * Starts the webapp at the specified context path. * * @param path the webapp context path to start * @return the Tomcat manager response * @throws TomcatManagerException if the Tomcat manager request fails * @throws IOException if an i/o error occurs */ public String start( String path ) throws TomcatManagerException, IOException { return invoke( "/start?path=" + URLEncoder.encode( path, charset ) ); } /** * Stops the webapp at the specified context path. * * @param path the webapp context path to stop * @return the Tomcat manager response * @throws TomcatManagerException if the Tomcat manager request fails * @throws IOException if an i/o error occurs */ public String stop( String path ) throws TomcatManagerException, IOException { return invoke( "/stop?path=" + URLEncoder.encode( path, charset ) ); } /** * Lists all the currently deployed web applications. * * @return the list of currently deployed applications * @throws TomcatManagerException if the Tomcat manager request fails * @throws IOException if an i/o error occurs */ public String list() throws TomcatManagerException, IOException { return invoke( "/list" ); } /** * Lists information about the Tomcat version, OS, and JVM properties. * * @return the server information * @throws TomcatManagerException if the Tomcat manager request fails * @throws IOException if an i/o error occurs */ public String getServerInfo() throws TomcatManagerException, IOException { return invoke( "/serverinfo" ); } /** * Lists all of the global JNDI resources. * * @return the list of all global JNDI resources * @throws TomcatManagerException if the Tomcat manager request fails * @throws IOException if an i/o error occurs */ public String getResources() throws TomcatManagerException, IOException { return getResources( null ); } /** * Lists the global JNDI resources of the given type. * * @param type the class name of the resources to list, or null for all * @return the list of global JNDI resources of the given type * @throws TomcatManagerException if the Tomcat manager request fails * @throws IOException if an i/o error occurs */ public String getResources( String type ) throws TomcatManagerException, IOException { StringBuffer buffer = new StringBuffer(); buffer.append( "/resources" ); if ( type != null ) { buffer.append( "?type=" + URLEncoder.encode( type, charset ) ); } return invoke( buffer.toString() ); } /** * Lists the security role names and corresponding descriptions that are available. * * @return the list of security role names and corresponding descriptions * @throws TomcatManagerException if the Tomcat manager request fails * @throws IOException if an i/o error occurs */ public String getRoles() throws TomcatManagerException, IOException { return invoke( "/roles" ); } /** * Lists the default session timeout and the number of currently active sessions for the given context path. * * @param path the context path to list session information for * @return the default session timeout and the number of currently active sessions * @throws TomcatManagerException if the Tomcat manager request fails * @throws IOException if an i/o error occurs */ public String getSessions( String path ) throws TomcatManagerException, IOException { return invoke( "/sessions?path=" + URLEncoder.encode( path, charset ) ); } // ---------------------------------------------------------------------- // Protected Methods // ---------------------------------------------------------------------- /** * Invokes Tomcat manager with the specified command. * * @param path the Tomcat manager command to invoke * @return the Tomcat manager response * @throws TomcatManagerException if the Tomcat manager request fails * @throws IOException if an i/o error occurs */ protected String invoke( String path ) throws TomcatManagerException, IOException { return invoke( path, null ); } /** * Invokes Tomcat manager with the specified command and content data. * * @param path the Tomcat manager command to invoke * @param data an input stream to the content data * @return the Tomcat manager response * @throws TomcatManagerException if the Tomcat manager request fails * @throws IOException if an i/o error occurs */ protected String invoke( String path, InputStream data ) throws TomcatManagerException, IOException { HttpURLConnection connection = (HttpURLConnection) new URL( url + path ).openConnection(); connection.setAllowUserInteraction( false ); connection.setDoInput( true ); connection.setUseCaches( false ); if ( data == null ) { connection.setDoOutput( false ); connection.setRequestMethod( "GET" ); } else { connection.setDoOutput( true ); connection.setRequestMethod( "PUT" ); connection.setRequestProperty( "Content-Type", "application/octet-stream" ); } if ( userAgent != null ) { connection.setRequestProperty( "User-Agent", userAgent ); } connection.setRequestProperty( "Authorization", toAuthorization( username, password ) ); connection.connect(); if ( data != null ) { pipe( data, connection.getOutputStream() ); } String response = toString( connection.getInputStream(), MANAGER_CHARSET ); if ( !response.startsWith( "OK -" ) ) { throw new TomcatManagerException( response ); } return response; } // ---------------------------------------------------------------------- // Private Methods // ---------------------------------------------------------------------- /** * Deploys the specified WAR. * * @param path the webapp context path to deploy to * @param config the URL of the context XML configuration to deploy, or null for none * @param war the URL of the WAR to deploy, or null to use data * @param data an input stream to the WAR to deploy, or null to use war * @param update whether to first undeploy the webapp if it already exists * @param tag the tag name to use * @return the Tomcat manager response * @throws TomcatManagerException if the Tomcat manager request fails * @throws IOException if an i/o error occurs */ private String deployImpl( String path, URL config, URL war, InputStream data, boolean update, String tag ) throws TomcatManagerException, IOException { StringBuffer buffer = new StringBuffer( "/deploy" ); buffer.append( "?path=" ).append( URLEncoder.encode( path, charset ) ); if ( config != null ) { buffer.append( "&config=" ).append( URLEncoder.encode( config.toString(), charset ) ); } if ( war != null ) { buffer.append( "&war=" ).append( URLEncoder.encode( war.toString(), charset ) ); } else { // for Tomcat 5.0.27 buffer.append( "&war=" ); } if ( update ) { buffer.append( "&update=true" ); } if ( tag != null ) { buffer.append( "&tag=" ).append( URLEncoder.encode( tag, charset ) ); } return invoke( buffer.toString(), data ); } /** * Gets the HTTP Basic Authorization header value for the supplied username and password. * * @param username the username to use for authentication * @param password the password to use for authentication * @return the HTTP Basic Authorization header value */ private String toAuthorization( String username, String password ) { StringBuffer buffer = new StringBuffer(); buffer.append( username ).append( ':' ); if ( password != null ) { buffer.append( password ); } return "Basic " + new String( Base64.encodeBase64( buffer.toString().getBytes() ) ); } /** * Reads all the data from the specified input stream and writes it to the specified output stream. Both streams are * also closed. * * @param in the input stream to read from * @param out the output stream to write to * @throws IOException if an i/o error occurs */ private void pipe( InputStream in, OutputStream out ) throws IOException { out = new BufferedOutputStream( out ); int n; byte[] bytes = new byte[1024 * 4]; while ( ( n = in.read( bytes ) ) != -1 ) { out.write( bytes, 0, n ); } out.flush(); out.close(); in.close(); } /** * Gets the data from the specified input stream as a string using the specified charset. * * @param in the input stream to read from * @param charset the charset to use when constructing the string * @return a string representation of the data read from the input stream * @throws IOException if an i/o error occurs */ private String toString( InputStream in, String charset ) throws IOException { InputStreamReader reader = new InputStreamReader( in, charset ); StringBuffer buffer = new StringBuffer(); char[] chars = new char[1024]; int n; while ( ( n = reader.read( chars, 0, chars.length ) ) != -1 ) { buffer.append( chars, 0, n ); } return buffer.toString(); } } ./tomcat-maven-plugin-1.1/src/main/java/org/codehaus/mojo/tomcat/UndeployMojo.java0000600000175000017500000000447311453106424026263 0ustar neoneopackage org.codehaus.mojo.tomcat; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import org.apache.maven.plugin.MojoExecutionException; import java.io.IOException; /** * Undeploy a WAR from Tomcat. * * @goal undeploy * @author Mark Hobson * @version $Id: UndeployMojo.java 8855 2009-01-21 11:23:04Z olamy $ */ public class UndeployMojo extends AbstractWarCatalinaMojo { // ---------------------------------------------------------------------- // Mojo Parameters // ---------------------------------------------------------------------- /** * Whether to fail the build if the web application cannot be undeployed. * * @parameter expression = "${maven.tomcat.failOnError}" default-value = "true" */ private boolean failOnError; // ---------------------------------------------------------------------- // Protected Methods // ---------------------------------------------------------------------- /** * {@inheritDoc} */ @Override protected void invokeManager() throws MojoExecutionException, TomcatManagerException, IOException { getLog().info( getMessage( "UndeployMojo.undeployingApp", getDeployedURL() ) ); try { log( getManager().undeploy( getPath() ) ); } catch ( TomcatManagerException exception ) { if ( failOnError ) { throw exception; } getLog().warn( getMessage( "UndeployMojo.undeployError", exception.getMessage() ) ); } } } ./tomcat-maven-plugin-1.1/src/main/java/org/codehaus/mojo/tomcat/AbstractI18NMojo.java0000600000175000017500000001112711453106424026621 0ustar neoneopackage org.codehaus.mojo.tomcat; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.text.MessageFormat; import java.util.MissingResourceException; import java.util.ResourceBundle; import org.apache.maven.plugin.AbstractMojo; /** * Abstract goal that provides i18n support. * * @author Mark Hobson * @version $Id: AbstractI18NMojo.java 8855 2009-01-21 11:23:04Z olamy $ */ public abstract class AbstractI18NMojo extends AbstractMojo { // ---------------------------------------------------------------------- // Mojo Parameters // ---------------------------------------------------------------------- /** * The webapp context path to use for the web application being run. This must always start with a forward-slash * ('/'). * * @parameter expression="${maven.tomcat.path}" default-value="/${project.artifactId}" * @required */ protected String path; // ---------------------------------------------------------------------- // Fields // ---------------------------------------------------------------------- /** * The plugin messages. */ private ResourceBundle messages; // ---------------------------------------------------------------------- // Constructors // ---------------------------------------------------------------------- /** * Creates a new AbstractI18NMojo. */ public AbstractI18NMojo() { String packageName = getClass().getPackage().getName(); messages = ResourceBundle.getBundle( packageName + ".messages" ); } // ---------------------------------------------------------------------- // Protected Methods // ---------------------------------------------------------------------- /** * Gets the message for the given key from this packages resource bundle. * * @param key the key for the required message * @return the message */ protected String getMessage( String key ) { try { return messages.getString( key ); } catch ( NullPointerException exception ) { return "???" + key + "???"; } catch ( MissingResourceException exception ) { return "???" + key + "???"; } catch ( ClassCastException exception ) { return "???" + key + "???"; } } /** * Gets the message for the given key from this packages resource bundle and formats it with the given parameter. * * @param key the key for the required message * @param param the parameter to be used to format the message with * @return the formatted message */ protected String getMessage( String key, Object param ) { return MessageFormat.format( getMessage( key ), new Object[] { param } ); } /** * Gets the message for the given key from this packages resource bundle and formats it with the given parameters. * * @param key the key for the required message * @param param1 the first parameter to be used to format the message with * @param param2 the second parameter to be used to format the message with * @return the formatted message */ protected String getMessage( String key, Object param1, Object param2 ) { return MessageFormat.format( getMessage( key ), new Object[] { param1, param2 } ); } /** * Gets the message for the given key from this packages resource bundle and formats it with the given parameters. * * @param key the key for the required message * @param params the parameters to be used to format the message with * @return the formatted message */ protected String getMessage( String key, Object[] params ) { return MessageFormat.format( getMessage( key ), params ); } } ./tomcat-maven-plugin-1.1/src/main/java/org/codehaus/mojo/tomcat/TomcatManagerException.java0000600000175000017500000000445511453106424030240 0ustar neoneopackage org.codehaus.mojo.tomcat; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ /** * Indicates an error received from Tomcat manager. * * @author Mark Hobson * @version $Id: TomcatManagerException.java 8855 2009-01-21 11:23:04Z olamy $ */ public class TomcatManagerException extends Exception { // ---------------------------------------------------------------------- // Constants // ---------------------------------------------------------------------- /** * The Java serialization UID for this class. */ private static final long serialVersionUID = 4167819069046408371L; // ---------------------------------------------------------------------- // Constructors // ---------------------------------------------------------------------- /** * Creates a new TomcatManagerException with no message or cause. */ public TomcatManagerException() { super(); } /** * Creates a new TomcatManagerException with the specified message and no cause. * * @param message the message for this exception */ public TomcatManagerException( String message ) { super( message ); } /** * Creates a new TomcatManagerException with the specified message and cause. * * @param message the message for this exception * @param cause the cause of this exception */ public TomcatManagerException( String message, Throwable cause ) { super( message, cause ); } } ./tomcat-maven-plugin-1.1/src/main/java/org/codehaus/mojo/tomcat/ShutdownMojo.java0000600000175000017500000000370011453106424026267 0ustar neoneopackage org.codehaus.mojo.tomcat; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import org.apache.catalina.LifecycleException; import org.apache.maven.plugin.MojoExecutionException; /** *

* Shuts down all possibly started embedded tomcat servers. This will be automatically down * through a shutdown hook or you may call this Mojo to shut them down explictly. *

*

* By default the shutdown goal is not bound to any phase. For integration tests * you might want to bind it to post-integration-test. *

* @goal shutdown * @requiresDependencyResolution runtime * @author Mark Michaelis * @since 1.1 */ public class ShutdownMojo extends AbstractI18NMojo { /** * Shuts down all embedded tomcats which got started up to now. * * @throws MojoExecutionException if shutting down one or all servers failed */ public void execute() throws MojoExecutionException { try { EmbeddedRegistry.getInstance().shutdownAll( getLog() ); } catch ( LifecycleException e ) { throw new MojoExecutionException( getMessage( "ShutdownMojo.shutdownError" ), e ); } } } ./tomcat-maven-plugin-1.1/src/main/java/org/codehaus/mojo/tomcat/DeployOnlyMojo.java0000600000175000017500000000221111453106424026546 0ustar neoneopackage org.codehaus.mojo.tomcat; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ /** * Deploy a WAR to Tomcat witjout forking the package lifecycle * * @goal deploy-only * @author olamy * @version $Id: DeployOnlyMojo.java 8853 2009-01-21 09:25:22Z mark $ * @since 1.0-alpha-2 */ public class DeployOnlyMojo extends AbstractDeployWarMojo { // no-op : only mojo metadata overriding } ./tomcat-maven-plugin-1.1/src/main/java/org/codehaus/mojo/tomcat/RedeployMojo.java0000600000175000017500000000272111453106424026241 0ustar neoneopackage org.codehaus.mojo.tomcat; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ /** * Redeploy a WAR in Tomcat. Deploy with forcing update flag to true * * @goal redeploy * @author Mark Hobson * @version $Id: RedeployMojo.java 8855 2009-01-21 11:23:04Z olamy $ * @todo depend on war:war, war:exploded or war:inplace when MNG-1649 resolved */ public class RedeployMojo extends DeployMojo { // ---------------------------------------------------------------------- // Protected Methods // ---------------------------------------------------------------------- /** * {@inheritDoc} */ @Override protected boolean isUpdate() { return true; } } ./tomcat-maven-plugin-1.1/src/main/java/org/codehaus/mojo/tomcat/RunWarOnlyMojo.java0000600000175000017500000000224611453106424026540 0ustar neoneopackage org.codehaus.mojo.tomcat; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ /** * Runs the current project as a packaged web application using an embedded Tomcat server without forking the package cycle. * * * @goal run-war-only * @requiresDependencyResolution runtime * @author vlatombe * @version */ public class RunWarOnlyMojo extends AbstractRunWarMojo { // no-op : only mojo metadata overriding } ./tomcat-maven-plugin-1.1/src/main/java/org/codehaus/mojo/tomcat/AbstractRunMojo.java0000600000175000017500000005647311453106424026723 0ustar neoneopackage org.codehaus.mojo.tomcat; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.net.InetAddress; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.Map; 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.Catalina; import org.apache.catalina.startup.Embedded; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.archiver.ArchiverException; import org.codehaus.plexus.archiver.UnArchiver; import org.codehaus.plexus.archiver.manager.ArchiverManager; import org.codehaus.plexus.archiver.manager.NoSuchArchiverException; import org.codehaus.plexus.classworlds.ClassWorld; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.classworlds.realm.DuplicateRealmException; import org.codehaus.plexus.util.DirectoryScanner; import org.codehaus.plexus.util.FileUtils; /** * Abstract goal that provides common configuration for embedded Tomcat goals. * * @author Jurgen Lust * @author Mark Hobson * @version $Id: AbstractRunMojo.java 12745 2010-10-01 09:04:32Z olamy $ */ public abstract class AbstractRunMojo extends AbstractI18NMojo { // ---------------------------------------------------------------------- // Mojo Parameters // ---------------------------------------------------------------------- /** * The packaging of the Maven project that this goal operates upon. * * @parameter expression = "${project.packaging}" * @required * @readonly */ private String packaging; /** * The directory to create the Tomcat server configuration under. * * @parameter expression="${project.build.directory}/tomcat" */ private File configurationDir; /** * The port to run the Tomcat server on. * * @parameter expression="${maven.tomcat.port}" default-value="8080" */ private int port; /** * The https port to run the Tomcat server on. * By default it's 0 this means won't be started. * The https connector will be started only for value > 0. * @since 1.0 * @parameter expression="${maven.tomcat.httpsPort}" default-value="0" */ private int httpsPort; /** * The character encoding to use for decoding URIs. * @since 1.0 * @parameter expression="${maven.tomcat.uriEncoding}" default-value="ISO-8859-1" */ private String uriEncoding; /** * List of System properties to pass to the Tomcat Server. * * @parameter * @since 1.0-alpha-2 */ private Map systemProperties; /** * The directory contains additional configuration Files that copied in the Tomcat conf Directory. * * @parameter expression = "${maven.tomcat.additionalConfigFilesDir}" default-value="${basedir}/src/main/tomcatconf" * @since 1.0-alpha-2 */ private File additionalConfigFilesDir; /** * server.xml to use Note if you use this you must configure in this file your webapp paths. * * @parameter expression="${maven.tomcat.serverXml}" * @since 1.0-alpha-2 */ private File serverXml; /** * overriding the providing web.xml to run tomcat * * @parameter expression="${maven.tomcat.webXml}" * @since 1.0-alpha-2 */ private File tomcatWebXml; /** * Set this to true to allow Maven to continue to execute after invoking * the run goal. * * @parameter expression="${maven.tomcat.fork}" default-value="false" * @since 1.0 */ private boolean fork; /** * Will create a tomcat context for each dependencies of war type. * To preserve backward compatibility it's false by default. * @parameter expression="${maven.tomcat.addContextWarDependencies}" default-value="false" * @since 1.0 */ private boolean addContextWarDependencies; /** * The maven project. * * @parameter expression="${project}" * @since 1.0 * @required * @readonly */ protected MavenProject project; /** * The archive manager. * @since 1.0 * @component */ private ArchiverManager archiverManager; /** * if true a new classLoader separated from maven core will be created to start tomcat. * @parameter expression="${tomcat.useSeparateTomcatClassLoader}" default-value="false" * @since 1.0 */ protected boolean useSeparateTomcatClassLoader; /** * @parameter expression="${plugin.artifacts}" * @required * @since 1.0 */ @SuppressWarnings("rawtypes") private List pluginArtifacts; /** * If set to true ignore if packaging of project is not 'war'. * @since 1.0 * @parameter expression="${tomcat.ignorePackaging}" default-value="false" */ private boolean ignorePackaging; /** * Override the default keystoreFile for the HTTPS connector (if enabled) * @since 1.1 * @parameter */ private String keystoreFile; /** * Override the default keystorePass for the HTTPS connector (if enabled) * @since 1.1 * @parameter */ private String keystorePass; // ---------------------------------------------------------------------- // Fields // ---------------------------------------------------------------------- /** * The embedded Tomcat server. */ private Embedded container; /** * @since 1.0 */ private ClassRealm tomcatRealm; // ---------------------------------------------------------------------- // Mojo Implementation // ---------------------------------------------------------------------- /** * {@inheritDoc} */ public void execute() throws MojoExecutionException, MojoFailureException { // ensure project is a web application if ( !isWar() ) { getLog().info( getMessage( "AbstractRunMojo.nonWar" ) ); return; } ClassLoader originalClassLoaser = Thread.currentThread().getContextClassLoader(); try { if ( useSeparateTomcatClassLoader ) { Thread.currentThread().setContextClassLoader( getTomcatClassLoader() ); } getLog().info( getMessage( "AbstractRunMojo.runningWar", getWebappUrl() ) ); initConfiguration(); startContainer(); if ( !fork ) { waitIndefinitely(); } } catch ( LifecycleException exception ) { throw new MojoExecutionException( getMessage( "AbstractRunMojo.cannotStart" ), exception ); } catch ( IOException exception ) { throw new MojoExecutionException( getMessage( "AbstractRunMojo.cannotCreateConfiguration" ), exception ); } finally { if (useSeparateTomcatClassLoader) { Thread.currentThread().setContextClassLoader( originalClassLoaser ); } } } // ---------------------------------------------------------------------- // Protected Methods // ---------------------------------------------------------------------- /** * Gets the webapp context path to use for the web application being run. * * @return the webapp context path */ protected String getPath() { return path; } /** * Gets the context to run this web application under for the specified embedded Tomcat. * * @param container the embedded Tomcat container being used * @return the context to run this web application under * @throws IOException if the context could not be created * @throws MojoExecutionException */ protected Context createContext( Embedded container ) throws IOException, MojoExecutionException { String contextPath = getPath(); Context context = container.createContext( "/".equals( contextPath ) ? "" : contextPath, getDocBase() .getAbsolutePath() ); if ( useSeparateTomcatClassLoader ) { context.setParentClassLoader( getTomcatClassLoader() ); } context.setLoader( createWebappLoader() ); context.setConfigFile( getContextFile().getAbsolutePath() ); return context; } /** * Gets the webapp loader to run this web application under. * * @return the webapp loader to use * @throws IOException if the webapp loader could not be created * @throws MojoExecutionException */ protected WebappLoader createWebappLoader() throws IOException, MojoExecutionException { if ( useSeparateTomcatClassLoader ) { return new WebappLoader( getTomcatClassLoader() ); } return new WebappLoader( Thread.currentThread().getContextClassLoader() ); } /** * Gets the webapp directory to run. * * @return the webapp directory */ protected abstract File getDocBase(); /** * Gets the Tomcat context XML file to use. * * @return the context XML file */ protected abstract File getContextFile(); // ---------------------------------------------------------------------- // Private Methods // ---------------------------------------------------------------------- /** * Gets whether this project uses WAR packaging. * * @return whether this project uses WAR packaging */ protected boolean isWar() { return "war".equals( packaging ) || ignorePackaging; } /** * Gets the URL of the running webapp. * * @return the URL of the running webapp * @throws MalformedURLException if the running webapp URL is invalid */ private URL getWebappUrl() throws MalformedURLException { return new URL( "http", "localhost", port, getPath() ); } /** * Creates the Tomcat configuration directory with the necessary resources. * * @throws IOException if the Tomcat configuration could not be created * @throws MojoExecutionException if the Tomcat configuration could not be created */ private void initConfiguration() throws IOException, MojoExecutionException { if ( configurationDir.exists() ) { getLog().info( getMessage( "AbstractRunMojo.usingConfiguration", configurationDir ) ); } else { getLog().info( getMessage( "AbstractRunMojo.creatingConfiguration", configurationDir ) ); configurationDir.mkdirs(); File confDir = new File( configurationDir, "conf" ); confDir.mkdir(); copyFile( "/conf/tomcat-users.xml", new File( confDir, "tomcat-users.xml" ) ); if ( tomcatWebXml != null ) { if ( !tomcatWebXml.exists() ) { throw new MojoExecutionException( " tomcatWebXml " + tomcatWebXml.getPath() + " not exists" ); } //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" ) ); } else { copyFile( "/conf/web.xml", new File( confDir, "web.xml" ) ); } File logDir = new File( configurationDir, "logs" ); logDir.mkdir(); File webappsDir = new File( configurationDir, "webapps" ); webappsDir.mkdir(); if ( additionalConfigFilesDir != null && additionalConfigFilesDir.exists() ) { DirectoryScanner scanner = new DirectoryScanner(); scanner.addDefaultExcludes(); scanner.setBasedir( additionalConfigFilesDir.getPath() ); scanner.scan(); String[] files = scanner.getIncludedFiles(); if ( files != null && files.length > 0 ) { getLog().info( "Coping additional tomcat config files" ); for ( int i = 0; i < files.length; i++ ) { File file = new File( additionalConfigFilesDir, files[i] ); getLog().info( " copy " + file.getName() ); FileUtils.copyFileToDirectory( file, confDir ); } } } } } /** * Copies the specified class resource to the specified file. * * @param fromPath the path of the class resource to copy * @param toFile the file to copy to * @throws IOException if the file could not be copied */ private void copyFile( String fromPath, File toFile ) throws IOException { URL fromURL = getClass().getResource( fromPath ); if ( fromURL == null ) { throw new FileNotFoundException( fromPath ); } FileUtils.copyURLToFile( fromURL, toFile ); } /** * Starts the embedded Tomcat server. * * @throws IOException if the server could not be configured * @throws LifecycleException if the server could not be started * @throws MojoExecutionException if the server could not be configured */ private void startContainer() throws IOException, LifecycleException, MojoExecutionException { // Set the system properties setupSystemProperties(); try { if ( serverXml != null ) { if ( !serverXml.exists() ) { throw new MojoExecutionException( serverXml.getPath() + " not exists" ); } container = new Catalina(); container.setCatalinaHome( configurationDir.getAbsolutePath() ); ( (Catalina) container ).setConfigFile( serverXml.getPath() ); container.start(); } else { // create server container = new Embedded(); container.setCatalinaHome( configurationDir.getAbsolutePath() ); container.setRealm( new MemoryRealm() ); //container.createLoader( getTomcatClassLoader() ). // create context Context context = createContext( container ); // create host String appBase = new File( configurationDir, "webapps" ).getAbsolutePath(); Host host = container.createHost( "localHost", appBase ); host.addChild( context ); if ( addContextWarDependencies ) { Collection dependecyContexts = createDependencyContexts( container ); for ( Context extraContext : dependecyContexts ) { host.addChild( extraContext ); } } // create engine Engine engine = container.createEngine(); engine.setName( "localEngine" ); engine.addChild( host ); engine.setDefaultHost( host.getName() ); container.addEngine( engine ); if ( useSeparateTomcatClassLoader ) { engine.setParentClassLoader( getTomcatClassLoader() ); } // create http connector Connector httpConnector = container.createConnector( (InetAddress) null, port, false ); if ( httpsPort > 0 ) { httpConnector.setRedirectPort( httpsPort ); } httpConnector.setURIEncoding( uriEncoding ); container.addConnector( httpConnector ); // create https connector if ( httpsPort > 0 ) { Connector httpsConnector = container.createConnector( (InetAddress) null, httpsPort, true ); if ( keystoreFile!=null) { httpsConnector.setAttribute("keystoreFile", keystoreFile); } if ( keystorePass!=null) { httpsConnector.setAttribute("keystorePass", keystorePass); } container.addConnector( httpsConnector ); } } // start server container.start(); EmbeddedRegistry.getInstance().register(container); } finally { // no op } } protected ClassRealm getTomcatClassLoader() throws MojoExecutionException { if ( this.tomcatRealm != null ) { return tomcatRealm; } try { ClassWorld world = new ClassWorld(); ClassRealm root = world.newRealm( "tomcat", Thread.currentThread().getContextClassLoader() ); for ( @SuppressWarnings("rawtypes") Iterator i = pluginArtifacts.iterator(); i.hasNext(); ) { Artifact pluginArtifact = (Artifact) i.next(); if ( "org.apache.tomcat".equals( pluginArtifact.getGroupId() ) ) { if ( pluginArtifact.getFile() != null ) { root.addURL( pluginArtifact.getFile().toURI().toURL() ); } } } tomcatRealm = root; return root; } catch ( DuplicateRealmException e ) { throw new MojoExecutionException( e.getMessage(), e ); } catch ( MalformedURLException e ) { throw new MojoExecutionException( e.getMessage(), e ); } } @SuppressWarnings( "unchecked" ) public Set getProjectArtifacts() { return project.getArtifacts(); } /** * Causes the current thread to wait indefinitely. This method does not return. */ private void waitIndefinitely() { Object lock = new Object(); synchronized ( lock ) { try { lock.wait(); } catch ( InterruptedException exception ) { getLog().warn( getMessage( "AbstractRunMojo.interrupted" ), exception ); } } } /** * Set the SystemProperties from the configuration. */ private void setupSystemProperties() { if ( systemProperties != null && !systemProperties.isEmpty() ) { getLog().info( "setting SystemProperties:" ); for ( String key : systemProperties.keySet() ) { String value = systemProperties.get( key ); if ( value != null ) { getLog().info( " " + key + "=" + value ); System.setProperty( key, value ); } else { getLog().info( "skip sysProps " + key + " with empty value" ); } } } } /** * Allows the startup of additional webapps in the tomcat container by declaration with scope * "tomcat". * * @param container tomcat * @return dependency tomcat contexts of warfiles in scope "tomcat" */ private Collection createDependencyContexts( Embedded container ) { getLog().info( "Deploying dependency wars" ); // Let's add other modules List contexts = new ArrayList(); ScopeArtifactFilter filter = new ScopeArtifactFilter( "tomcat" ); @SuppressWarnings("unchecked") Set artifacts = project.getArtifacts(); for ( Artifact artifact : artifacts ) { // Artifact is not yet registered and it has neither test, nor a // provided scope, not is it optional if ( "war".equals( artifact.getType() ) && !artifact.isOptional() && filter.include( artifact ) ) { getLog().info( "Deploy warfile: " + String.valueOf( artifact.getFile() ) ); File webapps = new File( configurationDir, "webapps" ); File artifactWarDir = new File( webapps, artifact.getArtifactId() ); if ( !artifactWarDir.exists() ) { //dont extract if exists artifactWarDir.mkdir(); try { UnArchiver unArchiver = archiverManager.getUnArchiver( "zip" ); unArchiver.setSourceFile( artifact.getFile() ); unArchiver.setDestDirectory( artifactWarDir ); // Extract the module unArchiver.extract(); } catch ( IOException e ) { getLog().error( e ); continue; } catch ( NoSuchArchiverException e ) { getLog().error( e ); continue; } catch ( ArchiverException e ) { getLog().error( e ); continue; } } WebappLoader webappLoader = new WebappLoader( Thread.currentThread().getContextClassLoader() ); Context context = container.createContext( "/" + artifact.getArtifactId(), artifactWarDir.getAbsolutePath() ); context.setLoader( webappLoader ); context.setConfigFile( getContextFile().getAbsolutePath() ); contexts.add( context ); } } return contexts; } } ./tomcat-maven-plugin-1.1/src/main/java/org/codehaus/mojo/tomcat/AbstractCatalinaMojo.java0000600000175000017500000002105411453106424027656 0ustar neoneopackage org.codehaus.mojo.tomcat; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.util.StringTokenizer; import org.apache.maven.artifact.manager.WagonManager; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.wagon.authentication.AuthenticationInfo; import org.codehaus.plexus.util.StringUtils; /** * Abstract goal that provides common configuration for Catalina-based goals. * * @author Mark Hobson * @version $Id: AbstractCatalinaMojo.java 9988 2009-06-16 14:09:16Z mark $ */ public abstract class AbstractCatalinaMojo extends AbstractI18NMojo { // ---------------------------------------------------------------------- // Constants // ---------------------------------------------------------------------- /** * The name of this Maven plugin. Used to produce the user agent when communicating with Tomcat manager. */ private String name = "Tomcat Maven Plugin"; /** * The default username to use when authenticating with Tomcat manager. */ private static final String DEFAULT_USERNAME = "admin"; /** * The default password to use when authenticating with Tomcat manager. */ private static final String DEFAULT_PASSWORD = ""; // ---------------------------------------------------------------------- // Mojo Parameters // ---------------------------------------------------------------------- /** * The Maven Wagon manager to use when obtaining server authentication details. * * @component role="org.apache.maven.artifact.manager.WagonManager" * @required * @readonly */ private WagonManager wagonManager; /** * The full URL of the Tomcat manager instance to use. * * @parameter expression="${maven.tomcat.url}" default-value="http://localhost:8080/manager" * @required */ private URL url; /** * The server id in settings.xml to use when authenticating with Tomcat manager, or null to use * defaults of username admin and no password. * * @parameter expression="${maven.tomcat.server}" */ private String server; /** * The URL encoding charset to use when communicating with Tomcat manager. * * @parameter expression="${maven.tomcat.charset}" default-value="ISO-8859-1" * @required */ private String charset; /** * The tomcat username to use for deployment * * @parameter expression="${tomcat.username}" * @since 1.0-alpha-2 */ private String username; /** * The password to use for deployment * * @parameter expression="${tomcat.password}" * @since 1.0-alpha-2 */ private String password; /** * @parameter expression="${plugin.version}" * @required * @readonly */ private String version; // ---------------------------------------------------------------------- // Fields // ---------------------------------------------------------------------- /** * The Tomcat manager wrapper object. */ private TomcatManager manager; // ---------------------------------------------------------------------- // Mojo Implementation // ---------------------------------------------------------------------- /** * {@inheritDoc} */ public void execute() throws MojoExecutionException { try { invokeManager(); } catch ( TomcatManagerException exception ) { throw new MojoExecutionException( getMessage( "AbstractCatalinaMojo.managerError", exception.getMessage() ) ); } catch ( IOException exception ) { throw new MojoExecutionException( getMessage( "AbstractCatalinaMojo.managerIOError" ), exception ); } } // ---------------------------------------------------------------------- // Protected Methods // ---------------------------------------------------------------------- /** * Invokes Tomcat manager when this Mojo is executed. * * @throws MojoExecutionException if there was a problem executing this goal * @throws TomcatManagerException if the Tomcat manager request fails * @throws IOException if an i/o error occurs */ protected abstract void invokeManager() throws MojoExecutionException, TomcatManagerException, IOException; /** * Gets the Tomcat manager wrapper object configured for this goal. * * @return the Tomcat manager wrapper object * @throws MojoExecutionException if there was a problem obtaining the authentication details */ protected TomcatManager getManager() throws MojoExecutionException { // lazily instantiate when config values have been injected if ( manager == null ) { String userName; String password; if ( server == null ) { // no server set, use defaults getLog().debug( getMessage( "AbstractCatalinaMojo.defaultAuth" ) ); userName = DEFAULT_USERNAME; password = DEFAULT_PASSWORD; } else { // obtain authenication details for specified server from wagon AuthenticationInfo info = wagonManager.getAuthenticationInfo( server ); if ( info == null ) { throw new MojoExecutionException( getMessage( "AbstractCatalinaMojo.unknownServer", server ) ); } // derive username userName = info.getUserName(); if ( userName == null ) { getLog().debug( getMessage( "AbstractCatalinaMojo.defaultUserName" ) ); userName = DEFAULT_USERNAME; } // derive password password = info.getPassword(); if ( password == null ) { getLog().debug( getMessage( "AbstractCatalinaMojo.defaultPassword" ) ); password = DEFAULT_PASSWORD; } } // if userName/password are defined in the mojo or the cli they override if ( !StringUtils.isEmpty( this.username ) ) { userName = this.username; password = this.password == null ? "" : this.password; } manager = new TomcatManager( url, userName, password, charset ); manager.setUserAgent( name + "/" + version ); } return manager; } /** * Gets the full URL of the Tomcat manager instance. * * @return the full URL of the Tomcat manager instance to use */ protected URL getURL() { return url; } /** * Gets the webapp context path to use when communicating with Tomcat manager. * * @return the webapp context path to use */ protected String getPath() { return path; } /** * Gets the URL of the deployed webapp. * * @return the URL of the deployed webapp * @throws MalformedURLException if the deployed webapp URL is invalid */ protected URL getDeployedURL() throws MalformedURLException { return new URL( getURL(), getPath() ); } /** * Splits the given string into lines and writes each one separately to the log at info level. * * @param string the string to write */ protected void log( String string ) { StringTokenizer tokenizer = new StringTokenizer( string, "\n\r" ); while ( tokenizer.hasMoreTokens() ) { getLog().info( tokenizer.nextToken() ); } } } ./tomcat-maven-plugin-1.1/src/main/java/org/codehaus/mojo/tomcat/RunMojo.java0000600000175000017500000001554711453106424025234 0ustar neoneopackage org.codehaus.mojo.tomcat; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.io.File; import java.io.IOException; import java.util.Collection; import java.util.List; import java.util.Set; import org.apache.catalina.Context; import org.apache.catalina.loader.WebappLoader; import org.apache.catalina.startup.Embedded; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.DependencyResolutionRequiredException; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.util.StringUtils; /** * Runs the current project as a dynamic web application using an embedded Tomcat server. * * @goal run * @execute phase="compile" * @requiresDependencyResolution runtime * @author Jurgen Lust * @author Mark Hobson * @version $Id: RunMojo.java 12745 2010-10-01 09:04:32Z olamy $ */ public class RunMojo extends AbstractRunMojo { // ---------------------------------------------------------------------- // Mojo Parameters // ---------------------------------------------------------------------- /** * The classes directory for the web application being run. * * @parameter expression = "${project.build.outputDirectory}" */ private File classesDir; /** * The set of dependencies for the web application being run. * * @parameter default-value = "${project.artifacts}" * @required * @readonly */ private Set dependencies; /** * The web resources directory for the web application being run. * * @parameter expression="${basedir}/src/main/webapp" */ private File warSourceDirectory; /** * The path of the Tomcat context XML file. * * @parameter expression = "src/main/webapp/META-INF/context.xml" */ private File contextFile; /** * Set the "follow standard delegation model" flag used to configure our ClassLoader. * @see http://tomcat.apache.org/tomcat-6.0-doc/api/org/apache/catalina/loader/WebappLoader.html#setDelegate(boolean) * @parameter expression = "${tomcat.delegate}" default-value="true" * @since 1.0 */ private boolean delegate = true; // ---------------------------------------------------------------------- // AbstractRunMojo Implementation // ---------------------------------------------------------------------- /** * {@inheritDoc} * @throws MojoExecutionException */ @Override protected Context createContext( Embedded container ) throws IOException, MojoExecutionException { Context context = super.createContext( container ); context.setReloadable( true ); return context; } /** * {@inheritDoc} * @throws MojoExecutionException */ @Override protected WebappLoader createWebappLoader() throws IOException, MojoExecutionException { WebappLoader loader = super.createWebappLoader(); //super.project. if ( useSeparateTomcatClassLoader ) { loader.setDelegate( delegate ); } // add classes directories to loader if ( classesDir != null ) { try { @SuppressWarnings("unchecked") List classPathElements = project.getCompileClasspathElements(); for (String classPathElement : classPathElements) { File classPathElementFile = new File(classPathElement); if (classPathElementFile.exists() && classPathElementFile.isDirectory()) { getLog().debug( "adding classPathElementFile " + classPathElementFile.toURI().toString() ); loader.addRepository( classPathElementFile.toURI().toString() ); } } } catch ( DependencyResolutionRequiredException e ) { throw new MojoExecutionException( e.getMessage(), e ); } //loader.addRepository( classesDir.toURI().toString() ); } // add artifacts to loader if ( dependencies != null ) { for ( Artifact artifact : dependencies ) { String scope = artifact.getScope(); // skip provided and test scoped artifacts if ( !Artifact.SCOPE_PROVIDED.equals( scope ) && !Artifact.SCOPE_TEST.equals( scope ) ) { getLog().debug( "add dependency to webapploader " + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion() + ":" + artifact.getScope() ); if ( !isInProjectReferences( artifact ) ) { loader.addRepository( artifact.getFile().toURI().toString() ); } else { getLog().debug( "skip adding artifact " + artifact.getArtifactId() + " as it's in reactors" ); } } } } return loader; } protected boolean isInProjectReferences(Artifact artifact) { if ( project.getProjectReferences() == null || project.getProjectReferences().isEmpty() ) { return false; } @SuppressWarnings("unchecked") Collection mavenProjects = project.getProjectReferences().values(); for ( MavenProject mavenProject : mavenProjects ) { if (StringUtils.equals( mavenProject.getId(), artifact.getId() )) { return true; } } return false; } /** * {@inheritDoc} */ @Override protected File getDocBase() { return warSourceDirectory; } /** * {@inheritDoc} */ @Override protected File getContextFile() { return contextFile; } } ./tomcat-maven-plugin-1.1/src/main/java/org/codehaus/mojo/tomcat/InplaceMojo.java0000600000175000017500000000432411453106424026032 0ustar neoneopackage org.codehaus.mojo.tomcat; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.io.File; import org.apache.maven.plugin.MojoExecutionException; /** * Deploy a WAR in-place to Tomcat. * * @goal inplace * @author Mark Hobson * @version $Id: InplaceMojo.java 8855 2009-01-21 11:23:04Z olamy $ * @todo depend on war:inplace when MNG-1649 resolved */ public class InplaceMojo extends AbstractDeployMojo { // ---------------------------------------------------------------------- // Mojo Parameters // ---------------------------------------------------------------------- /** * The path of the inplace WAR directory to deploy. * * @parameter expression = "${basedir}/src/main/webapp" * @required */ private File warSourceDirectory; // ---------------------------------------------------------------------- // Protected Methods // ---------------------------------------------------------------------- /** * {@inheritDoc} */ @Override protected File getWarFile() { return warSourceDirectory; } /** * {@inheritDoc} */ @Override protected void validateWarFile() throws MojoExecutionException { if ( !warSourceDirectory.exists() || !warSourceDirectory.isDirectory() ) { throw new MojoExecutionException( getMessage( "InplaceMojo.missingWar", warSourceDirectory.getPath() ) ); } } } ./tomcat-maven-plugin-1.1/src/main/java/org/codehaus/mojo/tomcat/ReloadMojo.java0000600000175000017500000000312511453106424025663 0ustar neoneopackage org.codehaus.mojo.tomcat; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import org.apache.maven.plugin.MojoExecutionException; import java.io.IOException; /** * Reload a WAR in Tomcat. * * @goal reload * @author olamy * @version $Id: ReloadMojo.java 8853 2009-01-21 09:25:22Z mark $ */ public class ReloadMojo extends AbstractWarCatalinaMojo { // ---------------------------------------------------------------------- // Protected Methods // ---------------------------------------------------------------------- /** * {@inheritDoc} */ @Override protected void invokeManager() throws MojoExecutionException, TomcatManagerException, IOException { getLog().info( getMessage( "RedeployMojo.redeployApp", getDeployedURL() ) ); log( getManager().reload( getPath() ) ); } } ./tomcat-maven-plugin-1.1/src/main/java/org/codehaus/mojo/tomcat/AbstractWarCatalinaMojo.java0000600000175000017500000000522611453106424030333 0ustar neoneopackage org.codehaus.mojo.tomcat; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import org.apache.maven.plugin.MojoExecutionException; /** * Abstract goal that provides common configuration for Catalina-based goals. * * @author Mark Hobson * @version $Id: AbstractWarCatalinaMojo.java 12741 2010-09-30 21:07:47Z olamy $ */ public abstract class AbstractWarCatalinaMojo extends AbstractCatalinaMojo { // ---------------------------------------------------------------------- // Mojo Parameters // ---------------------------------------------------------------------- /** * The packaging of the Maven project that this goal operates upon. * * @parameter expression = "${project.packaging}" * @required * @readonly */ private String packaging; /** * If set to true ignore if packaging of project is not 'war'. * @since 1.1 * @parameter expression="${tomcat.ignorePackaging}" default-value="false" */ private boolean ignorePackaging; // ---------------------------------------------------------------------- // Mojo Implementation // ---------------------------------------------------------------------- /** * {@inheritDoc} */ @Override public void execute() throws MojoExecutionException { if ( !isWar() ) { getLog().info( getMessage( "AbstractWarCatalinaMojo.nonWar" ) ); return; } super.execute(); } // ---------------------------------------------------------------------- // Protected Methods // ---------------------------------------------------------------------- /** * Gets whether this project uses WAR packaging. * * @return whether this project uses WAR packaging */ protected boolean isWar() { return "war".equals( packaging ) || ignorePackaging; } } ./tomcat-maven-plugin-1.1/src/main/java/org/codehaus/mojo/tomcat/ResourcesMojo.java0000600000175000017500000000423611453106424026433 0ustar neoneopackage org.codehaus.mojo.tomcat; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import org.apache.maven.plugin.MojoExecutionException; import java.io.IOException; /** * Lists JNDI resources in Tomcat. * * @goal resources * @author Mark Hobson * @version $Id: ResourcesMojo.java 8855 2009-01-21 11:23:04Z olamy $ */ public class ResourcesMojo extends AbstractCatalinaMojo { // ---------------------------------------------------------------------- // Mojo Parameters // ---------------------------------------------------------------------- /** * The class name of the resources to list, or null for all. * * @parameter expression = "${maven.tomcat.type}" */ private String type; // ---------------------------------------------------------------------- // Protected Methods // ---------------------------------------------------------------------- /** * {@inheritDoc} */ @Override protected void invokeManager() throws MojoExecutionException, TomcatManagerException, IOException { if ( type == null ) { getLog().info( getMessage( "ResourcesMojo.listAllResources", getURL() ) ); } else { getLog().info( getMessage( "ResourcesMojo.listTypedResources", type, getURL() ) ); } log( getManager().getResources( type ) ); } } ./tomcat-maven-plugin-1.1/src/main/java/org/codehaus/mojo/tomcat/ExplodedMojo.java0000600000175000017500000000433011453106424026220 0ustar neoneopackage org.codehaus.mojo.tomcat; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.io.File; import org.apache.maven.plugin.MojoExecutionException; /** * Deploy an exploded WAR to Tomcat. * * @goal exploded * @author Mark Hobson * @version $Id: ExplodedMojo.java 8855 2009-01-21 11:23:04Z olamy $ * @todo depend on war:exploded when MNG-1649 resolved */ public class ExplodedMojo extends AbstractDeployMojo { // ---------------------------------------------------------------------- // Mojo Parameters // ---------------------------------------------------------------------- /** * The path of the exploded WAR directory to deploy. * * @parameter expression = "${project.build.directory}/${project.build.finalName}" * @required */ private File warDirectory; // ---------------------------------------------------------------------- // Protected Methods // ---------------------------------------------------------------------- /** * {@inheritDoc} */ @Override protected File getWarFile() { return warDirectory; } /** * {@inheritDoc} */ @Override protected void validateWarFile() throws MojoExecutionException { if ( !warDirectory.exists() || !warDirectory.isDirectory() ) { throw new MojoExecutionException( getMessage( "ExplodedMojo.missingWar", warDirectory.getPath() ) ); } } } ./tomcat-maven-plugin-1.1/src/main/java/org/codehaus/mojo/tomcat/AbstractDeployMojo.java0000600000175000017500000001541711453106424027404 0ustar neoneopackage org.codehaus.mojo.tomcat; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.io.File; import java.io.IOException; import java.net.URL; import org.apache.maven.plugin.MojoExecutionException; /** * Deploy a WAR to Tomcat. * * @author Mark Hobson * @version $Id: AbstractDeployMojo.java 8855 2009-01-21 11:23:04Z olamy $ */ public abstract class AbstractDeployMojo extends AbstractWarCatalinaMojo { // ---------------------------------------------------------------------- // Mojo Parameters // ---------------------------------------------------------------------- /** * The deployment mode to use. This must be either war to deploy the war, context to * deploy the context XML file, or both to deploy the war with the context XML file. * * @parameter expression = "${maven.tomcat.mode}" default-value = "war" * @required */ private String mode; /** * The path of the Tomcat context XML file. This is not used for war deployment mode. * * @parameter expression = "${project.build.directory}/${project.build.finalName}/META-INF/context.xml" */ private File contextFile; /** * Whether Tomcat should automatically undeploy webapps that already exist when deploying. * * @parameter expression = "${maven.tomcat.update}" default-value = "false" * @required */ private boolean update; /** * The Tomcat webapp tag name to use. * * @parameter expression = "${maven.tomcat.tag}" */ private String tag; // ---------------------------------------------------------------------- // Protected Methods // ---------------------------------------------------------------------- /** * {@inheritDoc} */ @Override public void invokeManager() throws MojoExecutionException, TomcatManagerException, IOException { if ( "war".equals( mode ) ) { deployWar(); } else if ( "context".equals( mode ) ) { deployContext(); } else if ( "both".equals( mode ) ) { deployWarAndContext(); } else { throw new MojoExecutionException( getMessage( "AbstractDeployMojo.unknownMode", mode ) ); } } /** * Gets the Tomcat WAR file. This may be a file or a directory depending on the deployment mode. * * @return the Tomcat WAR file. */ protected abstract File getWarFile(); /** * Ensures that the Tomcat WAR file exists and is the correct type for the deployment mode. * * @throws MojoExecutionException if the WAR file does not exist or is not the correct type for the deployment mode */ protected abstract void validateWarFile() throws MojoExecutionException; /** * Gets the Tomcat context XML file. * * @return the Tomcat context XML file. */ protected File getContextFile() { return contextFile; } /** * Ensures that the Tomcat context XML file exists and is indeed a file. * * @throws MojoExecutionException if the context file does not exist or is not a file */ protected void validateContextFile() throws MojoExecutionException { if ( !contextFile.exists() || !contextFile.isFile() ) { throw new MojoExecutionException( getMessage( "AbstractDeployMojo.missingContext", contextFile.getPath() ) ); } } /** * Gets whether Tomcat should automatically undeploy webapps that already exist when deploying. * * @return whether Tomcat should automatically undeploy webapps that already exist when deploying */ protected boolean isUpdate() { return update; } /** * Gets the Tomcat webapp tag name to use. * * @return the Tomcat webapp tag name to use */ protected String getTag() { return tag; } /** * Deploys the WAR to Tomcat. * * @throws MojoExecutionException if there was a problem locating the WAR * @throws TomcatManagerException if the Tomcat manager request fails * @throws IOException if an i/o error occurs */ protected void deployWar() throws MojoExecutionException, TomcatManagerException, IOException { validateWarFile(); getLog().info( getMessage( "AbstractDeployMojo.deployingWar", getDeployedURL() ) ); URL warURL = getWarFile().toURL(); log( getManager().deploy( getPath(), warURL, isUpdate(), getTag() ) ); } /** * Deploys the context XML file to Tomcat. * * @throws MojoExecutionException if there was a problem locating the context XML file * @throws TomcatManagerException if the Tomcat manager request fails * @throws IOException if an i/o error occurs */ protected void deployContext() throws MojoExecutionException, TomcatManagerException, IOException { validateContextFile(); getLog().info( getMessage( "AbstractDeployMojo.deployingContext", getDeployedURL() ) ); URL contextURL = getContextFile().toURL(); log( getManager().deployContext( getPath(), contextURL, isUpdate(), getTag() ) ); } /** * Deploys the WAR and context XML file to Tomcat. * * @throws MojoExecutionException if there was a problem locating either the WAR or the context XML file * @throws TomcatManagerException if the Tomcat manager request fails * @throws IOException if an i/o error occurs */ protected void deployWarAndContext() throws MojoExecutionException, TomcatManagerException, IOException { validateWarFile(); validateContextFile(); getLog().info( getMessage( "AbstractDeployMojo.deployingWarContext", getDeployedURL() ) ); URL warURL = getWarFile().toURL(); URL contextURL = getContextFile().toURL(); log( getManager().deployContext( getPath(), contextURL, warURL, isUpdate(), getTag() ) ); } } ./tomcat-maven-plugin-1.1/src/main/java/org/codehaus/mojo/tomcat/AbstractDeployWarMojo.java0000600000175000017500000000501411453106424030046 0ustar neoneopackage org.codehaus.mojo.tomcat; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import org.apache.maven.plugin.MojoExecutionException; /** * @author olamy * @version $Id: AbstractDeployWarMojo.java 8853 2009-01-21 09:25:22Z mark $ * @since 1.0-alpha-2 */ public class AbstractDeployWarMojo extends AbstractDeployMojo { // ---------------------------------------------------------------------- // Mojo Parameters // ---------------------------------------------------------------------- /** * The path of the WAR file to deploy. * * @parameter expression = "${project.build.directory}/${project.build.finalName}.war" * @required */ private File warFile; // ---------------------------------------------------------------------- // Protected Methods // ---------------------------------------------------------------------- /** * {@inheritDoc} */ @Override protected File getWarFile() { return warFile; } /** * {@inheritDoc} */ @Override protected void validateWarFile() throws MojoExecutionException { if ( !warFile.exists() || !warFile.isFile() ) { throw new MojoExecutionException( getMessage( "DeployMojo.missingWar", warFile.getPath() ) ); } } /** * {@inheritDoc} */ @Override protected void deployWar() throws MojoExecutionException, TomcatManagerException, IOException { validateWarFile(); getLog().info( getMessage( "AbstractDeployMojo.deployingWar", getDeployedURL() ) ); log( getManager().deploy( getPath(), new FileInputStream( warFile ), isUpdate(), getTag() ) ); } } ./tomcat-maven-plugin-1.1/src/test/0000700000175000017500000000000011453106422015255 5ustar neoneo./tomcat-maven-plugin-1.1/src/test/resources/0000700000175000017500000000000011453106422017267 5ustar neoneo./tomcat-maven-plugin-1.1/src/test/java/0000700000175000017500000000000011453106422016176 5ustar neoneo./tomcat-maven-plugin-1.1/src/it/0000700000175000017500000000000011453106426014716 5ustar neoneo./tomcat-maven-plugin-1.1/src/it/simple-war-project/0000700000175000017500000000000011453106430020435 5ustar neoneo./tomcat-maven-plugin-1.1/src/it/simple-war-project/pom.xml0000600000175000017500000000504011453106430021753 0ustar neoneo 4.0.0 org.codehaus.mojo.tomcat.it simple-war-project 1.0-SNAPSHOT war @pom.version@ maven-war-plugin 2.1-alpha-2 org.codehaus.mojo tomcat-maven-plugin ${pluginVersion} maven-war-plugin 2.1-alpha-2 src/main/webapp/web.xml org.codehaus.mojo tomcat-maven-plugin ${pluginVersion} / false org.springframework spring-context-support 2.5.6 ./tomcat-maven-plugin-1.1/src/it/simple-war-project/src/0000700000175000017500000000000011453106426021231 5ustar neoneo./tomcat-maven-plugin-1.1/src/it/simple-war-project/src/main/0000700000175000017500000000000011453106426022155 5ustar neoneo./tomcat-maven-plugin-1.1/src/it/simple-war-project/src/main/tomcatconf/0000700000175000017500000000000011453106426024312 5ustar neoneo./tomcat-maven-plugin-1.1/src/it/simple-war-project/src/main/tomcatconf/empty.txt0000600000175000017500000000000011453106426026201 0ustar neoneo./tomcat-maven-plugin-1.1/src/it/simple-war-project/src/main/tomcatconf/server.xml0000600000175000017500000000207111453106426026344 0ustar neoneo ./tomcat-maven-plugin-1.1/src/it/simple-war-project/src/main/webapp/0000700000175000017500000000000011453106430023426 5ustar neoneo./tomcat-maven-plugin-1.1/src/it/simple-war-project/src/main/webapp/index.jsp0000600000175000017500000000001311453106430025247 0ustar neoneoIt works !!./tomcat-maven-plugin-1.1/src/it/simple-war-project/src/main/webapp/web.xml0000600000175000017500000000045711453106430024735 0ustar neoneo ./tomcat-maven-plugin-1.1/src/site/0000700000175000017500000000000011453106426015246 5ustar neoneo./tomcat-maven-plugin-1.1/src/site/site.xml0000600000175000017500000000166611453106426016747 0ustar neoneo ./tomcat-maven-plugin-1.1/src/site/fml/0000700000175000017500000000000011453106426016024 5ustar neoneo./tomcat-maven-plugin-1.1/src/site/fml/faq.fml0000600000175000017500000000156611453106426017305 0ustar neoneo Why do I have to specify a war goal when running tomcat:exploded or tomcat:inplace ? Because there's currently no way for a goal to depend upon another plugin's goal. See MNG-1649 for more information. Why do I have to specify a war goal when running tomcat:redeploy ? Because the different methods of deployment have different prerequisites - it would be tiresome to always package the WAR if you were just deploying an exploded WAR. ./tomcat-maven-plugin-1.1/src/site/apt/0000700000175000017500000000000011453106426016032 5ustar neoneo./tomcat-maven-plugin-1.1/src/site/apt/index.apt0000600000175000017500000000153711453106426017657 0ustar neoneo --- Introduction --- Mark Hobson --- 2010-02-15 --- Tomcat Maven Plugin The Tomcat Maven Plugin provides goals to manipulate WAR projects within the {{{http://tomcat.apache.org/}Tomcat}} servlet container. * Goals Overview The goals for this plugin come in two categories: * {{{context-goals.html}Goals to manipulate deployed projects within Tomcat}} * {{{container-goals.html}Goals to obtain information from Tomcat}} * Usage Instructions on how to use the Tomcat Maven Plugin can be found on the {{{usage.html}usage page}}. * Examples To provide you with better understanding of some usages of the Tomcat Maven Plugin, you can take a look into the following examples: * {{{examples/add-system-properties.html}Adding System Properties}} * {{{examples/deployment.html}How to deploy projects to Tomcat}} ./tomcat-maven-plugin-1.1/src/site/apt/container-goals.apt0000600000175000017500000000222511453106426021630 0ustar neoneo --- Container Goals --- Mark Hobson --- November 21, 2005 --- Container Goals The plugin provides goals to retrieve various information about the Tomcat container: * {{{#Listing deployed applications}Listing deployed applications}} * {{{#Listing server information}Listing server information}} * {{{#Listing JNDI resources}Listing JNDI resources}} * {{{#Listing security roles}Listing security roles}} [] These are described in more detail below. * {Listing deployed applications} To list all the currently deployed applications in Tomcat you can type: +-- mvn tomcat:list +-- * {Listing server information} To list information about the Tomcat version, OS, and JVM properties you can type: +-- mvn tomcat:info +-- * {Listing JNDI resources} To list all the JNDI resources available within Tomcat you can type: +-- mvn tomcat:resources +-- Alternatively, to only list JNDI resources of a specific type you can type: +-- mvn -Dmaven.tomcat.type=my.class.name tomcat:resources +-- * {Listing security roles} To list the available security roles available within Tomcat you can type: +-- mvn tomcat:roles +-- ./tomcat-maven-plugin-1.1/src/site/apt/examples/0000700000175000017500000000000011453106426017650 5ustar neoneo./tomcat-maven-plugin-1.1/src/site/apt/examples/adjust-embedded-tomcat-version.apt.vm0000600000175000017500000000634711453106426027004 0ustar neoneo --- Adjust Tomcat Version --- Mark Michaelis --- September 30, 2010 --- Adjust Tomcat Version In case you need to adjust the version of the embedded tomcat to run you can do so by changing the runtime-dependencies: +-- [...] 6.0.29 [...] [...] org.codehaus.mojo tomcat-maven-plugin ${project.version} org.apache.tomcat catalina ${tomcat.version} org.apache.tomcat catalina-ha ${tomcat.version} runtime org.apache.tomcat tribes ${tomcat.version} runtime org.apache.tomcat el-api ${tomcat.version} runtime org.apache.tomcat jasper ${tomcat.version} runtime org.apache.tomcat jasper-el ${tomcat.version} runtime org.apache.tomcat jasper-jdt ${tomcat.version} runtime org.apache.tomcat jsp-api ${tomcat.version} runtime org.apache.tomcat servlet-api ${tomcat.version} runtime org.apache.tomcat coyote ${tomcat.version} runtime org.apache.tomcat dbcp ${tomcat.version} runtime [...] [...] [...] +-- ./tomcat-maven-plugin-1.1/src/site/apt/examples/add-system-properties.apt.vm0000600000175000017500000000133011453106426025242 0ustar neoneo --- Adding System Properties --- Olivier Lamy --- October 17, 2009 --- Adding System Properties You can add system properties when running Tomcat (mvn tomcat:run). The syntax has the following format: +-- ... ... ... org.codehaus.mojo tomcat-maven-plugin ${project.version} alpha beta ... ... ... +-- ./tomcat-maven-plugin-1.1/src/site/apt/examples/deployment.apt.vm0000600000175000017500000001722011453106426023163 0ustar neoneo --- Deployment --- Mark Hobson --- 2010-02-15 --- Deployment The plugin provides various methods of deployment to Tomcat: * {{{#Deploying_a_WAR_file}Deploying a WAR file}} * {{{#Deploying_an_exploded_WAR_directory}Deploying an exploded WAR directory}}, with an optional <<>> file * {{{#Deploying_an_in-place_WAR_directory}Deploying an in-place WAR directory}}, with an optional <<>> file * {{{#Deploying_a_context.xml_file}Deploying a <<>> file}} * {{{#Running_a_WAR_project}Running a WAR project}} [] These are described in more detail below. * {Deploying a WAR file} The simplest way to deploy a WAR project to Tomcat is to type: +-- mvn tomcat:deploy +-- This goal will assemble and deploy the WAR file to Tomcat's manager using HTTP PUT. ** Using a different WAR file location To specify a different WAR file location, add a plugin configuration block to your <<>> as follows: +-- ... ... ... org.codehaus.mojo tomcat-maven-plugin ${project.version} path/to/my/warFile.war ... ... ... +-- The default location is <<<$\{project.build.directory\}/$\{project.build.finalName\}.war>>>. ** Using a <<>> file If you need to specify a <<>> file when deploying a WAR file to Tomcat, then it must be included within the WAR. The simplest way to achieve this is by adding it to your webapp resources: +-- src |_ main |_ webapp |_ META-INF |_ context.xml +-- * {Deploying an exploded WAR directory} To avoid building a WAR file upon deployment, a WAR directory can instead be deployed to Tomcat by typing: +-- mvn war:exploded tomcat:exploded +-- ** Using a different WAR directory location To specify a different WAR directory location, add a plugin configuration block to your <<>> as follows: +-- ... ... ... org.codehaus.mojo tomcat-maven-plugin ${project.version} path/to/my/warDir ... ... ... +-- The default location is <<<$\{project.build.directory\}/$\{project.build.finalName\}>>>. ** Using a <<>> file To supply a <<>> when deploying a WAR directory, add a plugin configuration block to your <<>> as follows: +-- ... ... ... org.codehaus.mojo tomcat-maven-plugin ${project.version} both ... ... ... +-- The default <<>> file use is located at <<>>. ** Using a different <<>> file location To specify a different <<>> file location, add a plugin configuration block to your <<>> as follows: +-- ... ... ... org.codehaus.mojo tomcat-maven-plugin ${project.version} path/to/my/contextFile.xml ... ... ... +-- The default location is <<<$\{project.build.directory\}/$\{project.build.finalName\}/META-INF/context.xml>>>. * {Deploying an in-place WAR directory} To avoid copying resources to the build directory, the webapp source directory can be deployed to Tomcat by typing: +-- mvn war:inplace tomcat:inplace +-- ** Using a different WAR directory location To specify a different WAR directory location, add a plugin configuration block to your <<>> as follows: +-- ... ... ... org.codehaus.mojo tomcat-maven-plugin ${project.version} path/to/my/warSourceDir ... ... ... +-- The default location is <<<$\{basedir\}/src/main/webapp>>>. ** Using a <<>> file To supply a <<>> when deploying a WAR directory to Tomcat, add a plugin configuration block to your <<>> as follows: +-- ... org.codehaus.mojo tomcat-maven-plugin ${project.version} both ... +-- The default <<>> file used is located at <<>>. ** Using a different <<>> file location To specify a different <<>> file location, add a plugin configuration block to your <<>> as follows: +-- ... ... ... org.codehaus.mojo tomcat-maven-plugin ${project.version} path/to/my/contextFile.xml ... ... ... +-- The default location is <<<$\{project.build.directory\}/$\{project.build.finalName\}/META-INF/context.xml>>>. * {Deploying a context.xml file} To simply deploy just a <<>> file to Tomcat: [[1]] Add a plugin configuration block to your <<>> as follows: +-- ... ... ... org.codehaus.mojo tomcat-maven-plugin ${project.version} context ... ... ... +-- [[2]] Deploy the <<>> file by typing: +-- mvn tomcat:deploy +-- [] The default <<>> file used is located at <<>>. ** Using a different <<>> file location To specify a different <<>> file location, add a plugin configuration block to your <<>> as follows: +-- ... ... ... org.codehaus.mojo tomcat-maven-plugin ${project.version} path/to/my/contextFile.xml ... ... ... +-- The default location is <<<$\{project.build.directory\}/$\{project.build.finalName\}/META-INF/context.xml>>>. * {Running a WAR project} A WAR project can be run under an embedded Tomcat server by typing: +-- mvn tomcat:run +-- To stop the embedded server, press <<>>. ./tomcat-maven-plugin-1.1/src/site/apt/context-goals.apt0000600000175000017500000000327211453106426021335 0ustar neoneo --- Context Goals --- Mark Hobson --- November 21, 2005 --- Context Goals The plugin provides goals to perform various tasks upon your project's context once deployed within Tomcat: * {{{#Redeploying a WAR project}Redeploying a WAR project}} * {{{#Undeploying a WAR project}Undeploying a WAR project}} * {{{#Starting a WAR project}Starting a WAR project}} * {{{#Stopping a WAR project}Stopping a WAR project}} * {{{#Listing session statistics}Listing session statistics}} [] These are described in more detail below. * {Redeploying a WAR project} The goals required to redeploy a WAR project depend upon how it was deployed: * To redeploy a WAR project deployed by <<>> you can type: +-- mvn package tomcat:redeploy +-- * To redeploy a WAR project deployed by <<>> you can type: +-- mvn war:exploded tomcat:redeploy +-- * To redeploy a WAR project deployed by <<>> you can type: +-- mvn war:inplace tomcat:redeploy +-- * To redeploy a context.xml file deployed by <<>> you can type: +-- mvn tomcat:redeploy +-- <> Depending on the <<>> specified in the <<>> you may also need to call <<>> or <<>> as above. * {Undeploying a WAR project} To undeploy a WAR from Tomcat you can type: +-- mvn tomcat:undeploy +-- * {Starting a WAR project} To start a WAR in Tomcat you can type: +-- mvn tomcat:start +-- * {Stopping a WAR project} To stop a WAR in Tomcat you can type: +-- mvn tomcat:stop +-- * {Listing session statistics} To list the session statistics for a deployed WAR project you can type: +-- mvn tomcat:sessions +-- ./tomcat-maven-plugin-1.1/src/site/apt/usage.apt.vm0000600000175000017500000000632211453106426020272 0ustar neoneo --- Usage --- Mark Hobson --- 2010-03-09 --- Usage If no explicit configuration is provided then the Tomcat Maven Plugin defaults to the following: * Tomcat manager URL of <<>> * Authentication details of username <<>> and no password * Context path of <<>> [] These can be overridden as described below. * Using a different Tomcat manager URL To configure the plugin for a different Tomcat instance, add a plugin configuration block to your <<>> as follows: +-- ... ... ... org.codehaus.mojo tomcat-maven-plugin ${project.version} http://www.mydomain.com:1234/mymanager ... ... ... +-- The default Tomcat manager URL is <<>>. * Using different Tomcat manager authentication details To specify a different username and password to use when authenticating with Tomcat manager: [[1]] Add a plugin configuration block to your <<>>: +-- ... ... ... org.codehaus.mojo tomcat-maven-plugin ${project.version} myserver ... ... ... +-- [[2]] Add a corresponding <<>> block to your <<>>: +-- ... ... myserver myusername mypassword ... ... +-- [] The default authentication details are username <<>> and no password. * Using a different context path The default context path is <<>>. To change the context path to <<>> configure the plugin like this: +-- ... ... ... org.codehaus.mojo tomcat-maven-plugin ${project.version} /mycontext ... ... ... +-- If you are using <<>> to change the name of your WAR file, you can use that value when you configure the context path as well. To do that add the following configuration block to your <<>>: +-- ... ... mycontext ... ... org.codehaus.mojo tomcat-maven-plugin ${project.version} /\${project.build.finalName} ... ... ... +-- ./tomcat-maven-plugin-1.1/LICENSE.txt0000600000175000017500000000105711453106432015340 0ustar neoneoCopyright 2005-2006 Mark Hobson. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.