001    /**
002     * Copyright (c) 2000-2013 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.deploy.auto.context.AutoDeploymentContext;
021    import com.liferay.portal.kernel.plugin.PluginPackage;
022    import com.liferay.portal.kernel.security.pacl.DoPrivileged;
023    import com.liferay.portal.kernel.util.ServerDetector;
024    import com.liferay.portal.plugin.PluginPackageUtil;
025    
026    import java.io.File;
027    
028    import java.util.List;
029    import java.util.Properties;
030    
031    /**
032     * @author Jonathan Potter
033     * @author Brian Wing Shun Chan
034     * @author Ryan Park
035     */
036    @DoPrivileged
037    public class DeployManagerImpl implements DeployManager {
038    
039            public void deploy(AutoDeploymentContext autoDeploymentContext)
040                    throws Exception {
041    
042                    List<AutoDeployListener> autoDeployListeners =
043                            GlobalStartupAction.getAutoDeployListeners();
044    
045                    for (AutoDeployListener autoDeployListener : autoDeployListeners) {
046                            autoDeployListener.deploy(autoDeploymentContext);
047                    }
048            }
049    
050            public String getDeployDir() throws Exception {
051                    return DeployUtil.getAutoDeployDestDir();
052            }
053    
054            public String getInstalledDir() throws Exception {
055                    if (ServerDetector.isGlassfish()) {
056                            File file = new File(
057                                    System.getProperty("com.sun.aas.instanceRoot"), "autodeploy");
058    
059                            return file.getAbsolutePath();
060                    }
061    
062                    return DeployUtil.getAutoDeployDestDir();
063            }
064    
065            public PluginPackage getInstalledPluginPackage(String context) {
066                    return PluginPackageUtil.getInstalledPluginPackage(context);
067            }
068    
069            public List<PluginPackage> getInstalledPluginPackages() {
070                    return PluginPackageUtil.getInstalledPluginPackages();
071            }
072    
073            public boolean isDeployed(String context) {
074                    return PluginPackageUtil.isInstalled(context);
075            }
076    
077            public PluginPackage readPluginPackageProperties(
078                    String displayName, Properties properties) {
079    
080                    return PluginPackageUtil.readPluginPackageProperties(
081                            displayName, properties);
082            }
083    
084            public PluginPackage readPluginPackageXml(String xml) throws Exception {
085                    return PluginPackageUtil.readPluginPackageXml(xml);
086            }
087    
088            public void redeploy(String context) throws Exception {
089                    if (ServerDetector.isJetty()) {
090                            DeployUtil.redeployJetty(context);
091                    }
092                    else if (ServerDetector.isTomcat()) {
093                            DeployUtil.redeployTomcat(context);
094                    }
095            }
096    
097            public void undeploy(String context) throws Exception {
098                    File deployDir = new File(getDeployDir(), context);
099    
100                    DeployUtil.undeploy(ServerDetector.getServerId(), deployDir);
101            }
102    
103    }