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 Class<?> clazz = autoDeployer.getClass();
084
085 _log.debug("Using deployer " + clazz.getName());
086 }
087
088 autoDeployer = new ThreadSafeAutoDeployer(autoDeployer);
089
090 int code = autoDeployer.autoDeploy(autoDeploymentContext);
091
092 if ((code == AutoDeployer.CODE_DEFAULT) && _log.isInfoEnabled()) {
093 _log.info(
094 "Portlets for " + file.getPath() + " copied successfully. " +
095 "Deployment will start in a few seconds.");
096 }
097
098 return code;
099 }
100
101 protected AutoDeployer getMvcDeployer() {
102 if (_mvcPortletAutoDeployer == null) {
103 _mvcPortletAutoDeployer = new MVCPortletAutoDeployer();
104 }
105
106 return _mvcPortletAutoDeployer;
107 }
108
109 protected AutoDeployer getPhpDeployer() throws AutoDeployException {
110 if (_phpPortletAutoDeployer == null) {
111 _phpPortletAutoDeployer = new PHPPortletAutoDeployer();
112 }
113
114 return _phpPortletAutoDeployer;
115 }
116
117 protected AutoDeployer getWaiDeployer() throws AutoDeployException {
118 if (_waiAutoDeployer == null) {
119 _waiAutoDeployer = new WAIAutoDeployer();
120 }
121
122 return _waiAutoDeployer;
123 }
124
125 private static final Log _log = LogFactoryUtil.getLog(
126 PortletAutoDeployListener.class);
127
128 private final AutoDeployer _autoDeployer;
129 private MVCPortletAutoDeployer _mvcPortletAutoDeployer;
130 private PHPPortletAutoDeployer _phpPortletAutoDeployer;
131 private WAIAutoDeployer _waiAutoDeployer;
132
133 }