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 autoDeployer = null;
050
051 if (isMatchingFile(
052 file, "WEB-INF/" + Portal.PORTLET_XML_FILE_NAME_STANDARD)) {
053
054 autoDeployer = _autoDeployer;
055 }
056 else if (isMatchingFile(file, "index_mvc.jsp")) {
057 autoDeployer = getMvcDeployer();
058 }
059 else if (isMatchingFile(file, "index.php")) {
060 autoDeployer = 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 autoDeployer = 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 " + autoDeployer.getClass().getName());
084 }
085
086 autoDeployer = new ThreadSafeAutoDeployer(autoDeployer);
087
088 int code = autoDeployer.autoDeploy(autoDeploymentContext);
089
090 if ((code == AutoDeployer.CODE_DEFAULT) && _log.isInfoEnabled()) {
091 _log.info(
092 "Portlets for " + file.getPath() + " copied successfully. " +
093 "Deployment will start in a few seconds.");
094 }
095
096 return code;
097 }
098
099 protected AutoDeployer getMvcDeployer() {
100 if (_mvcPortletAutoDeployer == null) {
101 _mvcPortletAutoDeployer = new MVCPortletAutoDeployer();
102 }
103
104 return _mvcPortletAutoDeployer;
105 }
106
107 protected AutoDeployer getPhpDeployer() throws AutoDeployException {
108 if (_phpPortletAutoDeployer == null) {
109 _phpPortletAutoDeployer = new PHPPortletAutoDeployer();
110 }
111
112 return _phpPortletAutoDeployer;
113 }
114
115 protected AutoDeployer getWaiDeployer() throws AutoDeployException {
116 if (_waiAutoDeployer == null) {
117 _waiAutoDeployer = new WAIAutoDeployer();
118 }
119
120 return _waiAutoDeployer;
121 }
122
123 private static Log _log = LogFactoryUtil.getLog(
124 PortletAutoDeployListener.class);
125
126 private AutoDeployer _autoDeployer;
127 private MVCPortletAutoDeployer _mvcPortletAutoDeployer;
128 private PHPPortletAutoDeployer _phpPortletAutoDeployer;
129 private WAIAutoDeployer _waiAutoDeployer;
130
131 }