001: //========================================================================
002: //$Id: Jetty6MavenConfiguration.java 1246 2006-11-18 10:40:27Z janb $
003: //Copyright 2000-2005 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: import java.net.URLClassLoader;
020: import java.util.Iterator;
021: import java.util.List;
022:
023: import org.mortbay.jetty.plugin.util.PluginLog;
024: import org.mortbay.jetty.plus.webapp.Configuration;
025: import org.mortbay.jetty.webapp.WebAppClassLoader;
026: import org.mortbay.resource.Resource;
027: import org.mortbay.util.LazyList;
028:
029: public class Jetty6MavenConfiguration extends Configuration {
030: private List classPathFiles;
031: private File webXmlFile;
032: private File webAppDir;
033:
034: public Jetty6MavenConfiguration() {
035: super ();
036: }
037:
038: public void setClassPathConfiguration(File webAppDir,
039: List classPathFiles) {
040: this .webAppDir = webAppDir;
041: this .classPathFiles = classPathFiles;
042: }
043:
044: public void setWebXml(File webXmlFile) {
045: this .webXmlFile = webXmlFile;
046: }
047:
048: /** Set up the classloader for the webapp, using the various parts of the Maven project
049: * @see org.mortbay.jetty.webapp.Configuration#configureClassLoader()
050: */
051: public void configureClassLoader() throws Exception {
052: PluginLog.getLog().debug("Setting up classpath ...");
053:
054: //put the classes dir and all dependencies into the classpath
055: Iterator itor = classPathFiles.iterator();
056: while (itor.hasNext())
057: ((WebAppClassLoader) getWebAppContext().getClassLoader())
058: .addClassPath(((File) itor.next())
059: .getCanonicalPath());
060:
061: PluginLog
062: .getLog()
063: .info(
064: "Classpath = "
065: + LazyList
066: .array2List(((URLClassLoader) getWebAppContext()
067: .getClassLoader())
068: .getURLs()));
069: }
070:
071: /** Parse the default webapp descriptor
072: * @see org.mortbay.jetty.webapp.Configuration#configureDefaults()
073: */
074: public void configureDefaults() throws Exception {
075: super .configureDefaults();
076:
077: }
078:
079: /** Prepare webapp for starting by parsing web.xml
080: * @see org.mortbay.jetty.webapp.Configuration#configureWebApp()
081: */
082: public void configureWebApp() throws Exception {
083: //cannot configure if the context is already started
084: if (getWebAppContext().isStarted()) {
085: PluginLog.getLog().error(
086: "Cannot configure webapp after it is started");
087: return;
088: }
089:
090: PluginLog.getLog().debug(
091: "Started configuring web.xml, resource base="
092: + webAppDir.getCanonicalPath());
093: getWebAppContext()
094: .setResourceBase(webAppDir.getCanonicalPath());
095: if (webXmlFile.exists())
096: configure(webXmlFile.toURL().toString());
097: PluginLog.getLog().debug("Finished configuring web.xml");
098:
099: //apply any override file
100: String overrideDescriptor = getWebAppContext()
101: .getOverrideDescriptor();
102: if (overrideDescriptor != null
103: && overrideDescriptor.length() > 0) {
104: PluginLog.getLog().debug(
105: "Applying override web.xml file at="
106: + overrideDescriptor);
107: Resource orideResource = Resource
108: .newSystemResource(overrideDescriptor);
109: if (orideResource == null)
110: orideResource = Resource
111: .newResource(overrideDescriptor);
112: //ensure we don't validate the override web.xml as it probably
113: //only contains a partial web.xml file
114: _xmlParser.setValidating(false);
115: configure(orideResource.getURL().toString());
116: PluginLog.getLog().debug(
117: "Finished applying override web.xml");
118: }
119:
120: bindUserTransaction();
121: lockCompEnv();
122: }
123:
124: /** Prepare webapp for stopping
125: * @see org.mortbay.jetty.webapp.Configuration#deconfigureWebApp()
126: */
127: public void deconfigureWebApp() throws Exception {
128: super.deconfigureWebApp();
129: }
130:
131: }
|