001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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    }