001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.tools.deploy;
016    
017    import com.liferay.portal.kernel.plugin.PluginPackage;
018    import com.liferay.portal.kernel.util.ServerDetector;
019    import com.liferay.portal.kernel.util.StringBundler;
020    import com.liferay.portal.util.InitUtil;
021    
022    import java.io.File;
023    
024    import java.util.ArrayList;
025    import java.util.List;
026    
027    /**
028     * @author Brian Wing Shun Chan
029     */
030    public class HookDeployer extends BaseDeployer {
031    
032            public static void main(String[] args) {
033                    InitUtil.initWithSpring();
034    
035                    List<String> wars = new ArrayList<String>();
036                    List<String> jars = new ArrayList<String>();
037    
038                    for (String arg : args) {
039                            if (arg.endsWith(".war")) {
040                                    wars.add(arg);
041                            }
042                            else if (arg.endsWith(".jar")) {
043                                    jars.add(arg);
044                            }
045                    }
046    
047                    new HookDeployer(wars, jars);
048            }
049    
050            protected HookDeployer() {
051            }
052    
053            protected HookDeployer(List<String> wars, List<String> jars) {
054                    super(wars, jars);
055            }
056    
057            protected void copyXmls(
058                            File srcFile, String displayName, PluginPackage pluginPackage)
059                    throws Exception {
060    
061                    super.copyXmls(srcFile, displayName, pluginPackage);
062    
063                    if (appServerType.equals(ServerDetector.TOMCAT_ID)) {
064                            copyDependencyXml("context.xml", srcFile + "/META-INF");
065                    }
066            }
067    
068            protected String getExtraContent(
069                            double webXmlVersion, File srcFile, String displayName)
070                    throws Exception {
071    
072                    StringBundler sb = new StringBundler(6);
073    
074                    String extraContent = super.getExtraContent(
075                            webXmlVersion, srcFile, displayName);
076    
077                    sb.append(extraContent);
078    
079                    // HookContextListener
080    
081                    sb.append("<listener>");
082                    sb.append("<listener-class>");
083                    sb.append("com.liferay.portal.kernel.servlet.HookContextListener");
084                    sb.append("</listener-class>");
085                    sb.append("</listener>");
086    
087                    return sb.toString();
088            }
089    
090    }