--- /dev/null
+/**\r
+ * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.\r
+ *\r
+ * This library is free software; you can redistribute it and/or modify it under\r
+ * the terms of the GNU Lesser General Public License as published by the Free\r
+ * Software Foundation; either version 2.1 of the License, or (at your option)\r
+ * any later version.\r
+ *\r
+ * This library is distributed in the hope that it will be useful, but WITHOUT\r
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more\r
+ * details.\r
+ */\r
+\r
+package com.liferay.portal.tools.deploy;\r
+\r
+import com.liferay.portal.deploy.DeployUtil;\r
+import com.liferay.portal.deploy.auto.AutoDeployer;\r
+import com.liferay.portal.kernel.deploy.Deployer;\r
+import com.liferay.portal.kernel.deploy.auto.AutoDeployException;\r
+import com.liferay.portal.kernel.deploy.auto.context.AutoDeploymentContext;\r
+import com.liferay.portal.kernel.log.Log;\r
+import com.liferay.portal.kernel.log.LogFactoryUtil;\r
+import com.liferay.portal.kernel.plugin.License;\r
+import com.liferay.portal.kernel.plugin.PluginPackage;\r
+import com.liferay.portal.kernel.servlet.PluginContextListener;\r
+import com.liferay.portal.kernel.servlet.PortletServlet;\r
+import com.liferay.portal.kernel.servlet.SecurePluginContextListener;\r
+import com.liferay.portal.kernel.servlet.SecureServlet;\r
+import com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter;\r
+import com.liferay.portal.kernel.util.CharPool;\r
+import com.liferay.portal.kernel.util.FileUtil;\r
+import com.liferay.portal.kernel.util.GetterUtil;\r
+import com.liferay.portal.kernel.util.HttpUtil;\r
+import com.liferay.portal.kernel.util.PropertiesUtil;\r
+import com.liferay.portal.kernel.util.PropsKeys;\r
+import com.liferay.portal.kernel.util.ServerDetector;\r
+import com.liferay.portal.kernel.util.StringBundler;\r
+import com.liferay.portal.kernel.util.StringPool;\r
+import com.liferay.portal.kernel.util.StringUtil;\r
+import com.liferay.portal.kernel.util.SystemProperties;\r
+import com.liferay.portal.kernel.util.TextFormatter;\r
+import com.liferay.portal.kernel.util.Time;\r
+import com.liferay.portal.kernel.util.Validator;\r
+import com.liferay.portal.kernel.xml.Document;\r
+import com.liferay.portal.kernel.xml.Element;\r
+import com.liferay.portal.kernel.xml.SAXReaderUtil;\r
+import com.liferay.portal.plugin.PluginPackageUtil;\r
+import com.liferay.portal.tools.WebXMLBuilder;\r
+import com.liferay.portal.util.ExtRegistry;\r
+import com.liferay.portal.util.InitUtil;\r
+import com.liferay.portal.util.PortalUtil;\r
+import com.liferay.portal.util.PrefsPropsUtil;\r
+import com.liferay.portal.util.PropsUtil;\r
+import com.liferay.portal.util.PropsValues;\r
+import com.liferay.util.ant.CopyTask;\r
+import com.liferay.util.ant.DeleteTask;\r
+import com.liferay.util.ant.ExpandTask;\r
+import com.liferay.util.ant.UpToDateTask;\r
+import com.liferay.util.ant.WarTask;\r
+import com.liferay.util.xml.DocUtil;\r
+import com.liferay.util.xml.XMLFormatter;\r
+\r
+import java.io.File;\r
+import java.io.FileInputStream;\r
+import java.io.IOException;\r
+import java.io.InputStream;\r
+\r
+import java.util.ArrayList;\r
+import java.util.HashMap;\r
+import java.util.List;\r
+import java.util.Map;\r
+import java.util.Properties;\r
+import java.util.Set;\r
+import java.util.zip.ZipEntry;\r
+import java.util.zip.ZipFile;\r
+\r
+import org.apache.oro.io.GlobFilenameFilter;\r
+\r
+/**\r
+ * @author Brian Wing Shun Chan\r
+ * @author Sandeep Soni\r
+ */\r
+public class BaseDeployer implements AutoDeployer, Deployer {\r
+\r
+ public static final String DEPLOY_TO_PREFIX = "DEPLOY_TO__";\r
+\r
+ public static void main(String[] args) {\r
+ InitUtil.initWithSpring();\r
+\r
+ List<String> wars = new ArrayList<String>();\r
+ List<String> jars = new ArrayList<String>();\r
+\r
+ for (String arg : args) {\r
+ String fileName = arg.toLowerCase();\r
+\r
+ if (fileName.endsWith(".war")) {\r
+ wars.add(arg);\r
+ }\r
+ else if (fileName.endsWith(".jar")) {\r
+ jars.add(arg);\r
+ }\r
+ }\r
+\r
+ new BaseDeployer(wars, jars);\r
+ }\r
+\r
+ public BaseDeployer() {\r
+ }\r
+\r
+ public BaseDeployer(List<String> wars, List<String> jars) {\r
+ baseDir = System.getProperty("deployer.base.dir");\r
+ destDir = System.getProperty("deployer.dest.dir");\r
+ appServerType = System.getProperty("deployer.app.server.type");\r
+ auiTaglibDTD = System.getProperty("deployer.aui.taglib.dtd");\r
+ portletTaglibDTD = System.getProperty("deployer.portlet.taglib.dtd");\r
+ portletExtTaglibDTD = System.getProperty(\r
+ "deployer.portlet.ext.taglib.dtd");\r
+ securityTaglibDTD = System.getProperty("deployer.security.taglib.dtd");\r
+ themeTaglibDTD = System.getProperty("deployer.theme.taglib.dtd");\r
+ uiTaglibDTD = System.getProperty("deployer.ui.taglib.dtd");\r
+ utilTaglibDTD = System.getProperty("deployer.util.taglib.dtd");\r
+ unpackWar = GetterUtil.getBoolean(\r
+ System.getProperty("deployer.unpack.war"), true);\r
+ filePattern = System.getProperty("deployer.file.pattern");\r
+ jbossPrefix = GetterUtil.getString(\r
+ System.getProperty("deployer.jboss.prefix"));\r
+ tomcatLibDir = System.getProperty("deployer.tomcat.lib.dir");\r
+ this.wars = wars;\r
+ this.jars = jars;\r
+\r
+ checkArguments();\r
+\r
+ String context = System.getProperty("deployer.context");\r
+\r
+ try {\r
+ deploy(context);\r
+ }\r
+ catch (Exception e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+\r
+ public void addExtJar(List<String> jars, String resource) throws Exception {\r
+ Set<String> servletContextNames = ExtRegistry.getServletContextNames();\r
+\r
+ for (String servletContextName : servletContextNames) {\r
+ String extResource =\r
+ "ext-" + servletContextName + resource.substring(3);\r
+\r
+ String path = DeployUtil.getResourcePath(extResource);\r
+\r
+ if (_log.isDebugEnabled()) {\r
+ if (path == null) {\r
+ _log.debug("Resource " + extResource + " is not available");\r
+ }\r
+ else {\r
+ _log.debug(\r
+ "Resource " + extResource + " is available at " + path);\r
+ }\r
+ }\r
+\r
+ if (path != null) {\r
+ jars.add(path);\r
+ }\r
+ }\r
+ }\r
+\r
+ public void addRequiredJar(List<String> jars, String resource)\r
+ throws Exception {\r
+\r
+ String path = DeployUtil.getResourcePath(resource);\r
+\r
+ if (path == null) {\r
+ throw new RuntimeException(\r
+ "Resource " + resource + " does not exist");\r
+ }\r
+\r
+ if (_log.isDebugEnabled()) {\r
+ _log.debug("Resource " + resource + " is available at " + path);\r
+ }\r
+\r
+ jars.add(path);\r
+ }\r
+\r
+ public int autoDeploy(AutoDeploymentContext autoDeploymentContext)\r
+ throws AutoDeployException {\r
+\r
+ List<String> wars = new ArrayList<String>();\r
+\r
+ File file = autoDeploymentContext.getFile();\r
+\r
+ wars.add(file.getName());\r
+\r
+ this.wars = wars;\r
+\r
+ try {\r
+ return deployFile(autoDeploymentContext);\r
+ }\r
+ catch (Exception e) {\r
+ throw new AutoDeployException(e);\r
+ }\r
+ }\r
+\r
+ public void checkArguments() {\r
+ if (Validator.isNull(baseDir)) {\r
+ throw new IllegalArgumentException(\r
+ "The system property deployer.base.dir is not set");\r
+ }\r
+\r
+ if (Validator.isNull(destDir)) {\r
+ throw new IllegalArgumentException(\r
+ "The system property deployer.dest.dir is not set");\r
+ }\r
+\r
+ if (Validator.isNull(appServerType)) {\r
+ throw new IllegalArgumentException(\r
+ "The system property deployer.app.server.type is not set");\r
+ }\r
+\r
+ if (!appServerType.equals(ServerDetector.GERONIMO_ID) &&\r
+ !appServerType.equals(ServerDetector.GLASSFISH_ID) &&\r
+ !appServerType.equals(ServerDetector.JBOSS_ID) &&\r
+ !appServerType.equals(ServerDetector.JONAS_ID) &&\r
+ !appServerType.equals(ServerDetector.JETTY_ID) &&\r
+ !appServerType.equals(ServerDetector.OC4J_ID) &&\r
+ !appServerType.equals(ServerDetector.RESIN_ID) &&\r
+ !appServerType.equals(ServerDetector.TOMCAT_ID) &&\r
+ !appServerType.equals(ServerDetector.WEBLOGIC_ID) &&\r
+ !appServerType.equals(ServerDetector.WEBSPHERE_ID)) {\r
+\r
+ throw new IllegalArgumentException(\r
+ appServerType + " is not a valid application server type");\r
+ }\r
+\r
+ if (appServerType.equals(ServerDetector.WEBSPHERE_ID)) {\r
+ unpackWar = false;\r
+ }\r
+\r
+ if (Validator.isNotNull(jbossPrefix) &&\r
+ !Validator.isNumber(jbossPrefix)) {\r
+\r
+ jbossPrefix = "1";\r
+ }\r
+ }\r
+\r
+ public void copyDependencyXml(String fileName, String targetDir)\r
+ throws Exception {\r
+\r
+ copyDependencyXml(fileName, targetDir, null);\r
+ }\r
+\r
+ public void copyDependencyXml(\r
+ String fileName, String targetDir, Map<String, String> filterMap)\r
+ throws Exception {\r
+\r
+ copyDependencyXml(fileName, targetDir, filterMap, false);\r
+ }\r
+\r
+ public void copyDependencyXml(\r
+ String fileName, String targetDir, Map<String, String> filterMap,\r
+ boolean overwrite)\r
+ throws Exception {\r
+\r
+ DeployUtil.copyDependencyXml(\r
+ fileName, targetDir, fileName, filterMap, overwrite);\r
+ }\r
+\r
+ public void copyJars(File srcFile, PluginPackage pluginPackage)\r
+ throws Exception {\r
+\r
+ for (int i = 0; i < jars.size(); i++) {\r
+ String jarFullName = jars.get(i);\r
+\r
+ String jarName = jarFullName.substring(\r
+ jarFullName.lastIndexOf("/") + 1);\r
+\r
+ if (!appServerType.equals(ServerDetector.TOMCAT_ID) ||\r
+ (appServerType.equals(ServerDetector.TOMCAT_ID) &&\r
+ !jarFullName.equals("util-java.jar"))) {\r
+\r
+ FileUtil.copyFile(\r
+ jarFullName, srcFile + "/WEB-INF/lib/" + jarName, true);\r
+ }\r
+ }\r
+\r
+ FileUtil.delete(srcFile + "/WEB-INF/lib/util-jsf.jar");\r
+ }\r
+\r
+ public void copyPortalDependencies(File srcFile) throws Exception {\r
+ Properties properties = getPluginPackageProperties(srcFile);\r
+\r
+ if (properties == null) {\r
+ return;\r
+ }\r
+\r
+ // jars\r
+\r
+ String[] portalJars = StringUtil.split(\r
+ properties.getProperty(\r
+ "portal-dependency-jars",\r
+ properties.getProperty("portal.dependency.jars")));\r
+\r
+ for (int i = 0; i < portalJars.length; i++) {\r
+ String portalJar = portalJars[i].trim();\r
+\r
+ portalJar = fixPortalDependencyJar(portalJar);\r
+\r
+ if (_log.isDebugEnabled()) {\r
+ _log.debug("Copy portal JAR " + portalJar);\r
+ }\r
+\r
+ try {\r
+ String portalJarPath = PortalUtil.getPortalLibDir() + portalJar;\r
+\r
+ FileUtil.copyFile(\r
+ portalJarPath, srcFile + "/WEB-INF/lib/" + portalJar, true);\r
+ }\r
+ catch (Exception e) {\r
+ _log.error("Unable to copy portal JAR " + portalJar, e);\r
+ }\r
+ }\r
+\r
+ // tlds\r
+\r
+ String[] portalTlds = StringUtil.split(\r
+ properties.getProperty(\r
+ "portal-dependency-tlds",\r
+ properties.getProperty("portal.dependency.tlds")));\r
+\r
+ for (int i = 0; i < portalTlds.length; i++) {\r
+ String portalTld = portalTlds[i].trim();\r
+\r
+ if (_log.isDebugEnabled()) {\r
+ _log.debug("Copy portal TLD " + portalTld);\r
+ }\r
+\r
+ try {\r
+ String portalTldPath = DeployUtil.getResourcePath(portalTld);\r
+\r
+ FileUtil.copyFile(\r
+ portalTldPath, srcFile + "/WEB-INF/tld/" + portalTld, true);\r
+ }\r
+ catch (Exception e) {\r
+ _log.error("Unable to copy portal TLD " + portalTld, e);\r
+ }\r
+ }\r
+\r
+ // commons-logging*.jar\r
+\r
+ File pluginLibDir = new File(srcFile + "/WEB-INF/lib/");\r
+\r
+ if (PropsValues.AUTO_DEPLOY_COPY_COMMONS_LOGGING) {\r
+ String[] commonsLoggingJars = pluginLibDir.list(\r
+ new GlobFilenameFilter("commons-logging*.jar"));\r
+\r
+ if ((commonsLoggingJars == null) ||\r
+ (commonsLoggingJars.length == 0)) {\r
+\r
+ String portalJarPath =\r
+ PortalUtil.getPortalLibDir() + "commons-logging.jar";\r
+\r
+ FileUtil.copyFile(\r
+ portalJarPath, srcFile + "/WEB-INF/lib/commons-logging.jar",\r
+ true);\r
+ }\r
+ }\r
+\r
+ // log4j*.jar\r
+\r
+ if (PropsValues.AUTO_DEPLOY_COPY_LOG4J) {\r
+ String[] log4jJars = pluginLibDir.list(\r
+ new GlobFilenameFilter("log4j*.jar"));\r
+\r
+ if ((log4jJars == null) || (log4jJars.length == 0)) {\r
+ String portalJarPath =\r
+ PortalUtil.getPortalLibDir() + "log4j.jar";\r
+\r
+ FileUtil.copyFile(\r
+ portalJarPath, srcFile + "/WEB-INF/lib/log4j.jar", true);\r
+ }\r
+ }\r
+ }\r
+\r
+ public void copyProperties(File srcFile, PluginPackage pluginPackage)\r
+ throws Exception {\r
+\r
+ if (PropsValues.AUTO_DEPLOY_COPY_COMMONS_LOGGING) {\r
+ copyDependencyXml(\r
+ "logging.properties", srcFile + "/WEB-INF/classes");\r
+ }\r
+\r
+ if (PropsValues.AUTO_DEPLOY_COPY_LOG4J) {\r
+ copyDependencyXml("log4j.properties", srcFile + "/WEB-INF/classes");\r
+ }\r
+\r
+ File servicePropertiesFile = new File(\r
+ srcFile.getAbsolutePath() + "/WEB-INF/classes/service.properties");\r
+\r
+ if (servicePropertiesFile.exists()) {\r
+ File portletPropertiesFile = new File(\r
+ srcFile.getAbsolutePath() +\r
+ "/WEB-INF/classes/portlet.properties");\r
+\r
+ if (!portletPropertiesFile.exists()) {\r
+ String pluginPackageName = null;\r
+\r
+ if (pluginPackage != null) {\r
+ pluginPackageName = pluginPackage.getName();\r
+ }\r
+ else {\r
+ pluginPackageName = srcFile.getName();\r
+ }\r
+\r
+ FileUtil.write(\r
+ portletPropertiesFile,\r
+ "plugin.package.name=" + pluginPackageName);\r
+ }\r
+ }\r
+ }\r
+\r
+ public void copyTlds(File srcFile, PluginPackage pluginPackage)\r
+ throws Exception {\r
+\r
+ if (Validator.isNotNull(auiTaglibDTD)) {\r
+ FileUtil.copyFile(\r
+ auiTaglibDTD, srcFile + "/WEB-INF/tld/aui.tld", true);\r
+ }\r
+\r
+ if (Validator.isNotNull(portletTaglibDTD)) {\r
+ FileUtil.copyFile(\r
+ portletTaglibDTD, srcFile + "/WEB-INF/tld/liferay-portlet.tld",\r
+ true);\r
+ }\r
+\r
+ if (Validator.isNotNull(portletExtTaglibDTD)) {\r
+ FileUtil.copyFile(\r
+ portletExtTaglibDTD,\r
+ srcFile + "/WEB-INF/tld/liferay-portlet-ext.tld", true);\r
+ }\r
+\r
+ if (Validator.isNotNull(securityTaglibDTD)) {\r
+ FileUtil.copyFile(\r
+ securityTaglibDTD,\r
+ srcFile + "/WEB-INF/tld/liferay-security.tld", true);\r
+ }\r
+\r
+ if (Validator.isNotNull(themeTaglibDTD)) {\r
+ FileUtil.copyFile(\r
+ themeTaglibDTD, srcFile + "/WEB-INF/tld/liferay-theme.tld",\r
+ true);\r
+ }\r
+\r
+ if (Validator.isNotNull(uiTaglibDTD)) {\r
+ FileUtil.copyFile(\r
+ uiTaglibDTD, srcFile + "/WEB-INF/tld/liferay-ui.tld", true);\r
+ }\r
+\r
+ if (Validator.isNotNull(utilTaglibDTD)) {\r
+ FileUtil.copyFile(\r
+ utilTaglibDTD, srcFile + "/WEB-INF/tld/liferay-util.tld", true);\r
+ }\r
+ }\r
+\r
+ public void copyTomcatContextXml(File targetDir) throws Exception {\r
+ if (!appServerType.equals(ServerDetector.TOMCAT_ID)) {\r
+ return;\r
+ }\r
+\r
+ // Update to keep context.xml file in META-INF if file exists\r
+ File contextXml = new File(targetDir + "/META-INF/context.xml");\r
+ String contextPath = "";\r
+ if (contextXml.exists()) {\r
+ contextPath = contextXml.getAbsolutePath();\r
+ }\r
+ else {\r
+ contextPath = DeployUtil.getResourcePath("context.xml");\r
+ }\r
+ \r
+ String content = FileUtil.read(contextPath);\r
+ \r
+ if (!PropsValues.AUTO_DEPLOY_UNPACK_WAR) {\r
+ content = StringUtil.replace(\r
+ content, "antiResourceLocking=\"true\"", StringPool.BLANK);\r
+ }\r
+ \r
+ FileUtil.write(new File(targetDir, "META-INF/context.xml"), content);\r
+ }\r
+\r
+ public void copyXmls(\r
+ File srcFile, String displayName, PluginPackage pluginPackage)\r
+ throws Exception {\r
+\r
+ if (appServerType.equals(ServerDetector.GERONIMO_ID)) {\r
+ copyDependencyXml("geronimo-web.xml", srcFile + "/WEB-INF");\r
+ }\r
+ else if (appServerType.equals(ServerDetector.JBOSS_ID)) {\r
+ copyDependencyXml(\r
+ "jboss-deployment-structure.xml", srcFile + "/WEB-INF");\r
+ }\r
+ else if (appServerType.equals(ServerDetector.WEBLOGIC_ID)) {\r
+ copyDependencyXml("weblogic.xml", srcFile + "/WEB-INF");\r
+ }\r
+ else if (appServerType.equals(ServerDetector.WEBSPHERE_ID)) {\r
+ copyDependencyXml("ibm-web-ext.xmi", srcFile + "/WEB-INF");\r
+ }\r
+\r
+ copyDependencyXml("web.xml", srcFile + "/WEB-INF");\r
+ }\r
+\r
+ public void deploy(String context) throws Exception {\r
+ try {\r
+ File baseDirFile = new File(baseDir);\r
+\r
+ File[] files = baseDirFile.listFiles();\r
+\r
+ if (files == null) {\r
+ return;\r
+ }\r
+\r
+ files = FileUtil.sortFiles(files);\r
+\r
+ for (int i = 0; i < files.length; i++) {\r
+ File srcFile = files[i];\r
+\r
+ String fileName = srcFile.getName().toLowerCase();\r
+\r
+ boolean deploy = false;\r
+\r
+ if (fileName.endsWith(".war") || fileName.endsWith(".zip")) {\r
+ deploy = true;\r
+\r
+ if (wars.size() > 0) {\r
+ if (!wars.contains(srcFile.getName())) {\r
+ deploy = false;\r
+ }\r
+ }\r
+ else if (Validator.isNotNull(filePattern)) {\r
+ if (!StringUtil.matchesIgnoreCase(\r
+ fileName, filePattern)) {\r
+\r
+ deploy = false;\r
+ }\r
+ }\r
+ }\r
+\r
+ if (deploy) {\r
+ AutoDeploymentContext autoDeploymentContext =\r
+ new AutoDeploymentContext();\r
+\r
+ autoDeploymentContext.setContext(context);\r
+ autoDeploymentContext.setFile(srcFile);\r
+\r
+ deployFile(autoDeploymentContext);\r
+ }\r
+ }\r
+ }\r
+ catch (Exception e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+\r
+ public void deployDirectory(\r
+ File srcFile, File mergeDir, File deployDir, String displayName,\r
+ boolean overwrite, PluginPackage pluginPackage)\r
+ throws Exception {\r
+\r
+ rewriteFiles(srcFile);\r
+\r
+ mergeDirectory(mergeDir, srcFile);\r
+\r
+ processPluginPackageProperties(srcFile, displayName, pluginPackage);\r
+\r
+ copyJars(srcFile, pluginPackage);\r
+ copyProperties(srcFile, pluginPackage);\r
+ copyTlds(srcFile, pluginPackage);\r
+ copyXmls(srcFile, displayName, pluginPackage);\r
+ copyPortalDependencies(srcFile);\r
+\r
+ updateGeronimoWebXml(srcFile, displayName, pluginPackage);\r
+\r
+ File webXml = new File(srcFile + "/WEB-INF/web.xml");\r
+\r
+ updateWebXml(webXml, srcFile, displayName, pluginPackage);\r
+\r
+ File extLibGlobalDir = new File(\r
+ srcFile.getAbsolutePath() + "/WEB-INF/ext-lib/global");\r
+\r
+ if (extLibGlobalDir.exists()) {\r
+ File globalLibDir = new File(PortalUtil.getGlobalLibDir());\r
+\r
+ CopyTask.copyDirectory(\r
+ extLibGlobalDir, globalLibDir, "*.jar", StringPool.BLANK,\r
+ overwrite, true);\r
+ }\r
+\r
+ File extLibPortalDir = new File(\r
+ srcFile.getAbsolutePath() + "/WEB-INF/ext-lib/portal");\r
+\r
+ if (extLibPortalDir.exists()) {\r
+ File portalLibDir = new File(PortalUtil.getPortalLibDir());\r
+\r
+ CopyTask.copyDirectory(\r
+ extLibPortalDir, portalLibDir, "*.jar", StringPool.BLANK,\r
+ overwrite, true);\r
+ }\r
+\r
+ if ((deployDir == null) || baseDir.equals(destDir)) {\r
+ return;\r
+ }\r
+\r
+ updateDeployDirectory(srcFile);\r
+\r
+ String excludes = StringPool.BLANK;\r
+\r
+ if (appServerType.equals(ServerDetector.JBOSS_ID)) {\r
+ excludes += "**/WEB-INF/lib/log4j.jar,";\r
+ }\r
+ else if (appServerType.equals(ServerDetector.TOMCAT_ID)) {\r
+ String[] libs = FileUtil.listFiles(tomcatLibDir);\r
+\r
+ for (int i = 0; i < libs.length; i++) {\r
+ excludes += "**/WEB-INF/lib/" + libs[i] + ",";\r
+ }\r
+\r
+ File contextXml = new File(srcFile + "/META-INF/context.xml");\r
+\r
+ if (contextXml.exists()) {\r
+ String content = FileUtil.read(contextXml);\r
+\r
+ if (content.indexOf(_PORTAL_CLASS_LOADER) != -1) {\r
+ excludes += "**/WEB-INF/lib/util-bridges.jar,";\r
+ excludes += "**/WEB-INF/lib/util-java.jar,";\r
+ excludes += "**/WEB-INF/lib/util-taglib.jar,";\r
+ }\r
+ }\r
+\r
+ try {\r
+\r
+ // LEP-2990\r
+\r
+ Class.forName("javax.el.ELContext");\r
+\r
+ excludes += "**/WEB-INF/lib/el-api.jar,";\r
+ }\r
+ catch (ClassNotFoundException cnfe) {\r
+ }\r
+ }\r
+\r
+ // LPS-11268\r
+\r
+ Properties properties = getPluginPackageProperties(srcFile);\r
+\r
+ if (properties != null) {\r
+ String deployExcludes = properties.getProperty("deploy-excludes");\r
+\r
+ if (deployExcludes != null) {\r
+ excludes += deployExcludes.trim();\r
+\r
+ if (!excludes.endsWith(",")) {\r
+ excludes += ",";\r
+ }\r
+ }\r
+\r
+ deployExcludes = properties.getProperty(\r
+ "deploy-excludes-" + appServerType);\r
+\r
+ if (deployExcludes != null) {\r
+ excludes += deployExcludes.trim();\r
+\r
+ if (!excludes.endsWith(",")) {\r
+ excludes += ",";\r
+ }\r
+ }\r
+ }\r
+\r
+ if (_log.isDebugEnabled()) {\r
+ _log.debug("Excludes " + excludes);\r
+ }\r
+\r
+ if (!unpackWar) {\r
+ File tempDir = new File(\r
+ SystemProperties.get(SystemProperties.TMP_DIR) +\r
+ File.separator + Time.getTimestamp());\r
+\r
+ excludes += "**/WEB-INF/web.xml";\r
+\r
+ WarTask.war(srcFile, tempDir, excludes, webXml);\r
+\r
+ if (isJEEDeploymentEnabled()) {\r
+ File tempWarDir = new File(\r
+ tempDir.getParent(), deployDir.getName());\r
+\r
+ if (tempWarDir.exists()) {\r
+ tempWarDir.delete();\r
+ }\r
+\r
+ if (!tempDir.renameTo(tempWarDir)) {\r
+ tempWarDir = tempDir;\r
+ }\r
+\r
+ DeploymentHandler deploymentHandler = getDeploymentHandler();\r
+\r
+ deploymentHandler.deploy(tempWarDir, displayName);\r
+\r
+ deploymentHandler.releaseDeploymentManager();\r
+\r
+ DeleteTask.deleteDirectory(tempWarDir);\r
+ }\r
+ else {\r
+ if (!tempDir.renameTo(deployDir)) {\r
+ WarTask.war(srcFile, deployDir, excludes, webXml);\r
+ }\r
+\r
+ DeleteTask.deleteDirectory(tempDir);\r
+ }\r
+ }\r
+ else {\r
+\r
+ // The deployer might only copy files that have been modified.\r
+ // However, the deployer always copies and overwrites web.xml after\r
+ // the other files have been copied because application servers\r
+ // usually detect that a WAR has been modified based on the web.xml\r
+ // timestamp.\r
+\r
+ excludes += "**/WEB-INF/web.xml";\r
+\r
+ CopyTask.copyDirectory(\r
+ srcFile, deployDir, StringPool.BLANK, excludes, overwrite,\r
+ true);\r
+\r
+ CopyTask.copyDirectory(\r
+ srcFile, deployDir, "**/WEB-INF/web.xml", StringPool.BLANK,\r
+ true, false);\r
+\r
+ if (appServerType.equals(ServerDetector.TOMCAT_ID)) {\r
+\r
+ // See org.apache.catalina.startup.HostConfig to see how Tomcat\r
+ // checks to make sure that web.xml was modified 5 seconds after\r
+ // WEB-INF\r
+\r
+ File deployWebXml = new File(deployDir + "/WEB-INF/web.xml");\r
+\r
+ deployWebXml.setLastModified(\r
+ System.currentTimeMillis() + (Time.SECOND * 6));\r
+ }\r
+ }\r
+\r
+ if (appServerType.equals(ServerDetector.JETTY_ID)) {\r
+ DeployUtil.redeployJetty(displayName);\r
+ }\r
+ }\r
+\r
+ public void deployDirectory(\r
+ File srcFile, String displayName, boolean override,\r
+ PluginPackage pluginPackage)\r
+ throws Exception {\r
+\r
+ deployDirectory(\r
+ srcFile, null, null, displayName, override, pluginPackage);\r
+ }\r
+\r
+ public int deployFile(AutoDeploymentContext autoDeploymentContext)\r
+ throws Exception {\r
+\r
+ File srcFile = autoDeploymentContext.getFile();\r
+\r
+ PluginPackage pluginPackage = readPluginPackage(srcFile);\r
+\r
+ if (_log.isInfoEnabled()) {\r
+ _log.info("Deploying " + srcFile.getName());\r
+ }\r
+\r
+ String specifiedContext = autoDeploymentContext.getContext();\r
+\r
+ String displayName = specifiedContext;\r
+ boolean overwrite = false;\r
+ String preliminaryContext = specifiedContext;\r
+\r
+ // The order of priority of the context is: 1.) the specified context,\r
+ // 2.) if the file name starts with DEPLOY_TO_PREFIX, use the file name\r
+ // after the prefix, or 3.) the recommended deployment context as\r
+ // specified in liferay-plugin-package.properties, or 4.) the file name.\r
+\r
+ if ((specifiedContext != null) &&\r
+ srcFile.getName().startsWith(DEPLOY_TO_PREFIX)) {\r
+\r
+ displayName = srcFile.getName().substring(\r
+ DEPLOY_TO_PREFIX.length(), srcFile.getName().length() - 4);\r
+\r
+ overwrite = true;\r
+ preliminaryContext = displayName;\r
+ }\r
+\r
+ if (preliminaryContext == null) {\r
+ preliminaryContext = getDisplayName(srcFile);\r
+ }\r
+\r
+ if (pluginPackage != null) {\r
+ if (!PluginPackageUtil.isCurrentVersionSupported(\r
+ pluginPackage.getLiferayVersions())) {\r
+\r
+ throw new AutoDeployException(\r
+ srcFile.getName() +\r
+ " does not support this version of Liferay");\r
+ }\r
+\r
+ if (displayName == null) {\r
+ displayName = pluginPackage.getRecommendedDeploymentContext();\r
+ }\r
+\r
+ if (Validator.isNull(displayName)) {\r
+ displayName = getDisplayName(srcFile);\r
+ }\r
+\r
+ pluginPackage.setContext(displayName);\r
+\r
+ PluginPackageUtil.updateInstallingPluginPackage(\r
+ preliminaryContext, pluginPackage);\r
+ }\r
+\r
+ String deployDir = null;\r
+\r
+ if (Validator.isNotNull(displayName)) {\r
+ deployDir = displayName + ".war";\r
+ }\r
+ else {\r
+ deployDir = srcFile.getName();\r
+ displayName = getDisplayName(srcFile);\r
+ }\r
+\r
+ if (appServerType.equals(ServerDetector.JBOSS_ID)) {\r
+ deployDir = jbossPrefix + deployDir;\r
+ }\r
+ else if (appServerType.equals(ServerDetector.GERONIMO_ID) ||\r
+ appServerType.equals(ServerDetector.GLASSFISH_ID) ||\r
+ appServerType.equals(ServerDetector.JETTY_ID) ||\r
+ appServerType.equals(ServerDetector.JONAS_ID) ||\r
+ appServerType.equals(ServerDetector.OC4J_ID) ||\r
+ appServerType.equals(ServerDetector.RESIN_ID) ||\r
+ appServerType.equals(ServerDetector.TOMCAT_ID) ||\r
+ appServerType.equals(ServerDetector.WEBLOGIC_ID)) {\r
+\r
+ if (unpackWar) {\r
+ deployDir = deployDir.substring(0, deployDir.length() - 4);\r
+ }\r
+ }\r
+\r
+ String destDir = this.destDir;\r
+\r
+ if (autoDeploymentContext.getDestDir() != null) {\r
+ destDir = autoDeploymentContext.getDestDir();\r
+ }\r
+\r
+ File deployDirFile = new File(destDir + "/" + deployDir);\r
+\r
+ try {\r
+ PluginPackage previousPluginPackage = readPluginPackage(\r
+ deployDirFile);\r
+\r
+ if ((pluginPackage != null) && (previousPluginPackage != null)) {\r
+ String name = pluginPackage.getName();\r
+ String previousVersion = previousPluginPackage.getVersion();\r
+ String version = pluginPackage.getVersion();\r
+\r
+ if (_log.isInfoEnabled()) {\r
+ _log.info(\r
+ "Updating " + name + " from version " +\r
+ previousVersion + " to version " + version);\r
+ }\r
+\r
+ if (pluginPackage.isPreviousVersionThan(\r
+ previousPluginPackage)) {\r
+\r
+ if (_log.isInfoEnabled()) {\r
+ _log.info(\r
+ "Not updating " + name + " because version " +\r
+ previousVersion + " is newer than version " +\r
+ version);\r
+ }\r
+\r
+ return AutoDeployer.CODE_SKIP_NEWER_VERSION;\r
+ }\r
+\r
+ overwrite = true;\r
+ }\r
+\r
+ File mergeDirFile = new File(\r
+ srcFile.getParent() + "/merge/" + srcFile.getName());\r
+\r
+ if (srcFile.isDirectory()) {\r
+ deployDirectory(\r
+ srcFile, mergeDirFile, deployDirFile, displayName,\r
+ overwrite, pluginPackage);\r
+ }\r
+ else {\r
+ boolean deployed = deployFile(\r
+ srcFile, mergeDirFile, deployDirFile, displayName,\r
+ overwrite, pluginPackage);\r
+\r
+ if (!deployed) {\r
+ String context = preliminaryContext;\r
+\r
+ if (pluginPackage != null) {\r
+ context = pluginPackage.getContext();\r
+ }\r
+\r
+ PluginPackageUtil.endPluginPackageInstallation(context);\r
+ }\r
+ else {\r
+ postDeploy(destDir, deployDir);\r
+ }\r
+ }\r
+\r
+ return AutoDeployer.CODE_DEFAULT;\r
+ }\r
+ catch (Exception e) {\r
+ if (pluginPackage != null) {\r
+ PluginPackageUtil.endPluginPackageInstallation(\r
+ pluginPackage.getContext());\r
+ }\r
+\r
+ throw e;\r
+ }\r
+ }\r
+\r
+ public boolean deployFile(\r
+ File srcFile, File mergeDir, File deployDir, String displayName,\r
+ boolean overwrite, PluginPackage pluginPackage)\r
+ throws Exception {\r
+\r
+ boolean undeployOnRedeploy = false;\r
+\r
+ try {\r
+ undeployOnRedeploy = PrefsPropsUtil.getBoolean(\r
+ PropsKeys.HOT_UNDEPLOY_ON_REDEPLOY,\r
+ PropsValues.HOT_UNDEPLOY_ON_REDEPLOY);\r
+ }\r
+ catch (Exception e) {\r
+\r
+ // This will only happen when running the deploy tool in Ant in the\r
+ // classical way where the WAR file is actually massaged and\r
+ // packaged.\r
+\r
+ }\r
+\r
+ if (undeployOnRedeploy) {\r
+ DeployUtil.undeploy(appServerType, deployDir);\r
+ }\r
+\r
+ if (!overwrite && UpToDateTask.isUpToDate(srcFile, deployDir)) {\r
+ if (_log.isInfoEnabled()) {\r
+ _log.info(deployDir + " is already up to date");\r
+ }\r
+\r
+ return false;\r
+ }\r
+\r
+ File tempDir = new File(\r
+ SystemProperties.get(SystemProperties.TMP_DIR) + File.separator +\r
+ Time.getTimestamp());\r
+\r
+ ExpandTask.expand(srcFile, tempDir);\r
+\r
+ deployDirectory(\r
+ tempDir, mergeDir, deployDir, displayName, overwrite,\r
+ pluginPackage);\r
+\r
+ DeleteTask.deleteDirectory(tempDir);\r
+\r
+ return true;\r
+ }\r
+\r
+ public String downloadJar(String jar) throws Exception {\r
+ String tmpDir = SystemProperties.get(SystemProperties.TMP_DIR);\r
+\r
+ File file = new File(\r
+ tmpDir + "/liferay/com/liferay/portal/deploy/dependencies/" + jar);\r
+\r
+ if (!file.exists()) {\r
+ synchronized (this) {\r
+ String url = PropsUtil.get(\r
+ PropsKeys.LIBRARY_DOWNLOAD_URL + jar);\r
+\r
+ if (_log.isInfoEnabled()) {\r
+ _log.info("Downloading library from " + url);\r
+ }\r
+\r
+ byte[] bytes = HttpUtil.URLtoByteArray(url);\r
+\r
+ FileUtil.write(file, bytes);\r
+ }\r
+ }\r
+\r
+ return FileUtil.getAbsolutePath(file);\r
+ }\r
+\r
+ public String fixPortalDependencyJar(String portalJar) {\r
+ if (portalJar.equals("antlr.jar")) {\r
+ portalJar = "antlr2.jar";\r
+ }\r
+\r
+ return portalJar;\r
+ }\r
+\r
+ public DeploymentHandler getDeploymentHandler() {\r
+ String prefix = "auto.deploy." + ServerDetector.getServerId() + ".jee.";\r
+\r
+ String dmId = PropsUtil.get(prefix + "dm.id");\r
+ String dmUser = PropsUtil.get(prefix + "dm.user");\r
+ String dmPassword = PropsUtil.get(prefix + "dm.passwd");\r
+ String dfClassName = PropsUtil.get(prefix + "df.classname");\r
+\r
+ return new DeploymentHandler(dmId, dmUser, dmPassword, dfClassName);\r
+ }\r
+\r
+ public String getDisplayName(File srcFile) {\r
+ String displayName = srcFile.getName();\r
+\r
+ if (StringUtil.endsWith(displayName, ".war") ||\r
+ StringUtil.endsWith(displayName, ".xml")) {\r
+\r
+ displayName = displayName.substring(0, displayName.length() - 4);\r
+ }\r
+\r
+ if (appServerType.equals(ServerDetector.JBOSS_ID) &&\r
+ Validator.isNotNull(jbossPrefix) &&\r
+ displayName.startsWith(jbossPrefix)) {\r
+\r
+ displayName = displayName.substring(1);\r
+ }\r
+\r
+ return displayName;\r
+ }\r
+\r
+ public String getExtraContent(\r
+ double webXmlVersion, File srcFile, String displayName)\r
+ throws Exception {\r
+\r
+ StringBundler sb = new StringBundler();\r
+\r
+ sb.append("<display-name>");\r
+ sb.append(displayName);\r
+ sb.append("</display-name>");\r
+\r
+ if (webXmlVersion < 2.4) {\r
+ sb.append("<context-param>");\r
+ sb.append("<param-name>liferay-invoker-enabled</param-name>");\r
+ sb.append("<param-value>false</param-value>");\r
+ sb.append("</context-param>");\r
+ }\r
+\r
+ sb.append("<listener>");\r
+ sb.append("<listener-class>");\r
+ sb.append("com.liferay.portal.kernel.servlet.");\r
+ sb.append("SerializableSessionAttributeListener");\r
+ sb.append("</listener-class>");\r
+ sb.append("</listener>");\r
+\r
+ File serverConfigWsdd = new File(\r
+ srcFile + "/WEB-INF/server-config.wsdd");\r
+\r
+ if (serverConfigWsdd.exists()) {\r
+ File webXml = new File(srcFile + "/WEB-INF/web.xml");\r
+\r
+ String content = FileUtil.read(webXml);\r
+\r
+ if (!content.contains("axis.servicesPath")) {\r
+ String remotingContent = FileUtil.read(\r
+ DeployUtil.getResourcePath("remoting-web.xml"));\r
+\r
+ sb.append(remotingContent);\r
+ }\r
+ }\r
+\r
+ boolean hasTaglib = false;\r
+\r
+ if (Validator.isNotNull(auiTaglibDTD) ||\r
+ Validator.isNotNull(portletTaglibDTD) ||\r
+ Validator.isNotNull(portletExtTaglibDTD) ||\r
+ Validator.isNotNull(securityTaglibDTD) ||\r
+ Validator.isNotNull(themeTaglibDTD) ||\r
+ Validator.isNotNull(uiTaglibDTD) ||\r
+ Validator.isNotNull(utilTaglibDTD)) {\r
+\r
+ hasTaglib = true;\r
+ }\r
+\r
+ if (hasTaglib && (webXmlVersion > 2.3)) {\r
+ sb.append("<jsp-config>");\r
+ }\r
+\r
+ if (Validator.isNotNull(auiTaglibDTD)) {\r
+ sb.append("<taglib>");\r
+ sb.append("<taglib-uri>http://liferay.com/tld/aui</taglib-uri>");\r
+ sb.append("<taglib-location>");\r
+ sb.append("/WEB-INF/tld/aui.tld");\r
+ sb.append("</taglib-location>");\r
+ sb.append("</taglib>");\r
+ }\r
+\r
+ if (Validator.isNotNull(portletTaglibDTD)) {\r
+ sb.append("<taglib>");\r
+ sb.append(\r
+ "<taglib-uri>http://java.sun.com/portlet_2_0</taglib-uri>");\r
+ sb.append("<taglib-location>");\r
+ sb.append("/WEB-INF/tld/liferay-portlet.tld");\r
+ sb.append("</taglib-location>");\r
+ sb.append("</taglib>");\r
+ }\r
+\r
+ if (Validator.isNotNull(portletExtTaglibDTD)) {\r
+ sb.append("<taglib>");\r
+ sb.append("<taglib-uri>");\r
+ sb.append("http://liferay.com/tld/portlet");\r
+ sb.append("</taglib-uri>");\r
+ sb.append("<taglib-location>");\r
+ sb.append("/WEB-INF/tld/liferay-portlet-ext.tld");\r
+ sb.append("</taglib-location>");\r
+ sb.append("</taglib>");\r
+ }\r
+\r
+ if (Validator.isNotNull(securityTaglibDTD)) {\r
+ sb.append("<taglib>");\r
+ sb.append("<taglib-uri>");\r
+ sb.append("http://liferay.com/tld/security");\r
+ sb.append("</taglib-uri>");\r
+ sb.append("<taglib-location>");\r
+ sb.append("/WEB-INF/tld/liferay-security.tld");\r
+ sb.append("</taglib-location>");\r
+ sb.append("</taglib>");\r
+ }\r
+\r
+ if (Validator.isNotNull(themeTaglibDTD)) {\r
+ sb.append("<taglib>");\r
+ sb.append("<taglib-uri>http://liferay.com/tld/theme</taglib-uri>");\r
+ sb.append("<taglib-location>");\r
+ sb.append("/WEB-INF/tld/liferay-theme.tld");\r
+ sb.append("</taglib-location>");\r
+ sb.append("</taglib>");\r
+ }\r
+\r
+ if (Validator.isNotNull(uiTaglibDTD)) {\r
+ sb.append("<taglib>");\r
+ sb.append("<taglib-uri>http://liferay.com/tld/ui</taglib-uri>");\r
+ sb.append("<taglib-location>");\r
+ sb.append("/WEB-INF/tld/liferay-ui.tld");\r
+ sb.append("</taglib-location>");\r
+ sb.append("</taglib>");\r
+ }\r
+\r
+ if (Validator.isNotNull(utilTaglibDTD)) {\r
+ sb.append("<taglib>");\r
+ sb.append("<taglib-uri>http://liferay.com/tld/util</taglib-uri>");\r
+ sb.append("<taglib-location>");\r
+ sb.append("/WEB-INF/tld/liferay-util.tld");\r
+ sb.append("</taglib-location>");\r
+ sb.append("</taglib>");\r
+ }\r
+\r
+ if (hasTaglib && (webXmlVersion > 2.3)) {\r
+ sb.append("</jsp-config>");\r
+ }\r
+\r
+ return sb.toString();\r
+ }\r
+\r
+ public String getExtraFiltersContent(double webXmlVersion, File srcFile)\r
+ throws Exception {\r
+\r
+ return getSessionFiltersContent();\r
+ }\r
+\r
+ public String getIgnoreFiltersContent(File srcFile) throws Exception {\r
+ boolean ignoreFiltersEnabled = true;\r
+\r
+ Properties properties = getPluginPackageProperties(srcFile);\r
+\r
+ if (properties != null) {\r
+ ignoreFiltersEnabled = GetterUtil.getBoolean(\r
+ properties.getProperty("ignore-filters-enabled"), true);\r
+ }\r
+\r
+ if (ignoreFiltersEnabled) {\r
+ String ignoreFiltersContent = FileUtil.read(\r
+ DeployUtil.getResourcePath("ignore-filters-web.xml"));\r
+\r
+ return ignoreFiltersContent;\r
+ }\r
+ else {\r
+ return StringPool.BLANK;\r
+ }\r
+ }\r
+\r
+ public String getInvokerFilterContent() {\r
+ StringBundler sb = new StringBundler(4);\r
+\r
+ sb.append(getInvokerFilterContent("ERROR"));\r
+ sb.append(getInvokerFilterContent("FORWARD"));\r
+ sb.append(getInvokerFilterContent("INCLUDE"));\r
+ sb.append(getInvokerFilterContent("REQUEST"));\r
+\r
+ return sb.toString();\r
+ }\r
+\r
+ public String getInvokerFilterContent(String dispatcher) {\r
+ StringBundler sb = new StringBundler(23);\r
+\r
+ sb.append("<filter>");\r
+ sb.append("<filter-name>Invoker Filter - ");\r
+ sb.append(dispatcher);\r
+ sb.append("</filter-name>");\r
+ sb.append("<filter-class>");\r
+ sb.append(InvokerFilter.class.getName());\r
+ sb.append("</filter-class>");\r
+ sb.append("<init-param>");\r
+ sb.append("<param-name>dispatcher</param-name>");\r
+ sb.append("<param-value>");\r
+ sb.append(dispatcher);\r
+ sb.append("</param-value>");\r
+ sb.append("</init-param>");\r
+ sb.append("</filter>");\r
+\r
+ sb.append("<filter-mapping>");\r
+ sb.append("<filter-name>Invoker Filter - ");\r
+ sb.append(dispatcher);\r
+ sb.append("</filter-name>");\r
+ sb.append("<url-pattern>/*</url-pattern>");\r
+ sb.append("<dispatcher>");\r
+ sb.append(dispatcher);\r
+ sb.append("</dispatcher>");\r
+ sb.append("</filter-mapping>");\r
+\r
+ return sb.toString();\r
+ }\r
+\r
+ public String getPluginPackageLicensesXml(List<License> licenses) {\r
+ if (licenses.isEmpty()) {\r
+ return StringPool.BLANK;\r
+ }\r
+\r
+ StringBundler sb = new StringBundler(5 * licenses.size() + 2);\r
+\r
+ for (int i = 0; i < licenses.size(); i++) {\r
+ License license = licenses.get(i);\r
+\r
+ if (i == 0) {\r
+ sb.append("\r\n");\r
+ }\r
+\r
+ sb.append("\t\t<license osi-approved=\"");\r
+ sb.append(license.isOsiApproved());\r
+ sb.append("\">");\r
+ sb.append(license.getName());\r
+ sb.append("</license>\r\n");\r
+\r
+ if ((i + 1) == licenses.size()) {\r
+ sb.append("\t");\r
+ }\r
+ }\r
+\r
+ return sb.toString();\r
+ }\r
+\r
+ public String getPluginPackageLiferayVersionsXml(\r
+ List<String> liferayVersions) {\r
+\r
+ if (liferayVersions.isEmpty()) {\r
+ return StringPool.BLANK;\r
+ }\r
+\r
+ StringBundler sb = new StringBundler(liferayVersions.size() * 3 + 2);\r
+\r
+ for (int i = 0; i < liferayVersions.size(); i++) {\r
+ String liferayVersion = liferayVersions.get(i);\r
+\r
+ if (i == 0) {\r
+ sb.append("\r\n");\r
+ }\r
+\r
+ sb.append("\t\t<liferay-version>");\r
+ sb.append(liferayVersion);\r
+ sb.append("</liferay-version>\r\n");\r
+\r
+ if ((i + 1) == liferayVersions.size()) {\r
+ sb.append("\t");\r
+ }\r
+ }\r
+\r
+ return sb.toString();\r
+ }\r
+\r
+ public Properties getPluginPackageProperties(File srcFile)\r
+ throws Exception {\r
+\r
+ File propertiesFile = new File(\r
+ srcFile + "/WEB-INF/liferay-plugin-package.properties");\r
+\r
+ if (!propertiesFile.exists()) {\r
+ return null;\r
+ }\r
+\r
+ String propertiesString = FileUtil.read(propertiesFile);\r
+\r
+ return PropertiesUtil.load(propertiesString);\r
+ }\r
+\r
+ public String getPluginPackageTagsXml(List<String> tags) {\r
+ if (tags.isEmpty()) {\r
+ return StringPool.BLANK;\r
+ }\r
+\r
+ StringBundler sb = new StringBundler(tags.size() * 3 + 2);\r
+\r
+ for (int i = 0; i < tags.size(); i++) {\r
+ String tag = tags.get(i);\r
+\r
+ if (i == 0) {\r
+ sb.append("\r\n");\r
+ }\r
+\r
+ sb.append("\t\t<tag>");\r
+ sb.append(tag);\r
+ sb.append("</tag>\r\n");\r
+\r
+ if ((i + 1) == tags.size()) {\r
+ sb.append("\t");\r
+ }\r
+ }\r
+\r
+ return sb.toString();\r
+ }\r
+\r
+ public Map<String, String> getPluginPackageXmlFilterMap(\r
+ PluginPackage pluginPackage) {\r
+\r
+ List<String> pluginTypes = pluginPackage.getTypes();\r
+\r
+ String pluginType = pluginTypes.get(0);\r
+\r
+ if (!pluginType.equals(getPluginType())) {\r
+ return null;\r
+ }\r
+\r
+ Map<String, String> filterMap = new HashMap<String, String>();\r
+\r
+ filterMap.put("module_group_id", pluginPackage.getGroupId());\r
+ filterMap.put("module_artifact_id", pluginPackage.getArtifactId());\r
+ filterMap.put("module_version", pluginPackage.getVersion());\r
+\r
+ filterMap.put("plugin_name", pluginPackage.getName());\r
+ filterMap.put("plugin_type", pluginType);\r
+ filterMap.put(\r
+ "plugin_type_name",\r
+ TextFormatter.format(pluginType, TextFormatter.J));\r
+\r
+ filterMap.put("tags", getPluginPackageTagsXml(pluginPackage.getTags()));\r
+ filterMap.put("short_description", pluginPackage.getShortDescription());\r
+ filterMap.put("long_description", pluginPackage.getLongDescription());\r
+ filterMap.put("change_log", pluginPackage.getChangeLog());\r
+ filterMap.put("page_url", pluginPackage.getPageURL());\r
+ filterMap.put("author", pluginPackage.getAuthor());\r
+ filterMap.put(\r
+ "licenses",\r
+ getPluginPackageLicensesXml(pluginPackage.getLicenses()));\r
+ filterMap.put(\r
+ "liferay_versions",\r
+ getPluginPackageLiferayVersionsXml(\r
+ pluginPackage.getLiferayVersions()));\r
+\r
+ return filterMap;\r
+ }\r
+\r
+ public String getPluginType() {\r
+ return null;\r
+ }\r
+\r
+ public String getServletContextIncludeFiltersContent(\r
+ double webXmlVersion, File srcFile)\r
+ throws Exception {\r
+\r
+ if (webXmlVersion < 2.4) {\r
+ return StringPool.BLANK;\r
+ }\r
+\r
+ Properties properties = getPluginPackageProperties(srcFile);\r
+\r
+ if (properties == null) {\r
+ return StringPool.BLANK;\r
+ }\r
+\r
+ if (!GetterUtil.getBoolean(\r
+ properties.getProperty(\r
+ "servlet-context-include-filters-enabled"), true)) {\r
+\r
+ return StringPool.BLANK;\r
+ }\r
+\r
+ return FileUtil.read(\r
+ DeployUtil.getResourcePath(\r
+ "servlet-context-include-filters-web.xml"));\r
+ }\r
+\r
+ public String getSessionFiltersContent() throws Exception {\r
+ String sessionFiltersContent = FileUtil.read(\r
+ DeployUtil.getResourcePath("session-filters-web.xml"));\r
+\r
+ return sessionFiltersContent;\r
+ }\r
+\r
+ public String getSpeedFiltersContent(File srcFile) throws Exception {\r
+ boolean speedFiltersEnabled = true;\r
+\r
+ Properties properties = getPluginPackageProperties(srcFile);\r
+\r
+ if (properties != null) {\r
+ speedFiltersEnabled = GetterUtil.getBoolean(\r
+ properties.getProperty("speed-filters-enabled"), true);\r
+ }\r
+\r
+ if (speedFiltersEnabled) {\r
+ String speedFiltersContent = FileUtil.read(\r
+ DeployUtil.getResourcePath("speed-filters-web.xml"));\r
+\r
+ return speedFiltersContent;\r
+ }\r
+ else {\r
+ return StringPool.BLANK;\r
+ }\r
+ }\r
+\r
+ public boolean isJEEDeploymentEnabled() {\r
+ return GetterUtil.getBoolean(PropsUtil.get(\r
+ "auto.deploy." + ServerDetector.getServerId() +\r
+ ".jee.deployment.enabled"));\r
+ }\r
+\r
+ public void mergeDirectory(File mergeDir, File targetDir) {\r
+ if ((mergeDir == null) || !mergeDir.exists()) {\r
+ return;\r
+ }\r
+\r
+ CopyTask.copyDirectory(mergeDir, targetDir, null, null, true, false);\r
+ }\r
+\r
+ public void postDeploy(String destDir, String deployDir) throws Exception {\r
+ if (appServerType.equals(ServerDetector.GLASSFISH_ID)) {\r
+ postDeployGlassfish(destDir, deployDir);\r
+ }\r
+ else if (appServerType.equals(ServerDetector.JBOSS_ID)) {\r
+ postDeployJBoss(destDir, deployDir);\r
+ }\r
+ else if (appServerType.equals(ServerDetector.WEBSPHERE_ID)) {\r
+ postDeployWebSphere(destDir, deployDir);\r
+ }\r
+ }\r
+\r
+ public void postDeployGlassfish(String destDir, String deployDir)\r
+ throws Exception {\r
+\r
+ FileUtil.delete(destDir + "/.autodeploystatus/" + deployDir);\r
+ }\r
+\r
+ public void postDeployJBoss(String destDir, String deployDir)\r
+ throws Exception {\r
+\r
+ FileUtil.write(\r
+ destDir + "/" + deployDir + ".dodeploy", StringPool.BLANK);\r
+ }\r
+\r
+ public void postDeployWebSphere(String destDir, String deployDir)\r
+ throws Exception {\r
+\r
+ if (Validator.isNull(\r
+ PropsValues.AUTO_DEPLOY_WEBSPHERE_WSADMIN_APP_MANAGER_QUERY)) {\r
+\r
+ if (_log.isInfoEnabled()) {\r
+ StringBundler sb = new StringBundler();\r
+\r
+ sb.append("Do not install the plugin with wsadmin since the ");\r
+ sb.append("property \"");\r
+ sb.append(\r
+ PropsKeys.AUTO_DEPLOY_WEBSPHERE_WSADMIN_APP_MANAGER_QUERY);\r
+ sb.append("\"is not configured");\r
+\r
+ _log.info(sb.toString());\r
+ }\r
+\r
+ return;\r
+ }\r
+\r
+ String wsadminContent = FileUtil.read(\r
+ DeployUtil.getResourcePath("wsadmin.py"));\r
+\r
+ String pluginServletContextName = deployDir.substring(\r
+ 0, deployDir.length() - 4);\r
+\r
+ wsadminContent = StringUtil.replace(\r
+ wsadminContent,\r
+ new String[] {\r
+ "${auto.deploy.dest.dir}",\r
+ "${auto.deploy.websphere.wsadmin.app.manager.query}",\r
+ "${plugin.servlet.context.name}"\r
+ },\r
+ new String[] {\r
+ destDir,\r
+ PropsValues.AUTO_DEPLOY_WEBSPHERE_WSADMIN_APP_MANAGER_QUERY,\r
+ pluginServletContextName\r
+ });\r
+\r
+ String wsadminFileName = FileUtil.createTempFileName("py");\r
+\r
+ FileUtil.write(wsadminFileName, wsadminContent);\r
+\r
+ String webSphereHome = System.getenv("WAS_HOME");\r
+\r
+ if (_log.isInfoEnabled()) {\r
+ _log.info(\r
+ "Installing plugin by executing " + webSphereHome +\r
+ "\\bin\\wsadmin.bat -f " + wsadminFileName);\r
+ }\r
+\r
+ ProcessBuilder processBuilder = new ProcessBuilder(\r
+ webSphereHome + "\\bin\\wsadmin.bat", "-f", wsadminFileName);\r
+\r
+ processBuilder.redirectErrorStream(true);\r
+\r
+ Process process = processBuilder.start();\r
+\r
+ if (_log.isInfoEnabled()) {\r
+ InputStream inputStream = process.getInputStream();\r
+\r
+ String output = StringUtil.read(inputStream);\r
+\r
+ for (String line : StringUtil.split(output, CharPool.NEW_LINE)) {\r
+ _log.info("Process output: " + line);\r
+ }\r
+\r
+ inputStream.close();\r
+\r
+ int exitValue = process.exitValue();\r
+\r
+ if (exitValue == 0) {\r
+ _log.info(\r
+ "Successfully executed command with an exit value of " +\r
+ exitValue);\r
+ }\r
+ else {\r
+ _log.info(\r
+ "Unsuccessfully executed command with an exit value of " +\r
+ exitValue);\r
+ }\r
+ }\r
+\r
+ FileUtil.delete(wsadminFileName);\r
+ }\r
+\r
+ public Map<String, String> processPluginPackageProperties(\r
+ File srcFile, String displayName, PluginPackage pluginPackage)\r
+ throws Exception {\r
+\r
+ if (pluginPackage == null) {\r
+ return null;\r
+ }\r
+\r
+ Properties properties = getPluginPackageProperties(srcFile);\r
+\r
+ if ((properties == null) || (properties.size() == 0)) {\r
+ return null;\r
+ }\r
+\r
+ Map<String, String> filterMap = getPluginPackageXmlFilterMap(\r
+ pluginPackage);\r
+\r
+ if (filterMap == null) {\r
+ return null;\r
+ }\r
+\r
+ copyDependencyXml(\r
+ "liferay-plugin-package.xml", srcFile + "/WEB-INF", filterMap,\r
+ true);\r
+\r
+ return filterMap;\r
+ }\r
+\r
+ /**\r
+ * @see {@link PluginPackageUtil#_readPluginPackageServletContext(\r
+ * javax.servlet.ServletContext)}\r
+ */\r
+ public PluginPackage readPluginPackage(File file) {\r
+ if (!file.exists()) {\r
+ return null;\r
+ }\r
+\r
+ InputStream is = null;\r
+ ZipFile zipFile = null;\r
+\r
+ try {\r
+ boolean parseProps = false;\r
+\r
+ if (file.isDirectory()) {\r
+ String path = file.getPath();\r
+\r
+ File pluginPackageXmlFile = new File(\r
+ file.getParent() + "/merge/" + file.getName() +\r
+ "/WEB-INF/liferay-plugin-package.xml");\r
+\r
+ if (pluginPackageXmlFile.exists()) {\r
+ is = new FileInputStream(pluginPackageXmlFile);\r
+ }\r
+ else {\r
+ pluginPackageXmlFile = new File(\r
+ path + "/WEB-INF/liferay-plugin-package.xml");\r
+\r
+ if (pluginPackageXmlFile.exists()) {\r
+ is = new FileInputStream(pluginPackageXmlFile);\r
+ }\r
+ }\r
+\r
+ File pluginPackagePropertiesFile = new File(\r
+ file.getParent() + "/merge/" + file.getName() +\r
+ "/WEB-INF/liferay-plugin-package.properties");\r
+\r
+ if ((is == null) && pluginPackagePropertiesFile.exists()) {\r
+ is = new FileInputStream(pluginPackagePropertiesFile);\r
+\r
+ parseProps = true;\r
+ }\r
+ else {\r
+ pluginPackagePropertiesFile = new File(\r
+ path + "/WEB-INF/liferay-plugin-package.properties");\r
+\r
+ if ((is == null) && pluginPackagePropertiesFile.exists()) {\r
+ is = new FileInputStream(pluginPackagePropertiesFile);\r
+\r
+ parseProps = true;\r
+ }\r
+ }\r
+ }\r
+ else {\r
+ zipFile = new ZipFile(file);\r
+\r
+ File pluginPackageXmlFile = new File(\r
+ file.getParent() + "/merge/" + file.getName() +\r
+ "/WEB-INF/liferay-plugin-package.xml");\r
+\r
+ if (pluginPackageXmlFile.exists()) {\r
+ is = new FileInputStream(pluginPackageXmlFile);\r
+ }\r
+ else {\r
+ ZipEntry zipEntry = zipFile.getEntry(\r
+ "WEB-INF/liferay-plugin-package.xml");\r
+\r
+ if (zipEntry != null) {\r
+ is = zipFile.getInputStream(zipEntry);\r
+ }\r
+ }\r
+\r
+ File pluginPackagePropertiesFile = new File(\r
+ file.getParent() + "/merge/" + file.getName() +\r
+ "/WEB-INF/liferay-plugin-package.properties");\r
+\r
+ if ((is == null) && pluginPackagePropertiesFile.exists()) {\r
+ is = new FileInputStream(pluginPackagePropertiesFile);\r
+\r
+ parseProps = true;\r
+ }\r
+ else {\r
+ ZipEntry zipEntry = zipFile.getEntry(\r
+ "WEB-INF/liferay-plugin-package.properties");\r
+\r
+ if ((is == null) && (zipEntry != null)) {\r
+ is = zipFile.getInputStream(zipEntry);\r
+\r
+ parseProps = true;\r
+ }\r
+ }\r
+ }\r
+\r
+ if (is == null) {\r
+ if (_log.isInfoEnabled()) {\r
+ _log.info(\r
+ file.getPath() + " does not have a " +\r
+ "WEB-INF/liferay-plugin-package.xml or " +\r
+ "WEB-INF/liferay-plugin-package.properties");\r
+ }\r
+\r
+ return null;\r
+ }\r
+\r
+ if (parseProps) {\r
+ String displayName = getDisplayName(file);\r
+\r
+ String propertiesString = StringUtil.read(is);\r
+\r
+ Properties properties = PropertiesUtil.load(propertiesString);\r
+\r
+ return PluginPackageUtil.readPluginPackageProperties(\r
+ displayName, properties);\r
+ }\r
+ else {\r
+ String xml = StringUtil.read(is);\r
+\r
+ xml = XMLFormatter.fixProlog(xml);\r
+\r
+ return PluginPackageUtil.readPluginPackageXml(xml);\r
+ }\r
+ }\r
+ catch (Exception e) {\r
+ _log.error(file.getPath() + ": " + e.toString());\r
+ }\r
+ finally {\r
+ if (is != null) {\r
+ try {\r
+ is.close();\r
+ }\r
+ catch (IOException ioe) {\r
+ }\r
+ }\r
+\r
+ if (zipFile != null) {\r
+ try {\r
+ zipFile.close();\r
+ }\r
+ catch (IOException ioe) {\r
+ }\r
+ }\r
+ }\r
+\r
+ return null;\r
+ }\r
+\r
+ public void rewriteFiles(File srcDir) throws Exception {\r
+ String[] files = FileUtil.listFiles(srcDir + "/WEB-INF/");\r
+\r
+ for (int i = 0; i < files.length; i++) {\r
+ String fileName = GetterUtil.getString(\r
+ FileUtil.getShortFileName(files[i]));\r
+\r
+ // LEP-6415\r
+\r
+ if (fileName.equalsIgnoreCase("mule-config.xml")) {\r
+ continue;\r
+ }\r
+\r
+ String ext = GetterUtil.getString(FileUtil.getExtension(files[i]));\r
+\r
+ if (!ext.equalsIgnoreCase("xml")) {\r
+ continue;\r
+ }\r
+\r
+ // Make sure to rewrite any XML files to include external entities\r
+ // into same file. See LEP-3142.\r
+\r
+ File file = new File(srcDir + "/WEB-INF/" + files[i]);\r
+\r
+ try {\r
+ Document doc = SAXReaderUtil.read(file);\r
+\r
+ String content = doc.formattedString(StringPool.TAB, true);\r
+\r
+ FileUtil.write(file, content);\r
+ }\r
+ catch (Exception e) {\r
+ if (_log.isWarnEnabled()) {\r
+ _log.warn(\r
+ "Unable to format " + file + ": " + e.getMessage());\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ public String secureWebXml(String content) throws Exception {\r
+ Document document = SAXReaderUtil.read(content);\r
+\r
+ Element rootElement = document.getRootElement();\r
+\r
+ List<String> listenerClasses = new ArrayList<String>();\r
+\r
+ List<Element> listenerElements = rootElement.elements("listener");\r
+\r
+ for (Element listenerElement : listenerElements) {\r
+ String listenerClass = GetterUtil.getString(\r
+ listenerElement.elementText("listener-class"));\r
+\r
+ if (listenerClass.equals(\r
+ SecurePluginContextListener.class.getName())) {\r
+\r
+ continue;\r
+ }\r
+\r
+ listenerClasses.add(listenerClass);\r
+\r
+ listenerElement.detach();\r
+ }\r
+\r
+ Element contextParamElement = rootElement.addElement("context-param");\r
+\r
+ DocUtil.add(contextParamElement, "param-name", "portalListenerClasses");\r
+ DocUtil.add(\r
+ contextParamElement, "param-value",\r
+ StringUtil.merge(listenerClasses));\r
+\r
+ List<Element> servletElements = rootElement.elements("servlet");\r
+\r
+ for (Element servletElement : servletElements) {\r
+ Element servletClassElement = servletElement.element(\r
+ "servlet-class");\r
+\r
+ String servletClass = GetterUtil.getString(\r
+ servletClassElement.getText());\r
+\r
+ if (servletClass.equals(PortletServlet.class.getName())) {\r
+ continue;\r
+ }\r
+\r
+ servletClassElement.setText(SecureServlet.class.getName());\r
+\r
+ Element initParamElement = servletElement.addElement("init-param");\r
+\r
+ DocUtil.add(initParamElement, "param-name", "servlet-class");\r
+ DocUtil.add(initParamElement, "param-value", servletClass);\r
+ }\r
+\r
+ return document.compactString();\r
+ }\r
+\r
+ public void setAppServerType(String appServerType) {\r
+ this.appServerType = appServerType;\r
+ }\r
+\r
+ public void setAuiTaglibDTD(String auiTaglibDTD) {\r
+ this.auiTaglibDTD = auiTaglibDTD;\r
+ }\r
+\r
+ public void setBaseDir(String baseDir) {\r
+ this.baseDir = baseDir;\r
+ }\r
+\r
+ public void setDestDir(String destDir) {\r
+ this.destDir = destDir;\r
+ }\r
+\r
+ public void setFilePattern(String filePattern) {\r
+ this.filePattern = filePattern;\r
+ }\r
+\r
+ public void setJars(List<String> jars) {\r
+ this.jars = jars;\r
+ }\r
+\r
+ public void setJbossPrefix(String jbossPrefix) {\r
+ this.jbossPrefix = jbossPrefix;\r
+ }\r
+\r
+ public void setPortletExtTaglibDTD(String portletExtTaglibDTD) {\r
+ this.portletExtTaglibDTD = portletExtTaglibDTD;\r
+ }\r
+\r
+ public void setPortletTaglibDTD(String portletTaglibDTD) {\r
+ this.portletTaglibDTD = portletTaglibDTD;\r
+ }\r
+\r
+ public void setSecurityTaglibDTD(String securityTaglibDTD) {\r
+ this.securityTaglibDTD = securityTaglibDTD;\r
+ }\r
+\r
+ public void setThemeTaglibDTD(String themeTaglibDTD) {\r
+ this.themeTaglibDTD = themeTaglibDTD;\r
+ }\r
+\r
+ public void setTomcatLibDir(String tomcatLibDir) {\r
+ this.tomcatLibDir = tomcatLibDir;\r
+ }\r
+\r
+ public void setUiTaglibDTD(String uiTaglibDTD) {\r
+ this.uiTaglibDTD = uiTaglibDTD;\r
+ }\r
+\r
+ public void setUnpackWar(boolean unpackWar) {\r
+ this.unpackWar = unpackWar;\r
+ }\r
+\r
+ public void setUtilTaglibDTD(String utilTaglibDTD) {\r
+ this.utilTaglibDTD = utilTaglibDTD;\r
+ }\r
+\r
+ public void setWars(List<String> wars) {\r
+ this.wars = wars;\r
+ }\r
+\r
+ public void updateDeployDirectory(File srcFile) throws Exception {\r
+ }\r
+\r
+ public void updateGeronimoWebXml(\r
+ File srcFile, String displayName, PluginPackage pluginPackage)\r
+ throws Exception {\r
+\r
+ if (!appServerType.equals(ServerDetector.GERONIMO_ID)) {\r
+ return;\r
+ }\r
+\r
+ File geronimoWebXml = new File(srcFile + "/WEB-INF/geronimo-web.xml");\r
+\r
+ Document document = SAXReaderUtil.read(geronimoWebXml);\r
+\r
+ Element rootElement = document.getRootElement();\r
+\r
+ Element environmentElement = rootElement.element("environment");\r
+\r
+ Element moduleIdElement = environmentElement.element("moduleId");\r
+\r
+ Element artifactIdElement = moduleIdElement.element("artifactId");\r
+\r
+ artifactIdElement.setText(displayName);\r
+\r
+ Element versionElement = moduleIdElement.element("version");\r
+\r
+ versionElement.setText(pluginPackage.getVersion());\r
+\r
+ String content = document.formattedString();\r
+\r
+ FileUtil.write(geronimoWebXml, content);\r
+\r
+ if (_log.isInfoEnabled()) {\r
+ _log.info("Modifying Geronimo " + geronimoWebXml);\r
+ }\r
+ }\r
+\r
+ public String updateLiferayWebXml(\r
+ double webXmlVersion, File srcFile, String webXmlContent)\r
+ throws Exception {\r
+\r
+ boolean liferayWebXmlEnabled = true;\r
+\r
+ Properties properties = getPluginPackageProperties(srcFile);\r
+\r
+ if (properties != null) {\r
+ liferayWebXmlEnabled = GetterUtil.getBoolean(\r
+ properties.getProperty("liferay-web-xml-enabled"), true);\r
+ }\r
+\r
+ webXmlContent = WebXMLBuilder.organizeWebXML(webXmlContent);\r
+\r
+ int x = webXmlContent.indexOf("<filter>");\r
+ int y = webXmlContent.lastIndexOf("</filter-mapping>");\r
+\r
+ String webXmlFiltersContent = StringPool.BLANK;\r
+\r
+ if ((x == -1) || (y == -1)) {\r
+ x = webXmlContent.lastIndexOf("</display-name>") + 15;\r
+ y = x;\r
+ }\r
+ else {\r
+ if (liferayWebXmlEnabled && (webXmlVersion > 2.3)) {\r
+ webXmlFiltersContent = webXmlContent.substring(x, y + 17);\r
+\r
+ y = y + 17;\r
+ }\r
+ else {\r
+ x = y + 17;\r
+ y = y + 17;\r
+ }\r
+ }\r
+\r
+ if (webXmlVersion < 2.4) {\r
+ webXmlContent =\r
+ webXmlContent.substring(0, x) +\r
+ getExtraFiltersContent(webXmlVersion, srcFile) +\r
+ webXmlContent.substring(y);\r
+\r
+ return webXmlContent;\r
+ }\r
+\r
+ String filtersContent =\r
+ webXmlFiltersContent +\r
+ getExtraFiltersContent(webXmlVersion, srcFile);\r
+\r
+ String liferayWebXmlContent = FileUtil.read(\r
+ DeployUtil.getResourcePath("web.xml"));\r
+\r
+ int z = liferayWebXmlContent.indexOf("</web-app>");\r
+\r
+ liferayWebXmlContent =\r
+ liferayWebXmlContent.substring(0, z) + filtersContent +\r
+ liferayWebXmlContent.substring(z);\r
+\r
+ liferayWebXmlContent = WebXMLBuilder.organizeWebXML(\r
+ liferayWebXmlContent);\r
+\r
+ FileUtil.write(\r
+ srcFile + "/WEB-INF/liferay-web.xml", liferayWebXmlContent);\r
+\r
+ webXmlContent =\r
+ webXmlContent.substring(0, x) + getInvokerFilterContent() +\r
+ webXmlContent.substring(y);\r
+\r
+ return webXmlContent;\r
+ }\r
+\r
+ public void updateWebXml(\r
+ File webXml, File srcFile, String displayName,\r
+ PluginPackage pluginPackage)\r
+ throws Exception {\r
+\r
+ // Check version\r
+\r
+ String content = FileUtil.read(webXml);\r
+\r
+ int x = content.indexOf("<display-name>");\r
+\r
+ if (x != -1) {\r
+ int y = content.indexOf("</display-name>", x);\r
+\r
+ y = content.indexOf(">", y) + 1;\r
+\r
+ content = content.substring(0, x) + content.substring(y);\r
+ }\r
+\r
+ Document document = SAXReaderUtil.read(content);\r
+\r
+ Element rootElement = document.getRootElement();\r
+\r
+ double webXmlVersion = GetterUtil.getDouble(\r
+ rootElement.attributeValue("version"), 2.3);\r
+\r
+ if (!PropsValues.TCK_URL && (webXmlVersion <= 2.3)) {\r
+ throw new AutoDeployException(\r
+ webXml.getName() +\r
+ " must be updated to the Servlet 2.4 specification");\r
+ }\r
+\r
+ // Plugin context listener\r
+\r
+ StringBundler sb = new StringBundler(5);\r
+\r
+ sb.append("<listener>");\r
+ sb.append("<listener-class>");\r
+\r
+ boolean securityManagerEnabled = false;\r
+\r
+ Properties properties = getPluginPackageProperties(srcFile);\r
+\r
+ if (properties != null) {\r
+ securityManagerEnabled = GetterUtil.getBoolean(\r
+ properties.getProperty("security-manager-enabled"));\r
+ }\r
+\r
+ if (securityManagerEnabled) {\r
+ sb.append(SecurePluginContextListener.class.getName());\r
+ }\r
+ else {\r
+ sb.append(PluginContextListener.class.getName());\r
+ }\r
+\r
+ sb.append("</listener-class>");\r
+ sb.append("</listener>");\r
+\r
+ String pluginContextListenerContent = sb.toString();\r
+\r
+ // Merge content\r
+\r
+ String extraContent = getExtraContent(\r
+ webXmlVersion, srcFile, displayName);\r
+\r
+ int pos = content.indexOf("<listener>");\r
+\r
+ if (pos == -1) {\r
+ pos = content.indexOf("</web-app>");\r
+ }\r
+\r
+ String newContent =\r
+ content.substring(0, pos) + pluginContextListenerContent +\r
+ extraContent + content.substring(pos);\r
+\r
+ // Update liferay-web.xml\r
+\r
+ newContent = updateLiferayWebXml(webXmlVersion, srcFile, newContent);\r
+\r
+ // Update web.xml\r
+\r
+ if (securityManagerEnabled) {\r
+ newContent = secureWebXml(newContent);\r
+ }\r
+\r
+ newContent = WebXMLBuilder.organizeWebXML(newContent);\r
+\r
+ FileUtil.write(webXml, newContent, true);\r
+\r
+ if (_log.isInfoEnabled()) {\r
+ _log.info("Modifying Servlet " + webXmlVersion + " " + webXml);\r
+ }\r
+ }\r
+\r
+ protected String appServerType;\r
+ protected String auiTaglibDTD;\r
+ protected String baseDir;\r
+ protected String destDir;\r
+ protected String filePattern;\r
+ protected List<String> jars;\r
+ protected String jbossPrefix;\r
+ protected String portletExtTaglibDTD;\r
+ protected String portletTaglibDTD;\r
+ protected String securityTaglibDTD;\r
+ protected String themeTaglibDTD;\r
+ protected String tomcatLibDir;\r
+ protected String uiTaglibDTD;\r
+ protected boolean unpackWar;\r
+ protected String utilTaglibDTD;\r
+ protected List<String> wars;\r
+\r
+ private static final String _PORTAL_CLASS_LOADER =\r
+ "com.liferay.support.tomcat.loader.PortalClassLoader";\r
+\r
+ private static Log _log = LogFactoryUtil.getLog(BaseDeployer.class);\r
+\r
+}
\ No newline at end of file