1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.tools.deploy;
16  
17  import com.liferay.portal.kernel.plugin.PluginPackage;
18  import com.liferay.portal.kernel.util.ServerDetector;
19  import com.liferay.portal.kernel.util.StringBundler;
20  import com.liferay.portal.util.InitUtil;
21  
22  import java.io.File;
23  
24  import java.util.ArrayList;
25  import java.util.List;
26  
27  /**
28   * <a href="HookDeployer.java.html"><b><i>View Source</i></b></a>
29   *
30   * @author Brian Wing Shun Chan
31   */
32  public class HookDeployer extends BaseDeployer {
33  
34      public static void main(String[] args) {
35          InitUtil.initWithSpring();
36  
37          List<String> wars = new ArrayList<String>();
38          List<String> jars = new ArrayList<String>();
39  
40          for (String arg : args) {
41              if (arg.endsWith(".war")) {
42                  wars.add(arg);
43              }
44              else if (arg.endsWith(".jar")) {
45                  jars.add(arg);
46              }
47          }
48  
49          new HookDeployer(wars, jars);
50      }
51  
52      protected HookDeployer() {
53      }
54  
55      protected HookDeployer(List<String> wars, List<String> jars) {
56          super(wars, jars);
57      }
58  
59      protected void copyXmls(
60              File srcFile, String displayName, PluginPackage pluginPackage)
61          throws Exception {
62  
63          super.copyXmls(srcFile, displayName, pluginPackage);
64  
65          if (appServerType.equals(ServerDetector.TOMCAT_ID)) {
66              copyDependencyXml("context.xml", srcFile + "/META-INF");
67          }
68      }
69  
70      protected String getExtraContent(
71              double webXmlVersion, File srcFile, String displayName)
72          throws Exception {
73  
74          StringBundler sb = new StringBundler(6);
75  
76          String extraContent = super.getExtraContent(
77              webXmlVersion, srcFile, displayName);
78  
79          sb.append(extraContent);
80  
81          // HookContextListener
82  
83          sb.append("<listener>");
84          sb.append("<listener-class>");
85          sb.append("com.liferay.portal.kernel.servlet.HookContextListener");
86          sb.append("</listener-class>");
87          sb.append("</listener>");
88  
89          return sb.toString();
90      }
91  
92  }