2 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
\r
4 * This library is free software; you can redistribute it and/or modify it under
\r
5 * the terms of the GNU Lesser General Public License as published by the Free
\r
6 * Software Foundation; either version 2.1 of the License, or (at your option)
\r
9 * This library is distributed in the hope that it will be useful, but WITHOUT
\r
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
\r
15 package com.liferay.portal.tools.deploy;
\r
17 import com.liferay.portal.deploy.DeployUtil;
\r
18 import com.liferay.portal.deploy.auto.AutoDeployer;
\r
19 import com.liferay.portal.kernel.deploy.Deployer;
\r
20 import com.liferay.portal.kernel.deploy.auto.AutoDeployException;
\r
21 import com.liferay.portal.kernel.deploy.auto.context.AutoDeploymentContext;
\r
22 import com.liferay.portal.kernel.log.Log;
\r
23 import com.liferay.portal.kernel.log.LogFactoryUtil;
\r
24 import com.liferay.portal.kernel.plugin.License;
\r
25 import com.liferay.portal.kernel.plugin.PluginPackage;
\r
26 import com.liferay.portal.kernel.servlet.PluginContextListener;
\r
27 import com.liferay.portal.kernel.servlet.PortletServlet;
\r
28 import com.liferay.portal.kernel.servlet.SecurePluginContextListener;
\r
29 import com.liferay.portal.kernel.servlet.SecureServlet;
\r
30 import com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter;
\r
31 import com.liferay.portal.kernel.util.CharPool;
\r
32 import com.liferay.portal.kernel.util.FileUtil;
\r
33 import com.liferay.portal.kernel.util.GetterUtil;
\r
34 import com.liferay.portal.kernel.util.HttpUtil;
\r
35 import com.liferay.portal.kernel.util.PropertiesUtil;
\r
36 import com.liferay.portal.kernel.util.PropsKeys;
\r
37 import com.liferay.portal.kernel.util.ServerDetector;
\r
38 import com.liferay.portal.kernel.util.StringBundler;
\r
39 import com.liferay.portal.kernel.util.StringPool;
\r
40 import com.liferay.portal.kernel.util.StringUtil;
\r
41 import com.liferay.portal.kernel.util.SystemProperties;
\r
42 import com.liferay.portal.kernel.util.TextFormatter;
\r
43 import com.liferay.portal.kernel.util.Time;
\r
44 import com.liferay.portal.kernel.util.Validator;
\r
45 import com.liferay.portal.kernel.xml.Document;
\r
46 import com.liferay.portal.kernel.xml.Element;
\r
47 import com.liferay.portal.kernel.xml.SAXReaderUtil;
\r
48 import com.liferay.portal.plugin.PluginPackageUtil;
\r
49 import com.liferay.portal.tools.WebXMLBuilder;
\r
50 import com.liferay.portal.util.ExtRegistry;
\r
51 import com.liferay.portal.util.InitUtil;
\r
52 import com.liferay.portal.util.PortalUtil;
\r
53 import com.liferay.portal.util.PrefsPropsUtil;
\r
54 import com.liferay.portal.util.PropsUtil;
\r
55 import com.liferay.portal.util.PropsValues;
\r
56 import com.liferay.util.ant.CopyTask;
\r
57 import com.liferay.util.ant.DeleteTask;
\r
58 import com.liferay.util.ant.ExpandTask;
\r
59 import com.liferay.util.ant.UpToDateTask;
\r
60 import com.liferay.util.ant.WarTask;
\r
61 import com.liferay.util.xml.DocUtil;
\r
62 import com.liferay.util.xml.XMLFormatter;
\r
64 import java.io.File;
\r
65 import java.io.FileInputStream;
\r
66 import java.io.IOException;
\r
67 import java.io.InputStream;
\r
69 import java.util.ArrayList;
\r
70 import java.util.HashMap;
\r
71 import java.util.List;
\r
72 import java.util.Map;
\r
73 import java.util.Properties;
\r
74 import java.util.Set;
\r
75 import java.util.zip.ZipEntry;
\r
76 import java.util.zip.ZipFile;
\r
78 import org.apache.oro.io.GlobFilenameFilter;
\r
81 * @author Brian Wing Shun Chan
\r
82 * @author Sandeep Soni
\r
84 public class BaseDeployer implements AutoDeployer, Deployer {
\r
86 public static final String DEPLOY_TO_PREFIX = "DEPLOY_TO__";
\r
88 public static void main(String[] args) {
\r
89 InitUtil.initWithSpring();
\r
91 List<String> wars = new ArrayList<String>();
\r
92 List<String> jars = new ArrayList<String>();
\r
94 for (String arg : args) {
\r
95 String fileName = arg.toLowerCase();
\r
97 if (fileName.endsWith(".war")) {
\r
100 else if (fileName.endsWith(".jar")) {
\r
105 new BaseDeployer(wars, jars);
\r
108 public BaseDeployer() {
\r
111 public BaseDeployer(List<String> wars, List<String> jars) {
\r
112 baseDir = System.getProperty("deployer.base.dir");
\r
113 destDir = System.getProperty("deployer.dest.dir");
\r
114 appServerType = System.getProperty("deployer.app.server.type");
\r
115 auiTaglibDTD = System.getProperty("deployer.aui.taglib.dtd");
\r
116 portletTaglibDTD = System.getProperty("deployer.portlet.taglib.dtd");
\r
117 portletExtTaglibDTD = System.getProperty(
\r
118 "deployer.portlet.ext.taglib.dtd");
\r
119 securityTaglibDTD = System.getProperty("deployer.security.taglib.dtd");
\r
120 themeTaglibDTD = System.getProperty("deployer.theme.taglib.dtd");
\r
121 uiTaglibDTD = System.getProperty("deployer.ui.taglib.dtd");
\r
122 utilTaglibDTD = System.getProperty("deployer.util.taglib.dtd");
\r
123 unpackWar = GetterUtil.getBoolean(
\r
124 System.getProperty("deployer.unpack.war"), true);
\r
125 filePattern = System.getProperty("deployer.file.pattern");
\r
126 jbossPrefix = GetterUtil.getString(
\r
127 System.getProperty("deployer.jboss.prefix"));
\r
128 tomcatLibDir = System.getProperty("deployer.tomcat.lib.dir");
\r
134 String context = System.getProperty("deployer.context");
\r
139 catch (Exception e) {
\r
140 e.printStackTrace();
\r
144 public void addExtJar(List<String> jars, String resource) throws Exception {
\r
145 Set<String> servletContextNames = ExtRegistry.getServletContextNames();
\r
147 for (String servletContextName : servletContextNames) {
\r
148 String extResource =
\r
149 "ext-" + servletContextName + resource.substring(3);
\r
151 String path = DeployUtil.getResourcePath(extResource);
\r
153 if (_log.isDebugEnabled()) {
\r
154 if (path == null) {
\r
155 _log.debug("Resource " + extResource + " is not available");
\r
159 "Resource " + extResource + " is available at " + path);
\r
163 if (path != null) {
\r
169 public void addRequiredJar(List<String> jars, String resource)
\r
172 String path = DeployUtil.getResourcePath(resource);
\r
174 if (path == null) {
\r
175 throw new RuntimeException(
\r
176 "Resource " + resource + " does not exist");
\r
179 if (_log.isDebugEnabled()) {
\r
180 _log.debug("Resource " + resource + " is available at " + path);
\r
186 public int autoDeploy(AutoDeploymentContext autoDeploymentContext)
\r
187 throws AutoDeployException {
\r
189 List<String> wars = new ArrayList<String>();
\r
191 File file = autoDeploymentContext.getFile();
\r
193 wars.add(file.getName());
\r
198 return deployFile(autoDeploymentContext);
\r
200 catch (Exception e) {
\r
201 throw new AutoDeployException(e);
\r
205 public void checkArguments() {
\r
206 if (Validator.isNull(baseDir)) {
\r
207 throw new IllegalArgumentException(
\r
208 "The system property deployer.base.dir is not set");
\r
211 if (Validator.isNull(destDir)) {
\r
212 throw new IllegalArgumentException(
\r
213 "The system property deployer.dest.dir is not set");
\r
216 if (Validator.isNull(appServerType)) {
\r
217 throw new IllegalArgumentException(
\r
218 "The system property deployer.app.server.type is not set");
\r
221 if (!appServerType.equals(ServerDetector.GERONIMO_ID) &&
\r
222 !appServerType.equals(ServerDetector.GLASSFISH_ID) &&
\r
223 !appServerType.equals(ServerDetector.JBOSS_ID) &&
\r
224 !appServerType.equals(ServerDetector.JONAS_ID) &&
\r
225 !appServerType.equals(ServerDetector.JETTY_ID) &&
\r
226 !appServerType.equals(ServerDetector.OC4J_ID) &&
\r
227 !appServerType.equals(ServerDetector.RESIN_ID) &&
\r
228 !appServerType.equals(ServerDetector.TOMCAT_ID) &&
\r
229 !appServerType.equals(ServerDetector.WEBLOGIC_ID) &&
\r
230 !appServerType.equals(ServerDetector.WEBSPHERE_ID)) {
\r
232 throw new IllegalArgumentException(
\r
233 appServerType + " is not a valid application server type");
\r
236 if (appServerType.equals(ServerDetector.WEBSPHERE_ID)) {
\r
240 if (Validator.isNotNull(jbossPrefix) &&
\r
241 !Validator.isNumber(jbossPrefix)) {
\r
247 public void copyDependencyXml(String fileName, String targetDir)
\r
250 copyDependencyXml(fileName, targetDir, null);
\r
253 public void copyDependencyXml(
\r
254 String fileName, String targetDir, Map<String, String> filterMap)
\r
257 copyDependencyXml(fileName, targetDir, filterMap, false);
\r
260 public void copyDependencyXml(
\r
261 String fileName, String targetDir, Map<String, String> filterMap,
\r
265 DeployUtil.copyDependencyXml(
\r
266 fileName, targetDir, fileName, filterMap, overwrite);
\r
269 public void copyJars(File srcFile, PluginPackage pluginPackage)
\r
272 for (int i = 0; i < jars.size(); i++) {
\r
273 String jarFullName = jars.get(i);
\r
275 String jarName = jarFullName.substring(
\r
276 jarFullName.lastIndexOf("/") + 1);
\r
278 if (!appServerType.equals(ServerDetector.TOMCAT_ID) ||
\r
279 (appServerType.equals(ServerDetector.TOMCAT_ID) &&
\r
280 !jarFullName.equals("util-java.jar"))) {
\r
283 jarFullName, srcFile + "/WEB-INF/lib/" + jarName, true);
\r
287 FileUtil.delete(srcFile + "/WEB-INF/lib/util-jsf.jar");
\r
290 public void copyPortalDependencies(File srcFile) throws Exception {
\r
291 Properties properties = getPluginPackageProperties(srcFile);
\r
293 if (properties == null) {
\r
299 String[] portalJars = StringUtil.split(
\r
300 properties.getProperty(
\r
301 "portal-dependency-jars",
\r
302 properties.getProperty("portal.dependency.jars")));
\r
304 for (int i = 0; i < portalJars.length; i++) {
\r
305 String portalJar = portalJars[i].trim();
\r
307 portalJar = fixPortalDependencyJar(portalJar);
\r
309 if (_log.isDebugEnabled()) {
\r
310 _log.debug("Copy portal JAR " + portalJar);
\r
314 String portalJarPath = PortalUtil.getPortalLibDir() + portalJar;
\r
317 portalJarPath, srcFile + "/WEB-INF/lib/" + portalJar, true);
\r
319 catch (Exception e) {
\r
320 _log.error("Unable to copy portal JAR " + portalJar, e);
\r
326 String[] portalTlds = StringUtil.split(
\r
327 properties.getProperty(
\r
328 "portal-dependency-tlds",
\r
329 properties.getProperty("portal.dependency.tlds")));
\r
331 for (int i = 0; i < portalTlds.length; i++) {
\r
332 String portalTld = portalTlds[i].trim();
\r
334 if (_log.isDebugEnabled()) {
\r
335 _log.debug("Copy portal TLD " + portalTld);
\r
339 String portalTldPath = DeployUtil.getResourcePath(portalTld);
\r
342 portalTldPath, srcFile + "/WEB-INF/tld/" + portalTld, true);
\r
344 catch (Exception e) {
\r
345 _log.error("Unable to copy portal TLD " + portalTld, e);
\r
349 // commons-logging*.jar
\r
351 File pluginLibDir = new File(srcFile + "/WEB-INF/lib/");
\r
353 if (PropsValues.AUTO_DEPLOY_COPY_COMMONS_LOGGING) {
\r
354 String[] commonsLoggingJars = pluginLibDir.list(
\r
355 new GlobFilenameFilter("commons-logging*.jar"));
\r
357 if ((commonsLoggingJars == null) ||
\r
358 (commonsLoggingJars.length == 0)) {
\r
360 String portalJarPath =
\r
361 PortalUtil.getPortalLibDir() + "commons-logging.jar";
\r
364 portalJarPath, srcFile + "/WEB-INF/lib/commons-logging.jar",
\r
371 if (PropsValues.AUTO_DEPLOY_COPY_LOG4J) {
\r
372 String[] log4jJars = pluginLibDir.list(
\r
373 new GlobFilenameFilter("log4j*.jar"));
\r
375 if ((log4jJars == null) || (log4jJars.length == 0)) {
\r
376 String portalJarPath =
\r
377 PortalUtil.getPortalLibDir() + "log4j.jar";
\r
380 portalJarPath, srcFile + "/WEB-INF/lib/log4j.jar", true);
\r
385 public void copyProperties(File srcFile, PluginPackage pluginPackage)
\r
388 if (PropsValues.AUTO_DEPLOY_COPY_COMMONS_LOGGING) {
\r
390 "logging.properties", srcFile + "/WEB-INF/classes");
\r
393 if (PropsValues.AUTO_DEPLOY_COPY_LOG4J) {
\r
394 copyDependencyXml("log4j.properties", srcFile + "/WEB-INF/classes");
\r
397 File servicePropertiesFile = new File(
\r
398 srcFile.getAbsolutePath() + "/WEB-INF/classes/service.properties");
\r
400 if (servicePropertiesFile.exists()) {
\r
401 File portletPropertiesFile = new File(
\r
402 srcFile.getAbsolutePath() +
\r
403 "/WEB-INF/classes/portlet.properties");
\r
405 if (!portletPropertiesFile.exists()) {
\r
406 String pluginPackageName = null;
\r
408 if (pluginPackage != null) {
\r
409 pluginPackageName = pluginPackage.getName();
\r
412 pluginPackageName = srcFile.getName();
\r
416 portletPropertiesFile,
\r
417 "plugin.package.name=" + pluginPackageName);
\r
422 public void copyTlds(File srcFile, PluginPackage pluginPackage)
\r
425 if (Validator.isNotNull(auiTaglibDTD)) {
\r
427 auiTaglibDTD, srcFile + "/WEB-INF/tld/aui.tld", true);
\r
430 if (Validator.isNotNull(portletTaglibDTD)) {
\r
432 portletTaglibDTD, srcFile + "/WEB-INF/tld/liferay-portlet.tld",
\r
436 if (Validator.isNotNull(portletExtTaglibDTD)) {
\r
438 portletExtTaglibDTD,
\r
439 srcFile + "/WEB-INF/tld/liferay-portlet-ext.tld", true);
\r
442 if (Validator.isNotNull(securityTaglibDTD)) {
\r
445 srcFile + "/WEB-INF/tld/liferay-security.tld", true);
\r
448 if (Validator.isNotNull(themeTaglibDTD)) {
\r
450 themeTaglibDTD, srcFile + "/WEB-INF/tld/liferay-theme.tld",
\r
454 if (Validator.isNotNull(uiTaglibDTD)) {
\r
456 uiTaglibDTD, srcFile + "/WEB-INF/tld/liferay-ui.tld", true);
\r
459 if (Validator.isNotNull(utilTaglibDTD)) {
\r
461 utilTaglibDTD, srcFile + "/WEB-INF/tld/liferay-util.tld", true);
\r
465 public void copyTomcatContextXml(File targetDir) throws Exception {
\r
466 if (!appServerType.equals(ServerDetector.TOMCAT_ID)) {
\r
470 // Update to keep context.xml file in META-INF if file exists
\r
471 File contextXml = new File(targetDir + "/META-INF/context.xml");
\r
472 String contextPath = "";
\r
473 if (contextXml.exists()) {
\r
474 contextPath = contextXml.getAbsolutePath();
\r
477 contextPath = DeployUtil.getResourcePath("context.xml");
\r
480 String content = FileUtil.read(contextPath);
\r
482 if (!PropsValues.AUTO_DEPLOY_UNPACK_WAR) {
\r
483 content = StringUtil.replace(
\r
484 content, "antiResourceLocking=\"true\"", StringPool.BLANK);
\r
487 FileUtil.write(new File(targetDir, "META-INF/context.xml"), content);
\r
490 public void copyXmls(
\r
491 File srcFile, String displayName, PluginPackage pluginPackage)
\r
494 if (appServerType.equals(ServerDetector.GERONIMO_ID)) {
\r
495 copyDependencyXml("geronimo-web.xml", srcFile + "/WEB-INF");
\r
497 else if (appServerType.equals(ServerDetector.JBOSS_ID)) {
\r
499 "jboss-deployment-structure.xml", srcFile + "/WEB-INF");
\r
501 else if (appServerType.equals(ServerDetector.WEBLOGIC_ID)) {
\r
502 copyDependencyXml("weblogic.xml", srcFile + "/WEB-INF");
\r
504 else if (appServerType.equals(ServerDetector.WEBSPHERE_ID)) {
\r
505 copyDependencyXml("ibm-web-ext.xmi", srcFile + "/WEB-INF");
\r
508 copyDependencyXml("web.xml", srcFile + "/WEB-INF");
\r
511 public void deploy(String context) throws Exception {
\r
513 File baseDirFile = new File(baseDir);
\r
515 File[] files = baseDirFile.listFiles();
\r
517 if (files == null) {
\r
521 files = FileUtil.sortFiles(files);
\r
523 for (int i = 0; i < files.length; i++) {
\r
524 File srcFile = files[i];
\r
526 String fileName = srcFile.getName().toLowerCase();
\r
528 boolean deploy = false;
\r
530 if (fileName.endsWith(".war") || fileName.endsWith(".zip")) {
\r
533 if (wars.size() > 0) {
\r
534 if (!wars.contains(srcFile.getName())) {
\r
538 else if (Validator.isNotNull(filePattern)) {
\r
539 if (!StringUtil.matchesIgnoreCase(
\r
540 fileName, filePattern)) {
\r
548 AutoDeploymentContext autoDeploymentContext =
\r
549 new AutoDeploymentContext();
\r
551 autoDeploymentContext.setContext(context);
\r
552 autoDeploymentContext.setFile(srcFile);
\r
554 deployFile(autoDeploymentContext);
\r
558 catch (Exception e) {
\r
559 e.printStackTrace();
\r
563 public void deployDirectory(
\r
564 File srcFile, File mergeDir, File deployDir, String displayName,
\r
565 boolean overwrite, PluginPackage pluginPackage)
\r
568 rewriteFiles(srcFile);
\r
570 mergeDirectory(mergeDir, srcFile);
\r
572 processPluginPackageProperties(srcFile, displayName, pluginPackage);
\r
574 copyJars(srcFile, pluginPackage);
\r
575 copyProperties(srcFile, pluginPackage);
\r
576 copyTlds(srcFile, pluginPackage);
\r
577 copyXmls(srcFile, displayName, pluginPackage);
\r
578 copyPortalDependencies(srcFile);
\r
580 updateGeronimoWebXml(srcFile, displayName, pluginPackage);
\r
582 File webXml = new File(srcFile + "/WEB-INF/web.xml");
\r
584 updateWebXml(webXml, srcFile, displayName, pluginPackage);
\r
586 File extLibGlobalDir = new File(
\r
587 srcFile.getAbsolutePath() + "/WEB-INF/ext-lib/global");
\r
589 if (extLibGlobalDir.exists()) {
\r
590 File globalLibDir = new File(PortalUtil.getGlobalLibDir());
\r
592 CopyTask.copyDirectory(
\r
593 extLibGlobalDir, globalLibDir, "*.jar", StringPool.BLANK,
\r
597 File extLibPortalDir = new File(
\r
598 srcFile.getAbsolutePath() + "/WEB-INF/ext-lib/portal");
\r
600 if (extLibPortalDir.exists()) {
\r
601 File portalLibDir = new File(PortalUtil.getPortalLibDir());
\r
603 CopyTask.copyDirectory(
\r
604 extLibPortalDir, portalLibDir, "*.jar", StringPool.BLANK,
\r
608 if ((deployDir == null) || baseDir.equals(destDir)) {
\r
612 updateDeployDirectory(srcFile);
\r
614 String excludes = StringPool.BLANK;
\r
616 if (appServerType.equals(ServerDetector.JBOSS_ID)) {
\r
617 excludes += "**/WEB-INF/lib/log4j.jar,";
\r
619 else if (appServerType.equals(ServerDetector.TOMCAT_ID)) {
\r
620 String[] libs = FileUtil.listFiles(tomcatLibDir);
\r
622 for (int i = 0; i < libs.length; i++) {
\r
623 excludes += "**/WEB-INF/lib/" + libs[i] + ",";
\r
626 File contextXml = new File(srcFile + "/META-INF/context.xml");
\r
628 if (contextXml.exists()) {
\r
629 String content = FileUtil.read(contextXml);
\r
631 if (content.indexOf(_PORTAL_CLASS_LOADER) != -1) {
\r
632 excludes += "**/WEB-INF/lib/util-bridges.jar,";
\r
633 excludes += "**/WEB-INF/lib/util-java.jar,";
\r
634 excludes += "**/WEB-INF/lib/util-taglib.jar,";
\r
642 Class.forName("javax.el.ELContext");
\r
644 excludes += "**/WEB-INF/lib/el-api.jar,";
\r
646 catch (ClassNotFoundException cnfe) {
\r
652 Properties properties = getPluginPackageProperties(srcFile);
\r
654 if (properties != null) {
\r
655 String deployExcludes = properties.getProperty("deploy-excludes");
\r
657 if (deployExcludes != null) {
\r
658 excludes += deployExcludes.trim();
\r
660 if (!excludes.endsWith(",")) {
\r
665 deployExcludes = properties.getProperty(
\r
666 "deploy-excludes-" + appServerType);
\r
668 if (deployExcludes != null) {
\r
669 excludes += deployExcludes.trim();
\r
671 if (!excludes.endsWith(",")) {
\r
677 if (_log.isDebugEnabled()) {
\r
678 _log.debug("Excludes " + excludes);
\r
682 File tempDir = new File(
\r
683 SystemProperties.get(SystemProperties.TMP_DIR) +
\r
684 File.separator + Time.getTimestamp());
\r
686 excludes += "**/WEB-INF/web.xml";
\r
688 WarTask.war(srcFile, tempDir, excludes, webXml);
\r
690 if (isJEEDeploymentEnabled()) {
\r
691 File tempWarDir = new File(
\r
692 tempDir.getParent(), deployDir.getName());
\r
694 if (tempWarDir.exists()) {
\r
695 tempWarDir.delete();
\r
698 if (!tempDir.renameTo(tempWarDir)) {
\r
699 tempWarDir = tempDir;
\r
702 DeploymentHandler deploymentHandler = getDeploymentHandler();
\r
704 deploymentHandler.deploy(tempWarDir, displayName);
\r
706 deploymentHandler.releaseDeploymentManager();
\r
708 DeleteTask.deleteDirectory(tempWarDir);
\r
711 if (!tempDir.renameTo(deployDir)) {
\r
712 WarTask.war(srcFile, deployDir, excludes, webXml);
\r
715 DeleteTask.deleteDirectory(tempDir);
\r
720 // The deployer might only copy files that have been modified.
\r
721 // However, the deployer always copies and overwrites web.xml after
\r
722 // the other files have been copied because application servers
\r
723 // usually detect that a WAR has been modified based on the web.xml
\r
726 excludes += "**/WEB-INF/web.xml";
\r
728 CopyTask.copyDirectory(
\r
729 srcFile, deployDir, StringPool.BLANK, excludes, overwrite,
\r
732 CopyTask.copyDirectory(
\r
733 srcFile, deployDir, "**/WEB-INF/web.xml", StringPool.BLANK,
\r
736 if (appServerType.equals(ServerDetector.TOMCAT_ID)) {
\r
738 // See org.apache.catalina.startup.HostConfig to see how Tomcat
\r
739 // checks to make sure that web.xml was modified 5 seconds after
\r
742 File deployWebXml = new File(deployDir + "/WEB-INF/web.xml");
\r
744 deployWebXml.setLastModified(
\r
745 System.currentTimeMillis() + (Time.SECOND * 6));
\r
749 if (appServerType.equals(ServerDetector.JETTY_ID)) {
\r
750 DeployUtil.redeployJetty(displayName);
\r
754 public void deployDirectory(
\r
755 File srcFile, String displayName, boolean override,
\r
756 PluginPackage pluginPackage)
\r
760 srcFile, null, null, displayName, override, pluginPackage);
\r
763 public int deployFile(AutoDeploymentContext autoDeploymentContext)
\r
766 File srcFile = autoDeploymentContext.getFile();
\r
768 PluginPackage pluginPackage = readPluginPackage(srcFile);
\r
770 if (_log.isInfoEnabled()) {
\r
771 _log.info("Deploying " + srcFile.getName());
\r
774 String specifiedContext = autoDeploymentContext.getContext();
\r
776 String displayName = specifiedContext;
\r
777 boolean overwrite = false;
\r
778 String preliminaryContext = specifiedContext;
\r
780 // The order of priority of the context is: 1.) the specified context,
\r
781 // 2.) if the file name starts with DEPLOY_TO_PREFIX, use the file name
\r
782 // after the prefix, or 3.) the recommended deployment context as
\r
783 // specified in liferay-plugin-package.properties, or 4.) the file name.
\r
785 if ((specifiedContext != null) &&
\r
786 srcFile.getName().startsWith(DEPLOY_TO_PREFIX)) {
\r
788 displayName = srcFile.getName().substring(
\r
789 DEPLOY_TO_PREFIX.length(), srcFile.getName().length() - 4);
\r
792 preliminaryContext = displayName;
\r
795 if (preliminaryContext == null) {
\r
796 preliminaryContext = getDisplayName(srcFile);
\r
799 if (pluginPackage != null) {
\r
800 if (!PluginPackageUtil.isCurrentVersionSupported(
\r
801 pluginPackage.getLiferayVersions())) {
\r
803 throw new AutoDeployException(
\r
804 srcFile.getName() +
\r
805 " does not support this version of Liferay");
\r
808 if (displayName == null) {
\r
809 displayName = pluginPackage.getRecommendedDeploymentContext();
\r
812 if (Validator.isNull(displayName)) {
\r
813 displayName = getDisplayName(srcFile);
\r
816 pluginPackage.setContext(displayName);
\r
818 PluginPackageUtil.updateInstallingPluginPackage(
\r
819 preliminaryContext, pluginPackage);
\r
822 String deployDir = null;
\r
824 if (Validator.isNotNull(displayName)) {
\r
825 deployDir = displayName + ".war";
\r
828 deployDir = srcFile.getName();
\r
829 displayName = getDisplayName(srcFile);
\r
832 if (appServerType.equals(ServerDetector.JBOSS_ID)) {
\r
833 deployDir = jbossPrefix + deployDir;
\r
835 else if (appServerType.equals(ServerDetector.GERONIMO_ID) ||
\r
836 appServerType.equals(ServerDetector.GLASSFISH_ID) ||
\r
837 appServerType.equals(ServerDetector.JETTY_ID) ||
\r
838 appServerType.equals(ServerDetector.JONAS_ID) ||
\r
839 appServerType.equals(ServerDetector.OC4J_ID) ||
\r
840 appServerType.equals(ServerDetector.RESIN_ID) ||
\r
841 appServerType.equals(ServerDetector.TOMCAT_ID) ||
\r
842 appServerType.equals(ServerDetector.WEBLOGIC_ID)) {
\r
845 deployDir = deployDir.substring(0, deployDir.length() - 4);
\r
849 String destDir = this.destDir;
\r
851 if (autoDeploymentContext.getDestDir() != null) {
\r
852 destDir = autoDeploymentContext.getDestDir();
\r
855 File deployDirFile = new File(destDir + "/" + deployDir);
\r
858 PluginPackage previousPluginPackage = readPluginPackage(
\r
861 if ((pluginPackage != null) && (previousPluginPackage != null)) {
\r
862 String name = pluginPackage.getName();
\r
863 String previousVersion = previousPluginPackage.getVersion();
\r
864 String version = pluginPackage.getVersion();
\r
866 if (_log.isInfoEnabled()) {
\r
868 "Updating " + name + " from version " +
\r
869 previousVersion + " to version " + version);
\r
872 if (pluginPackage.isPreviousVersionThan(
\r
873 previousPluginPackage)) {
\r
875 if (_log.isInfoEnabled()) {
\r
877 "Not updating " + name + " because version " +
\r
878 previousVersion + " is newer than version " +
\r
882 return AutoDeployer.CODE_SKIP_NEWER_VERSION;
\r
888 File mergeDirFile = new File(
\r
889 srcFile.getParent() + "/merge/" + srcFile.getName());
\r
891 if (srcFile.isDirectory()) {
\r
893 srcFile, mergeDirFile, deployDirFile, displayName,
\r
894 overwrite, pluginPackage);
\r
897 boolean deployed = deployFile(
\r
898 srcFile, mergeDirFile, deployDirFile, displayName,
\r
899 overwrite, pluginPackage);
\r
902 String context = preliminaryContext;
\r
904 if (pluginPackage != null) {
\r
905 context = pluginPackage.getContext();
\r
908 PluginPackageUtil.endPluginPackageInstallation(context);
\r
911 postDeploy(destDir, deployDir);
\r
915 return AutoDeployer.CODE_DEFAULT;
\r
917 catch (Exception e) {
\r
918 if (pluginPackage != null) {
\r
919 PluginPackageUtil.endPluginPackageInstallation(
\r
920 pluginPackage.getContext());
\r
927 public boolean deployFile(
\r
928 File srcFile, File mergeDir, File deployDir, String displayName,
\r
929 boolean overwrite, PluginPackage pluginPackage)
\r
932 boolean undeployOnRedeploy = false;
\r
935 undeployOnRedeploy = PrefsPropsUtil.getBoolean(
\r
936 PropsKeys.HOT_UNDEPLOY_ON_REDEPLOY,
\r
937 PropsValues.HOT_UNDEPLOY_ON_REDEPLOY);
\r
939 catch (Exception e) {
\r
941 // This will only happen when running the deploy tool in Ant in the
\r
942 // classical way where the WAR file is actually massaged and
\r
947 if (undeployOnRedeploy) {
\r
948 DeployUtil.undeploy(appServerType, deployDir);
\r
951 if (!overwrite && UpToDateTask.isUpToDate(srcFile, deployDir)) {
\r
952 if (_log.isInfoEnabled()) {
\r
953 _log.info(deployDir + " is already up to date");
\r
959 File tempDir = new File(
\r
960 SystemProperties.get(SystemProperties.TMP_DIR) + File.separator +
\r
961 Time.getTimestamp());
\r
963 ExpandTask.expand(srcFile, tempDir);
\r
966 tempDir, mergeDir, deployDir, displayName, overwrite,
\r
969 DeleteTask.deleteDirectory(tempDir);
\r
974 public String downloadJar(String jar) throws Exception {
\r
975 String tmpDir = SystemProperties.get(SystemProperties.TMP_DIR);
\r
977 File file = new File(
\r
978 tmpDir + "/liferay/com/liferay/portal/deploy/dependencies/" + jar);
\r
980 if (!file.exists()) {
\r
981 synchronized (this) {
\r
982 String url = PropsUtil.get(
\r
983 PropsKeys.LIBRARY_DOWNLOAD_URL + jar);
\r
985 if (_log.isInfoEnabled()) {
\r
986 _log.info("Downloading library from " + url);
\r
989 byte[] bytes = HttpUtil.URLtoByteArray(url);
\r
991 FileUtil.write(file, bytes);
\r
995 return FileUtil.getAbsolutePath(file);
\r
998 public String fixPortalDependencyJar(String portalJar) {
\r
999 if (portalJar.equals("antlr.jar")) {
\r
1000 portalJar = "antlr2.jar";
\r
1006 public DeploymentHandler getDeploymentHandler() {
\r
1007 String prefix = "auto.deploy." + ServerDetector.getServerId() + ".jee.";
\r
1009 String dmId = PropsUtil.get(prefix + "dm.id");
\r
1010 String dmUser = PropsUtil.get(prefix + "dm.user");
\r
1011 String dmPassword = PropsUtil.get(prefix + "dm.passwd");
\r
1012 String dfClassName = PropsUtil.get(prefix + "df.classname");
\r
1014 return new DeploymentHandler(dmId, dmUser, dmPassword, dfClassName);
\r
1017 public String getDisplayName(File srcFile) {
\r
1018 String displayName = srcFile.getName();
\r
1020 if (StringUtil.endsWith(displayName, ".war") ||
\r
1021 StringUtil.endsWith(displayName, ".xml")) {
\r
1023 displayName = displayName.substring(0, displayName.length() - 4);
\r
1026 if (appServerType.equals(ServerDetector.JBOSS_ID) &&
\r
1027 Validator.isNotNull(jbossPrefix) &&
\r
1028 displayName.startsWith(jbossPrefix)) {
\r
1030 displayName = displayName.substring(1);
\r
1033 return displayName;
\r
1036 public String getExtraContent(
\r
1037 double webXmlVersion, File srcFile, String displayName)
\r
1038 throws Exception {
\r
1040 StringBundler sb = new StringBundler();
\r
1042 sb.append("<display-name>");
\r
1043 sb.append(displayName);
\r
1044 sb.append("</display-name>");
\r
1046 if (webXmlVersion < 2.4) {
\r
1047 sb.append("<context-param>");
\r
1048 sb.append("<param-name>liferay-invoker-enabled</param-name>");
\r
1049 sb.append("<param-value>false</param-value>");
\r
1050 sb.append("</context-param>");
\r
1053 sb.append("<listener>");
\r
1054 sb.append("<listener-class>");
\r
1055 sb.append("com.liferay.portal.kernel.servlet.");
\r
1056 sb.append("SerializableSessionAttributeListener");
\r
1057 sb.append("</listener-class>");
\r
1058 sb.append("</listener>");
\r
1060 File serverConfigWsdd = new File(
\r
1061 srcFile + "/WEB-INF/server-config.wsdd");
\r
1063 if (serverConfigWsdd.exists()) {
\r
1064 File webXml = new File(srcFile + "/WEB-INF/web.xml");
\r
1066 String content = FileUtil.read(webXml);
\r
1068 if (!content.contains("axis.servicesPath")) {
\r
1069 String remotingContent = FileUtil.read(
\r
1070 DeployUtil.getResourcePath("remoting-web.xml"));
\r
1072 sb.append(remotingContent);
\r
1076 boolean hasTaglib = false;
\r
1078 if (Validator.isNotNull(auiTaglibDTD) ||
\r
1079 Validator.isNotNull(portletTaglibDTD) ||
\r
1080 Validator.isNotNull(portletExtTaglibDTD) ||
\r
1081 Validator.isNotNull(securityTaglibDTD) ||
\r
1082 Validator.isNotNull(themeTaglibDTD) ||
\r
1083 Validator.isNotNull(uiTaglibDTD) ||
\r
1084 Validator.isNotNull(utilTaglibDTD)) {
\r
1089 if (hasTaglib && (webXmlVersion > 2.3)) {
\r
1090 sb.append("<jsp-config>");
\r
1093 if (Validator.isNotNull(auiTaglibDTD)) {
\r
1094 sb.append("<taglib>");
\r
1095 sb.append("<taglib-uri>http://liferay.com/tld/aui</taglib-uri>");
\r
1096 sb.append("<taglib-location>");
\r
1097 sb.append("/WEB-INF/tld/aui.tld");
\r
1098 sb.append("</taglib-location>");
\r
1099 sb.append("</taglib>");
\r
1102 if (Validator.isNotNull(portletTaglibDTD)) {
\r
1103 sb.append("<taglib>");
\r
1105 "<taglib-uri>http://java.sun.com/portlet_2_0</taglib-uri>");
\r
1106 sb.append("<taglib-location>");
\r
1107 sb.append("/WEB-INF/tld/liferay-portlet.tld");
\r
1108 sb.append("</taglib-location>");
\r
1109 sb.append("</taglib>");
\r
1112 if (Validator.isNotNull(portletExtTaglibDTD)) {
\r
1113 sb.append("<taglib>");
\r
1114 sb.append("<taglib-uri>");
\r
1115 sb.append("http://liferay.com/tld/portlet");
\r
1116 sb.append("</taglib-uri>");
\r
1117 sb.append("<taglib-location>");
\r
1118 sb.append("/WEB-INF/tld/liferay-portlet-ext.tld");
\r
1119 sb.append("</taglib-location>");
\r
1120 sb.append("</taglib>");
\r
1123 if (Validator.isNotNull(securityTaglibDTD)) {
\r
1124 sb.append("<taglib>");
\r
1125 sb.append("<taglib-uri>");
\r
1126 sb.append("http://liferay.com/tld/security");
\r
1127 sb.append("</taglib-uri>");
\r
1128 sb.append("<taglib-location>");
\r
1129 sb.append("/WEB-INF/tld/liferay-security.tld");
\r
1130 sb.append("</taglib-location>");
\r
1131 sb.append("</taglib>");
\r
1134 if (Validator.isNotNull(themeTaglibDTD)) {
\r
1135 sb.append("<taglib>");
\r
1136 sb.append("<taglib-uri>http://liferay.com/tld/theme</taglib-uri>");
\r
1137 sb.append("<taglib-location>");
\r
1138 sb.append("/WEB-INF/tld/liferay-theme.tld");
\r
1139 sb.append("</taglib-location>");
\r
1140 sb.append("</taglib>");
\r
1143 if (Validator.isNotNull(uiTaglibDTD)) {
\r
1144 sb.append("<taglib>");
\r
1145 sb.append("<taglib-uri>http://liferay.com/tld/ui</taglib-uri>");
\r
1146 sb.append("<taglib-location>");
\r
1147 sb.append("/WEB-INF/tld/liferay-ui.tld");
\r
1148 sb.append("</taglib-location>");
\r
1149 sb.append("</taglib>");
\r
1152 if (Validator.isNotNull(utilTaglibDTD)) {
\r
1153 sb.append("<taglib>");
\r
1154 sb.append("<taglib-uri>http://liferay.com/tld/util</taglib-uri>");
\r
1155 sb.append("<taglib-location>");
\r
1156 sb.append("/WEB-INF/tld/liferay-util.tld");
\r
1157 sb.append("</taglib-location>");
\r
1158 sb.append("</taglib>");
\r
1161 if (hasTaglib && (webXmlVersion > 2.3)) {
\r
1162 sb.append("</jsp-config>");
\r
1165 return sb.toString();
\r
1168 public String getExtraFiltersContent(double webXmlVersion, File srcFile)
\r
1169 throws Exception {
\r
1171 return getSessionFiltersContent();
\r
1174 public String getIgnoreFiltersContent(File srcFile) throws Exception {
\r
1175 boolean ignoreFiltersEnabled = true;
\r
1177 Properties properties = getPluginPackageProperties(srcFile);
\r
1179 if (properties != null) {
\r
1180 ignoreFiltersEnabled = GetterUtil.getBoolean(
\r
1181 properties.getProperty("ignore-filters-enabled"), true);
\r
1184 if (ignoreFiltersEnabled) {
\r
1185 String ignoreFiltersContent = FileUtil.read(
\r
1186 DeployUtil.getResourcePath("ignore-filters-web.xml"));
\r
1188 return ignoreFiltersContent;
\r
1191 return StringPool.BLANK;
\r
1195 public String getInvokerFilterContent() {
\r
1196 StringBundler sb = new StringBundler(4);
\r
1198 sb.append(getInvokerFilterContent("ERROR"));
\r
1199 sb.append(getInvokerFilterContent("FORWARD"));
\r
1200 sb.append(getInvokerFilterContent("INCLUDE"));
\r
1201 sb.append(getInvokerFilterContent("REQUEST"));
\r
1203 return sb.toString();
\r
1206 public String getInvokerFilterContent(String dispatcher) {
\r
1207 StringBundler sb = new StringBundler(23);
\r
1209 sb.append("<filter>");
\r
1210 sb.append("<filter-name>Invoker Filter - ");
\r
1211 sb.append(dispatcher);
\r
1212 sb.append("</filter-name>");
\r
1213 sb.append("<filter-class>");
\r
1214 sb.append(InvokerFilter.class.getName());
\r
1215 sb.append("</filter-class>");
\r
1216 sb.append("<init-param>");
\r
1217 sb.append("<param-name>dispatcher</param-name>");
\r
1218 sb.append("<param-value>");
\r
1219 sb.append(dispatcher);
\r
1220 sb.append("</param-value>");
\r
1221 sb.append("</init-param>");
\r
1222 sb.append("</filter>");
\r
1224 sb.append("<filter-mapping>");
\r
1225 sb.append("<filter-name>Invoker Filter - ");
\r
1226 sb.append(dispatcher);
\r
1227 sb.append("</filter-name>");
\r
1228 sb.append("<url-pattern>/*</url-pattern>");
\r
1229 sb.append("<dispatcher>");
\r
1230 sb.append(dispatcher);
\r
1231 sb.append("</dispatcher>");
\r
1232 sb.append("</filter-mapping>");
\r
1234 return sb.toString();
\r
1237 public String getPluginPackageLicensesXml(List<License> licenses) {
\r
1238 if (licenses.isEmpty()) {
\r
1239 return StringPool.BLANK;
\r
1242 StringBundler sb = new StringBundler(5 * licenses.size() + 2);
\r
1244 for (int i = 0; i < licenses.size(); i++) {
\r
1245 License license = licenses.get(i);
\r
1248 sb.append("\r\n");
\r
1251 sb.append("\t\t<license osi-approved=\"");
\r
1252 sb.append(license.isOsiApproved());
\r
1254 sb.append(license.getName());
\r
1255 sb.append("</license>\r\n");
\r
1257 if ((i + 1) == licenses.size()) {
\r
1262 return sb.toString();
\r
1265 public String getPluginPackageLiferayVersionsXml(
\r
1266 List<String> liferayVersions) {
\r
1268 if (liferayVersions.isEmpty()) {
\r
1269 return StringPool.BLANK;
\r
1272 StringBundler sb = new StringBundler(liferayVersions.size() * 3 + 2);
\r
1274 for (int i = 0; i < liferayVersions.size(); i++) {
\r
1275 String liferayVersion = liferayVersions.get(i);
\r
1278 sb.append("\r\n");
\r
1281 sb.append("\t\t<liferay-version>");
\r
1282 sb.append(liferayVersion);
\r
1283 sb.append("</liferay-version>\r\n");
\r
1285 if ((i + 1) == liferayVersions.size()) {
\r
1290 return sb.toString();
\r
1293 public Properties getPluginPackageProperties(File srcFile)
\r
1294 throws Exception {
\r
1296 File propertiesFile = new File(
\r
1297 srcFile + "/WEB-INF/liferay-plugin-package.properties");
\r
1299 if (!propertiesFile.exists()) {
\r
1303 String propertiesString = FileUtil.read(propertiesFile);
\r
1305 return PropertiesUtil.load(propertiesString);
\r
1308 public String getPluginPackageTagsXml(List<String> tags) {
\r
1309 if (tags.isEmpty()) {
\r
1310 return StringPool.BLANK;
\r
1313 StringBundler sb = new StringBundler(tags.size() * 3 + 2);
\r
1315 for (int i = 0; i < tags.size(); i++) {
\r
1316 String tag = tags.get(i);
\r
1319 sb.append("\r\n");
\r
1322 sb.append("\t\t<tag>");
\r
1324 sb.append("</tag>\r\n");
\r
1326 if ((i + 1) == tags.size()) {
\r
1331 return sb.toString();
\r
1334 public Map<String, String> getPluginPackageXmlFilterMap(
\r
1335 PluginPackage pluginPackage) {
\r
1337 List<String> pluginTypes = pluginPackage.getTypes();
\r
1339 String pluginType = pluginTypes.get(0);
\r
1341 if (!pluginType.equals(getPluginType())) {
\r
1345 Map<String, String> filterMap = new HashMap<String, String>();
\r
1347 filterMap.put("module_group_id", pluginPackage.getGroupId());
\r
1348 filterMap.put("module_artifact_id", pluginPackage.getArtifactId());
\r
1349 filterMap.put("module_version", pluginPackage.getVersion());
\r
1351 filterMap.put("plugin_name", pluginPackage.getName());
\r
1352 filterMap.put("plugin_type", pluginType);
\r
1354 "plugin_type_name",
\r
1355 TextFormatter.format(pluginType, TextFormatter.J));
\r
1357 filterMap.put("tags", getPluginPackageTagsXml(pluginPackage.getTags()));
\r
1358 filterMap.put("short_description", pluginPackage.getShortDescription());
\r
1359 filterMap.put("long_description", pluginPackage.getLongDescription());
\r
1360 filterMap.put("change_log", pluginPackage.getChangeLog());
\r
1361 filterMap.put("page_url", pluginPackage.getPageURL());
\r
1362 filterMap.put("author", pluginPackage.getAuthor());
\r
1365 getPluginPackageLicensesXml(pluginPackage.getLicenses()));
\r
1367 "liferay_versions",
\r
1368 getPluginPackageLiferayVersionsXml(
\r
1369 pluginPackage.getLiferayVersions()));
\r
1374 public String getPluginType() {
\r
1378 public String getServletContextIncludeFiltersContent(
\r
1379 double webXmlVersion, File srcFile)
\r
1380 throws Exception {
\r
1382 if (webXmlVersion < 2.4) {
\r
1383 return StringPool.BLANK;
\r
1386 Properties properties = getPluginPackageProperties(srcFile);
\r
1388 if (properties == null) {
\r
1389 return StringPool.BLANK;
\r
1392 if (!GetterUtil.getBoolean(
\r
1393 properties.getProperty(
\r
1394 "servlet-context-include-filters-enabled"), true)) {
\r
1396 return StringPool.BLANK;
\r
1399 return FileUtil.read(
\r
1400 DeployUtil.getResourcePath(
\r
1401 "servlet-context-include-filters-web.xml"));
\r
1404 public String getSessionFiltersContent() throws Exception {
\r
1405 String sessionFiltersContent = FileUtil.read(
\r
1406 DeployUtil.getResourcePath("session-filters-web.xml"));
\r
1408 return sessionFiltersContent;
\r
1411 public String getSpeedFiltersContent(File srcFile) throws Exception {
\r
1412 boolean speedFiltersEnabled = true;
\r
1414 Properties properties = getPluginPackageProperties(srcFile);
\r
1416 if (properties != null) {
\r
1417 speedFiltersEnabled = GetterUtil.getBoolean(
\r
1418 properties.getProperty("speed-filters-enabled"), true);
\r
1421 if (speedFiltersEnabled) {
\r
1422 String speedFiltersContent = FileUtil.read(
\r
1423 DeployUtil.getResourcePath("speed-filters-web.xml"));
\r
1425 return speedFiltersContent;
\r
1428 return StringPool.BLANK;
\r
1432 public boolean isJEEDeploymentEnabled() {
\r
1433 return GetterUtil.getBoolean(PropsUtil.get(
\r
1434 "auto.deploy." + ServerDetector.getServerId() +
\r
1435 ".jee.deployment.enabled"));
\r
1438 public void mergeDirectory(File mergeDir, File targetDir) {
\r
1439 if ((mergeDir == null) || !mergeDir.exists()) {
\r
1443 CopyTask.copyDirectory(mergeDir, targetDir, null, null, true, false);
\r
1446 public void postDeploy(String destDir, String deployDir) throws Exception {
\r
1447 if (appServerType.equals(ServerDetector.GLASSFISH_ID)) {
\r
1448 postDeployGlassfish(destDir, deployDir);
\r
1450 else if (appServerType.equals(ServerDetector.JBOSS_ID)) {
\r
1451 postDeployJBoss(destDir, deployDir);
\r
1453 else if (appServerType.equals(ServerDetector.WEBSPHERE_ID)) {
\r
1454 postDeployWebSphere(destDir, deployDir);
\r
1458 public void postDeployGlassfish(String destDir, String deployDir)
\r
1459 throws Exception {
\r
1461 FileUtil.delete(destDir + "/.autodeploystatus/" + deployDir);
\r
1464 public void postDeployJBoss(String destDir, String deployDir)
\r
1465 throws Exception {
\r
1468 destDir + "/" + deployDir + ".dodeploy", StringPool.BLANK);
\r
1471 public void postDeployWebSphere(String destDir, String deployDir)
\r
1472 throws Exception {
\r
1474 if (Validator.isNull(
\r
1475 PropsValues.AUTO_DEPLOY_WEBSPHERE_WSADMIN_APP_MANAGER_QUERY)) {
\r
1477 if (_log.isInfoEnabled()) {
\r
1478 StringBundler sb = new StringBundler();
\r
1480 sb.append("Do not install the plugin with wsadmin since the ");
\r
1481 sb.append("property \"");
\r
1483 PropsKeys.AUTO_DEPLOY_WEBSPHERE_WSADMIN_APP_MANAGER_QUERY);
\r
1484 sb.append("\"is not configured");
\r
1486 _log.info(sb.toString());
\r
1492 String wsadminContent = FileUtil.read(
\r
1493 DeployUtil.getResourcePath("wsadmin.py"));
\r
1495 String pluginServletContextName = deployDir.substring(
\r
1496 0, deployDir.length() - 4);
\r
1498 wsadminContent = StringUtil.replace(
\r
1501 "${auto.deploy.dest.dir}",
\r
1502 "${auto.deploy.websphere.wsadmin.app.manager.query}",
\r
1503 "${plugin.servlet.context.name}"
\r
1507 PropsValues.AUTO_DEPLOY_WEBSPHERE_WSADMIN_APP_MANAGER_QUERY,
\r
1508 pluginServletContextName
\r
1511 String wsadminFileName = FileUtil.createTempFileName("py");
\r
1513 FileUtil.write(wsadminFileName, wsadminContent);
\r
1515 String webSphereHome = System.getenv("WAS_HOME");
\r
1517 if (_log.isInfoEnabled()) {
\r
1519 "Installing plugin by executing " + webSphereHome +
\r
1520 "\\bin\\wsadmin.bat -f " + wsadminFileName);
\r
1523 ProcessBuilder processBuilder = new ProcessBuilder(
\r
1524 webSphereHome + "\\bin\\wsadmin.bat", "-f", wsadminFileName);
\r
1526 processBuilder.redirectErrorStream(true);
\r
1528 Process process = processBuilder.start();
\r
1530 if (_log.isInfoEnabled()) {
\r
1531 InputStream inputStream = process.getInputStream();
\r
1533 String output = StringUtil.read(inputStream);
\r
1535 for (String line : StringUtil.split(output, CharPool.NEW_LINE)) {
\r
1536 _log.info("Process output: " + line);
\r
1539 inputStream.close();
\r
1541 int exitValue = process.exitValue();
\r
1543 if (exitValue == 0) {
\r
1545 "Successfully executed command with an exit value of " +
\r
1550 "Unsuccessfully executed command with an exit value of " +
\r
1555 FileUtil.delete(wsadminFileName);
\r
1558 public Map<String, String> processPluginPackageProperties(
\r
1559 File srcFile, String displayName, PluginPackage pluginPackage)
\r
1560 throws Exception {
\r
1562 if (pluginPackage == null) {
\r
1566 Properties properties = getPluginPackageProperties(srcFile);
\r
1568 if ((properties == null) || (properties.size() == 0)) {
\r
1572 Map<String, String> filterMap = getPluginPackageXmlFilterMap(
\r
1575 if (filterMap == null) {
\r
1579 copyDependencyXml(
\r
1580 "liferay-plugin-package.xml", srcFile + "/WEB-INF", filterMap,
\r
1587 * @see {@link PluginPackageUtil#_readPluginPackageServletContext(
\r
1588 * javax.servlet.ServletContext)}
\r
1590 public PluginPackage readPluginPackage(File file) {
\r
1591 if (!file.exists()) {
\r
1595 InputStream is = null;
\r
1596 ZipFile zipFile = null;
\r
1599 boolean parseProps = false;
\r
1601 if (file.isDirectory()) {
\r
1602 String path = file.getPath();
\r
1604 File pluginPackageXmlFile = new File(
\r
1605 file.getParent() + "/merge/" + file.getName() +
\r
1606 "/WEB-INF/liferay-plugin-package.xml");
\r
1608 if (pluginPackageXmlFile.exists()) {
\r
1609 is = new FileInputStream(pluginPackageXmlFile);
\r
1612 pluginPackageXmlFile = new File(
\r
1613 path + "/WEB-INF/liferay-plugin-package.xml");
\r
1615 if (pluginPackageXmlFile.exists()) {
\r
1616 is = new FileInputStream(pluginPackageXmlFile);
\r
1620 File pluginPackagePropertiesFile = new File(
\r
1621 file.getParent() + "/merge/" + file.getName() +
\r
1622 "/WEB-INF/liferay-plugin-package.properties");
\r
1624 if ((is == null) && pluginPackagePropertiesFile.exists()) {
\r
1625 is = new FileInputStream(pluginPackagePropertiesFile);
\r
1627 parseProps = true;
\r
1630 pluginPackagePropertiesFile = new File(
\r
1631 path + "/WEB-INF/liferay-plugin-package.properties");
\r
1633 if ((is == null) && pluginPackagePropertiesFile.exists()) {
\r
1634 is = new FileInputStream(pluginPackagePropertiesFile);
\r
1636 parseProps = true;
\r
1641 zipFile = new ZipFile(file);
\r
1643 File pluginPackageXmlFile = new File(
\r
1644 file.getParent() + "/merge/" + file.getName() +
\r
1645 "/WEB-INF/liferay-plugin-package.xml");
\r
1647 if (pluginPackageXmlFile.exists()) {
\r
1648 is = new FileInputStream(pluginPackageXmlFile);
\r
1651 ZipEntry zipEntry = zipFile.getEntry(
\r
1652 "WEB-INF/liferay-plugin-package.xml");
\r
1654 if (zipEntry != null) {
\r
1655 is = zipFile.getInputStream(zipEntry);
\r
1659 File pluginPackagePropertiesFile = new File(
\r
1660 file.getParent() + "/merge/" + file.getName() +
\r
1661 "/WEB-INF/liferay-plugin-package.properties");
\r
1663 if ((is == null) && pluginPackagePropertiesFile.exists()) {
\r
1664 is = new FileInputStream(pluginPackagePropertiesFile);
\r
1666 parseProps = true;
\r
1669 ZipEntry zipEntry = zipFile.getEntry(
\r
1670 "WEB-INF/liferay-plugin-package.properties");
\r
1672 if ((is == null) && (zipEntry != null)) {
\r
1673 is = zipFile.getInputStream(zipEntry);
\r
1675 parseProps = true;
\r
1681 if (_log.isInfoEnabled()) {
\r
1683 file.getPath() + " does not have a " +
\r
1684 "WEB-INF/liferay-plugin-package.xml or " +
\r
1685 "WEB-INF/liferay-plugin-package.properties");
\r
1692 String displayName = getDisplayName(file);
\r
1694 String propertiesString = StringUtil.read(is);
\r
1696 Properties properties = PropertiesUtil.load(propertiesString);
\r
1698 return PluginPackageUtil.readPluginPackageProperties(
\r
1699 displayName, properties);
\r
1702 String xml = StringUtil.read(is);
\r
1704 xml = XMLFormatter.fixProlog(xml);
\r
1706 return PluginPackageUtil.readPluginPackageXml(xml);
\r
1709 catch (Exception e) {
\r
1710 _log.error(file.getPath() + ": " + e.toString());
\r
1717 catch (IOException ioe) {
\r
1721 if (zipFile != null) {
\r
1725 catch (IOException ioe) {
\r
1733 public void rewriteFiles(File srcDir) throws Exception {
\r
1734 String[] files = FileUtil.listFiles(srcDir + "/WEB-INF/");
\r
1736 for (int i = 0; i < files.length; i++) {
\r
1737 String fileName = GetterUtil.getString(
\r
1738 FileUtil.getShortFileName(files[i]));
\r
1742 if (fileName.equalsIgnoreCase("mule-config.xml")) {
\r
1746 String ext = GetterUtil.getString(FileUtil.getExtension(files[i]));
\r
1748 if (!ext.equalsIgnoreCase("xml")) {
\r
1752 // Make sure to rewrite any XML files to include external entities
\r
1753 // into same file. See LEP-3142.
\r
1755 File file = new File(srcDir + "/WEB-INF/" + files[i]);
\r
1758 Document doc = SAXReaderUtil.read(file);
\r
1760 String content = doc.formattedString(StringPool.TAB, true);
\r
1762 FileUtil.write(file, content);
\r
1764 catch (Exception e) {
\r
1765 if (_log.isWarnEnabled()) {
\r
1767 "Unable to format " + file + ": " + e.getMessage());
\r
1773 public String secureWebXml(String content) throws Exception {
\r
1774 Document document = SAXReaderUtil.read(content);
\r
1776 Element rootElement = document.getRootElement();
\r
1778 List<String> listenerClasses = new ArrayList<String>();
\r
1780 List<Element> listenerElements = rootElement.elements("listener");
\r
1782 for (Element listenerElement : listenerElements) {
\r
1783 String listenerClass = GetterUtil.getString(
\r
1784 listenerElement.elementText("listener-class"));
\r
1786 if (listenerClass.equals(
\r
1787 SecurePluginContextListener.class.getName())) {
\r
1792 listenerClasses.add(listenerClass);
\r
1794 listenerElement.detach();
\r
1797 Element contextParamElement = rootElement.addElement("context-param");
\r
1799 DocUtil.add(contextParamElement, "param-name", "portalListenerClasses");
\r
1801 contextParamElement, "param-value",
\r
1802 StringUtil.merge(listenerClasses));
\r
1804 List<Element> servletElements = rootElement.elements("servlet");
\r
1806 for (Element servletElement : servletElements) {
\r
1807 Element servletClassElement = servletElement.element(
\r
1810 String servletClass = GetterUtil.getString(
\r
1811 servletClassElement.getText());
\r
1813 if (servletClass.equals(PortletServlet.class.getName())) {
\r
1817 servletClassElement.setText(SecureServlet.class.getName());
\r
1819 Element initParamElement = servletElement.addElement("init-param");
\r
1821 DocUtil.add(initParamElement, "param-name", "servlet-class");
\r
1822 DocUtil.add(initParamElement, "param-value", servletClass);
\r
1825 return document.compactString();
\r
1828 public void setAppServerType(String appServerType) {
\r
1829 this.appServerType = appServerType;
\r
1832 public void setAuiTaglibDTD(String auiTaglibDTD) {
\r
1833 this.auiTaglibDTD = auiTaglibDTD;
\r
1836 public void setBaseDir(String baseDir) {
\r
1837 this.baseDir = baseDir;
\r
1840 public void setDestDir(String destDir) {
\r
1841 this.destDir = destDir;
\r
1844 public void setFilePattern(String filePattern) {
\r
1845 this.filePattern = filePattern;
\r
1848 public void setJars(List<String> jars) {
\r
1852 public void setJbossPrefix(String jbossPrefix) {
\r
1853 this.jbossPrefix = jbossPrefix;
\r
1856 public void setPortletExtTaglibDTD(String portletExtTaglibDTD) {
\r
1857 this.portletExtTaglibDTD = portletExtTaglibDTD;
\r
1860 public void setPortletTaglibDTD(String portletTaglibDTD) {
\r
1861 this.portletTaglibDTD = portletTaglibDTD;
\r
1864 public void setSecurityTaglibDTD(String securityTaglibDTD) {
\r
1865 this.securityTaglibDTD = securityTaglibDTD;
\r
1868 public void setThemeTaglibDTD(String themeTaglibDTD) {
\r
1869 this.themeTaglibDTD = themeTaglibDTD;
\r
1872 public void setTomcatLibDir(String tomcatLibDir) {
\r
1873 this.tomcatLibDir = tomcatLibDir;
\r
1876 public void setUiTaglibDTD(String uiTaglibDTD) {
\r
1877 this.uiTaglibDTD = uiTaglibDTD;
\r
1880 public void setUnpackWar(boolean unpackWar) {
\r
1881 this.unpackWar = unpackWar;
\r
1884 public void setUtilTaglibDTD(String utilTaglibDTD) {
\r
1885 this.utilTaglibDTD = utilTaglibDTD;
\r
1888 public void setWars(List<String> wars) {
\r
1892 public void updateDeployDirectory(File srcFile) throws Exception {
\r
1895 public void updateGeronimoWebXml(
\r
1896 File srcFile, String displayName, PluginPackage pluginPackage)
\r
1897 throws Exception {
\r
1899 if (!appServerType.equals(ServerDetector.GERONIMO_ID)) {
\r
1903 File geronimoWebXml = new File(srcFile + "/WEB-INF/geronimo-web.xml");
\r
1905 Document document = SAXReaderUtil.read(geronimoWebXml);
\r
1907 Element rootElement = document.getRootElement();
\r
1909 Element environmentElement = rootElement.element("environment");
\r
1911 Element moduleIdElement = environmentElement.element("moduleId");
\r
1913 Element artifactIdElement = moduleIdElement.element("artifactId");
\r
1915 artifactIdElement.setText(displayName);
\r
1917 Element versionElement = moduleIdElement.element("version");
\r
1919 versionElement.setText(pluginPackage.getVersion());
\r
1921 String content = document.formattedString();
\r
1923 FileUtil.write(geronimoWebXml, content);
\r
1925 if (_log.isInfoEnabled()) {
\r
1926 _log.info("Modifying Geronimo " + geronimoWebXml);
\r
1930 public String updateLiferayWebXml(
\r
1931 double webXmlVersion, File srcFile, String webXmlContent)
\r
1932 throws Exception {
\r
1934 boolean liferayWebXmlEnabled = true;
\r
1936 Properties properties = getPluginPackageProperties(srcFile);
\r
1938 if (properties != null) {
\r
1939 liferayWebXmlEnabled = GetterUtil.getBoolean(
\r
1940 properties.getProperty("liferay-web-xml-enabled"), true);
\r
1943 webXmlContent = WebXMLBuilder.organizeWebXML(webXmlContent);
\r
1945 int x = webXmlContent.indexOf("<filter>");
\r
1946 int y = webXmlContent.lastIndexOf("</filter-mapping>");
\r
1948 String webXmlFiltersContent = StringPool.BLANK;
\r
1950 if ((x == -1) || (y == -1)) {
\r
1951 x = webXmlContent.lastIndexOf("</display-name>") + 15;
\r
1955 if (liferayWebXmlEnabled && (webXmlVersion > 2.3)) {
\r
1956 webXmlFiltersContent = webXmlContent.substring(x, y + 17);
\r
1966 if (webXmlVersion < 2.4) {
\r
1968 webXmlContent.substring(0, x) +
\r
1969 getExtraFiltersContent(webXmlVersion, srcFile) +
\r
1970 webXmlContent.substring(y);
\r
1972 return webXmlContent;
\r
1975 String filtersContent =
\r
1976 webXmlFiltersContent +
\r
1977 getExtraFiltersContent(webXmlVersion, srcFile);
\r
1979 String liferayWebXmlContent = FileUtil.read(
\r
1980 DeployUtil.getResourcePath("web.xml"));
\r
1982 int z = liferayWebXmlContent.indexOf("</web-app>");
\r
1984 liferayWebXmlContent =
\r
1985 liferayWebXmlContent.substring(0, z) + filtersContent +
\r
1986 liferayWebXmlContent.substring(z);
\r
1988 liferayWebXmlContent = WebXMLBuilder.organizeWebXML(
\r
1989 liferayWebXmlContent);
\r
1992 srcFile + "/WEB-INF/liferay-web.xml", liferayWebXmlContent);
\r
1995 webXmlContent.substring(0, x) + getInvokerFilterContent() +
\r
1996 webXmlContent.substring(y);
\r
1998 return webXmlContent;
\r
2001 public void updateWebXml(
\r
2002 File webXml, File srcFile, String displayName,
\r
2003 PluginPackage pluginPackage)
\r
2004 throws Exception {
\r
2008 String content = FileUtil.read(webXml);
\r
2010 int x = content.indexOf("<display-name>");
\r
2013 int y = content.indexOf("</display-name>", x);
\r
2015 y = content.indexOf(">", y) + 1;
\r
2017 content = content.substring(0, x) + content.substring(y);
\r
2020 Document document = SAXReaderUtil.read(content);
\r
2022 Element rootElement = document.getRootElement();
\r
2024 double webXmlVersion = GetterUtil.getDouble(
\r
2025 rootElement.attributeValue("version"), 2.3);
\r
2027 if (!PropsValues.TCK_URL && (webXmlVersion <= 2.3)) {
\r
2028 throw new AutoDeployException(
\r
2029 webXml.getName() +
\r
2030 " must be updated to the Servlet 2.4 specification");
\r
2033 // Plugin context listener
\r
2035 StringBundler sb = new StringBundler(5);
\r
2037 sb.append("<listener>");
\r
2038 sb.append("<listener-class>");
\r
2040 boolean securityManagerEnabled = false;
\r
2042 Properties properties = getPluginPackageProperties(srcFile);
\r
2044 if (properties != null) {
\r
2045 securityManagerEnabled = GetterUtil.getBoolean(
\r
2046 properties.getProperty("security-manager-enabled"));
\r
2049 if (securityManagerEnabled) {
\r
2050 sb.append(SecurePluginContextListener.class.getName());
\r
2053 sb.append(PluginContextListener.class.getName());
\r
2056 sb.append("</listener-class>");
\r
2057 sb.append("</listener>");
\r
2059 String pluginContextListenerContent = sb.toString();
\r
2063 String extraContent = getExtraContent(
\r
2064 webXmlVersion, srcFile, displayName);
\r
2066 int pos = content.indexOf("<listener>");
\r
2069 pos = content.indexOf("</web-app>");
\r
2072 String newContent =
\r
2073 content.substring(0, pos) + pluginContextListenerContent +
\r
2074 extraContent + content.substring(pos);
\r
2076 // Update liferay-web.xml
\r
2078 newContent = updateLiferayWebXml(webXmlVersion, srcFile, newContent);
\r
2082 if (securityManagerEnabled) {
\r
2083 newContent = secureWebXml(newContent);
\r
2086 newContent = WebXMLBuilder.organizeWebXML(newContent);
\r
2088 FileUtil.write(webXml, newContent, true);
\r
2090 if (_log.isInfoEnabled()) {
\r
2091 _log.info("Modifying Servlet " + webXmlVersion + " " + webXml);
\r
2095 protected String appServerType;
\r
2096 protected String auiTaglibDTD;
\r
2097 protected String baseDir;
\r
2098 protected String destDir;
\r
2099 protected String filePattern;
\r
2100 protected List<String> jars;
\r
2101 protected String jbossPrefix;
\r
2102 protected String portletExtTaglibDTD;
\r
2103 protected String portletTaglibDTD;
\r
2104 protected String securityTaglibDTD;
\r
2105 protected String themeTaglibDTD;
\r
2106 protected String tomcatLibDir;
\r
2107 protected String uiTaglibDTD;
\r
2108 protected boolean unpackWar;
\r
2109 protected String utilTaglibDTD;
\r
2110 protected List<String> wars;
\r
2112 private static final String _PORTAL_CLASS_LOADER =
\r
2113 "com.liferay.support.tomcat.loader.PortalClassLoader";
\r
2115 private static Log _log = LogFactoryUtil.getLog(BaseDeployer.class);
\r