001: //========================================================================
002: //$Id: Jetty6RunMojo.java 669 2006-07-10 10:51:55Z janb $
003: //Copyright 2000-2004 Mort Bay Consulting Pty. Ltd.
004: //------------------------------------------------------------------------
005: //Licensed under the Apache License, Version 2.0 (the "License");
006: //you may not use this file except in compliance with the License.
007: //You may obtain a copy of the License at
008: //http://www.apache.org/licenses/LICENSE-2.0
009: //Unless required by applicable law or agreed to in writing, software
010: //distributed under the License is distributed on an "AS IS" BASIS,
011: //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: //See the License for the specific language governing permissions and
013: //limitations under the License.
014: //========================================================================
015:
016: package org.mortbay.jetty.plugin;
017:
018: import java.io.File;
019:
020: import org.apache.maven.plugin.MojoExecutionException;
021: import org.apache.maven.plugin.MojoFailureException;
022: import org.mortbay.jetty.Connector;
023: import org.mortbay.jetty.Handler;
024: import org.mortbay.jetty.RequestLog;
025: import org.mortbay.jetty.Server;
026: import org.mortbay.jetty.handler.ContextHandler;
027: import org.mortbay.jetty.handler.ContextHandlerCollection;
028: import org.mortbay.jetty.handler.HandlerCollection;
029: import org.mortbay.jetty.plugin.util.JettyPluginServer;
030: import org.mortbay.jetty.security.UserRealm;
031: import org.mortbay.xml.XmlConfiguration;
032:
033: /**
034: * <p>
035: * This goal is used in-situ on a Maven project without first requiring that the project
036: * is assembled into a war, saving time during the development cycle.
037: * The plugin forks a parallel lifecycle to ensure that the "compile" phase has been completed before invoking Jetty. This means
038: * that you do not need to explicity execute a "mvn compile" first. It also means that a "mvn clean jetty:run" will ensure that
039: * a full fresh compile is done before invoking Jetty.
040: * </p>
041: * <p>
042: * Once invoked, the plugin can be configured to run continuously, scanning for changes in the project and automatically performing a
043: * hot redeploy when necessary. This allows the developer to concentrate on coding changes to the project using their IDE of choice and have those changes
044: * immediately and transparently reflected in the running web container, eliminating development time that is wasted on rebuilding, reassembling and redeploying.
045: * </p>
046: * <p>
047: * You may also specify the location of a jetty.xml file whose contents will be applied before any plugin configuration.
048: * This can be used, for example, to deploy a static webapp that is not part of your maven build.
049: * </p>
050: * <p>
051: * There is a <a href="run-mojo.html">reference guide</a> to the configuration parameters for this plugin, and more detailed information
052: * with examples in the <a href="howto.html">Configuration How-To</a>.
053: * </p>
054: * @author janb
055: *
056: * @goal run
057: * @requiresDependencyResolution runtime
058: * @execute phase="compile"
059: * @description Runs jetty6 directly from a maven project
060: */
061: public class Jetty6RunMojo extends AbstractJettyRunMojo {
062:
063: /**
064: * List of connectors to use. If none are configured
065: * then we use a single SelectChannelConnector at port 8080
066: *
067: * @parameter
068: */
069: private Connector[] connectors;
070:
071: /**
072: * List of other contexts to set up. Optional.
073: * @parameter
074: */
075: private ContextHandler[] contextHandlers;
076:
077: /**
078: * List of security realms to set up. Optional.
079: * @parameter
080: */
081: private UserRealm[] userRealms;
082:
083: /**
084: * A RequestLog implementation to use for the webapp at runtime.
085: * Optional.
086: * @parameter
087: */
088: private RequestLog requestLog;
089:
090: public Object getConfiguredRequestLog() {
091: return this .requestLog;
092: }
093:
094: /**
095: *
096: *
097: * @see org.mortbay.jetty.plugin.AbstractJettyRunMojo#getConfiguredConnectors()
098: */
099: public Object[] getConfiguredConnectors() {
100: return this .connectors;
101: }
102:
103: /**
104: *
105: *
106: * @see org.mortbay.jetty.plugin.AbstractJettyRunMojo#getConfiguredUserRealms()
107: */
108: public Object[] getConfiguredUserRealms() {
109: return this .userRealms;
110: }
111:
112: /**
113: * @return Returns the contextHandlers.
114: */
115: public ContextHandler[] getConfiguredContextHandlers() {
116: return this .contextHandlers;
117: }
118:
119: /**
120: *
121: *
122: * @see org.mortbay.jetty.plugin.AbstractJettyRunMojo#createServer()
123: */
124: public JettyPluginServer createServer() {
125: return new Jetty6PluginServer();
126: }
127:
128: public void finishConfigurationBeforeStart() throws Exception {
129: Handler[] handlers = getConfiguredContextHandlers();
130: JettyPluginServer plugin = getServer();
131: Server server = (Server) plugin.getProxiedObject();
132:
133: HandlerCollection contexts = (HandlerCollection) server
134: .getChildHandlerByClass(ContextHandlerCollection.class);
135: if (contexts == null)
136: contexts = (HandlerCollection) server
137: .getChildHandlerByClass(HandlerCollection.class);
138:
139: for (int i = 0; (handlers != null) && (i < handlers.length); i++) {
140: contexts.addHandler(handlers[i]);
141: }
142: }
143:
144: public void applyJettyXml() throws Exception {
145: if (getJettyXmlFileName() == null)
146: return;
147:
148: getLog().info(
149: "Configuring Jetty from xml configuration file = "
150: + getJettyXmlFileName());
151: File f = new File(getJettyXmlFileName());
152: XmlConfiguration xmlConfiguration = new XmlConfiguration(f
153: .toURL());
154: xmlConfiguration.configure(getServer().getProxiedObject());
155: }
156:
157: public void execute() throws MojoExecutionException,
158: MojoFailureException {
159: super.execute();
160: }
161: }
|