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 String pluginPackageName = null;
384
385 if (pluginPackage != null) {
386 pluginPackageName = pluginPackage.getName();
387 }
388 else {
389 pluginPackageName = srcFile.getName();
390 }
391
392 FileUtil.write(
393 portletPropertiesFile,
394 "plugin.package.name=" + pluginPackageName);
395 }
396 }
397 }
398
399 public void copyTlds(File srcFile, PluginPackage pluginPackage)
400 throws Exception {
401
402 if (Validator.isNotNull(auiTaglibDTD)) {
403 FileUtil.copyFile(
404 auiTaglibDTD, srcFile + "/WEB-INF/tld/aui.tld", true);
405 }
406
407 if (Validator.isNotNull(portletTaglibDTD)) {
408 FileUtil.copyFile(
409 portletTaglibDTD, srcFile + "/WEB-INF/tld/liferay-portlet.tld",
410 true);
411 }
412
413 if (Validator.isNotNull(portletExtTaglibDTD)) {
414 FileUtil.copyFile(
415 portletExtTaglibDTD,
416 srcFile + "/WEB-INF/tld/liferay-portlet-ext.tld", true);
417 }
418
419 if (Validator.isNotNull(securityTaglibDTD)) {
420 FileUtil.copyFile(
421 securityTaglibDTD,
422 srcFile + "/WEB-INF/tld/liferay-security.tld", true);
423 }
424
425 if (Validator.isNotNull(themeTaglibDTD)) {
426 FileUtil.copyFile(
427 themeTaglibDTD, srcFile + "/WEB-INF/tld/liferay-theme.tld",
428 true);
429 }
430
431 if (Validator.isNotNull(uiTaglibDTD)) {
432 FileUtil.copyFile(
433 uiTaglibDTD, srcFile + "/WEB-INF/tld/liferay-ui.tld", true);
434 }
435
436 if (Validator.isNotNull(utilTaglibDTD)) {
437 FileUtil.copyFile(
438 utilTaglibDTD, srcFile + "/WEB-INF/tld/liferay-util.tld", true);
439 }
440 }
441
442 public void copyXmls(
443 File srcFile, String displayName, PluginPackage pluginPackage)
444 throws Exception {
445
446 if (appServerType.equals(ServerDetector.GERONIMO_ID)) {
447 copyDependencyXml("geronimo-web.xml", srcFile + "/WEB-INF");
448 }
449 else if (appServerType.equals(ServerDetector.JBOSS_ID)) {
450 copyDependencyXml(
451 "jboss-deployment-structure.xml", srcFile + "/WEB-INF");
452 }
453 else if (appServerType.equals(ServerDetector.WEBLOGIC_ID)) {
454 copyDependencyXml("weblogic.xml", srcFile + "/WEB-INF");
455 }
456 else if (appServerType.equals(ServerDetector.WEBSPHERE_ID)) {
457 copyDependencyXml("ibm-web-ext.xmi", srcFile + "/WEB-INF");
458 }
459
460 copyDependencyXml("web.xml", srcFile + "/WEB-INF");
461 }
462
463 public void deploy(String context) throws Exception {
464 try {
465 File baseDirFile = new File(baseDir);
466
467 File[] files = baseDirFile.listFiles();
468
469 if (files == null) {
470 return;
471 }
472
473 files = FileUtil.sortFiles(files);
474
475 for (int i = 0; i < files.length; i++) {
476 File srcFile = files[i];
477
478 String fileName = srcFile.getName().toLowerCase();
479
480 boolean deploy = false;
481
482 if (fileName.endsWith(".war") || fileName.endsWith(".zip")) {
483 deploy = true;
484
485 if (wars.size() > 0) {
486 if (!wars.contains(srcFile.getName())) {
487 deploy = false;
488 }
489 }
490 else if (Validator.isNotNull(filePattern)) {
491 if (!StringUtil.matchesIgnoreCase(
492 fileName, filePattern)) {
493
494 deploy = false;
495 }
496 }
497 }
498
499 if (deploy) {
500 deployFile(srcFile, context);
501 }
502 }
503 }
504 catch (Exception e) {
505 e.printStackTrace();
506 }
507 }
508
509 public void deployDirectory(
510 File srcFile, File mergeDir, File deployDir, String displayName,
511 boolean overwrite, PluginPackage pluginPackage)
512 throws Exception {
513
514 rewriteFiles(srcFile);
515
516 mergeDirectory(mergeDir, srcFile);
517
518 processPluginPackageProperties(srcFile, displayName, pluginPackage);
519
520 copyJars(srcFile, pluginPackage);
521 copyProperties(srcFile, pluginPackage);
522 copyTlds(srcFile, pluginPackage);
523 copyXmls(srcFile, displayName, pluginPackage);
524 copyPortalDependencies(srcFile);
525
526 updateGeronimoWebXml(srcFile, displayName, pluginPackage);
527
528 File webXml = new File(srcFile + "/WEB-INF/web.xml");
529
530 updateWebXml(webXml, srcFile, displayName, pluginPackage);
531
532 File extLibGlobalDir = new File(
533 srcFile.getAbsolutePath() + "/WEB-INF/ext-lib/global");
534
535 if (extLibGlobalDir.exists()) {
536 File globalLibDir = new File(PortalUtil.getGlobalLibDir());
537
538 CopyTask.copyDirectory(
539 extLibGlobalDir, globalLibDir, "*.jar", StringPool.BLANK,
540 overwrite, true);
541 }
542
543 File extLibPortalDir = new File(
544 srcFile.getAbsolutePath() + "/WEB-INF/ext-lib/portal");
545
546 if (extLibPortalDir.exists()) {
547 File portalLibDir = new File(PortalUtil.getPortalLibDir());
548
549 CopyTask.copyDirectory(
550 extLibPortalDir, portalLibDir, "*.jar", StringPool.BLANK,
551 overwrite, true);
552 }
553
554 if ((deployDir == null) || baseDir.equals(destDir)) {
555 return;
556 }
557
558 updateDeployDirectory(srcFile);
559
560 String excludes = StringPool.BLANK;
561
562 if (appServerType.equals(ServerDetector.JBOSS_ID)) {
563 excludes += "**/WEB-INF/lib/log4j.jar,";
564 }
565 else if (appServerType.equals(ServerDetector.TOMCAT_ID)) {
566 String[] libs = FileUtil.listFiles(tomcatLibDir);
567
568 for (int i = 0; i < libs.length; i++) {
569 excludes += "**/WEB-INF/lib/" + libs[i] + ",";
570 }
571
572 File contextXml = new File(srcFile + "/META-INF/context.xml");
573
574 if (contextXml.exists()) {
575 String content = FileUtil.read(contextXml);
576
577 if (content.indexOf(_PORTAL_CLASS_LOADER) != -1) {
578 excludes += "**/WEB-INF/lib/util-bridges.jar,";
579 excludes += "**/WEB-INF/lib/util-java.jar,";
580 excludes += "**/WEB-INF/lib/util-taglib.jar,";
581 }
582 }
583
584 try {
585
586
587
588 Class.forName("javax.el.ELContext");
589
590 excludes += "**/WEB-INF/lib/el-api.jar,";
591 }
592 catch (ClassNotFoundException cnfe) {
593 }
594 }
595
596
597
598 Properties properties = getPluginPackageProperties(srcFile);
599
600 if (properties != null) {
601 String deployExcludes = properties.getProperty("deploy-excludes");
602
603 if (deployExcludes != null) {
604 excludes += deployExcludes.trim();
605
606 if (!excludes.endsWith(",")) {
607 excludes += ",";
608 }
609 }
610
611 deployExcludes = properties.getProperty(
612 "deploy-excludes-" + appServerType);
613
614 if (deployExcludes != null) {
615 excludes += deployExcludes.trim();
616
617 if (!excludes.endsWith(",")) {
618 excludes += ",";
619 }
620 }
621 }
622
623 if (_log.isDebugEnabled()) {
624 _log.debug("Excludes " + excludes);
625 }
626
627 if (!unpackWar || appServerType.equals(ServerDetector.WEBSPHERE_ID)) {
628 File tempDir = new File(
629 SystemProperties.get(SystemProperties.TMP_DIR) +
630 File.separator + Time.getTimestamp());
631
632 excludes += "**/WEB-INF/web.xml";
633
634 WarTask.war(srcFile, tempDir, excludes, webXml);
635
636 if (isJEEDeploymentEnabled()) {
637 File tempWarDir = new File(
638 tempDir.getParent(), deployDir.getName());
639
640 if (tempWarDir.exists()) {
641 tempWarDir.delete();
642 }
643
644 if (!tempDir.renameTo(tempWarDir)) {
645 tempWarDir = tempDir;
646 }
647
648 DeploymentHandler deploymentHandler = getDeploymentHandler();
649
650 deploymentHandler.deploy(tempWarDir, displayName);
651
652 deploymentHandler.releaseDeploymentManager();
653
654 DeleteTask.deleteDirectory(tempWarDir);
655 }
656 else {
657 if (!tempDir.renameTo(deployDir)) {
658 WarTask.war(srcFile, deployDir, excludes, webXml);
659 }
660
661 DeleteTask.deleteDirectory(tempDir);
662 }
663 }
664 else {
665
666
667
668
669
670
671
672 excludes += "**/WEB-INF/web.xml";
673
674 CopyTask.copyDirectory(
675 srcFile, deployDir, StringPool.BLANK, excludes, overwrite,
676 true);
677
678 CopyTask.copyDirectory(
679 srcFile, deployDir, "**/WEB-INF/web.xml", StringPool.BLANK,
680 true, false);
681
682 if (appServerType.equals(ServerDetector.TOMCAT_ID)) {
683
684
685
686
687
688 File deployWebXml = new File(deployDir + "/WEB-INF/web.xml");
689
690 deployWebXml.setLastModified(
691 System.currentTimeMillis() + (Time.SECOND * 6));
692 }
693 }
694
695 if (appServerType.equals(ServerDetector.JETTY_ID)) {
696 DeployUtil.redeployJetty(displayName);
697 }
698 }
699
700 public void deployDirectory(
701 File srcFile, String displayName, boolean override,
702 PluginPackage pluginPackage)
703 throws Exception {
704
705 deployDirectory(
706 srcFile, null, null, displayName, override, pluginPackage);
707 }
708
709 public void deployFile(File srcFile, String specifiedContext)
710 throws Exception {
711
712 PluginPackage pluginPackage = readPluginPackage(srcFile);
713
714 if (_log.isInfoEnabled()) {
715 _log.info("Deploying " + srcFile.getName());
716 }
717
718 String deployDir = null;
719 String displayName = specifiedContext;
720 boolean overwrite = false;
721 String preliminaryContext = specifiedContext;
722
723
724
725
726
727
728 if ((specifiedContext != null) &&
729 srcFile.getName().startsWith(DEPLOY_TO_PREFIX)) {
730
731 displayName = srcFile.getName().substring(
732 DEPLOY_TO_PREFIX.length(), srcFile.getName().length() - 4);
733
734 overwrite = true;
735 preliminaryContext = displayName;
736 }
737
738 if (preliminaryContext == null) {
739 preliminaryContext = getDisplayName(srcFile);
740 }
741
742 if (pluginPackage != null) {
743 if (!PluginPackageUtil.isCurrentVersionSupported(
744 pluginPackage.getLiferayVersions())) {
745
746 throw new AutoDeployException(
747 srcFile.getName() +
748 " does not support this version of Liferay");
749 }
750
751 if (displayName == null) {
752 displayName = pluginPackage.getRecommendedDeploymentContext();
753 }
754
755 if (Validator.isNull(displayName)) {
756 displayName = getDisplayName(srcFile);
757 }
758
759 pluginPackage.setContext(displayName);
760
761 PluginPackageUtil.updateInstallingPluginPackage(
762 preliminaryContext, pluginPackage);
763 }
764
765 if (Validator.isNotNull(displayName)) {
766 deployDir = displayName + ".war";
767 }
768 else {
769 deployDir = srcFile.getName();
770 displayName = getDisplayName(srcFile);
771 }
772
773 if (appServerType.equals(ServerDetector.JBOSS_ID)) {
774 deployDir = jbossPrefix + deployDir;
775 }
776 else if (appServerType.equals(ServerDetector.JETTY_ID) ||
777 appServerType.equals(ServerDetector.OC4J_ID) ||
778 appServerType.equals(ServerDetector.RESIN_ID) ||
779 appServerType.equals(ServerDetector.TOMCAT_ID)) {
780
781 if (unpackWar) {
782 deployDir = deployDir.substring(0, deployDir.length() - 4);
783 }
784 }
785
786 deployDir = destDir + "/" + deployDir;
787
788 File deployDirFile = new File(deployDir);
789
790 try {
791 PluginPackage previousPluginPackage = readPluginPackage(
792 deployDirFile);
793
794 if ((pluginPackage != null) && (previousPluginPackage != null)) {
795 if (_log.isInfoEnabled()) {
796 String name = pluginPackage.getName();
797 String previousVersion = previousPluginPackage.getVersion();
798 String version = pluginPackage.getVersion();
799
800 _log.info(
801 "Updating " + name + " from version " +
802 previousVersion + " to version " + version);
803 }
804
805 if (pluginPackage.isLaterVersionThan(previousPluginPackage)) {
806 overwrite = true;
807 }
808 }
809
810 File mergeDirFile = new File(
811 srcFile.getParent() + "/merge/" + srcFile.getName());
812
813 if (srcFile.isDirectory()) {
814 deployDirectory(
815 srcFile, mergeDirFile, deployDirFile, displayName,
816 overwrite, pluginPackage);
817 }
818 else {
819 boolean deployed = deployFile(
820 srcFile, mergeDirFile, deployDirFile, displayName,
821 overwrite, pluginPackage);
822
823 if (!deployed) {
824 String context = preliminaryContext;
825
826 if (pluginPackage != null) {
827 context = pluginPackage.getContext();
828 }
829
830 PluginPackageUtil.endPluginPackageInstallation(context);
831 }
832 else {
833 if (appServerType.equals(ServerDetector.JBOSS_ID)) {
834 File doDeployFile = new File(deployDir + ".dodeploy");
835
836 FileUtil.write(doDeployFile, StringPool.BLANK);
837 }
838 }
839 }
840 }
841 catch (Exception e) {
842 if (pluginPackage != null) {
843 PluginPackageUtil.endPluginPackageInstallation(
844 pluginPackage.getContext());
845 }
846
847 throw e;
848 }
849 }
850
851 public boolean deployFile(
852 File srcFile, File mergeDir, File deployDir, String displayName,
853 boolean overwrite, PluginPackage pluginPackage)
854 throws Exception {
855
856 boolean undeployOnRedeploy = false;
857
858 try {
859 undeployOnRedeploy = PrefsPropsUtil.getBoolean(
860 PropsKeys.HOT_UNDEPLOY_ON_REDEPLOY,
861 PropsValues.HOT_UNDEPLOY_ON_REDEPLOY);
862 }
863 catch (Exception e) {
864
865
866
867
868
869 }
870
871 if (undeployOnRedeploy) {
872 DeployUtil.undeploy(appServerType, deployDir);
873 }
874
875 if (!overwrite && UpToDateTask.isUpToDate(srcFile, deployDir)) {
876 if (_log.isInfoEnabled()) {
877 _log.info(deployDir + " is already up to date");
878 }
879
880 return false;
881 }
882
883 File tempDir = new File(
884 SystemProperties.get(SystemProperties.TMP_DIR) + File.separator +
885 Time.getTimestamp());
886
887 ExpandTask.expand(srcFile, tempDir);
888
889 deployDirectory(
890 tempDir, mergeDir, deployDir, displayName, overwrite,
891 pluginPackage);
892
893 DeleteTask.deleteDirectory(tempDir);
894
895 return true;
896 }
897
898 public String downloadJar(String jar) throws Exception {
899 String tmpDir = SystemProperties.get(SystemProperties.TMP_DIR);
900
901 File file = new File(
902 tmpDir + "/liferay/com/liferay/portal/deploy/dependencies/" +
903 jar);
904
905 if (!file.exists()) {
906 synchronized (this) {
907 String url = PropsUtil.get(
908 PropsKeys.LIBRARY_DOWNLOAD_URL + jar);
909
910 if (_log.isInfoEnabled()) {
911 _log.info("Downloading library from " + url);
912 }
913
914 byte[] bytes = HttpUtil.URLtoByteArray(url);
915
916 FileUtil.write(file, bytes);
917 }
918 }
919
920 return FileUtil.getAbsolutePath(file);
921 }
922
923 public String fixPortalDependencyJar(String portalJar) {
924 if (portalJar.equals("antlr.jar")) {
925 portalJar = "antlr2.jar";
926 }
927
928 return portalJar;
929 }
930
931 public DeploymentHandler getDeploymentHandler() {
932 String prefix = "auto.deploy." + ServerDetector.getServerId() + ".jee.";
933
934 String dmId = PropsUtil.get(prefix + "dm.id");
935 String dmUser = PropsUtil.get(prefix + "dm.user");
936 String dmPassword = PropsUtil.get(prefix + "dm.passwd");
937 String dfClassName = PropsUtil.get(prefix + "df.classname");
938
939 return new DeploymentHandler(dmId, dmUser, dmPassword, dfClassName);
940 }
941
942 public String getDisplayName(File srcFile) {
943 String displayName = srcFile.getName();
944
945 if (StringUtil.endsWith(displayName, ".war") ||
946 StringUtil.endsWith(displayName, ".xml")) {
947
948 displayName = displayName.substring(0, displayName.length() - 4);
949 }
950
951 if (appServerType.equals(ServerDetector.JBOSS_ID) &&
952 Validator.isNotNull(jbossPrefix) &&
953 displayName.startsWith(jbossPrefix)) {
954
955 displayName = displayName.substring(1, displayName.length());
956 }
957
958 return displayName;
959 }
960
961 public String getExtraContent(
962 double webXmlVersion, File srcFile, String displayName)
963 throws Exception {
964
965 StringBundler sb = new StringBundler();
966
967 sb.append("<display-name>");
968 sb.append(displayName);
969 sb.append("</display-name>");
970
971 sb.append("<listener>");
972 sb.append("<listener-class>");
973 sb.append("com.liferay.portal.kernel.servlet.");
974 sb.append("SerializableSessionAttributeListener");
975 sb.append("</listener-class>");
976 sb.append("</listener>");
977
978 File serviceXml = new File(srcFile + "/WEB-INF/service.xml");
979
980 if (serviceXml.exists()) {
981 sb.append("<listener>");
982 sb.append("<listener-class>");
983 sb.append("com.liferay.portal.kernel.spring.context.");
984 sb.append("PortletContextLoaderListener");
985 sb.append("</listener-class>");
986 sb.append("</listener>");
987 }
988
989 File serverConfigWsdd = new File(
990 srcFile + "/WEB-INF/server-config.wsdd");
991
992 if (serverConfigWsdd.exists()) {
993 File webXml = new File(srcFile + "/WEB-INF/web.xml");
994
995 String content = FileUtil.read(webXml);
996
997 if (!content.contains("axis.servicesPath")) {
998 String remotingContent = FileUtil.read(
999 DeployUtil.getResourcePath("remoting-web.xml"));
1000
1001 sb.append(remotingContent);
1002 }
1003 }
1004
1005 sb.append("<servlet>");
1006 sb.append("<servlet-name>");
1007 sb.append("Set Portlet Class Loader Servlet");
1008 sb.append("</servlet-name>");
1009 sb.append("<servlet-class>");
1010 sb.append("com.liferay.portal.kernel.servlet.");
1011 sb.append("SetPortletClassLoaderServlet");
1012 sb.append("</servlet-class>");
1013 sb.append("<load-on-startup>0</load-on-startup>");
1014 sb.append("</servlet>");
1015
1016 boolean hasTaglib = false;
1017
1018 if (Validator.isNotNull(auiTaglibDTD) ||
1019 Validator.isNotNull(portletTaglibDTD) ||
1020 Validator.isNotNull(portletExtTaglibDTD) ||
1021 Validator.isNotNull(securityTaglibDTD) ||
1022 Validator.isNotNull(themeTaglibDTD) ||
1023 Validator.isNotNull(uiTaglibDTD) ||
1024 Validator.isNotNull(utilTaglibDTD)) {
1025
1026 hasTaglib = true;
1027 }
1028
1029 if (hasTaglib && (webXmlVersion > 2.3)) {
1030 sb.append("<jsp-config>");
1031 }
1032
1033 if (Validator.isNotNull(auiTaglibDTD)) {
1034 sb.append("<taglib>");
1035 sb.append("<taglib-uri>http:
1036 sb.append("<taglib-location>");
1037 sb.append("/WEB-INF/tld/aui.tld");
1038 sb.append("</taglib-location>");
1039 sb.append("</taglib>");
1040 }
1041
1042 if (Validator.isNotNull(portletTaglibDTD)) {
1043 sb.append("<taglib>");
1044 sb.append(
1045 "<taglib-uri>http:
1046 sb.append("<taglib-location>");
1047 sb.append("/WEB-INF/tld/liferay-portlet.tld");
1048 sb.append("</taglib-location>");
1049 sb.append("</taglib>");
1050 }
1051
1052 if (Validator.isNotNull(portletExtTaglibDTD)) {
1053 sb.append("<taglib>");
1054 sb.append("<taglib-uri>");
1055 sb.append("http:
1056 sb.append("</taglib-uri>");
1057 sb.append("<taglib-location>");
1058 sb.append("/WEB-INF/tld/liferay-portlet-ext.tld");
1059 sb.append("</taglib-location>");
1060 sb.append("</taglib>");
1061 }
1062
1063 if (Validator.isNotNull(securityTaglibDTD)) {
1064 sb.append("<taglib>");
1065 sb.append("<taglib-uri>");
1066 sb.append("http:
1067 sb.append("</taglib-uri>");
1068 sb.append("<taglib-location>");
1069 sb.append("/WEB-INF/tld/liferay-security.tld");
1070 sb.append("</taglib-location>");
1071 sb.append("</taglib>");
1072 }
1073
1074 if (Validator.isNotNull(themeTaglibDTD)) {
1075 sb.append("<taglib>");
1076 sb.append("<taglib-uri>http:
1077 sb.append("<taglib-location>");
1078 sb.append("/WEB-INF/tld/liferay-theme.tld");
1079 sb.append("</taglib-location>");
1080 sb.append("</taglib>");
1081 }
1082
1083 if (Validator.isNotNull(uiTaglibDTD)) {
1084 sb.append("<taglib>");
1085 sb.append("<taglib-uri>http:
1086 sb.append("<taglib-location>");
1087 sb.append("/WEB-INF/tld/liferay-ui.tld");
1088 sb.append("</taglib-location>");
1089 sb.append("</taglib>");
1090 }
1091
1092 if (Validator.isNotNull(utilTaglibDTD)) {
1093 sb.append("<taglib>");
1094 sb.append("<taglib-uri>http:
1095 sb.append("<taglib-location>");
1096 sb.append("/WEB-INF/tld/liferay-util.tld");
1097 sb.append("</taglib-location>");
1098 sb.append("</taglib>");
1099 }
1100
1101 if (hasTaglib && (webXmlVersion > 2.3)) {
1102 sb.append("</jsp-config>");
1103 }
1104
1105 sb.append(getSessionFiltersContent());
1106
1107 return sb.toString();
1108 }
1109
1110 public String getIgnoreFiltersContent(File srcFile) throws Exception {
1111 boolean ignoreFiltersEnabled = true;
1112
1113 Properties properties = getPluginPackageProperties(srcFile);
1114
1115 if (properties != null) {
1116 ignoreFiltersEnabled = GetterUtil.getBoolean(
1117 properties.getProperty("ignore-filters-enabled"), true);
1118 }
1119
1120 if (ignoreFiltersEnabled) {
1121 String ignoreFiltersContent = FileUtil.read(
1122 DeployUtil.getResourcePath("ignore-filters-web.xml"));
1123
1124 return ignoreFiltersContent;
1125 }
1126 else {
1127 return StringPool.BLANK;
1128 }
1129 }
1130
1131 public String getInvokerFilterContent() {
1132 StringBundler sb = new StringBundler(4);
1133
1134 sb.append(getInvokerFilterContent("ERROR"));
1135 sb.append(getInvokerFilterContent("FORWARD"));
1136 sb.append(getInvokerFilterContent("INCLUDE"));
1137 sb.append(getInvokerFilterContent("REQUEST"));
1138
1139 return sb.toString();
1140 }
1141
1142 public String getInvokerFilterContent(String dispatcher) {
1143 StringBundler sb = new StringBundler(23);
1144
1145 sb.append("<filter>");
1146 sb.append("<filter-name>Invoker Filter - ");
1147 sb.append(dispatcher);
1148 sb.append("</filter-name>");
1149 sb.append("<filter-class>");
1150 sb.append(InvokerFilter.class.getName());
1151 sb.append("</filter-class>");
1152 sb.append("<init-param>");
1153 sb.append("<param-name>dispatcher</param-name>");
1154 sb.append("<param-value>");
1155 sb.append(dispatcher);
1156 sb.append("</param-value>");
1157 sb.append("</init-param>");
1158 sb.append("</filter>");
1159
1160 sb.append("<filter-mapping>");
1161 sb.append("<filter-name>Invoker Filter - ");
1162 sb.append(dispatcher);
1163 sb.append("</filter-name>");
1164 sb.append("<url-pattern>