001
014
015 package com.liferay.portal.tools.deploy;
016
017 import com.liferay.portal.deploy.DeployUtil;
018 import com.liferay.portal.kernel.deploy.Deployer;
019 import com.liferay.portal.kernel.deploy.auto.AutoDeployException;
020 import com.liferay.portal.kernel.log.Log;
021 import com.liferay.portal.kernel.log.LogFactoryUtil;
022 import com.liferay.portal.kernel.plugin.License;
023 import com.liferay.portal.kernel.plugin.PluginPackage;
024 import com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter;
025 import com.liferay.portal.kernel.util.FileUtil;
026 import com.liferay.portal.kernel.util.GetterUtil;
027 import com.liferay.portal.kernel.util.HttpUtil;
028 import com.liferay.portal.kernel.util.PropertiesUtil;
029 import com.liferay.portal.kernel.util.PropsKeys;
030 import com.liferay.portal.kernel.util.ServerDetector;
031 import com.liferay.portal.kernel.util.StringBundler;
032 import com.liferay.portal.kernel.util.StringPool;
033 import com.liferay.portal.kernel.util.StringUtil;
034 import com.liferay.portal.kernel.util.SystemProperties;
035 import com.liferay.portal.kernel.util.TextFormatter;
036 import com.liferay.portal.kernel.util.Time;
037 import com.liferay.portal.kernel.util.Validator;
038 import com.liferay.portal.kernel.xml.Document;
039 import com.liferay.portal.kernel.xml.Element;
040 import com.liferay.portal.kernel.xml.SAXReaderUtil;
041 import com.liferay.portal.plugin.PluginPackageUtil;
042 import com.liferay.portal.tools.WebXMLBuilder;
043 import com.liferay.portal.util.ExtRegistry;
044 import com.liferay.portal.util.InitUtil;
045 import com.liferay.portal.util.PortalUtil;
046 import com.liferay.portal.util.PrefsPropsUtil;
047 import com.liferay.portal.util.PropsUtil;
048 import com.liferay.portal.util.PropsValues;
049 import com.liferay.util.ant.CopyTask;
050 import com.liferay.util.ant.DeleteTask;
051 import com.liferay.util.ant.ExpandTask;
052 import com.liferay.util.ant.UpToDateTask;
053 import com.liferay.util.ant.WarTask;
054 import com.liferay.util.xml.XMLFormatter;
055
056 import java.io.File;
057 import java.io.FileInputStream;
058 import java.io.IOException;
059 import java.io.InputStream;
060
061 import java.util.ArrayList;
062 import java.util.HashMap;
063 import java.util.List;
064 import java.util.Map;
065 import java.util.Properties;
066 import java.util.Set;
067 import java.util.zip.ZipEntry;
068 import java.util.zip.ZipFile;
069
070 import org.apache.oro.io.GlobFilenameFilter;
071
072
076 public class BaseDeployer implements Deployer {
077
078 public static final String DEPLOY_TO_PREFIX = "DEPLOY_TO__";
079
080 public static void main(String[] args) {
081 InitUtil.initWithSpring();
082
083 List<String> wars = new ArrayList<String>();
084 List<String> jars = new ArrayList<String>();
085
086 for (String arg : args) {
087 String fileName = arg.toLowerCase();
088
089 if (fileName.endsWith(".war")) {
090 wars.add(arg);
091 }
092 else if (fileName.endsWith(".jar")) {
093 jars.add(arg);
094 }
095 }
096
097 new BaseDeployer(wars, jars);
098 }
099
100 public BaseDeployer() {
101 }
102
103 public BaseDeployer(List<String> wars, List<String> jars) {
104 baseDir = System.getProperty("deployer.base.dir");
105 destDir = System.getProperty("deployer.dest.dir");
106 appServerType = System.getProperty("deployer.app.server.type");
107 auiTaglibDTD = System.getProperty("deployer.aui.taglib.dtd");
108 portletTaglibDTD = System.getProperty("deployer.portlet.taglib.dtd");
109 portletExtTaglibDTD = System.getProperty(
110 "deployer.portlet.ext.taglib.dtd");
111 securityTaglibDTD = System.getProperty("deployer.security.taglib.dtd");
112 themeTaglibDTD = System.getProperty("deployer.theme.taglib.dtd");
113 uiTaglibDTD = System.getProperty("deployer.ui.taglib.dtd");
114 utilTaglibDTD = System.getProperty("deployer.util.taglib.dtd");
115 unpackWar = GetterUtil.getBoolean(
116 System.getProperty("deployer.unpack.war"), true);
117 filePattern = System.getProperty("deployer.file.pattern");
118 jbossPrefix = GetterUtil.getString(
119 System.getProperty("deployer.jboss.prefix"));
120 tomcatLibDir = System.getProperty("deployer.tomcat.lib.dir");
121 this.wars = wars;
122 this.jars = jars;
123
124 checkArguments();
125
126 String context = System.getProperty("deployer.context");
127
128 try {
129 deploy(context);
130 }
131 catch (Exception e) {
132 e.printStackTrace();
133 }
134 }
135
136 public void addExtJar(List<String> jars, String resource)
137 throws Exception {
138
139 Set<String> servletContextNames = ExtRegistry.getServletContextNames();
140
141 for (String servletContextName : servletContextNames) {
142 String extResource =
143 "ext-" + servletContextName + resource.substring(3);
144
145 String path = DeployUtil.getResourcePath(extResource);
146
147 if (_log.isDebugEnabled()) {
148 if (path == null) {
149 _log.debug("Resource " + extResource + " is not available");
150 }
151 else {
152 _log.debug(
153 "Resource " + extResource + " is available at " + path);
154 }
155 }
156
157 if (path != null) {
158 jars.add(path);
159 }
160 }
161 }
162
163 public void addRequiredJar(List<String> jars, String resource)
164 throws Exception {
165
166 String path = DeployUtil.getResourcePath(resource);
167
168 if (path == null) {
169 throw new RuntimeException(
170 "Resource " + resource + " does not exist");
171 }
172
173 if (_log.isDebugEnabled()) {
174 _log.debug("Resource " + resource + " is available at " + path);
175 }
176
177 jars.add(path);
178 }
179
180 public void checkArguments() {
181 if (Validator.isNull(baseDir)) {
182 throw new IllegalArgumentException(
183 "The system property deployer.base.dir is not set");
184 }
185
186 if (Validator.isNull(destDir)) {
187 throw new IllegalArgumentException(
188 "The system property deployer.dest.dir is not set");
189 }
190
191 if (Validator.isNull(appServerType)) {
192 throw new IllegalArgumentException(
193 "The system property deployer.app.server.type is not set");
194 }
195
196 if (!appServerType.equals(ServerDetector.GERONIMO_ID) &&
197 !appServerType.equals(ServerDetector.GLASSFISH_ID) &&
198 !appServerType.equals(ServerDetector.JBOSS_ID) &&
199 !appServerType.equals(ServerDetector.JONAS_ID) &&
200 !appServerType.equals(ServerDetector.JETTY_ID) &&
201 !appServerType.equals(ServerDetector.OC4J_ID) &&
202 !appServerType.equals(ServerDetector.RESIN_ID) &&
203 !appServerType.equals(ServerDetector.TOMCAT_ID) &&
204 !appServerType.equals(ServerDetector.WEBLOGIC_ID) &&
205 !appServerType.equals(ServerDetector.WEBSPHERE_ID)) {
206
207 throw new IllegalArgumentException(
208 appServerType + " is not a valid application server type");
209 }
210
211 if (appServerType.equals(ServerDetector.GLASSFISH_ID) ||
212 appServerType.equals(ServerDetector.WEBLOGIC_ID)) {
213
214 unpackWar = false;
215 }
216
217 if (Validator.isNotNull(jbossPrefix) &&
218 !Validator.isNumber(jbossPrefix)) {
219
220 jbossPrefix = "1";
221 }
222 }
223
224 public void copyDependencyXml(String fileName, String targetDir)
225 throws Exception {
226
227 copyDependencyXml(fileName, targetDir, null);
228 }
229
230 public void copyDependencyXml(
231 String fileName, String targetDir, Map<String, String> filterMap)
232 throws Exception {
233
234 copyDependencyXml(fileName, targetDir, filterMap, false);
235 }
236
237 public void copyDependencyXml(
238 String fileName, String targetDir, Map<String, String> filterMap,
239 boolean overwrite)
240 throws Exception {
241
242 DeployUtil.copyDependencyXml(
243 fileName, targetDir, fileName, filterMap, overwrite);
244 }
245
246 public void copyJars(File srcFile, PluginPackage pluginPackage)
247 throws Exception {
248
249 for (int i = 0; i < jars.size(); i++) {
250 String jarFullName = jars.get(i);
251
252 String jarName = jarFullName.substring(
253 jarFullName.lastIndexOf("/") + 1, jarFullName.length());
254
255 if ((!appServerType.equals(ServerDetector.TOMCAT_ID)) ||
256 (appServerType.equals(ServerDetector.TOMCAT_ID) &&
257 !jarFullName.equals("util-java.jar"))) {
258
259 FileUtil.copyFile(
260 jarFullName, srcFile + "/WEB-INF/lib/" + jarName, true);
261 }
262 }
263
264 FileUtil.delete(srcFile + "/WEB-INF/lib/util-jsf.jar");
265 }
266
267 public void copyPortalDependencies(File srcFile) throws Exception {
268 Properties properties = getPluginPackageProperties(srcFile);
269
270 if (properties == null) {
271 return;
272 }
273
274
275
276 String[] portalJars = StringUtil.split(
277 properties.getProperty(
278 "portal-dependency-jars",
279 properties.getProperty("portal.dependency.jars")));
280
281 for (int i = 0; i < portalJars.length; i++) {
282 String portalJar = portalJars[i].trim();
283
284 portalJar = fixPortalDependencyJar(portalJar);
285
286 if (_log.isDebugEnabled()) {
287 _log.debug("Copy portal JAR " + portalJar);
288 }
289
290 try {
291 String portalJarPath = PortalUtil.getPortalLibDir() + portalJar;
292
293 FileUtil.copyFile(
294 portalJarPath, srcFile + "/WEB-INF/lib/" + portalJar, true);
295 }
296 catch (Exception e) {
297 _log.error("Unable to copy portal JAR " + portalJar, e);
298 }
299 }
300
301
302
303 String[] portalTlds = StringUtil.split(
304 properties.getProperty(
305 "portal-dependency-tlds",
306 properties.getProperty("portal.dependency.tlds")));
307
308 for (int i = 0; i < portalTlds.length; i++) {
309 String portalTld = portalTlds[i].trim();
310
311 if (_log.isDebugEnabled()) {
312 _log.debug("Copy portal TLD " + portalTld);
313 }
314
315 try {
316 String portalTldPath = DeployUtil.getResourcePath(portalTld);
317
318 FileUtil.copyFile(
319 portalTldPath, srcFile + "/WEB-INF/tld/" + portalTld, true);
320 }
321 catch (Exception e) {
322 _log.error("Unable to copy portal TLD " + portalTld, e);
323 }
324 }
325
326
327
328 File pluginLibDir = new File(srcFile + "/WEB-INF/lib/");
329
330 if (PropsValues.AUTO_DEPLOY_COPY_COMMONS_LOGGING) {
331 String[] commonsLoggingJars = pluginLibDir.list(
332 new GlobFilenameFilter("commons-logging*.jar"));
333
334 if ((commonsLoggingJars == null) ||
335 (commonsLoggingJars.length == 0)) {
336
337 String portalJarPath =
338 PortalUtil.getPortalLibDir() + "commons-logging.jar";
339
340 FileUtil.copyFile(
341 portalJarPath, srcFile + "/WEB-INF/lib/commons-logging.jar",
342 true);
343 }
344 }
345
346
347
348 if (PropsValues.AUTO_DEPLOY_COPY_LOG4J) {
349 String[] log4jJars = pluginLibDir.list(
350 new GlobFilenameFilter("log4j*.jar"));
351
352 if ((log4jJars == null) || (log4jJars.length == 0)) {
353 String portalJarPath =
354 PortalUtil.getPortalLibDir() + "log4j.jar";
355
356 FileUtil.copyFile(
357 portalJarPath, srcFile + "/WEB-INF/lib/log4j.jar", true);
358 }
359 }
360 }
361
362 public void copyProperties(File srcFile, PluginPackage pluginPackage)
363 throws Exception {
364
365 if (PropsValues.AUTO_DEPLOY_COPY_COMMONS_LOGGING) {
366 copyDependencyXml(
367 "logging.properties", srcFile + "/WEB-INF/classes");
368 }
369
370 if (PropsValues.AUTO_DEPLOY_COPY_LOG4J) {
371 copyDependencyXml("log4j.properties", srcFile + "/WEB-INF/classes");
372 }
373
374 File servicePropertiesFile = new File(
375 srcFile.getAbsolutePath() + "/WEB-INF/classes/service.properties");
376
377 if (servicePropertiesFile.exists()) {
378 File portletPropertiesFile = new File(
379 srcFile.getAbsolutePath() +
380 "/WEB-INF/classes/portlet.properties");
381
382 if (!portletPropertiesFile.exists()) {
383 FileUtil.write(
384 portletPropertiesFile,
385 "plugin.package.name=" + pluginPackage.getName());
386 }
387 }
388 }
389
390 public void copyTlds(File srcFile, PluginPackage pluginPackage)
391 throws Exception {
392
393 if (Validator.isNotNull(auiTaglibDTD)) {
394 FileUtil.copyFile(
395 auiTaglibDTD, srcFile + "/WEB-INF/tld/liferay-aui.tld", true);
396 }
397
398 if (Validator.isNotNull(portletTaglibDTD)) {
399 FileUtil.copyFile(
400 portletTaglibDTD, srcFile + "/WEB-INF/tld/liferay-portlet.tld",
401 true);
402 }
403
404 if (Validator.isNotNull(portletExtTaglibDTD)) {
405 FileUtil.copyFile(
406 portletExtTaglibDTD,
407 srcFile + "/WEB-INF/tld/liferay-portlet-ext.tld", true);
408 }
409
410 if (Validator.isNotNull(securityTaglibDTD)) {
411 FileUtil.copyFile(
412 securityTaglibDTD,
413 srcFile + "/WEB-INF/tld/liferay-security.tld", true);
414 }
415
416 if (Validator.isNotNull(themeTaglibDTD)) {
417 FileUtil.copyFile(
418 themeTaglibDTD, srcFile + "/WEB-INF/tld/liferay-theme.tld",
419 true);
420 }
421
422 if (Validator.isNotNull(uiTaglibDTD)) {
423 FileUtil.copyFile(
424 uiTaglibDTD, srcFile + "/WEB-INF/tld/liferay-ui.tld", true);
425 }
426
427 if (Validator.isNotNull(utilTaglibDTD)) {
428 FileUtil.copyFile(
429 utilTaglibDTD, srcFile + "/WEB-INF/tld/liferay-util.tld", true);
430 }
431 }
432
433 public void copyXmls(
434 File srcFile, String displayName, PluginPackage pluginPackage)
435 throws Exception {
436
437 if (appServerType.equals(ServerDetector.GERONIMO_ID)) {
438 copyDependencyXml("geronimo-web.xml", srcFile + "/WEB-INF");
439 }
440 else if (appServerType.equals(ServerDetector.JBOSS_ID)) {
441 copyDependencyXml(
442 "jboss-deployment-structure.xml", srcFile + "/WEB-INF");
443 }
444 else if (appServerType.equals(ServerDetector.WEBLOGIC_ID)) {
445 copyDependencyXml("weblogic.xml", srcFile + "/WEB-INF");
446 }
447 else if (appServerType.equals(ServerDetector.WEBSPHERE_ID)) {
448 copyDependencyXml("ibm-web-ext.xmi", srcFile + "/WEB-INF");
449 }
450
451 copyDependencyXml("web.xml", srcFile + "/WEB-INF");
452 }
453
454 public void deploy(String context) throws Exception {
455 try {
456 File baseDirFile = new File(baseDir);
457
458 File[] files = baseDirFile.listFiles();
459
460 if (files == null) {
461 return;
462 }
463
464 files = FileUtil.sortFiles(files);
465
466 for (int i = 0; i < files.length; i++) {
467 File srcFile = files[i];
468
469 String fileName = srcFile.getName().toLowerCase();
470
471 boolean deploy = false;
472
473 if (fileName.endsWith(".war") || fileName.endsWith(".zip")) {
474 deploy = true;
475
476 if (wars.size() > 0) {
477 if (!wars.contains(srcFile.getName())) {
478 deploy = false;
479 }
480 }
481 else if (Validator.isNotNull(filePattern)) {
482 if (!StringUtil.matchesIgnoreCase(
483 fileName, filePattern)) {
484
485 deploy = false;
486 }
487 }
488 }
489
490 if (deploy) {
491 deployFile(srcFile, context);
492 }
493 }
494 }
495 catch (Exception e) {
496 e.printStackTrace();
497 }
498 }
499
500 public void deployDirectory(
501 File srcFile, File mergeDir, File deployDir, String displayName,
502 boolean overwrite, PluginPackage pluginPackage)
503 throws Exception {
504
505 rewriteFiles(srcFile);
506
507 mergeDirectory(mergeDir, srcFile);
508
509 processPluginPackageProperties(srcFile, displayName, pluginPackage);
510
511 copyJars(srcFile, pluginPackage);
512 copyProperties(srcFile, pluginPackage);
513 copyTlds(srcFile, pluginPackage);
514 copyXmls(srcFile, displayName, pluginPackage);
515 copyPortalDependencies(srcFile);
516
517 updateGeronimoWebXml(srcFile, displayName, pluginPackage);
518
519 File webXml = new File(srcFile + "/WEB-INF/web.xml");
520
521 updateWebXml(webXml, srcFile, displayName, pluginPackage);
522
523 File extLibGlobalDir = new File(
524 srcFile.getAbsolutePath() + "/WEB-INF/ext-lib/global");
525
526 if (extLibGlobalDir.exists()) {
527 File globalLibDir = new File(PortalUtil.getGlobalLibDir());
528
529 CopyTask.copyDirectory(
530 extLibGlobalDir, globalLibDir, "*.jar", StringPool.BLANK,
531 overwrite, true);
532 }
533
534 File extLibPortalDir = new File(
535 srcFile.getAbsolutePath() + "/WEB-INF/ext-lib/portal");
536
537 if (extLibPortalDir.exists()) {
538 File portalLibDir = new File(PortalUtil.getPortalLibDir());
539
540 CopyTask.copyDirectory(
541 extLibPortalDir, portalLibDir, "*.jar", StringPool.BLANK,
542 overwrite, true);
543 }
544
545 if ((deployDir == null) || baseDir.equals(destDir)) {
546 return;
547 }
548
549 updateDeployDirectory(srcFile);
550
551 String excludes = StringPool.BLANK;
552
553 if (appServerType.equals(ServerDetector.JBOSS_ID)) {
554 excludes += "**/WEB-INF/lib/log4j.jar,";
555 }
556 else if (appServerType.equals(ServerDetector.TOMCAT_ID)) {
557 String[] libs = FileUtil.listFiles(tomcatLibDir);
558
559 for (int i = 0; i < libs.length; i++) {
560 excludes += "**/WEB-INF/lib/" + libs[i] + ",";
561 }
562
563 File contextXml = new File(srcFile + "/META-INF/context.xml");
564
565 if (contextXml.exists()) {
566 String content = FileUtil.read(contextXml);
567
568 if (content.indexOf(_PORTAL_CLASS_LOADER) != -1) {
569 excludes += "**/WEB-INF/lib/util-bridges.jar,";
570 excludes += "**/WEB-INF/lib/util-java.jar,";
571 excludes += "**/WEB-INF/lib/util-taglib.jar,";
572 }
573 }
574
575 try {
576
577
578
579 Class.forName("javax.el.ELContext");
580
581 excludes += "**/WEB-INF/lib/el-api.jar,";
582 }
583 catch (ClassNotFoundException cnfe) {
584 }
585 }
586
587
588
589 Properties properties = getPluginPackageProperties(srcFile);
590
591 if (properties != null) {
592 String deployExcludes = properties.getProperty("deploy-excludes");
593
594 if (deployExcludes != null) {
595 excludes += deployExcludes.trim();
596
597 if (!excludes.endsWith(",")) {
598 excludes += ",";
599 }
600 }
601
602 deployExcludes = properties.getProperty(
603 "deploy-excludes-" + appServerType);
604
605 if (deployExcludes != null) {
606 excludes += deployExcludes.trim();
607
608 if (!excludes.endsWith(",")) {
609 excludes += ",";
610 }
611 }
612 }
613
614 if (_log.isDebugEnabled()) {
615 _log.debug("Excludes " + excludes);
616 }
617
618 if (!unpackWar || appServerType.equals(ServerDetector.WEBSPHERE_ID)) {
619 File tempDir = new File(
620 SystemProperties.get(SystemProperties.TMP_DIR) +
621 File.separator + Time.getTimestamp());
622
623 excludes += "**/WEB-INF/web.xml";
624
625 WarTask.war(srcFile, tempDir, excludes, webXml);
626
627 if (isJEEDeploymentEnabled()) {
628 File tempWarDir = new File(
629 tempDir.getParent(), deployDir.getName());
630
631 if (tempWarDir.exists()) {
632 tempWarDir.delete();
633 }
634
635 if (!tempDir.renameTo(tempWarDir)) {
636 tempWarDir = tempDir;
637 }
638
639 DeploymentHandler deploymentHandler = getDeploymentHandler();
640
641 deploymentHandler.deploy(tempWarDir, displayName);
642
643 deploymentHandler.releaseDeploymentManager();
644
645 DeleteTask.deleteDirectory(tempWarDir);
646 }
647 else {
648 if (!tempDir.renameTo(deployDir)) {
649 WarTask.war(srcFile, deployDir, excludes, webXml);
650 }
651
652 DeleteTask.deleteDirectory(tempDir);
653 }
654 }
655 else {
656
657
658
659
660
661
662
663 excludes += "**/WEB-INF/web.xml";
664
665 CopyTask.copyDirectory(
666 srcFile, deployDir, StringPool.BLANK, excludes, overwrite,
667 true);
668
669 CopyTask.copyDirectory(
670 srcFile, deployDir, "**/WEB-INF/web.xml", StringPool.BLANK,
671 true, false);
672
673 if (appServerType.equals(ServerDetector.TOMCAT_ID)) {
674
675
676
677
678
679 File deployWebXml = new File(deployDir + "/WEB-INF/web.xml");
680
681 deployWebXml.setLastModified(
682 System.currentTimeMillis() + (Time.SECOND * 6));
683 }
684 }
685
686 if (appServerType.equals(ServerDetector.JETTY_ID)) {
687 DeployUtil.redeployJetty(displayName);
688 }
689 }
690
691 public void deployDirectory(
692 File srcFile, String displayName, boolean override,
693 PluginPackage pluginPackage)
694 throws Exception {
695
696 deployDirectory(
697 srcFile, null, null, displayName, override, pluginPackage);
698 }
699
700 public void deployFile(File srcFile, String specifiedContext)
701 throws Exception {
702
703 PluginPackage pluginPackage = readPluginPackage(srcFile);
704
705 if (_log.isInfoEnabled()) {
706 _log.info("Deploying " + srcFile.getName());
707 }
708
709 String deployDir = null;
710 String displayName = specifiedContext;
711 boolean overwrite = false;
712 String preliminaryContext = specifiedContext;
713
714
715
716
717
718
719 if ((specifiedContext != null) &&
720 srcFile.getName().startsWith(DEPLOY_TO_PREFIX)) {
721
722 displayName = srcFile.getName().substring(
723 DEPLOY_TO_PREFIX.length(), srcFile.getName().length() - 4);
724
725 overwrite = true;
726 preliminaryContext = displayName;
727 }
728
729 if (preliminaryContext == null) {
730 preliminaryContext = getDisplayName(srcFile);
731 }
732
733 if (pluginPackage != null) {
734 if (!PluginPackageUtil.isCurrentVersionSupported(
735 pluginPackage.getLiferayVersions())) {
736
737 throw new AutoDeployException(
738 srcFile.getName() +
739 " does not support this version of Liferay");
740 }
741
742 if (displayName == null) {
743 displayName = pluginPackage.getRecommendedDeploymentContext();
744 }
745
746 if (Validator.isNull(displayName)) {
747 displayName = getDisplayName(srcFile);
748 }
749
750 pluginPackage.setContext(displayName);
751
752 PluginPackageUtil.updateInstallingPluginPackage(
753 preliminaryContext, pluginPackage);
754 }
755
756 if (Validator.isNotNull(displayName)) {
757 deployDir = displayName + ".war";
758 }
759 else {
760 deployDir = srcFile.getName();
761 displayName = getDisplayName(srcFile);
762 }
763
764 if (appServerType.equals(ServerDetector.JBOSS_ID)) {
765 deployDir = jbossPrefix + deployDir;
766 }
767 else if (appServerType.equals(ServerDetector.JETTY_ID) ||
768 appServerType.equals(ServerDetector.OC4J_ID) ||
769 appServerType.equals(ServerDetector.RESIN_ID) ||
770 appServerType.equals(ServerDetector.TOMCAT_ID)) {
771
772 if (unpackWar) {
773 deployDir = deployDir.substring(0, deployDir.length() - 4);
774 }
775 }
776
777 deployDir = destDir + "/" + deployDir;
778
779 File deployDirFile = new File(deployDir);
780
781 try {
782 PluginPackage previousPluginPackage = readPluginPackage(
783 deployDirFile);
784
785 if ((pluginPackage != null) && (previousPluginPackage != null)) {
786 if (_log.isInfoEnabled()) {
787 String name = pluginPackage.getName();
788 String previousVersion = previousPluginPackage.getVersion();
789 String version = pluginPackage.getVersion();
790
791 _log.info(
792 "Updating " + name + " from version " +
793 previousVersion + " to version " + version);
794 }
795
796 if (pluginPackage.isLaterVersionThan(previousPluginPackage)) {
797 overwrite = true;
798 }
799 }
800
801 File mergeDirFile = new File(
802 srcFile.getParent() + "/merge/" + srcFile.getName());
803
804 if (srcFile.isDirectory()) {
805 deployDirectory(
806 srcFile, mergeDirFile, deployDirFile, displayName,
807 overwrite, pluginPackage);
808 }
809 else {
810 boolean deployed = deployFile(
811 srcFile, mergeDirFile, deployDirFile, displayName,
812 overwrite, pluginPackage);
813
814 if (!deployed) {
815 String context = preliminaryContext;
816
817 if (pluginPackage != null) {
818 context = pluginPackage.getContext();
819 }
820
821 PluginPackageUtil.endPluginPackageInstallation(context);
822 }
823 else {
824 if (appServerType.equals(ServerDetector.JBOSS_ID)) {
825 File doDeployFile = new File(deployDir + ".dodeploy");
826
827 FileUtil.write(doDeployFile, StringPool.BLANK);
828 }
829 }
830 }
831 }
832 catch (Exception e) {
833 if (pluginPackage != null) {
834 PluginPackageUtil.endPluginPackageInstallation(
835 pluginPackage.getContext());
836 }
837
838 throw e;
839 }
840 }
841
842 public boolean deployFile(
843 File srcFile, File mergeDir, File deployDir, String displayName,
844 boolean overwrite, PluginPackage pluginPackage)
845 throws Exception {
846
847 boolean undeployOnRedeploy = false;
848
849 try {
850 undeployOnRedeploy = PrefsPropsUtil.getBoolean(
851 PropsKeys.HOT_UNDEPLOY_ON_REDEPLOY,
852 PropsValues.HOT_UNDEPLOY_ON_REDEPLOY);
853 }
854 catch (Exception e) {
855
856
857
858
859
860 }
861
862 if (undeployOnRedeploy) {
863 DeployUtil.undeploy(appServerType, deployDir);
864 }
865
866 if (!overwrite && UpToDateTask.isUpToDate(srcFile, deployDir)) {
867 if (_log.isInfoEnabled()) {
868 _log.info(deployDir + " is already up to date");
869 }
870
871 return false;
872 }
873
874 File tempDir = new File(
875 SystemProperties.get(SystemProperties.TMP_DIR) + File.separator +
876 Time.getTimestamp());
877
878 ExpandTask.expand(srcFile, tempDir);
879
880 deployDirectory(
881 tempDir, mergeDir, deployDir, displayName, overwrite,
882 pluginPackage);
883
884 DeleteTask.deleteDirectory(tempDir);
885
886 return true;
887 }
888
889 public String downloadJar(String jar) throws Exception {
890 String tmpDir = SystemProperties.get(SystemProperties.TMP_DIR);
891
892 File file = new File(
893 tmpDir + "/liferay/com/liferay/portal/deploy/dependencies/" +
894 jar);
895
896 if (!file.exists()) {
897 synchronized (this) {
898 String url = PropsUtil.get(
899 PropsKeys.LIBRARY_DOWNLOAD_URL + jar);
900
901 if (_log.isInfoEnabled()) {
902 _log.info("Downloading library from " + url);
903 }
904
905 byte[] bytes = HttpUtil.URLtoByteArray(url);
906
907 FileUtil.write(file, bytes);
908 }
909 }
910
911 return FileUtil.getAbsolutePath(file);
912 }
913
914 public String fixPortalDependencyJar(String portalJar) {
915 if (portalJar.equals("antlr.jar")) {
916 portalJar = "antlr2.jar";
917 }
918
919 return portalJar;
920 }
921
922 public DeploymentHandler getDeploymentHandler() {
923 String prefix = "auto.deploy." + ServerDetector.getServerId() + ".jee.";
924
925 String dmId = PropsUtil.get(prefix + "dm.id");
926 String dmUser = PropsUtil.get(prefix + "dm.user");
927 String dmPassword = PropsUtil.get(prefix + "dm.passwd");
928 String dfClassName = PropsUtil.get(prefix + "df.classname");
929
930 return new DeploymentHandler(dmId, dmUser, dmPassword, dfClassName);
931 }
932
933 public String getDisplayName(File srcFile) {
934 String displayName = srcFile.getName();
935
936 if (StringUtil.endsWith(displayName, ".war") ||
937 StringUtil.endsWith(displayName, ".xml")) {
938
939 displayName = displayName.substring(0, displayName.length() - 4);
940 }
941
942 if (appServerType.equals(ServerDetector.JBOSS_ID) &&
943 Validator.isNotNull(jbossPrefix) &&
944 displayName.startsWith(jbossPrefix)) {
945
946 displayName = displayName.substring(1, displayName.length());
947 }
948
949 return displayName;
950 }
951
952 public String getExtraContent(
953 double webXmlVersion, File srcFile, String displayName)
954 throws Exception {
955
956 StringBundler sb = new StringBundler();
957
958 sb.append("<display-name>");
959 sb.append(displayName);
960 sb.append("</display-name>");
961
962 sb.append("<listener>");
963 sb.append("<listener-class>");
964 sb.append("com.liferay.portal.kernel.servlet.");
965 sb.append("SerializableSessionAttributeListener");
966 sb.append("</listener-class>");
967 sb.append("</listener>");
968
969 File serviceXml = new File(srcFile + "/WEB-INF/service.xml");
970
971 if (serviceXml.exists()) {
972 sb.append("<listener>");
973 sb.append("<listener-class>");
974 sb.append("com.liferay.portal.kernel.spring.context.");
975 sb.append("PortletContextLoaderListener");
976 sb.append("</listener-class>");
977 sb.append("</listener>");
978 }
979
980 File serverConfigWsdd = new File(
981 srcFile + "/WEB-INF/server-config.wsdd");
982
983 if (serverConfigWsdd.exists()) {
984 File webXml = new File(srcFile + "/WEB-INF/web.xml");
985
986 String content = FileUtil.read(webXml);
987
988 if (!content.contains("axis.servicesPath")) {
989 String remotingContent = FileUtil.read(
990 DeployUtil.getResourcePath("remoting-web.xml"));
991
992 sb.append(remotingContent);
993 }
994 }
995
996 boolean hasTaglib = false;
997
998 if (Validator.isNotNull(auiTaglibDTD) ||
999 Validator.isNotNull(portletTaglibDTD) ||
1000 Validator.isNotNull(portletExtTaglibDTD) ||
1001 Validator.isNotNull(securityTaglibDTD) ||
1002 Validator.isNotNull(themeTaglibDTD) ||
1003 Validator.isNotNull(uiTaglibDTD) ||
1004 Validator.isNotNull(utilTaglibDTD)) {
1005
1006 hasTaglib = true;
1007 }
1008
1009 if (hasTaglib && (webXmlVersion > 2.3)) {
1010 sb.append("<jsp-config>");
1011 }
1012
1013 if (Validator.isNotNull(auiTaglibDTD)) {
1014 sb.append("<taglib>");
1015 sb.append("<taglib-uri>http:
1016 sb.append("<taglib-location>");
1017 sb.append("/WEB-INF/tld/liferay-aui.tld");
1018 sb.append("</taglib-location>");
1019 sb.append("</taglib>");
1020 }
1021
1022 if (Validator.isNotNull(portletTaglibDTD)) {
1023 sb.append("<taglib>");
1024 sb.append(
1025 "<taglib-uri>http:
1026 sb.append("<taglib-location>");
1027 sb.append("/WEB-INF/tld/liferay-portlet.tld");
1028 sb.append("</taglib-location>");
1029 sb.append("</taglib>");
1030 }
1031
1032 if (Validator.isNotNull(portletExtTaglibDTD)) {
1033 sb.append("<taglib>");
1034 sb.append("<taglib-uri>");
1035 sb.append("http:
1036 sb.append("</taglib-uri>");
1037 sb.append("<taglib-location>");
1038 sb.append("/WEB-INF/tld/liferay-portlet-ext.tld");
1039 sb.append("</taglib-location>");
1040 sb.append("</taglib>");
1041 }
1042
1043 if (Validator.isNotNull(securityTaglibDTD)) {
1044 sb.append("<taglib>");
1045 sb.append("<taglib-uri>");
1046 sb.append("http:
1047 sb.append("</taglib-uri>");
1048 sb.append("<taglib-location>");
1049 sb.append("/WEB-INF/tld/liferay-security.tld");
1050 sb.append("</taglib-location>");
1051 sb.append("</taglib>");
1052 }
1053
1054 if (Validator.isNotNull(themeTaglibDTD)) {
1055 sb.append("<taglib>");
1056 sb.append("<taglib-uri>http:
1057 sb.append("<taglib-location>");
1058 sb.append("/WEB-INF/tld/liferay-theme.tld");
1059 sb.append("</taglib-location>");
1060 sb.append("</taglib>");
1061 }
1062
1063 if (Validator.isNotNull(uiTaglibDTD)) {
1064 sb.append("<taglib>");
1065 sb.append("<taglib-uri>http:
1066 sb.append("<taglib-location>");
1067 sb.append("/WEB-INF/tld/liferay-ui.tld");
1068 sb.append("</taglib-location>");
1069 sb.append("</taglib>");
1070 }
1071
1072 if (Validator.isNotNull(utilTaglibDTD)) {
1073 sb.append("<taglib>");
1074 sb.append("<taglib-uri>http:
1075 sb.append("<taglib-location>");
1076 sb.append("/WEB-INF/tld/liferay-util.tld");
1077 sb.append("</taglib-location>");
1078 sb.append("</taglib>");
1079 }
1080
1081 if (hasTaglib && (webXmlVersion > 2.3)) {
1082 sb.append("</jsp-config>");
1083 }
1084
1085 sb.append(getSessionFiltersContent());
1086
1087 return sb.toString();
1088 }
1089
1090 public String getIgnoreFiltersContent(File srcFile) throws Exception {
1091 boolean ignoreFiltersEnabled = true;
1092
1093 Properties properties = getPluginPackageProperties(srcFile);
1094
1095 if (properties != null) {
1096 ignoreFiltersEnabled = GetterUtil.getBoolean(
1097 properties.getProperty("ignore-filters-enabled"), true);
1098 }
1099
1100 if (ignoreFiltersEnabled) {
1101 String ignoreFiltersContent = FileUtil.read(
1102 DeployUtil.getResourcePath("ignore-filters-web.xml"));
1103
1104 return ignoreFiltersContent;
1105 }
1106 else {
1107 return StringPool.BLANK;
1108 }
1109 }
1110
1111 public String getInvokerFilterContent() {
1112 StringBundler sb = new StringBundler(4);
1113
1114 sb.append(getInvokerFilterContent("ERROR"));
1115 sb.append(getInvokerFilterContent("FORWARD"));
1116 sb.append(getInvokerFilterContent("INCLUDE"));
1117 sb.append(getInvokerFilterContent("REQUEST"));
1118
1119 return sb.toString();
1120 }
1121
1122 public String getInvokerFilterContent(String dispatcher) {
1123 StringBundler sb = new StringBundler(23);
1124
1125 sb.append("<filter>");
1126 sb.append("<filter-name>Invoker Filter - ");
1127 sb.append(dispatcher);
1128 sb.append("</filter-name>");
1129 sb.append("<filter-class>");
1130 sb.append(InvokerFilter.class.getName());
1131 sb.append("</filter-class>");
1132 sb.append("<init-param>");
1133 sb.append("<param-name>dispatcher</param-name>");
1134 sb.append("<param-value>");
1135 sb.append(dispatcher);
1136 sb.append("</param-value>");
1137 sb.append("</init-param>");
1138 sb.append("</filter>");
1139
1140 sb.append("<filter-mapping>");
1141 sb.append("<filter-name>Invoker Filter - ");
1142 sb.append(dispatcher);
1143 sb.append("</filter-name>");
1144 sb.append("<url-pattern>