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