001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
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.log.Log;
021    import com.liferay.portal.kernel.log.LogFactoryUtil;
022    import com.liferay.portal.kernel.util.Portal;
023    
024    import java.io.File;
025    
026    /**
027     * @author Ivica Cardic
028     * @author Brian Wing Shun Chan
029     * @author Jorge Ferrer
030     * @author Miguel Pastor
031     * @author Manuel de la Peña
032     */
033    public class PortletAutoDeployListener extends BaseAutoDeployListener {
034    
035            @Override
036            protected AutoDeployer buildAutoDeployer() throws AutoDeployException {
037                    AutoDeployer autoDeployer = null;
038    
039                    if (_portletDeployer) {
040                            autoDeployer = new PortletAutoDeployer();
041                    }
042                    else if (_mvcDeployer) {
043                            autoDeployer = new MVCPortletAutoDeployer();
044                    }
045                    else if (_phpDeployer) {
046                            autoDeployer = new PHPPortletAutoDeployer();
047                    }
048                    else if (_waiDeployer) {
049                            if (_log.isInfoEnabled()) {
050                                    _log.info("Deploying package as a web application");
051                            }
052    
053                            autoDeployer = new WAIAutoDeployer();
054                    }
055    
056                    if (autoDeployer == null) {
057                            throw new AutoDeployException("Unable to find an auto deployer");
058                    }
059    
060                    if (_log.isDebugEnabled()) {
061                            Class<?> clazz = autoDeployer.getClass();
062    
063                            _log.debug("Using deployer " + clazz.getName());
064                    }
065    
066                    return new ThreadSafeAutoDeployer(autoDeployer);
067            }
068    
069            @Override
070            protected String getPluginPathInfoMessage(File file) {
071                    return "Copying portlets for " + file.getPath();
072            }
073    
074            @Override
075            protected String getSuccessMessage(File file) {
076                    return "Portlets for " + file.getPath() + " copied successfully";
077            }
078    
079            @Override
080            protected boolean isDeployable(File file) throws AutoDeployException {
081                    PluginAutoDeployListenerHelper pluginAutoDeployListenerHelper =
082                            new PluginAutoDeployListenerHelper(file);
083    
084                    if (pluginAutoDeployListenerHelper.isMatchingFile(
085                                    "WEB-INF/" + Portal.PORTLET_XML_FILE_NAME_STANDARD)) {
086    
087                            _portletDeployer = true;
088    
089                            return true;
090                    }
091    
092                    if (pluginAutoDeployListenerHelper.isMatchingFile("index_mvc.jsp")) {
093                            _mvcDeployer = true;
094    
095                            return true;
096                    }
097    
098                    if (pluginAutoDeployListenerHelper.isMatchingFile("index.php")) {
099                            _phpDeployer = true;
100    
101                            return true;
102                    }
103    
104                    if (!pluginAutoDeployListenerHelper.isExtPlugin() &&
105                            !pluginAutoDeployListenerHelper.isHookPlugin() &&
106                            !pluginAutoDeployListenerHelper.isMatchingFile(
107                                    "WEB-INF/liferay-layout-templates.xml") &&
108                            !pluginAutoDeployListenerHelper.isThemePlugin() &&
109                            !pluginAutoDeployListenerHelper.isWebPlugin() &&
110                            file.getName().endsWith(".war")) {
111    
112                            _waiDeployer = true;
113    
114                            return true;
115                    }
116    
117                    return false;
118            }
119    
120            private static final Log _log = LogFactoryUtil.getLog(
121                    PortletAutoDeployListener.class);
122    
123            private boolean _mvcDeployer;
124            private boolean _phpDeployer;
125            private boolean _portletDeployer;
126            private boolean _waiDeployer;
127    
128    }