001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.deploy;
016    
017    import com.liferay.portal.events.GlobalStartupAction;
018    import com.liferay.portal.kernel.deploy.DeployManager;
019    import com.liferay.portal.kernel.deploy.auto.AutoDeployListener;
020    import com.liferay.portal.kernel.plugin.PluginPackage;
021    import com.liferay.portal.kernel.util.ServerDetector;
022    import com.liferay.portal.plugin.PluginPackageUtil;
023    
024    import java.io.File;
025    
026    import java.util.List;
027    
028    /**
029     * @author Jonathan Potter
030     * @author Brian Wing Shun Chan
031     * @author Ryan Park
032     */
033    public class DeployManagerImpl implements DeployManager {
034    
035            public void deploy(File file) throws Exception {
036                    deploy(file, null);
037            }
038    
039            public void deploy(File file, String context) throws Exception {
040                    List<AutoDeployListener> autoDeployListeners =
041                            GlobalStartupAction.getAutoDeployListeners();
042    
043                    for (AutoDeployListener autoDeployListener : autoDeployListeners) {
044                            autoDeployListener.deploy(file, context);
045                    }
046            }
047    
048            public String getDeployDir() throws Exception {
049                    return DeployUtil.getAutoDeployDestDir();
050            }
051    
052            public PluginPackage getInstalledPluginPackage(String context) {
053                    return PluginPackageUtil.getInstalledPluginPackage(context);
054            }
055    
056            public List<PluginPackage> getInstalledPluginPackages() {
057                    return PluginPackageUtil.getInstalledPluginPackages();
058            }
059    
060            public boolean isDeployed(String context) {
061                    return PluginPackageUtil.isInstalled(context);
062            }
063    
064            public void redeploy(String context) throws Exception {
065                    if (ServerDetector.isJetty()) {
066                            DeployUtil.redeployJetty(context);
067                    }
068                    else if (ServerDetector.isTomcat()) {
069                            DeployUtil.redeployTomcat(context);
070                    }
071            }
072    
073            public void undeploy(String context) throws Exception {
074                    File deployDir = new File(getDeployDir(), context);
075    
076                    if (!deployDir.exists()) {
077                            deployDir = new File(getDeployDir(), context + ".war");
078                    }
079    
080                    DeployUtil.undeploy(ServerDetector.getServerId(), deployDir);
081            }
082    
083    }