001
014
015 package com.liferay.portal.deploy.auto;
016
017 import com.liferay.portal.kernel.deploy.auto.AutoDeployException;
018 import com.liferay.portal.kernel.deploy.auto.BaseAutoDeployListener;
019 import com.liferay.portal.kernel.deploy.auto.context.AutoDeploymentContext;
020 import com.liferay.portal.kernel.log.Log;
021 import com.liferay.portal.kernel.log.LogFactoryUtil;
022 import com.liferay.portal.util.Portal;
023
024 import java.io.File;
025
026
032 public class PortletAutoDeployListener extends BaseAutoDeployListener {
033
034 public PortletAutoDeployListener() {
035 _autoDeployer = new PortletAutoDeployer();
036 }
037
038 public void deploy(AutoDeploymentContext autoDeploymentContext)
039 throws AutoDeployException {
040
041 File file = autoDeploymentContext.getFile();
042
043 if (_log.isDebugEnabled()) {
044 _log.debug("Invoking deploy for " + file.getPath());
045 }
046
047 AutoDeployer deployer = null;
048
049 if (isMatchingFile(
050 file, "WEB-INF/" + Portal.PORTLET_XML_FILE_NAME_STANDARD)) {
051
052 deployer = _autoDeployer;
053 }
054 else if (isMatchingFile(file, "index_mvc.jsp")) {
055 deployer = getMvcDeployer();
056 }
057 else if (isMatchingFile(file, "index.php")) {
058 deployer = getPhpDeployer();
059 }
060 else if (!isExtPlugin(file) && !isHookPlugin(file) &&
061 !isMatchingFile(
062 file, "WEB-INF/liferay-layout-templates.xml") &&
063 !isThemePlugin(file) && !isWebPlugin(file) &&
064 file.getName().endsWith(".war")) {
065
066 if (_log.isInfoEnabled()) {
067 _log.info("Deploying package as a web application");
068 }
069
070 deployer = getWaiDeployer();
071 }
072 else {
073 return;
074 }
075
076 if (_log.isInfoEnabled()) {
077 _log.info("Copying portlets for " + file.getPath());
078 }
079
080 if (_log.isDebugEnabled()) {
081 _log.debug("Using deployer " + deployer.getClass().getName());
082 }
083
084 int code = deployer.autoDeploy(autoDeploymentContext);
085
086 if ((code == AutoDeployer.CODE_DEFAULT) && _log.isInfoEnabled()) {
087 _log.info(
088 "Portlets for " + file.getPath() + " copied successfully. " +
089 "Deployment will start in a few seconds.");
090 }
091 }
092
093 protected AutoDeployer getMvcDeployer() {
094 if (_mvcPortletAutoDeployer == null) {
095 _mvcPortletAutoDeployer = new MVCPortletAutoDeployer();
096 }
097
098 return _mvcPortletAutoDeployer;
099 }
100
101 protected AutoDeployer getPhpDeployer() throws AutoDeployException {
102 if (_phpPortletAutoDeployer == null) {
103 _phpPortletAutoDeployer = new PHPPortletAutoDeployer();
104 }
105
106 return _phpPortletAutoDeployer;
107 }
108
109 protected AutoDeployer getWaiDeployer() throws AutoDeployException {
110 if (_waiAutoDeployer == null) {
111 _waiAutoDeployer = new WAIAutoDeployer();
112 }
113
114 return _waiAutoDeployer;
115 }
116
117 private static Log _log = LogFactoryUtil.getLog(
118 PortletAutoDeployListener.class);
119
120 private AutoDeployer _autoDeployer;
121 private MVCPortletAutoDeployer _mvcPortletAutoDeployer;
122 private PHPPortletAutoDeployer _phpPortletAutoDeployer;
123 private WAIAutoDeployer _waiAutoDeployer;
124
125 }