001    /**
002     * Copyright (c) 2000-2012 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;
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 String getInstalledDir() throws Exception {
053                    if (ServerDetector.isGlassfish()) {
054                            File file = new File(
055                                    System.getProperty("catalina.home"), "applications");
056    
057                            return file.getAbsolutePath();
058                    }
059                    else {
060                            return DeployUtil.getAutoDeployDestDir();
061                    }
062            }
063    
064            public PluginPackage getInstalledPluginPackage(String context) {
065                    return PluginPackageUtil.getInstalledPluginPackage(context);
066            }
067    
068            public List<PluginPackage> getInstalledPluginPackages() {
069                    return PluginPackageUtil.getInstalledPluginPackages();
070            }
071    
072            public boolean isDeployed(String context) {
073                    return PluginPackageUtil.isInstalled(context);
074            }
075    
076            public void redeploy(String context) throws Exception {
077                    if (ServerDetector.isJetty()) {
078                            DeployUtil.redeployJetty(context);
079                    }
080                    else if (ServerDetector.isTomcat()) {
081                            DeployUtil.redeployTomcat(context);
082                    }
083            }
084    
085            public void undeploy(String context) throws Exception {
086                    File deployDir = new File(getDeployDir(), context);
087    
088                    if (!deployDir.exists()) {
089                            deployDir = new File(getDeployDir(), context + ".war");
090                    }
091    
092                    DeployUtil.undeploy(ServerDetector.getServerId(), deployDir);
093            }
094    
095    }