001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.tools.deploy;
016    
017    import com.liferay.portal.deploy.DeployUtil;
018    import com.liferay.portal.deploy.auto.AutoDeployer;
019    import com.liferay.portal.kernel.deploy.Deployer;
020    import com.liferay.portal.kernel.deploy.auto.AutoDeployException;
021    import com.liferay.portal.kernel.deploy.auto.context.AutoDeploymentContext;
022    import com.liferay.portal.kernel.log.Log;
023    import com.liferay.portal.kernel.log.LogFactoryUtil;
024    import com.liferay.portal.kernel.plugin.License;
025    import com.liferay.portal.kernel.plugin.PluginPackage;
026    import com.liferay.portal.kernel.servlet.PluginContextListener;
027    import com.liferay.portal.kernel.servlet.PortletServlet;
028    import com.liferay.portal.kernel.servlet.SecurePluginContextListener;
029    import com.liferay.portal.kernel.servlet.SecureServlet;
030    import com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter;
031    import com.liferay.portal.kernel.util.CharPool;
032    import com.liferay.portal.kernel.util.FileUtil;
033    import com.liferay.portal.kernel.util.GetterUtil;
034    import com.liferay.portal.kernel.util.HttpUtil;
035    import com.liferay.portal.kernel.util.PropertiesUtil;
036    import com.liferay.portal.kernel.util.PropsKeys;
037    import com.liferay.portal.kernel.util.ServerDetector;
038    import com.liferay.portal.kernel.util.StringBundler;
039    import com.liferay.portal.kernel.util.StringPool;
040    import com.liferay.portal.kernel.util.StringUtil;
041    import com.liferay.portal.kernel.util.SystemProperties;
042    import com.liferay.portal.kernel.util.TextFormatter;
043    import com.liferay.portal.kernel.util.Time;
044    import com.liferay.portal.kernel.util.Validator;
045    import com.liferay.portal.kernel.xml.Document;
046    import com.liferay.portal.kernel.xml.Element;
047    import com.liferay.portal.kernel.xml.SAXReaderUtil;
048    import com.liferay.portal.plugin.PluginPackageUtil;
049    import com.liferay.portal.tools.WebXMLBuilder;
050    import com.liferay.portal.util.ExtRegistry;
051    import com.liferay.portal.util.InitUtil;
052    import com.liferay.portal.util.PortalUtil;
053    import com.liferay.portal.util.PrefsPropsUtil;
054    import com.liferay.portal.util.PropsUtil;
055    import com.liferay.portal.util.PropsValues;
056    import com.liferay.util.ant.CopyTask;
057    import com.liferay.util.ant.DeleteTask;
058    import com.liferay.util.ant.ExpandTask;
059    import com.liferay.util.ant.UpToDateTask;
060    import com.liferay.util.ant.WarTask;
061    import com.liferay.util.xml.DocUtil;
062    import com.liferay.util.xml.XMLFormatter;
063    
064    import java.io.File;
065    import java.io.FileInputStream;
066    import java.io.IOException;
067    import java.io.InputStream;
068    
069    import java.util.ArrayList;
070    import java.util.HashMap;
071    import java.util.List;
072    import java.util.Map;
073    import java.util.Properties;
074    import java.util.Set;
075    import java.util.zip.ZipEntry;
076    import java.util.zip.ZipFile;
077    
078    import org.apache.oro.io.GlobFilenameFilter;
079    
080    /**
081     * @author Brian Wing Shun Chan
082     * @author Sandeep Soni
083     */
084    public class BaseDeployer implements AutoDeployer, Deployer {
085    
086            public static final String DEPLOY_TO_PREFIX = "DEPLOY_TO__";
087    
088            public static void main(String[] args) {
089                    InitUtil.initWithSpring();
090    
091                    List<String> wars = new ArrayList<String>();
092                    List<String> jars = new ArrayList<String>();
093    
094                    for (String arg : args) {
095                            String fileName = arg.toLowerCase();
096    
097                            if (fileName.endsWith(".war")) {
098                                    wars.add(arg);
099                            }
100                            else if (fileName.endsWith(".jar")) {
101                                    jars.add(arg);
102                            }
103                    }
104    
105                    new BaseDeployer(wars, jars);
106            }
107    
108            public BaseDeployer() {
109            }
110    
111            public BaseDeployer(List<String> wars, List<String> jars) {
112                    baseDir = System.getProperty("deployer.base.dir");
113                    destDir = System.getProperty("deployer.dest.dir");
114                    appServerType = System.getProperty("deployer.app.server.type");
115                    auiTaglibDTD = System.getProperty("deployer.aui.taglib.dtd");
116                    portletTaglibDTD = System.getProperty("deployer.portlet.taglib.dtd");
117                    portletExtTaglibDTD = System.getProperty(
118                            "deployer.portlet.ext.taglib.dtd");
119                    securityTaglibDTD = System.getProperty("deployer.security.taglib.dtd");
120                    themeTaglibDTD = System.getProperty("deployer.theme.taglib.dtd");
121                    uiTaglibDTD = System.getProperty("deployer.ui.taglib.dtd");
122                    utilTaglibDTD = System.getProperty("deployer.util.taglib.dtd");
123                    unpackWar = GetterUtil.getBoolean(
124                            System.getProperty("deployer.unpack.war"), true);
125                    filePattern = System.getProperty("deployer.file.pattern");
126                    jbossPrefix = GetterUtil.getString(
127                            System.getProperty("deployer.jboss.prefix"));
128                    tomcatLibDir = System.getProperty("deployer.tomcat.lib.dir");
129                    this.wars = wars;
130                    this.jars = jars;
131    
132                    checkArguments();
133    
134                    String context = System.getProperty("deployer.context");
135    
136                    try {
137                            deploy(context);
138                    }
139                    catch (Exception e) {
140                            e.printStackTrace();
141                    }
142            }
143    
144            public void addExtJar(List<String> jars, String resource) throws Exception {
145                    Set<String> servletContextNames = ExtRegistry.getServletContextNames();
146    
147                    for (String servletContextName : servletContextNames) {
148                            String extResource =
149                                    "ext-" + servletContextName + resource.substring(3);
150    
151                            String path = DeployUtil.getResourcePath(extResource);
152    
153                            if (_log.isDebugEnabled()) {
154                                    if (path == null) {
155                                            _log.debug("Resource " + extResource + " is not available");
156                                    }
157                                    else {
158                                            _log.debug(
159                                                    "Resource " + extResource + " is available at " + path);
160                                    }
161                            }
162    
163                            if (path != null) {
164                                    jars.add(path);
165                            }
166                    }
167            }
168    
169            public void addRequiredJar(List<String> jars, String resource)
170                    throws Exception {
171    
172                    String path = DeployUtil.getResourcePath(resource);
173    
174                    if (path == null) {
175                            throw new RuntimeException(
176                                    "Resource " + resource + " does not exist");
177                    }
178    
179                    if (_log.isDebugEnabled()) {
180                            _log.debug("Resource " + resource + " is available at " + path);
181                    }
182    
183                    jars.add(path);
184            }
185    
186            public int autoDeploy(AutoDeploymentContext autoDeploymentContext)
187                    throws AutoDeployException {
188    
189                    List<String> wars = new ArrayList<String>();
190    
191                    File file = autoDeploymentContext.getFile();
192    
193                    wars.add(file.getName());
194    
195                    this.wars = wars;
196    
197                    try {
198                            return deployFile(autoDeploymentContext);
199                    }
200                    catch (Exception e) {
201                            throw new AutoDeployException(e);
202                    }
203            }
204    
205            public void checkArguments() {
206                    if (Validator.isNull(baseDir)) {
207                            throw new IllegalArgumentException(
208                                    "The system property deployer.base.dir is not set");
209                    }
210    
211                    if (Validator.isNull(destDir)) {
212                            throw new IllegalArgumentException(
213                                    "The system property deployer.dest.dir is not set");
214                    }
215    
216                    if (Validator.isNull(appServerType)) {
217                            throw new IllegalArgumentException(
218                                    "The system property deployer.app.server.type is not set");
219                    }
220    
221                    if (!appServerType.equals(ServerDetector.GERONIMO_ID) &&
222                            !appServerType.equals(ServerDetector.GLASSFISH_ID) &&
223                            !appServerType.equals(ServerDetector.JBOSS_ID) &&
224                            !appServerType.equals(ServerDetector.JONAS_ID) &&
225                            !appServerType.equals(ServerDetector.JETTY_ID) &&
226                            !appServerType.equals(ServerDetector.OC4J_ID) &&
227                            !appServerType.equals(ServerDetector.RESIN_ID) &&
228                            !appServerType.equals(ServerDetector.TOMCAT_ID) &&
229                            !appServerType.equals(ServerDetector.WEBLOGIC_ID) &&
230                            !appServerType.equals(ServerDetector.WEBSPHERE_ID)) {
231    
232                            throw new IllegalArgumentException(
233                                    appServerType + " is not a valid application server type");
234                    }
235    
236                    if (appServerType.equals(ServerDetector.WEBSPHERE_ID)) {
237                            unpackWar = false;
238                    }
239    
240                    if (Validator.isNotNull(jbossPrefix) &&
241                            !Validator.isNumber(jbossPrefix)) {
242    
243                            jbossPrefix = "1";
244                    }
245            }
246    
247            public void copyDependencyXml(String fileName, String targetDir)
248                    throws Exception {
249    
250                    copyDependencyXml(fileName, targetDir, null);
251            }
252    
253            public void copyDependencyXml(
254                            String fileName, String targetDir, Map<String, String> filterMap)
255                    throws Exception {
256    
257                    copyDependencyXml(fileName, targetDir, filterMap, false);
258            }
259    
260            public void copyDependencyXml(
261                            String fileName, String targetDir, Map<String, String> filterMap,
262                            boolean overwrite)
263                    throws Exception {
264    
265                    DeployUtil.copyDependencyXml(
266                            fileName, targetDir, fileName, filterMap, overwrite);
267            }
268    
269            public void copyJars(File srcFile, PluginPackage pluginPackage)
270                    throws Exception {
271    
272                    for (int i = 0; i < jars.size(); i++) {
273                            String jarFullName = jars.get(i);
274    
275                            String jarName = jarFullName.substring(
276                                    jarFullName.lastIndexOf("/") + 1);
277    
278                            if (!appServerType.equals(ServerDetector.TOMCAT_ID) ||
279                                    (appServerType.equals(ServerDetector.TOMCAT_ID) &&
280                                     !jarFullName.equals("util-java.jar"))) {
281    
282                                    FileUtil.copyFile(
283                                            jarFullName, srcFile + "/WEB-INF/lib/" + jarName, true);
284                            }
285                    }
286    
287                    FileUtil.delete(srcFile + "/WEB-INF/lib/util-jsf.jar");
288            }
289    
290            public void copyPortalDependencies(File srcFile) throws Exception {
291                    Properties properties = getPluginPackageProperties(srcFile);
292    
293                    if (properties == null) {
294                            return;
295                    }
296    
297                    // jars
298    
299                    String[] portalJars = StringUtil.split(
300                            properties.getProperty(
301                                    "portal-dependency-jars",
302                                    properties.getProperty("portal.dependency.jars")));
303    
304                    for (int i = 0; i < portalJars.length; i++) {
305                            String portalJar = portalJars[i].trim();
306    
307                            portalJar = fixPortalDependencyJar(portalJar);
308    
309                            if (_log.isDebugEnabled()) {
310                                    _log.debug("Copy portal JAR " + portalJar);
311                            }
312    
313                            try {
314                                    String portalJarPath = PortalUtil.getPortalLibDir() + portalJar;
315    
316                                    FileUtil.copyFile(
317                                            portalJarPath, srcFile + "/WEB-INF/lib/" + portalJar, true);
318                            }
319                            catch (Exception e) {
320                                    _log.error("Unable to copy portal JAR " + portalJar, e);
321                            }
322                    }
323    
324                    // tlds
325    
326                    String[] portalTlds = StringUtil.split(
327                            properties.getProperty(
328                                    "portal-dependency-tlds",
329                                    properties.getProperty("portal.dependency.tlds")));
330    
331                    for (int i = 0; i < portalTlds.length; i++) {
332                            String portalTld = portalTlds[i].trim();
333    
334                            if (_log.isDebugEnabled()) {
335                                    _log.debug("Copy portal TLD " + portalTld);
336                            }
337    
338                            try {
339                                    String portalTldPath = DeployUtil.getResourcePath(portalTld);
340    
341                                    FileUtil.copyFile(
342                                            portalTldPath, srcFile + "/WEB-INF/tld/" + portalTld, true);
343                            }
344                            catch (Exception e) {
345                                    _log.error("Unable to copy portal TLD " + portalTld, e);
346                            }
347                    }
348    
349                    // commons-logging*.jar
350    
351                    File pluginLibDir = new File(srcFile + "/WEB-INF/lib/");
352    
353                    if (PropsValues.AUTO_DEPLOY_COPY_COMMONS_LOGGING) {
354                            String[] commonsLoggingJars = pluginLibDir.list(
355                                    new GlobFilenameFilter("commons-logging*.jar"));
356    
357                            if ((commonsLoggingJars == null) ||
358                                    (commonsLoggingJars.length == 0)) {
359    
360                                    String portalJarPath =
361                                            PortalUtil.getPortalLibDir() + "commons-logging.jar";
362    
363                                    FileUtil.copyFile(
364                                            portalJarPath, srcFile + "/WEB-INF/lib/commons-logging.jar",
365                                            true);
366                            }
367                    }
368    
369                    // log4j*.jar
370    
371                    if (PropsValues.AUTO_DEPLOY_COPY_LOG4J) {
372                            String[] log4jJars = pluginLibDir.list(
373                                    new GlobFilenameFilter("log4j*.jar"));
374    
375                            if ((log4jJars == null) || (log4jJars.length == 0)) {
376                                    String portalJarPath =
377                                            PortalUtil.getPortalLibDir() + "log4j.jar";
378    
379                                    FileUtil.copyFile(
380                                            portalJarPath, srcFile + "/WEB-INF/lib/log4j.jar", true);
381                            }
382                    }
383            }
384    
385            public void copyProperties(File srcFile, PluginPackage pluginPackage)
386                    throws Exception {
387    
388                    if (PropsValues.AUTO_DEPLOY_COPY_COMMONS_LOGGING) {
389                            copyDependencyXml(
390                                    "logging.properties", srcFile + "/WEB-INF/classes");
391                    }
392    
393                    if (PropsValues.AUTO_DEPLOY_COPY_LOG4J) {
394                            copyDependencyXml("log4j.properties", srcFile + "/WEB-INF/classes");
395                    }
396    
397                    File servicePropertiesFile = new File(
398                            srcFile.getAbsolutePath() + "/WEB-INF/classes/service.properties");
399    
400                    if (servicePropertiesFile.exists()) {
401                            File portletPropertiesFile = new File(
402                                    srcFile.getAbsolutePath() +
403                                            "/WEB-INF/classes/portlet.properties");
404    
405                            if (!portletPropertiesFile.exists()) {
406                                    String pluginPackageName = null;
407    
408                                    if (pluginPackage != null) {
409                                            pluginPackageName = pluginPackage.getName();
410                                    }
411                                    else {
412                                            pluginPackageName = srcFile.getName();
413                                    }
414    
415                                    FileUtil.write(
416                                            portletPropertiesFile,
417                                            "plugin.package.name=" + pluginPackageName);
418                            }
419                    }
420            }
421    
422            public void copyTlds(File srcFile, PluginPackage pluginPackage)
423                    throws Exception {
424    
425                    if (Validator.isNotNull(auiTaglibDTD)) {
426                            FileUtil.copyFile(
427                                    auiTaglibDTD, srcFile + "/WEB-INF/tld/aui.tld", true);
428                    }
429    
430                    if (Validator.isNotNull(portletTaglibDTD)) {
431                            FileUtil.copyFile(
432                                    portletTaglibDTD, srcFile + "/WEB-INF/tld/liferay-portlet.tld",
433                                    true);
434                    }
435    
436                    if (Validator.isNotNull(portletExtTaglibDTD)) {
437                            FileUtil.copyFile(
438                                    portletExtTaglibDTD,
439                                    srcFile + "/WEB-INF/tld/liferay-portlet-ext.tld", true);
440                    }
441    
442                    if (Validator.isNotNull(securityTaglibDTD)) {
443                            FileUtil.copyFile(
444                                    securityTaglibDTD,
445                                    srcFile + "/WEB-INF/tld/liferay-security.tld", true);
446                    }
447    
448                    if (Validator.isNotNull(themeTaglibDTD)) {
449                            FileUtil.copyFile(
450                                    themeTaglibDTD, srcFile + "/WEB-INF/tld/liferay-theme.tld",
451                                    true);
452                    }
453    
454                    if (Validator.isNotNull(uiTaglibDTD)) {
455                            FileUtil.copyFile(
456                                    uiTaglibDTD, srcFile + "/WEB-INF/tld/liferay-ui.tld", true);
457                    }
458    
459                    if (Validator.isNotNull(utilTaglibDTD)) {
460                            FileUtil.copyFile(
461                                    utilTaglibDTD, srcFile + "/WEB-INF/tld/liferay-util.tld", true);
462                    }
463            }
464    
465            public void copyTomcatContextXml(File targetDir) throws Exception {
466                    if (!appServerType.equals(ServerDetector.TOMCAT_ID)) {
467                            return;
468                    }
469    
470                    String contextPath = DeployUtil.getResourcePath("context.xml");
471    
472                    String content = FileUtil.read(contextPath);
473    
474                    if (!PropsValues.AUTO_DEPLOY_UNPACK_WAR) {
475                            content = StringUtil.replace(
476                                    content, "antiResourceLocking=\"true\"", StringPool.BLANK);
477                    }
478    
479                    FileUtil.write(new File(targetDir, "META-INF/context.xml"), content);
480            }
481    
482            public void copyXmls(
483                            File srcFile, String displayName, PluginPackage pluginPackage)
484                    throws Exception {
485    
486                    if (appServerType.equals(ServerDetector.GERONIMO_ID)) {
487                            copyDependencyXml("geronimo-web.xml", srcFile + "/WEB-INF");
488                    }
489                    else if (appServerType.equals(ServerDetector.JBOSS_ID)) {
490                            copyDependencyXml(
491                                    "jboss-deployment-structure.xml", srcFile + "/WEB-INF");
492                    }
493                    else if (appServerType.equals(ServerDetector.WEBLOGIC_ID)) {
494                            copyDependencyXml("weblogic.xml", srcFile + "/WEB-INF");
495                    }
496                    else if (appServerType.equals(ServerDetector.WEBSPHERE_ID)) {
497                            copyDependencyXml("ibm-web-ext.xmi", srcFile + "/WEB-INF");
498                    }
499    
500                    copyDependencyXml("web.xml", srcFile + "/WEB-INF");
501            }
502    
503            public void deploy(String context) throws Exception {
504                    try {
505                            File baseDirFile = new File(baseDir);
506    
507                            File[] files = baseDirFile.listFiles();
508    
509                            if (files == null) {
510                                    return;
511                            }
512    
513                            files = FileUtil.sortFiles(files);
514    
515                            for (int i = 0; i < files.length; i++) {
516                                    File srcFile = files[i];
517    
518                                    String fileName = srcFile.getName().toLowerCase();
519    
520                                    boolean deploy = false;
521    
522                                    if (fileName.endsWith(".war") || fileName.endsWith(".zip")) {
523                                            deploy = true;
524    
525                                            if (wars.size() > 0) {
526                                                    if (!wars.contains(srcFile.getName())) {
527                                                            deploy = false;
528                                                    }
529                                            }
530                                            else if (Validator.isNotNull(filePattern)) {
531                                                    if (!StringUtil.matchesIgnoreCase(
532                                                                    fileName, filePattern)) {
533    
534                                                            deploy = false;
535                                                    }
536                                            }
537                                    }
538    
539                                    if (deploy) {
540                                            AutoDeploymentContext autoDeploymentContext =
541                                                    new AutoDeploymentContext();
542    
543                                            autoDeploymentContext.setContext(context);
544                                            autoDeploymentContext.setFile(srcFile);
545    
546                                            deployFile(autoDeploymentContext);
547                                    }
548                            }
549                    }
550                    catch (Exception e) {
551                            e.printStackTrace();
552                    }
553            }
554    
555            public void deployDirectory(
556                            File srcFile, File mergeDir, File deployDir, String displayName,
557                            boolean overwrite, PluginPackage pluginPackage)
558                    throws Exception {
559    
560                    rewriteFiles(srcFile);
561    
562                    mergeDirectory(mergeDir, srcFile);
563    
564                    processPluginPackageProperties(srcFile, displayName, pluginPackage);
565    
566                    copyJars(srcFile, pluginPackage);
567                    copyProperties(srcFile, pluginPackage);
568                    copyTlds(srcFile, pluginPackage);
569                    copyXmls(srcFile, displayName, pluginPackage);
570                    copyPortalDependencies(srcFile);
571    
572                    updateGeronimoWebXml(srcFile, displayName, pluginPackage);
573    
574                    File webXml = new File(srcFile + "/WEB-INF/web.xml");
575    
576                    updateWebXml(webXml, srcFile, displayName, pluginPackage);
577    
578                    File extLibGlobalDir = new File(
579                            srcFile.getAbsolutePath() + "/WEB-INF/ext-lib/global");
580    
581                    if (extLibGlobalDir.exists()) {
582                            File globalLibDir = new File(PortalUtil.getGlobalLibDir());
583    
584                            CopyTask.copyDirectory(
585                                    extLibGlobalDir, globalLibDir, "*.jar", StringPool.BLANK,
586                                    overwrite, true);
587                    }
588    
589                    File extLibPortalDir = new File(
590                            srcFile.getAbsolutePath() + "/WEB-INF/ext-lib/portal");
591    
592                    if (extLibPortalDir.exists()) {
593                            File portalLibDir = new File(PortalUtil.getPortalLibDir());
594    
595                            CopyTask.copyDirectory(
596                                    extLibPortalDir, portalLibDir, "*.jar", StringPool.BLANK,
597                                    overwrite, true);
598                    }
599    
600                    if ((deployDir == null) || baseDir.equals(destDir)) {
601                            return;
602                    }
603    
604                    updateDeployDirectory(srcFile);
605    
606                    String excludes = StringPool.BLANK;
607    
608                    if (appServerType.equals(ServerDetector.JBOSS_ID)) {
609                            excludes += "**/WEB-INF/lib/log4j.jar,";
610                    }
611                    else if (appServerType.equals(ServerDetector.TOMCAT_ID)) {
612                            String[] libs = FileUtil.listFiles(tomcatLibDir);
613    
614                            for (int i = 0; i < libs.length; i++) {
615                                    excludes += "**/WEB-INF/lib/" + libs[i] + ",";
616                            }
617    
618                            File contextXml = new File(srcFile + "/META-INF/context.xml");
619    
620                            if (contextXml.exists()) {
621                                    String content = FileUtil.read(contextXml);
622    
623                                    if (content.indexOf(_PORTAL_CLASS_LOADER) != -1) {
624                                            excludes += "**/WEB-INF/lib/util-bridges.jar,";
625                                            excludes += "**/WEB-INF/lib/util-java.jar,";
626                                            excludes += "**/WEB-INF/lib/util-taglib.jar,";
627                                    }
628                            }
629    
630                            try {
631    
632                                    // LEP-2990
633    
634                                    Class.forName("javax.el.ELContext");
635    
636                                    excludes += "**/WEB-INF/lib/el-api.jar,";
637                            }
638                            catch (ClassNotFoundException cnfe) {
639                            }
640                    }
641    
642                    // LPS-11268
643    
644                    Properties properties = getPluginPackageProperties(srcFile);
645    
646                    if (properties != null) {
647                            String deployExcludes = properties.getProperty("deploy-excludes");
648    
649                            if (deployExcludes != null) {
650                                    excludes += deployExcludes.trim();
651    
652                                    if (!excludes.endsWith(",")) {
653                                            excludes += ",";
654                                    }
655                            }
656    
657                            deployExcludes = properties.getProperty(
658                                    "deploy-excludes-" + appServerType);
659    
660                            if (deployExcludes != null) {
661                                    excludes += deployExcludes.trim();
662    
663                                    if (!excludes.endsWith(",")) {
664                                            excludes += ",";
665                                    }
666                            }
667                    }
668    
669                    if (_log.isDebugEnabled()) {
670                            _log.debug("Excludes " + excludes);
671                    }
672    
673                    if (!unpackWar) {
674                            File tempDir = new File(
675                                    SystemProperties.get(SystemProperties.TMP_DIR) +
676                                            File.separator + Time.getTimestamp());
677    
678                            excludes += "**/WEB-INF/web.xml";
679    
680                            WarTask.war(srcFile, tempDir, excludes, webXml);
681    
682                            if (isJEEDeploymentEnabled()) {
683                                    File tempWarDir = new File(
684                                            tempDir.getParent(), deployDir.getName());
685    
686                                    if (tempWarDir.exists()) {
687                                            tempWarDir.delete();
688                                    }
689    
690                                    if (!tempDir.renameTo(tempWarDir)) {
691                                            tempWarDir = tempDir;
692                                    }
693    
694                                    DeploymentHandler deploymentHandler = getDeploymentHandler();
695    
696                                    deploymentHandler.deploy(tempWarDir, displayName);
697    
698                                    deploymentHandler.releaseDeploymentManager();
699    
700                                    DeleteTask.deleteDirectory(tempWarDir);
701                            }
702                            else {
703                                    if (!tempDir.renameTo(deployDir)) {
704                                            WarTask.war(srcFile, deployDir, excludes, webXml);
705                                    }
706    
707                                    DeleteTask.deleteDirectory(tempDir);
708                            }
709                    }
710                    else {
711    
712                            // The deployer might only copy files that have been modified.
713                            // However, the deployer always copies and overwrites web.xml after
714                            // the other files have been copied because application servers
715                            // usually detect that a WAR has been modified based on the web.xml
716                            // timestamp.
717    
718                            excludes += "**/WEB-INF/web.xml";
719    
720                            CopyTask.copyDirectory(
721                                    srcFile, deployDir, StringPool.BLANK, excludes, overwrite,
722                                    true);
723    
724                            CopyTask.copyDirectory(
725                                    srcFile, deployDir, "**/WEB-INF/web.xml", StringPool.BLANK,
726                                    true, false);
727    
728                            if (appServerType.equals(ServerDetector.TOMCAT_ID)) {
729    
730                                    // See org.apache.catalina.startup.HostConfig to see how Tomcat
731                                    // checks to make sure that web.xml was modified 5 seconds after
732                                    // WEB-INF
733    
734                                    File deployWebXml = new File(deployDir + "/WEB-INF/web.xml");
735    
736                                    deployWebXml.setLastModified(
737                                            System.currentTimeMillis() + (Time.SECOND * 6));
738                            }
739                    }
740    
741                    if (appServerType.equals(ServerDetector.JETTY_ID)) {
742                            DeployUtil.redeployJetty(displayName);
743                    }
744            }
745    
746            public void deployDirectory(
747                            File srcFile, String displayName, boolean override,
748                            PluginPackage pluginPackage)
749                    throws Exception {
750    
751                    deployDirectory(
752                            srcFile, null, null, displayName, override, pluginPackage);
753            }
754    
755            public int deployFile(AutoDeploymentContext autoDeploymentContext)
756                    throws Exception {
757    
758                    File srcFile = autoDeploymentContext.getFile();
759    
760                    PluginPackage pluginPackage = readPluginPackage(srcFile);
761    
762                    if (_log.isInfoEnabled()) {
763                            _log.info("Deploying " + srcFile.getName());
764                    }
765    
766                    String specifiedContext = autoDeploymentContext.getContext();
767    
768                    String displayName = specifiedContext;
769                    boolean overwrite = false;
770                    String preliminaryContext = specifiedContext;
771    
772                    // The order of priority of the context is: 1.) the specified context,
773                    // 2.) if the file name starts with DEPLOY_TO_PREFIX, use the file name
774                    // after the prefix, or 3.) the recommended deployment context as
775                    // specified in liferay-plugin-package.properties, or 4.) the file name.
776    
777                    if ((specifiedContext != null) &&
778                            srcFile.getName().startsWith(DEPLOY_TO_PREFIX)) {
779    
780                            displayName = srcFile.getName().substring(
781                                    DEPLOY_TO_PREFIX.length(), srcFile.getName().length() - 4);
782    
783                            overwrite = true;
784                            preliminaryContext = displayName;
785                    }
786    
787                    if (preliminaryContext == null) {
788                            preliminaryContext = getDisplayName(srcFile);
789                    }
790    
791                    if (pluginPackage != null) {
792                            if (!PluginPackageUtil.isCurrentVersionSupported(
793                                            pluginPackage.getLiferayVersions())) {
794    
795                                    throw new AutoDeployException(
796                                            srcFile.getName() +
797                                                    " does not support this version of Liferay");
798                            }
799    
800                            if (displayName == null) {
801                                    displayName = pluginPackage.getRecommendedDeploymentContext();
802                            }
803    
804                            if (Validator.isNull(displayName)) {
805                                    displayName = getDisplayName(srcFile);
806                            }
807    
808                            pluginPackage.setContext(displayName);
809    
810                            PluginPackageUtil.updateInstallingPluginPackage(
811                                    preliminaryContext, pluginPackage);
812                    }
813    
814                    String deployDir = null;
815    
816                    if (Validator.isNotNull(displayName)) {
817                            deployDir = displayName + ".war";
818                    }
819                    else {
820                            deployDir = srcFile.getName();
821                            displayName = getDisplayName(srcFile);
822                    }
823    
824                    if (appServerType.equals(ServerDetector.JBOSS_ID)) {
825                            deployDir = jbossPrefix + deployDir;
826                    }
827                    else if (appServerType.equals(ServerDetector.GERONIMO_ID) ||
828                                     appServerType.equals(ServerDetector.GLASSFISH_ID) ||
829                                     appServerType.equals(ServerDetector.JETTY_ID) ||
830                                     appServerType.equals(ServerDetector.JONAS_ID) ||
831                                     appServerType.equals(ServerDetector.OC4J_ID) ||
832                                     appServerType.equals(ServerDetector.RESIN_ID) ||
833                                     appServerType.equals(ServerDetector.TOMCAT_ID) ||
834                                     appServerType.equals(ServerDetector.WEBLOGIC_ID)) {
835    
836                            if (unpackWar) {
837                                    deployDir = deployDir.substring(0, deployDir.length() - 4);
838                            }
839                    }
840    
841                    String destDir = this.destDir;
842    
843                    if (autoDeploymentContext.getDestDir() != null) {
844                            destDir = autoDeploymentContext.getDestDir();
845                    }
846    
847                    File deployDirFile = new File(destDir + "/" + deployDir);
848    
849                    try {
850                            PluginPackage previousPluginPackage = readPluginPackage(
851                                    deployDirFile);
852    
853                            if ((pluginPackage != null) && (previousPluginPackage != null)) {
854                                    String name = pluginPackage.getName();
855                                    String previousVersion = previousPluginPackage.getVersion();
856                                    String version = pluginPackage.getVersion();
857    
858                                    if (_log.isInfoEnabled()) {
859                                            _log.info(
860                                                    "Updating " + name + " from version " +
861                                                            previousVersion + " to version " + version);
862                                    }
863    
864                                    if (pluginPackage.isPreviousVersionThan(
865                                                    previousPluginPackage)) {
866    
867                                            if (_log.isInfoEnabled()) {
868                                                    _log.info(
869                                                            "Not updating " + name + " because version " +
870                                                                    previousVersion + " is newer than version " +
871                                                                            version);
872                                            }
873    
874                                            return AutoDeployer.CODE_SKIP_NEWER_VERSION;
875                                    }
876    
877                                    overwrite = true;
878                            }
879    
880                            File mergeDirFile = new File(
881                                    srcFile.getParent() + "/merge/" + srcFile.getName());
882    
883                            if (srcFile.isDirectory()) {
884                                    deployDirectory(
885                                            srcFile, mergeDirFile, deployDirFile, displayName,
886                                            overwrite, pluginPackage);
887                            }
888                            else {
889                                    boolean deployed = deployFile(
890                                            srcFile, mergeDirFile, deployDirFile, displayName,
891                                            overwrite, pluginPackage);
892    
893                                    if (!deployed) {
894                                            String context = preliminaryContext;
895    
896                                            if (pluginPackage != null) {
897                                                    context = pluginPackage.getContext();
898                                            }
899    
900                                            PluginPackageUtil.endPluginPackageInstallation(context);
901                                    }
902                                    else {
903                                            postDeploy(destDir, deployDir);
904                                    }
905                            }
906    
907                            return AutoDeployer.CODE_DEFAULT;
908                    }
909                    catch (Exception e) {
910                            if (pluginPackage != null) {
911                                    PluginPackageUtil.endPluginPackageInstallation(
912                                            pluginPackage.getContext());
913                            }
914    
915                            throw e;
916                    }
917            }
918    
919            public boolean deployFile(
920                            File srcFile, File mergeDir, File deployDir, String displayName,
921                            boolean overwrite, PluginPackage pluginPackage)
922                    throws Exception {
923    
924                    boolean undeployOnRedeploy = false;
925    
926                    try {
927                            undeployOnRedeploy = PrefsPropsUtil.getBoolean(
928                                    PropsKeys.HOT_UNDEPLOY_ON_REDEPLOY,
929                                    PropsValues.HOT_UNDEPLOY_ON_REDEPLOY);
930                    }
931                    catch (Exception e) {
932    
933                            // This will only happen when running the deploy tool in Ant in the
934                            // classical way where the WAR file is actually massaged and
935                            // packaged.
936    
937                    }
938    
939                    if (undeployOnRedeploy) {
940                            DeployUtil.undeploy(appServerType, deployDir);
941                    }
942    
943                    if (!overwrite && UpToDateTask.isUpToDate(srcFile, deployDir)) {
944                            if (_log.isInfoEnabled()) {
945                                    _log.info(deployDir + " is already up to date");
946                            }
947    
948                            return false;
949                    }
950    
951                    File tempDir = new File(
952                            SystemProperties.get(SystemProperties.TMP_DIR) + File.separator +
953                                    Time.getTimestamp());
954    
955                    ExpandTask.expand(srcFile, tempDir);
956    
957                    deployDirectory(
958                            tempDir, mergeDir, deployDir, displayName, overwrite,
959                            pluginPackage);
960    
961                    DeleteTask.deleteDirectory(tempDir);
962    
963                    return true;
964            }
965    
966            public String downloadJar(String jar) throws Exception {
967                    String tmpDir = SystemProperties.get(SystemProperties.TMP_DIR);
968    
969                    File file = new File(
970                            tmpDir + "/liferay/com/liferay/portal/deploy/dependencies/" + jar);
971    
972                    if (!file.exists()) {
973                            synchronized (this) {
974                                    String url = PropsUtil.get(
975                                            PropsKeys.LIBRARY_DOWNLOAD_URL + jar);
976    
977                                    if (_log.isInfoEnabled()) {
978                                            _log.info("Downloading library from " + url);
979                                    }
980    
981                                    byte[] bytes = HttpUtil.URLtoByteArray(url);
982    
983                                    FileUtil.write(file, bytes);
984                            }
985                    }
986    
987                    return FileUtil.getAbsolutePath(file);
988            }
989    
990            public String fixPortalDependencyJar(String portalJar) {
991                    if (portalJar.equals("antlr.jar")) {
992                            portalJar = "antlr2.jar";
993                    }
994    
995                    return portalJar;
996            }
997    
998            public DeploymentHandler getDeploymentHandler() {
999                    String prefix = "auto.deploy." + ServerDetector.getServerId() + ".jee.";
1000    
1001                    String dmId = PropsUtil.get(prefix + "dm.id");
1002                    String dmUser = PropsUtil.get(prefix + "dm.user");
1003                    String dmPassword = PropsUtil.get(prefix + "dm.passwd");
1004                    String dfClassName = PropsUtil.get(prefix + "df.classname");
1005    
1006                    return new DeploymentHandler(dmId, dmUser, dmPassword, dfClassName);
1007            }
1008    
1009            public String getDisplayName(File srcFile) {
1010                    String displayName = srcFile.getName();
1011    
1012                    if (StringUtil.endsWith(displayName, ".war") ||
1013                            StringUtil.endsWith(displayName, ".xml")) {
1014    
1015                            displayName = displayName.substring(0, displayName.length() - 4);
1016                    }
1017    
1018                    if (appServerType.equals(ServerDetector.JBOSS_ID) &&
1019                            Validator.isNotNull(jbossPrefix) &&
1020                            displayName.startsWith(jbossPrefix)) {
1021    
1022                            displayName = displayName.substring(1);
1023                    }
1024    
1025                    return displayName;
1026            }
1027    
1028            public String getExtraContent(
1029                            double webXmlVersion, File srcFile, String displayName)
1030                    throws Exception {
1031    
1032                    StringBundler sb = new StringBundler();
1033    
1034                    sb.append("<display-name>");
1035                    sb.append(displayName);
1036                    sb.append("</display-name>");
1037    
1038                    if (webXmlVersion < 2.4) {
1039                            sb.append("<context-param>");
1040                            sb.append("<param-name>liferay-invoker-enabled</param-name>");
1041                            sb.append("<param-value>false</param-value>");
1042                            sb.append("</context-param>");
1043                    }
1044    
1045                    sb.append("<listener>");
1046                    sb.append("<listener-class>");
1047                    sb.append("com.liferay.portal.kernel.servlet.");
1048                    sb.append("SerializableSessionAttributeListener");
1049                    sb.append("</listener-class>");
1050                    sb.append("</listener>");
1051    
1052                    File serverConfigWsdd = new File(
1053                            srcFile + "/WEB-INF/server-config.wsdd");
1054    
1055                    if (serverConfigWsdd.exists()) {
1056                            File webXml = new File(srcFile + "/WEB-INF/web.xml");
1057    
1058                            String content = FileUtil.read(webXml);
1059    
1060                            if (!content.contains("axis.servicesPath")) {
1061                                    String remotingContent = FileUtil.read(
1062                                            DeployUtil.getResourcePath("remoting-web.xml"));
1063    
1064                                    sb.append(remotingContent);
1065                            }
1066                    }
1067    
1068                    boolean hasTaglib = false;
1069    
1070                    if (Validator.isNotNull(auiTaglibDTD) ||
1071                            Validator.isNotNull(portletTaglibDTD) ||
1072                            Validator.isNotNull(portletExtTaglibDTD) ||
1073                            Validator.isNotNull(securityTaglibDTD) ||
1074                            Validator.isNotNull(themeTaglibDTD) ||
1075                            Validator.isNotNull(uiTaglibDTD) ||
1076                            Validator.isNotNull(utilTaglibDTD)) {
1077    
1078                            hasTaglib = true;
1079                    }
1080    
1081                    if (hasTaglib && (webXmlVersion > 2.3)) {
1082                            sb.append("<jsp-config>");
1083                    }
1084    
1085                    if (Validator.isNotNull(auiTaglibDTD)) {
1086                            sb.append("<taglib>");
1087                            sb.append("<taglib-uri>http://liferay.com/tld/aui</taglib-uri>");
1088                            sb.append("<taglib-location>");
1089                            sb.append("/WEB-INF/tld/aui.tld");
1090                            sb.append("</taglib-location>");
1091                            sb.append("</taglib>");
1092                    }
1093    
1094                    if (Validator.isNotNull(portletTaglibDTD)) {
1095                            sb.append("<taglib>");
1096                            sb.append(
1097                                    "<taglib-uri>http://java.sun.com/portlet_2_0</taglib-uri>");
1098                            sb.append("<taglib-location>");
1099                            sb.append("/WEB-INF/tld/liferay-portlet.tld");
1100                            sb.append("</taglib-location>");
1101                            sb.append("</taglib>");
1102                    }
1103    
1104                    if (Validator.isNotNull(portletExtTaglibDTD)) {
1105                            sb.append("<taglib>");
1106                            sb.append("<taglib-uri>");
1107                            sb.append("http://liferay.com/tld/portlet");
1108                            sb.append("</taglib-uri>");
1109                            sb.append("<taglib-location>");
1110                            sb.append("/WEB-INF/tld/liferay-portlet-ext.tld");
1111                            sb.append("</taglib-location>");
1112                            sb.append("</taglib>");
1113                    }
1114    
1115                    if (Validator.isNotNull(securityTaglibDTD)) {
1116                            sb.append("<taglib>");
1117                            sb.append("<taglib-uri>");
1118                            sb.append("http://liferay.com/tld/security");
1119                            sb.append("</taglib-uri>");
1120                            sb.append("<taglib-location>");
1121                            sb.append("/WEB-INF/tld/liferay-security.tld");
1122                            sb.append("</taglib-location>");
1123                            sb.append("</taglib>");
1124                    }
1125    
1126                    if (Validator.isNotNull(themeTaglibDTD)) {
1127                            sb.append("<taglib>");
1128                            sb.append("<taglib-uri>http://liferay.com/tld/theme</taglib-uri>");
1129                            sb.append("<taglib-location>");
1130                            sb.append("/WEB-INF/tld/liferay-theme.tld");
1131                            sb.append("</taglib-location>");
1132                            sb.append("</taglib>");
1133                    }
1134    
1135                    if (Validator.isNotNull(uiTaglibDTD)) {
1136                            sb.append("<taglib>");
1137                            sb.append("<taglib-uri>http://liferay.com/tld/ui</taglib-uri>");
1138                            sb.append("<taglib-location>");
1139                            sb.append("/WEB-INF/tld/liferay-ui.tld");
1140                            sb.append("</taglib-location>");
1141                            sb.append("</taglib>");
1142                    }
1143    
1144                    if (Validator.isNotNull(utilTaglibDTD)) {
1145                            sb.append("<taglib>");
1146                            sb.append("<taglib-uri>http://liferay.com/tld/util</taglib-uri>");
1147                            sb.append("<taglib-location>");
1148                            sb.append("/WEB-INF/tld/liferay-util.tld");
1149                            sb.append("</taglib-location>");
1150                            sb.append("</taglib>");
1151                    }
1152    
1153                    if (hasTaglib && (webXmlVersion > 2.3)) {
1154                            sb.append("</jsp-config>");
1155                    }
1156    
1157                    return sb.toString();
1158            }
1159    
1160            public String getExtraFiltersContent(double webXmlVersion, File srcFile)
1161                    throws Exception {
1162    
1163                    return getSessionFiltersContent();
1164            }
1165    
1166            public String getIgnoreFiltersContent(File srcFile) throws Exception {
1167                    boolean ignoreFiltersEnabled = true;
1168    
1169                    Properties properties = getPluginPackageProperties(srcFile);
1170    
1171                    if (properties != null) {
1172                            ignoreFiltersEnabled = GetterUtil.getBoolean(
1173                                    properties.getProperty("ignore-filters-enabled"), true);
1174                    }
1175    
1176                    if (ignoreFiltersEnabled) {
1177                            String ignoreFiltersContent = FileUtil.read(
1178                                    DeployUtil.getResourcePath("ignore-filters-web.xml"));
1179    
1180                            return ignoreFiltersContent;
1181                    }
1182                    else {
1183                            return StringPool.BLANK;
1184                    }
1185            }
1186    
1187            public String getInvokerFilterContent() {
1188                    StringBundler sb = new StringBundler(4);
1189    
1190                    sb.append(getInvokerFilterContent("ERROR"));
1191                    sb.append(getInvokerFilterContent("FORWARD"));
1192                    sb.append(getInvokerFilterContent("INCLUDE"));
1193                    sb.append(getInvokerFilterContent("REQUEST"));
1194    
1195                    return sb.toString();
1196            }
1197    
1198            public String getInvokerFilterContent(String dispatcher) {
1199                    StringBundler sb = new StringBundler(23);
1200    
1201                    sb.append("<filter>");
1202                    sb.append("<filter-name>Invoker Filter - ");
1203                    sb.append(dispatcher);
1204                    sb.append("</filter-name>");
1205                    sb.append("<filter-class>");
1206                    sb.append(InvokerFilter.class.getName());
1207                    sb.append("</filter-class>");
1208                    sb.append("<init-param>");
1209                    sb.append("<param-name>dispatcher</param-name>");
1210                    sb.append("<param-value>");
1211                    sb.append(dispatcher);
1212                    sb.append("</param-value>");
1213                    sb.append("</init-param>");
1214                    sb.append("</filter>");
1215    
1216                    sb.append("<filter-mapping>");
1217                    sb.append("<filter-name>Invoker Filter - ");
1218                    sb.append(dispatcher);
1219                    sb.append("</filter-name>");
1220                    sb.append("<url-pattern>/*</url-pattern>");
1221                    sb.append("<dispatcher>");
1222                    sb.append(dispatcher);
1223                    sb.append("</dispatcher>");
1224                    sb.append("</filter-mapping>");
1225    
1226                    return sb.toString();
1227            }
1228    
1229            public String getPluginPackageLicensesXml(List<License> licenses) {
1230                    if (licenses.isEmpty()) {
1231                            return StringPool.BLANK;
1232                    }
1233    
1234                    StringBundler sb = new StringBundler(5 * licenses.size() + 2);
1235    
1236                    for (int i = 0; i < licenses.size(); i++) {
1237                            License license = licenses.get(i);
1238    
1239                            if (i == 0) {
1240                                    sb.append("\r\n");
1241                            }
1242    
1243                            sb.append("\t\t<license osi-approved=\"");
1244                            sb.append(license.isOsiApproved());
1245                            sb.append("\">");
1246                            sb.append(license.getName());
1247                            sb.append("</license>\r\n");
1248    
1249                            if ((i + 1) == licenses.size()) {
1250                                    sb.append("\t");
1251                            }
1252                    }
1253    
1254                    return sb.toString();
1255            }
1256    
1257            public String getPluginPackageLiferayVersionsXml(
1258                    List<String> liferayVersions) {
1259    
1260                    if (liferayVersions.isEmpty()) {
1261                            return StringPool.BLANK;
1262                    }
1263    
1264                    StringBundler sb = new StringBundler(liferayVersions.size() * 3 + 2);
1265    
1266                    for (int i = 0; i < liferayVersions.size(); i++) {
1267                            String liferayVersion = liferayVersions.get(i);
1268    
1269                            if (i == 0) {
1270                                    sb.append("\r\n");
1271                            }
1272    
1273                            sb.append("\t\t<liferay-version>");
1274                            sb.append(liferayVersion);
1275                            sb.append("</liferay-version>\r\n");
1276    
1277                            if ((i + 1) == liferayVersions.size()) {
1278                                    sb.append("\t");
1279                            }
1280                    }
1281    
1282                    return sb.toString();
1283            }
1284    
1285            public Properties getPluginPackageProperties(File srcFile)
1286                    throws Exception {
1287    
1288                    File propertiesFile = new File(
1289                            srcFile + "/WEB-INF/liferay-plugin-package.properties");
1290    
1291                    if (!propertiesFile.exists()) {
1292                            return null;
1293                    }
1294    
1295                    String propertiesString = FileUtil.read(propertiesFile);
1296    
1297                    return PropertiesUtil.load(propertiesString);
1298            }
1299    
1300            public String getPluginPackageTagsXml(List<String> tags) {
1301                    if (tags.isEmpty()) {
1302                            return StringPool.BLANK;
1303                    }
1304    
1305                    StringBundler sb = new StringBundler(tags.size() * 3 + 2);
1306    
1307                    for (int i = 0; i < tags.size(); i++) {
1308                            String tag = tags.get(i);
1309    
1310                            if (i == 0) {
1311                                    sb.append("\r\n");
1312                            }
1313    
1314                            sb.append("\t\t<tag>");
1315                            sb.append(tag);
1316                            sb.append("</tag>\r\n");
1317    
1318                            if ((i + 1) == tags.size()) {
1319                                    sb.append("\t");
1320                            }
1321                    }
1322    
1323                    return sb.toString();
1324            }
1325    
1326            public Map<String, String> getPluginPackageXmlFilterMap(
1327                    PluginPackage pluginPackage) {
1328    
1329                    List<String> pluginTypes = pluginPackage.getTypes();
1330    
1331                    String pluginType = pluginTypes.get(0);
1332    
1333                    if (!pluginType.equals(getPluginType())) {
1334                            return null;
1335                    }
1336    
1337                    Map<String, String> filterMap = new HashMap<String, String>();
1338    
1339                    filterMap.put("module_group_id", pluginPackage.getGroupId());
1340                    filterMap.put("module_artifact_id", pluginPackage.getArtifactId());
1341                    filterMap.put("module_version", pluginPackage.getVersion());
1342    
1343                    filterMap.put("plugin_name", pluginPackage.getName());
1344                    filterMap.put("plugin_type", pluginType);
1345                    filterMap.put(
1346                            "plugin_type_name",
1347                            TextFormatter.format(pluginType, TextFormatter.J));
1348    
1349                    filterMap.put("tags", getPluginPackageTagsXml(pluginPackage.getTags()));
1350                    filterMap.put("short_description", pluginPackage.getShortDescription());
1351                    filterMap.put("long_description", pluginPackage.getLongDescription());
1352                    filterMap.put("change_log", pluginPackage.getChangeLog());
1353                    filterMap.put("page_url", pluginPackage.getPageURL());
1354                    filterMap.put("author", pluginPackage.getAuthor());
1355                    filterMap.put(
1356                            "licenses",
1357                            getPluginPackageLicensesXml(pluginPackage.getLicenses()));
1358                    filterMap.put(
1359                            "liferay_versions",
1360                            getPluginPackageLiferayVersionsXml(
1361                                    pluginPackage.getLiferayVersions()));
1362    
1363                    return filterMap;
1364            }
1365    
1366            public String getPluginType() {
1367                    return null;
1368            }
1369    
1370            public String getServletContextIncludeFiltersContent(
1371                            double webXmlVersion, File srcFile)
1372                    throws Exception {
1373    
1374                    if (webXmlVersion < 2.4) {
1375                            return StringPool.BLANK;
1376                    }
1377    
1378                    Properties properties = getPluginPackageProperties(srcFile);
1379    
1380                    if (properties == null) {
1381                            return StringPool.BLANK;
1382                    }
1383    
1384                    if (!GetterUtil.getBoolean(
1385                                    properties.getProperty(
1386                                            "servlet-context-include-filters-enabled"), true)) {
1387    
1388                            return StringPool.BLANK;
1389                    }
1390    
1391                    return FileUtil.read(
1392                            DeployUtil.getResourcePath(
1393                                    "servlet-context-include-filters-web.xml"));
1394            }
1395    
1396            public String getSessionFiltersContent() throws Exception {
1397                    String sessionFiltersContent = FileUtil.read(
1398                            DeployUtil.getResourcePath("session-filters-web.xml"));
1399    
1400                    return sessionFiltersContent;
1401            }
1402    
1403            public String getSpeedFiltersContent(File srcFile) throws Exception {
1404                    boolean speedFiltersEnabled = true;
1405    
1406                    Properties properties = getPluginPackageProperties(srcFile);
1407    
1408                    if (properties != null) {
1409                            speedFiltersEnabled = GetterUtil.getBoolean(
1410                                    properties.getProperty("speed-filters-enabled"), true);
1411                    }
1412    
1413                    if (speedFiltersEnabled) {
1414                            String speedFiltersContent = FileUtil.read(
1415                                    DeployUtil.getResourcePath("speed-filters-web.xml"));
1416    
1417                            return speedFiltersContent;
1418                    }
1419                    else {
1420                            return StringPool.BLANK;
1421                    }
1422            }
1423    
1424            public boolean isJEEDeploymentEnabled() {
1425                    return GetterUtil.getBoolean(PropsUtil.get(
1426                            "auto.deploy." + ServerDetector.getServerId() +
1427                                    ".jee.deployment.enabled"));
1428            }
1429    
1430            public void mergeDirectory(File mergeDir, File targetDir) {
1431                    if ((mergeDir == null) || !mergeDir.exists()) {
1432                            return;
1433                    }
1434    
1435                    CopyTask.copyDirectory(mergeDir, targetDir, null, null, true, false);
1436            }
1437    
1438            public void postDeploy(String destDir, String deployDir) throws Exception {
1439                    if (appServerType.equals(ServerDetector.GLASSFISH_ID)) {
1440                            postDeployGlassfish(destDir, deployDir);
1441                    }
1442                    else if (appServerType.equals(ServerDetector.JBOSS_ID)) {
1443                            postDeployJBoss(destDir, deployDir);
1444                    }
1445                    else if (appServerType.equals(ServerDetector.WEBSPHERE_ID)) {
1446                            postDeployWebSphere(destDir, deployDir);
1447                    }
1448            }
1449    
1450            public void postDeployGlassfish(String destDir, String deployDir)
1451                    throws Exception {
1452    
1453                    FileUtil.delete(destDir + "/.autodeploystatus/" + deployDir);
1454            }
1455    
1456            public void postDeployJBoss(String destDir, String deployDir)
1457                    throws Exception {
1458    
1459                    FileUtil.write(
1460                            destDir + "/" + deployDir + ".dodeploy", StringPool.BLANK);
1461            }
1462    
1463            public void postDeployWebSphere(String destDir, String deployDir)
1464                    throws Exception {
1465    
1466                    if (Validator.isNull(
1467                                    PropsValues.AUTO_DEPLOY_WEBSPHERE_WSADMIN_APP_MANAGER_QUERY)) {
1468    
1469                            if (_log.isInfoEnabled()) {
1470                                    StringBundler sb = new StringBundler();
1471    
1472                                    sb.append("Do not install the plugin with wsadmin since the ");
1473                                    sb.append("property \"");
1474                                    sb.append(
1475                                            PropsKeys.AUTO_DEPLOY_WEBSPHERE_WSADMIN_APP_MANAGER_QUERY);
1476                                    sb.append("\"is not configured");
1477    
1478                                    _log.info(sb.toString());
1479                            }
1480    
1481                            return;
1482                    }
1483    
1484                    String wsadminContent = FileUtil.read(
1485                            DeployUtil.getResourcePath("wsadmin.py"));
1486    
1487                    String pluginServletContextName = deployDir.substring(
1488                            0, deployDir.length() - 4);
1489    
1490                    wsadminContent = StringUtil.replace(
1491                            wsadminContent,
1492                            new String[] {
1493                                    "${auto.deploy.dest.dir}",
1494                                    "${auto.deploy.websphere.wsadmin.app.manager.query}",
1495                                    "${plugin.servlet.context.name}"
1496                            },
1497                            new String[] {
1498                                    destDir,
1499                                    PropsValues.AUTO_DEPLOY_WEBSPHERE_WSADMIN_APP_MANAGER_QUERY,
1500                                    pluginServletContextName
1501                            });
1502    
1503                    String wsadminFileName = FileUtil.createTempFileName("py");
1504    
1505                    FileUtil.write(wsadminFileName, wsadminContent);
1506    
1507                    String webSphereHome = System.getenv("WAS_HOME");
1508    
1509                    if (_log.isInfoEnabled()) {
1510                            _log.info(
1511                                    "Installing plugin by executing " + webSphereHome +
1512                                            "\\bin\\wsadmin.bat -f " + wsadminFileName);
1513                    }
1514    
1515                    ProcessBuilder processBuilder = new ProcessBuilder(
1516                            webSphereHome + "\\bin\\wsadmin.bat", "-f", wsadminFileName);
1517    
1518                    processBuilder.redirectErrorStream(true);
1519    
1520                    Process process = processBuilder.start();
1521    
1522                    if (_log.isInfoEnabled()) {
1523                            InputStream inputStream = process.getInputStream();
1524    
1525                            String output = StringUtil.read(inputStream);
1526    
1527                            for (String line : StringUtil.split(output, CharPool.NEW_LINE)) {
1528                                    _log.info("Process output: " + line);
1529                            }
1530    
1531                            inputStream.close();
1532    
1533                            int exitValue = process.exitValue();
1534    
1535                            if (exitValue == 0) {
1536                                    _log.info(
1537                                            "Successfully executed command with an exit value of " +
1538                                                    exitValue);
1539                            }
1540                            else {
1541                                    _log.info(
1542                                            "Unsuccessfully executed command with an exit value of " +
1543                                                    exitValue);
1544                            }
1545                    }
1546    
1547                    FileUtil.delete(wsadminFileName);
1548            }
1549    
1550            public Map<String, String> processPluginPackageProperties(
1551                            File srcFile, String displayName, PluginPackage pluginPackage)
1552                    throws Exception {
1553    
1554                    if (pluginPackage == null) {
1555                            return null;
1556                    }
1557    
1558                    Properties properties = getPluginPackageProperties(srcFile);
1559    
1560                    if ((properties == null) || (properties.size() == 0)) {
1561                            return null;
1562                    }
1563    
1564                    Map<String, String> filterMap = getPluginPackageXmlFilterMap(
1565                            pluginPackage);
1566    
1567                    if (filterMap == null) {
1568                            return null;
1569                    }
1570    
1571                    copyDependencyXml(
1572                            "liferay-plugin-package.xml", srcFile + "/WEB-INF", filterMap,
1573                            true);
1574    
1575                    return filterMap;
1576            }
1577    
1578            /**
1579             * @see {@link PluginPackageUtil#_readPluginPackageServletContext(
1580             *      javax.servlet.ServletContext)}
1581             */
1582            public PluginPackage readPluginPackage(File file) {
1583                    if (!file.exists()) {
1584                            return null;
1585                    }
1586    
1587                    InputStream is = null;
1588                    ZipFile zipFile = null;
1589    
1590                    try {
1591                            boolean parseProps = false;
1592    
1593                            if (file.isDirectory()) {
1594                                    String path = file.getPath();
1595    
1596                                    File pluginPackageXmlFile = new File(
1597                                            file.getParent() + "/merge/" + file.getName() +
1598                                                    "/WEB-INF/liferay-plugin-package.xml");
1599    
1600                                    if (pluginPackageXmlFile.exists()) {
1601                                            is = new FileInputStream(pluginPackageXmlFile);
1602                                    }
1603                                    else {
1604                                            pluginPackageXmlFile = new File(
1605                                                    path + "/WEB-INF/liferay-plugin-package.xml");
1606    
1607                                            if (pluginPackageXmlFile.exists()) {
1608                                                    is = new FileInputStream(pluginPackageXmlFile);
1609                                            }
1610                                    }
1611    
1612                                    File pluginPackagePropertiesFile = new File(
1613                                            file.getParent() + "/merge/" + file.getName() +
1614                                                    "/WEB-INF/liferay-plugin-package.properties");
1615    
1616                                    if ((is == null) && pluginPackagePropertiesFile.exists()) {
1617                                            is = new FileInputStream(pluginPackagePropertiesFile);
1618    
1619                                            parseProps = true;
1620                                    }
1621                                    else {
1622                                            pluginPackagePropertiesFile = new File(
1623                                                    path + "/WEB-INF/liferay-plugin-package.properties");
1624    
1625                                            if ((is == null) && pluginPackagePropertiesFile.exists()) {
1626                                                    is = new FileInputStream(pluginPackagePropertiesFile);
1627    
1628                                                    parseProps = true;
1629                                            }
1630                                    }
1631                            }
1632                            else {
1633                                    zipFile = new ZipFile(file);
1634    
1635                                    File pluginPackageXmlFile = new File(
1636                                            file.getParent() + "/merge/" + file.getName() +
1637                                                    "/WEB-INF/liferay-plugin-package.xml");
1638    
1639                                    if (pluginPackageXmlFile.exists()) {
1640                                            is = new FileInputStream(pluginPackageXmlFile);
1641                                    }
1642                                    else {
1643                                            ZipEntry zipEntry = zipFile.getEntry(
1644                                                    "WEB-INF/liferay-plugin-package.xml");
1645    
1646                                            if (zipEntry != null) {
1647                                                    is = zipFile.getInputStream(zipEntry);
1648                                            }
1649                                    }
1650    
1651                                    File pluginPackagePropertiesFile = new File(
1652                                            file.getParent() + "/merge/" + file.getName() +
1653                                                    "/WEB-INF/liferay-plugin-package.properties");
1654    
1655                                    if ((is == null) && pluginPackagePropertiesFile.exists()) {
1656                                            is = new FileInputStream(pluginPackagePropertiesFile);
1657    
1658                                            parseProps = true;
1659                                    }
1660                                    else {
1661                                            ZipEntry zipEntry = zipFile.getEntry(
1662                                                    "WEB-INF/liferay-plugin-package.properties");
1663    
1664                                            if ((is == null) && (zipEntry != null)) {
1665                                                    is = zipFile.getInputStream(zipEntry);
1666    
1667                                                    parseProps = true;
1668                                            }
1669                                    }
1670                            }
1671    
1672                            if (is == null) {
1673                                    if (_log.isInfoEnabled()) {
1674                                            _log.info(
1675                                                    file.getPath() + " does not have a " +
1676                                                            "WEB-INF/liferay-plugin-package.xml or " +
1677                                                                    "WEB-INF/liferay-plugin-package.properties");
1678                                    }
1679    
1680                                    return null;
1681                            }
1682    
1683                            if (parseProps) {
1684                                    String displayName = getDisplayName(file);
1685    
1686                                    String propertiesString = StringUtil.read(is);
1687    
1688                                    Properties properties = PropertiesUtil.load(propertiesString);
1689    
1690                                    return PluginPackageUtil.readPluginPackageProperties(
1691                                            displayName, properties);
1692                            }
1693                            else {
1694                                    String xml = StringUtil.read(is);
1695    
1696                                    xml = XMLFormatter.fixProlog(xml);
1697    
1698                                    return PluginPackageUtil.readPluginPackageXml(xml);
1699                            }
1700                    }
1701                    catch (Exception e) {
1702                            _log.error(file.getPath() + ": " + e.toString());
1703                    }
1704                    finally {
1705                            if (is != null) {
1706                                    try {
1707                                            is.close();
1708                                    }
1709                                    catch (IOException ioe) {
1710                                    }
1711                            }
1712    
1713                            if (zipFile != null) {
1714                                    try {
1715                                            zipFile.close();
1716                                    }
1717                                    catch (IOException ioe) {
1718                                    }
1719                            }
1720                    }
1721    
1722                    return null;
1723            }
1724    
1725            public void rewriteFiles(File srcDir) throws Exception {
1726                    String[] files = FileUtil.listFiles(srcDir + "/WEB-INF/");
1727    
1728                    for (int i = 0; i < files.length; i++) {
1729                            String fileName = GetterUtil.getString(
1730                                    FileUtil.getShortFileName(files[i]));
1731    
1732                            // LEP-6415
1733    
1734                            if (fileName.equalsIgnoreCase("mule-config.xml")) {
1735                                    continue;
1736                            }
1737    
1738                            String ext = GetterUtil.getString(FileUtil.getExtension(files[i]));
1739    
1740                            if (!ext.equalsIgnoreCase("xml")) {
1741                                    continue;
1742                            }
1743    
1744                            // Make sure to rewrite any XML files to include external entities
1745                            // into same file. See LEP-3142.
1746    
1747                            File file = new File(srcDir + "/WEB-INF/" + files[i]);
1748    
1749                            try {
1750                                    Document doc = SAXReaderUtil.read(file);
1751    
1752                                    String content = doc.formattedString(StringPool.TAB, true);
1753    
1754                                    FileUtil.write(file, content);
1755                            }
1756                            catch (Exception e) {
1757                                    if (_log.isWarnEnabled()) {
1758                                            _log.warn(
1759                                                    "Unable to format " + file + ": " + e.getMessage());
1760                                    }
1761                            }
1762                    }
1763            }
1764    
1765            public String secureWebXml(String content) throws Exception {
1766                    Document document = SAXReaderUtil.read(content);
1767    
1768                    Element rootElement = document.getRootElement();
1769    
1770                    List<String> listenerClasses = new ArrayList<String>();
1771    
1772                    List<Element> listenerElements = rootElement.elements("listener");
1773    
1774                    for (Element listenerElement : listenerElements) {
1775                            String listenerClass = GetterUtil.getString(
1776                                    listenerElement.elementText("listener-class"));
1777    
1778                            if (listenerClass.equals(
1779                                            SecurePluginContextListener.class.getName())) {
1780    
1781                                    continue;
1782                            }
1783    
1784                            listenerClasses.add(listenerClass);
1785    
1786                            listenerElement.detach();
1787                    }
1788    
1789                    Element contextParamElement = rootElement.addElement("context-param");
1790    
1791                    DocUtil.add(contextParamElement, "param-name", "portalListenerClasses");
1792                    DocUtil.add(
1793                            contextParamElement, "param-value",
1794                            StringUtil.merge(listenerClasses));
1795    
1796                    List<Element> servletElements = rootElement.elements("servlet");
1797    
1798                    for (Element servletElement : servletElements) {
1799                            Element servletClassElement = servletElement.element(
1800                                    "servlet-class");
1801    
1802                            String servletClass = GetterUtil.getString(
1803                                    servletClassElement.getText());
1804    
1805                            if (servletClass.equals(PortletServlet.class.getName())) {
1806                                    continue;
1807                            }
1808    
1809                            servletClassElement.setText(SecureServlet.class.getName());
1810    
1811                            Element initParamElement = servletElement.addElement("init-param");
1812    
1813                            DocUtil.add(initParamElement, "param-name", "servlet-class");
1814                            DocUtil.add(initParamElement, "param-value", servletClass);
1815                    }
1816    
1817                    return document.compactString();
1818            }
1819    
1820            public void setAppServerType(String appServerType) {
1821                    this.appServerType = appServerType;
1822            }
1823    
1824            public void setAuiTaglibDTD(String auiTaglibDTD) {
1825                    this.auiTaglibDTD = auiTaglibDTD;
1826            }
1827    
1828            public void setBaseDir(String baseDir) {
1829                    this.baseDir = baseDir;
1830            }
1831    
1832            public void setDestDir(String destDir) {
1833                    this.destDir = destDir;
1834            }
1835    
1836            public void setFilePattern(String filePattern) {
1837                    this.filePattern = filePattern;
1838            }
1839    
1840            public void setJars(List<String> jars) {
1841                    this.jars = jars;
1842            }
1843    
1844            public void setJbossPrefix(String jbossPrefix) {
1845                    this.jbossPrefix = jbossPrefix;
1846            }
1847    
1848            public void setPortletExtTaglibDTD(String portletExtTaglibDTD) {
1849                    this.portletExtTaglibDTD = portletExtTaglibDTD;
1850            }
1851    
1852            public void setPortletTaglibDTD(String portletTaglibDTD) {
1853                    this.portletTaglibDTD = portletTaglibDTD;
1854            }
1855    
1856            public void setSecurityTaglibDTD(String securityTaglibDTD) {
1857                    this.securityTaglibDTD = securityTaglibDTD;
1858            }
1859    
1860            public void setThemeTaglibDTD(String themeTaglibDTD) {
1861                    this.themeTaglibDTD = themeTaglibDTD;
1862            }
1863    
1864            public void setTomcatLibDir(String tomcatLibDir) {
1865                    this.tomcatLibDir = tomcatLibDir;
1866            }
1867    
1868            public void setUiTaglibDTD(String uiTaglibDTD) {
1869                    this.uiTaglibDTD = uiTaglibDTD;
1870            }
1871    
1872            public void setUnpackWar(boolean unpackWar) {
1873                    this.unpackWar = unpackWar;
1874            }
1875    
1876            public void setUtilTaglibDTD(String utilTaglibDTD) {
1877                    this.utilTaglibDTD = utilTaglibDTD;
1878            }
1879    
1880            public void setWars(List<String> wars) {
1881                    this.wars = wars;
1882            }
1883    
1884            public void updateDeployDirectory(File srcFile) throws Exception {
1885            }
1886    
1887            public void updateGeronimoWebXml(
1888                            File srcFile, String displayName, PluginPackage pluginPackage)
1889                    throws Exception {
1890    
1891                    if (!appServerType.equals(ServerDetector.GERONIMO_ID)) {
1892                            return;
1893                    }
1894    
1895                    File geronimoWebXml = new File(srcFile + "/WEB-INF/geronimo-web.xml");
1896    
1897                    Document document = SAXReaderUtil.read(geronimoWebXml);
1898    
1899                    Element rootElement = document.getRootElement();
1900    
1901                    Element environmentElement = rootElement.element("environment");
1902    
1903                    Element moduleIdElement = environmentElement.element("moduleId");
1904    
1905                    Element artifactIdElement = moduleIdElement.element("artifactId");
1906    
1907                    artifactIdElement.setText(displayName);
1908    
1909                    Element versionElement = moduleIdElement.element("version");
1910    
1911                    versionElement.setText(pluginPackage.getVersion());
1912    
1913                    String content = document.formattedString();
1914    
1915                    FileUtil.write(geronimoWebXml, content);
1916    
1917                    if (_log.isInfoEnabled()) {
1918                            _log.info("Modifying Geronimo " + geronimoWebXml);
1919                    }
1920            }
1921    
1922            public String updateLiferayWebXml(
1923                            double webXmlVersion, File srcFile, String webXmlContent)
1924                    throws Exception {
1925    
1926                    boolean liferayWebXmlEnabled = true;
1927    
1928                    Properties properties = getPluginPackageProperties(srcFile);
1929    
1930                    if (properties != null) {
1931                            liferayWebXmlEnabled = GetterUtil.getBoolean(
1932                                    properties.getProperty("liferay-web-xml-enabled"), true);
1933                    }
1934    
1935                    webXmlContent = WebXMLBuilder.organizeWebXML(webXmlContent);
1936    
1937                    int x = webXmlContent.indexOf("<filter>");
1938                    int y = webXmlContent.lastIndexOf("</filter-mapping>");
1939    
1940                    String webXmlFiltersContent = StringPool.BLANK;
1941    
1942                    if ((x == -1) || (y == -1)) {
1943                            x = webXmlContent.lastIndexOf("</display-name>") + 15;
1944                            y = x;
1945                    }
1946                    else {
1947                            if (liferayWebXmlEnabled && (webXmlVersion > 2.3)) {
1948                                    webXmlFiltersContent = webXmlContent.substring(x, y + 17);
1949    
1950                                    y = y + 17;
1951                            }
1952                            else {
1953                                    x = y + 17;
1954                                    y = y + 17;
1955                            }
1956                    }
1957    
1958                    if (webXmlVersion < 2.4) {
1959                            webXmlContent =
1960                                    webXmlContent.substring(0, x) +
1961                                            getExtraFiltersContent(webXmlVersion, srcFile) +
1962                                                    webXmlContent.substring(y);
1963    
1964                            return webXmlContent;
1965                    }
1966    
1967                    String filtersContent =
1968                            webXmlFiltersContent +
1969                                    getExtraFiltersContent(webXmlVersion, srcFile);
1970    
1971                    String liferayWebXmlContent = FileUtil.read(
1972                            DeployUtil.getResourcePath("web.xml"));
1973    
1974                    int z = liferayWebXmlContent.indexOf("</web-app>");
1975    
1976                    liferayWebXmlContent =
1977                            liferayWebXmlContent.substring(0, z) + filtersContent +
1978                                    liferayWebXmlContent.substring(z);
1979    
1980                    liferayWebXmlContent = WebXMLBuilder.organizeWebXML(
1981                            liferayWebXmlContent);
1982    
1983                    FileUtil.write(
1984                            srcFile + "/WEB-INF/liferay-web.xml", liferayWebXmlContent);
1985    
1986                    webXmlContent =
1987                            webXmlContent.substring(0, x) + getInvokerFilterContent() +
1988                                    webXmlContent.substring(y);
1989    
1990                    return webXmlContent;
1991            }
1992    
1993            public void updateWebXml(
1994                            File webXml, File srcFile, String displayName,
1995                            PluginPackage pluginPackage)
1996                    throws Exception {
1997    
1998                    // Check version
1999    
2000                    String content = FileUtil.read(webXml);
2001    
2002                    int x = content.indexOf("<display-name>");
2003    
2004                    if (x != -1) {
2005                            int y = content.indexOf("</display-name>", x);
2006    
2007                            y = content.indexOf(">", y) + 1;
2008    
2009                            content = content.substring(0, x) + content.substring(y);
2010                    }
2011    
2012                    Document document = SAXReaderUtil.read(content);
2013    
2014                    Element rootElement = document.getRootElement();
2015    
2016                    double webXmlVersion = GetterUtil.getDouble(
2017                            rootElement.attributeValue("version"), 2.3);
2018    
2019                    if (!PropsValues.TCK_URL && (webXmlVersion <= 2.3)) {
2020                            throw new AutoDeployException(
2021                                    webXml.getName() +
2022                                            " must be updated to the Servlet 2.4 specification");
2023                    }
2024    
2025                    // Plugin context listener
2026    
2027                    StringBundler sb = new StringBundler(5);
2028    
2029                    sb.append("<listener>");
2030                    sb.append("<listener-class>");
2031    
2032                    boolean securityManagerEnabled = false;
2033    
2034                    Properties properties = getPluginPackageProperties(srcFile);
2035    
2036                    if (properties != null) {
2037                            securityManagerEnabled = GetterUtil.getBoolean(
2038                                    properties.getProperty("security-manager-enabled"));
2039                    }
2040    
2041                    if (securityManagerEnabled) {
2042                            sb.append(SecurePluginContextListener.class.getName());
2043                    }
2044                    else {
2045                            sb.append(PluginContextListener.class.getName());
2046                    }
2047    
2048                    sb.append("</listener-class>");
2049                    sb.append("</listener>");
2050    
2051                    String pluginContextListenerContent = sb.toString();
2052    
2053                    // Merge content
2054    
2055                    String extraContent = getExtraContent(
2056                            webXmlVersion, srcFile, displayName);
2057    
2058                    int pos = content.indexOf("<listener>");
2059    
2060                    if (pos == -1) {
2061                            pos = content.indexOf("</web-app>");
2062                    }
2063    
2064                    String newContent =
2065                            content.substring(0, pos) + pluginContextListenerContent +
2066                                    extraContent + content.substring(pos);
2067    
2068                    // Update liferay-web.xml
2069    
2070                    newContent = updateLiferayWebXml(webXmlVersion, srcFile, newContent);
2071    
2072                    // Update web.xml
2073    
2074                    if (securityManagerEnabled) {
2075                            newContent = secureWebXml(newContent);
2076                    }
2077    
2078                    newContent = WebXMLBuilder.organizeWebXML(newContent);
2079    
2080                    FileUtil.write(webXml, newContent, true);
2081    
2082                    if (_log.isInfoEnabled()) {
2083                            _log.info("Modifying Servlet " + webXmlVersion + " " + webXml);
2084                    }
2085            }
2086    
2087            protected String appServerType;
2088            protected String auiTaglibDTD;
2089            protected String baseDir;
2090            protected String destDir;
2091            protected String filePattern;
2092            protected List<String> jars;
2093            protected String jbossPrefix;
2094            protected String portletExtTaglibDTD;
2095            protected String portletTaglibDTD;
2096            protected String securityTaglibDTD;
2097            protected String themeTaglibDTD;
2098            protected String tomcatLibDir;
2099            protected String uiTaglibDTD;
2100            protected boolean unpackWar;
2101            protected String utilTaglibDTD;
2102            protected List<String> wars;
2103    
2104            private static final String _PORTAL_CLASS_LOADER =
2105                    "com.liferay.support.tomcat.loader.PortalClassLoader";
2106    
2107            private static Log _log = LogFactoryUtil.getLog(BaseDeployer.class);
2108    
2109    }