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 boolean deployFile(
710 File srcFile, File mergeDir, File deployDir, String displayName,
711 boolean overwrite, PluginPackage pluginPackage)
712 throws Exception {
713
714 boolean undeployOnRedeploy = false;
715
716 try {
717 undeployOnRedeploy = PrefsPropsUtil.getBoolean(
718 PropsKeys.HOT_UNDEPLOY_ON_REDEPLOY,
719 PropsValues.HOT_UNDEPLOY_ON_REDEPLOY);
720 }
721 catch (Exception e) {
722
723
724
725
726
727 }
728
729 if (undeployOnRedeploy) {
730 DeployUtil.undeploy(appServerType, deployDir);
731 }
732
733 if (!overwrite && UpToDateTask.isUpToDate(srcFile, deployDir)) {
734 if (_log.isInfoEnabled()) {
735 _log.info(deployDir + " is already up to date");
736 }
737
738 return false;
739 }
740
741 File tempDir = new File(
742 SystemProperties.get(SystemProperties.TMP_DIR) + File.separator +
743 Time.getTimestamp());
744
745 ExpandTask.expand(srcFile, tempDir);
746
747 deployDirectory(
748 tempDir, mergeDir, deployDir, displayName, overwrite,
749 pluginPackage);
750
751 DeleteTask.deleteDirectory(tempDir);
752
753 return true;
754 }
755
756 public void deployFile(File srcFile, String specifiedContext)
757 throws Exception {
758
759 PluginPackage pluginPackage = readPluginPackage(srcFile);
760
761 if (_log.isInfoEnabled()) {
762 _log.info("Deploying " + srcFile.getName());
763 }
764
765 String deployDir = null;
766 String displayName = specifiedContext;
767 boolean overwrite = false;
768 String preliminaryContext = specifiedContext;
769
770
771
772
773
774
775 if ((specifiedContext != null) &&
776 srcFile.getName().startsWith(DEPLOY_TO_PREFIX)) {
777
778 displayName = srcFile.getName().substring(
779 DEPLOY_TO_PREFIX.length(), srcFile.getName().length() - 4);
780
781 overwrite = true;
782 preliminaryContext = displayName;
783 }
784
785 if (preliminaryContext == null) {
786 preliminaryContext = getDisplayName(srcFile);
787 }
788
789 if (pluginPackage != null) {
790 if (!PluginPackageUtil.isCurrentVersionSupported(
791 pluginPackage.getLiferayVersions())) {
792
793 throw new AutoDeployException(
794 srcFile.getName() +
795 " does not support this version of Liferay");
796 }
797
798 if (displayName == null) {
799 displayName = pluginPackage.getRecommendedDeploymentContext();
800 }
801
802 if (Validator.isNull(displayName)) {
803 displayName = getDisplayName(srcFile);
804 }
805
806 pluginPackage.setContext(displayName);
807
808 PluginPackageUtil.updateInstallingPluginPackage(
809 preliminaryContext, pluginPackage);
810 }
811
812 if (Validator.isNotNull(displayName)) {
813 deployDir = displayName + ".war";
814 }
815 else {
816 deployDir = srcFile.getName();
817 displayName = getDisplayName(srcFile);
818 }
819
820 if (appServerType.equals(ServerDetector.JBOSS_ID)) {
821 deployDir = jbossPrefix + deployDir;
822 }
823 else if (appServerType.equals(ServerDetector.JETTY_ID) ||
824 appServerType.equals(ServerDetector.OC4J_ID) ||
825 appServerType.equals(ServerDetector.RESIN_ID) ||
826 appServerType.equals(ServerDetector.TOMCAT_ID)) {
827
828 if (unpackWar) {
829 deployDir = deployDir.substring(0, deployDir.length() - 4);
830 }
831 }
832
833 deployDir = destDir + "/" + deployDir;
834
835 File deployDirFile = new File(deployDir);
836
837 try {
838 PluginPackage previousPluginPackage = readPluginPackage(
839 deployDirFile);
840
841 if ((pluginPackage != null) && (previousPluginPackage != null)) {
842 if (_log.isInfoEnabled()) {
843 String name = pluginPackage.getName();
844 String previousVersion = previousPluginPackage.getVersion();
845 String version = pluginPackage.getVersion();
846
847 _log.info(
848 "Updating " + name + " from version " +
849 previousVersion + " to version " + version);
850 }
851
852 if (pluginPackage.isLaterVersionThan(previousPluginPackage)) {
853 overwrite = true;
854 }
855 }
856
857 File mergeDirFile = new File(
858 srcFile.getParent() + "/merge/" + srcFile.getName());
859
860 if (srcFile.isDirectory()) {
861 deployDirectory(
862 srcFile, mergeDirFile, deployDirFile, displayName,
863 overwrite, pluginPackage);
864 }
865 else {
866 boolean deployed = deployFile(
867 srcFile, mergeDirFile, deployDirFile, displayName,
868 overwrite, pluginPackage);
869
870 if (!deployed) {
871 String context = preliminaryContext;
872
873 if (pluginPackage != null) {
874 context = pluginPackage.getContext();
875 }
876
877 PluginPackageUtil.endPluginPackageInstallation(context);
878 }
879 else {
880 if (appServerType.equals(ServerDetector.JBOSS_ID)) {
881 File doDeployFile = new File(deployDir + ".dodeploy");
882
883 FileUtil.write(doDeployFile, StringPool.BLANK);
884 }
885 }
886 }
887 }
888 catch (Exception e) {
889 if (pluginPackage != null) {
890 PluginPackageUtil.endPluginPackageInstallation(
891 pluginPackage.getContext());
892 }
893
894 throw e;
895 }
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/" + jar);
903
904 if (!file.exists()) {
905 synchronized (this) {
906 String url = PropsUtil.get(
907 PropsKeys.LIBRARY_DOWNLOAD_URL + jar);
908
909 if (_log.isInfoEnabled()) {
910 _log.info("Downloading library from " + url);
911 }
912
913 byte[] bytes = HttpUtil.URLtoByteArray(url);
914
915 FileUtil.write(file, bytes);
916 }
917 }
918
919 return FileUtil.getAbsolutePath(file);
920 }
921
922 public String fixPortalDependencyJar(String portalJar) {
923 if (portalJar.equals("antlr.jar")) {
924 portalJar = "antlr2.jar";
925 }
926
927 return portalJar;
928 }
929
930 public DeploymentHandler getDeploymentHandler() {
931 String prefix = "auto.deploy." + ServerDetector.getServerId() + ".jee.";
932
933 String dmId = PropsUtil.get(prefix + "dm.id");
934 String dmUser = PropsUtil.get(prefix + "dm.user");
935 String dmPassword = PropsUtil.get(prefix + "dm.passwd");
936 String dfClassName = PropsUtil.get(prefix + "df.classname");
937
938 return new DeploymentHandler(dmId, dmUser, dmPassword, dfClassName);
939 }
940
941 public String getDisplayName(File srcFile) {
942 String displayName = srcFile.getName();
943
944 if (StringUtil.endsWith(displayName, ".war") ||
945 StringUtil.endsWith(displayName, ".xml")) {
946
947 displayName = displayName.substring(0, displayName.length() - 4);
948 }
949
950 if (appServerType.equals(ServerDetector.JBOSS_ID) &&
951 Validator.isNotNull(jbossPrefix) &&
952 displayName.startsWith(jbossPrefix)) {
953
954 displayName = displayName.substring(1, displayName.length());
955 }
956
957 return displayName;
958 }
959
960 public String getExtraContent(
961 double webXmlVersion, File srcFile, String displayName)
962 throws Exception {
963
964 StringBundler sb = new StringBundler();
965
966 sb.append("<display-name>");
967 sb.append(displayName);
968 sb.append("</display-name>");
969
970 if (webXmlVersion < 2.4) {
971 sb.append("<context-param>");
972 sb.append("<param-name>liferay-invoker-enabled</param-name>");
973 sb.append("<param-value>false</param-value>");
974 sb.append("</context-param>");
975 }
976
977 sb.append("<listener>");
978 sb.append("<listener-class>");
979 sb.append("com.liferay.portal.kernel.servlet.");
980 sb.append("SerializableSessionAttributeListener");
981 sb.append("</listener-class>");
982 sb.append("</listener>");
983
984 File serviceXml = new File(srcFile + "/WEB-INF/service.xml");
985
986 if (serviceXml.exists()) {
987 sb.append("<listener>");
988 sb.append("<listener-class>");
989 sb.append("com.liferay.portal.kernel.spring.context.");
990 sb.append("PortletContextLoaderListener");
991 sb.append("</listener-class>");
992 sb.append("</listener>");
993 }
994
995 File serverConfigWsdd = new File(
996 srcFile + "/WEB-INF/server-config.wsdd");
997
998 if (serverConfigWsdd.exists()) {
999 File webXml = new File(srcFile + "/WEB-INF/web.xml");
1000
1001 String content = FileUtil.read(webXml);
1002
1003 if (!content.contains("axis.servicesPath")) {
1004 String remotingContent = FileUtil.read(
1005 DeployUtil.getResourcePath("remoting-web.xml"));
1006
1007 sb.append(remotingContent);
1008 }
1009 }
1010
1011 sb.append("<servlet>");
1012 sb.append("<servlet-name>");
1013 sb.append("Set Portlet Class Loader Servlet");
1014 sb.append("</servlet-name>");
1015 sb.append("<servlet-class>");
1016 sb.append("com.liferay.portal.kernel.servlet.");
1017 sb.append("SetPortletClassLoaderServlet");
1018 sb.append("</servlet-class>");
1019 sb.append("<load-on-startup>0</load-on-startup>");
1020 sb.append("</servlet>");
1021
1022 boolean hasTaglib = false;
1023
1024 if (Validator.isNotNull(auiTaglibDTD) ||
1025 Validator.isNotNull(portletTaglibDTD) ||
1026 Validator.isNotNull(portletExtTaglibDTD) ||
1027 Validator.isNotNull(securityTaglibDTD) ||
1028 Validator.isNotNull(themeTaglibDTD) ||
1029 Validator.isNotNull(uiTaglibDTD) ||
1030 Validator.isNotNull(utilTaglibDTD)) {
1031
1032 hasTaglib = true;
1033 }
1034
1035 if (hasTaglib && (webXmlVersion > 2.3)) {
1036 sb.append("<jsp-config>");
1037 }
1038
1039 if (Validator.isNotNull(auiTaglibDTD)) {
1040 sb.append("<taglib>");
1041 sb.append("<taglib-uri>http:
1042 sb.append("<taglib-location>");
1043 sb.append("/WEB-INF/tld/aui.tld");
1044 sb.append("</taglib-location>");
1045 sb.append("</taglib>");
1046 }
1047
1048 if (Validator.isNotNull(portletTaglibDTD)) {
1049 sb.append("<taglib>");
1050 sb.append(
1051 "<taglib-uri>http:
1052 sb.append("<taglib-location>");
1053 sb.append("/WEB-INF/tld/liferay-portlet.tld");
1054 sb.append("</taglib-location>");
1055 sb.append("</taglib>");
1056 }
1057
1058 if (Validator.isNotNull(portletExtTaglibDTD)) {
1059 sb.append("<taglib>");
1060 sb.append("<taglib-uri>");
1061 sb.append("http:
1062 sb.append("</taglib-uri>");
1063 sb.append("<taglib-location>");
1064 sb.append("/WEB-INF/tld/liferay-portlet-ext.tld");
1065 sb.append("</taglib-location>");
1066 sb.append("</taglib>");
1067 }
1068
1069 if (Validator.isNotNull(securityTaglibDTD)) {
1070 sb.append("<taglib>");
1071 sb.append("<taglib-uri>");
1072 sb.append("http:
1073 sb.append("</taglib-uri>");
1074 sb.append("<taglib-location>");
1075 sb.append("/WEB-INF/tld/liferay-security.tld");
1076 sb.append("</taglib-location>");
1077 sb.append("</taglib>");
1078 }
1079
1080 if (Validator.isNotNull(themeTaglibDTD)) {
1081 sb.append("<taglib>");
1082 sb.append("<taglib-uri>http:
1083 sb.append("<taglib-location>");
1084 sb.append("/WEB-INF/tld/liferay-theme.tld");
1085 sb.append("</taglib-location>");
1086 sb.append("</taglib>");
1087 }
1088
1089 if (Validator.isNotNull(uiTaglibDTD)) {
1090 sb.append("<taglib>");
1091 sb.append("<taglib-uri>http:
1092 sb.append("<taglib-location>");
1093 sb.append("/WEB-INF/tld/liferay-ui.tld");
1094 sb.append("</taglib-location>");
1095 sb.append("</taglib>");
1096 }
1097
1098 if (Validator.isNotNull(utilTaglibDTD)) {
1099 sb.append("<taglib>");
1100 sb.append("<taglib-uri>http:
1101 sb.append("<taglib-location>");
1102 sb.append("/WEB-INF/tld/liferay-util.tld");
1103 sb.append("</taglib-location>");
1104 sb.append("</taglib>");
1105 }
1106
1107 if (hasTaglib && (webXmlVersion > 2.3)) {
1108 sb.append("</jsp-config>");
1109 }
1110
1111 return sb.toString();
1112 }
1113
1114 public String getExtraFiltersContent(double webXmlVersion, File srcFile)
1115 throws Exception {
1116
1117 if (webXmlVersion > 2.3) {
1118 return getSessionFiltersContent();
1119 }
1120 else {
1121 return StringPool.BLANK;
1122 }
1123 }
1124
1125 public String getIgnoreFiltersContent(File srcFile) throws Exception {
1126 boolean ignoreFiltersEnabled = true;
1127
1128 Properties properties = getPluginPackageProperties(srcFile);
1129
1130 if (properties != null) {
1131 ignoreFiltersEnabled = GetterUtil.getBoolean(
1132 properties.getProperty("ignore-filters-enabled"), true);
1133 }
1134
1135 if (ignoreFiltersEnabled) {
1136 String ignoreFiltersContent = FileUtil.read(
1137 DeployUtil.getResourcePath("ignore-filters-web.xml"));
1138
1139 return ignoreFiltersContent;
1140 }
1141 else {
1142 return StringPool.BLANK;
1143 }
1144 }
1145
1146 public String getInvokerFilterContent() {
1147 StringBundler sb = new StringBundler(4);
1148
1149 sb.append(getInvokerFilterContent("ERROR"));
1150 sb.append(getInvokerFilterContent("FORWARD"));
1151 sb.append(getInvokerFilterContent("INCLUDE"));
1152 sb.append(getInvokerFilterContent("REQUEST"));
1153
1154 return sb.toString();
1155 }
1156
1157 public String getInvokerFilterContent(String dispatcher) {
1158 StringBundler sb = new StringBundler(23);
1159
1160 sb.append("<filter>");
1161 sb.append("<filter-name>Invoker Filter - ");
1162 sb.append(dispatcher);
1163 sb.append("</filter-name>");
1164 sb.append("<filter-class>");
1165 sb.append(InvokerFilter.class.getName());
1166 sb.append("</filter-class>");
1167 sb.append("<init-param>");
1168 sb.append("<param-name>dispatcher</param-name>");
1169 sb.append("<param-value>");
1170 sb.append(dispatcher);
1171 sb.append("</param-value>");
1172 sb.append("</init-param>");
1173 sb.append("</filter>");
1174
1175 sb.append("<filter-mapping>");
1176 sb.append("<filter-name>Invoker Filter - ");
1177 sb.append(dispatcher);
1178 sb.append("</filter-name>");
1179 sb.append("<url-pattern>