001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.support.tomcat.startup;
022:
023: import com.liferay.portal.kernel.log.Log;
024: import com.liferay.portal.kernel.log.LogFactoryUtil;
025: import com.liferay.portal.kernel.util.StringComparator;
026:
027: import java.io.File;
028:
029: import java.util.Arrays;
030:
031: import org.apache.catalina.startup.HostConfig;
032:
033: /**
034: * <a href="PortalHostConfig.java.html"><b><i>View Source</i></b></a>
035: *
036: * <p>
037: * Tomcat will always process XML descriptors first, then packaged WARs, and
038: * then exploded WARs. However, Tomcat does not have a predictable load order
039: * for the XML descriptors or the WARs. It relies on Java's
040: * <code>java.io.File.list()</code> implementation which is not predictable.
041: * This class overrides several of the deploy methods to ensure that the files
042: * are always processed alphabetically (case sensitive).
043: * </p>
044: *
045: * <p>
046: * To use this class, modify Tomcat's conf/server.xml. Find the
047: * <code>Host</code> element and add the attribute <code>hostConfigClass</code>.
048: * </p>
049: *
050: * <p>
051: * See http://support.liferay.com/browse/LEP-2346.
052: * </p>
053: *
054: * <p>
055: * See <code>org.apache.catalina.startup.HostConfig</code>.
056: * </p>
057: *
058: * @author Brian Wing Shun Chan
059: *
060: */
061: public class PortalHostConfig extends HostConfig {
062:
063: public PortalHostConfig() {
064: super ();
065: }
066:
067: protected void deployDescriptor(String contextPath,
068: File contextXml, String file) {
069:
070: if (_log.isDebugEnabled()) {
071: _log.debug("deployDescriptor " + contextPath + " "
072: + contextXml + " " + file);
073: }
074:
075: super .deployDescriptor(contextPath, contextXml, file);
076: }
077:
078: protected void deployDescriptors(File configBase, String[] files) {
079: super .deployDescriptors(configBase, sortFiles(files));
080: }
081:
082: protected void deployDirectories(File appBase, String[] files) {
083: super .deployDirectories(appBase, sortFiles(files));
084: }
085:
086: protected void deployWARs(File appBase, String[] files) {
087: super .deployWARs(appBase, sortFiles(files));
088: }
089:
090: protected String[] sortFiles(String[] files) {
091: Arrays.sort(files, new StringComparator(true, true));
092:
093: if (_log.isDebugEnabled()) {
094: _log.debug("Sort " + files.length + " files");
095:
096: for (int i = 0; i < files.length; i++) {
097: _log.debug("File " + i + " " + files[i]);
098: }
099: }
100:
101: return files;
102: }
103:
104: private static Log _log = LogFactoryUtil
105: .getLog(PortalHostConfig.class);
106:
107: }
|