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.AutoDeployDir;
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            @Override
040            public void deploy(AutoDeploymentContext autoDeploymentContext)
041                    throws Exception {
042    
043                    AutoDeployDir.deploy(
044                            autoDeploymentContext,
045                            GlobalStartupAction.getAutoDeployListeners(false));
046            }
047    
048            @Override
049            public String getDeployDir() throws Exception {
050                    return DeployUtil.getAutoDeployDestDir();
051            }
052    
053            @Override
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            @Override
066            public PluginPackage getInstalledPluginPackage(String context) {
067                    return PluginPackageUtil.getInstalledPluginPackage(context);
068            }
069    
070            @Override
071            public List<PluginPackage> getInstalledPluginPackages() {
072                    return PluginPackageUtil.getInstalledPluginPackages();
073            }
074    
075            @Override
076            public boolean isDeployed(String context) {
077                    return PluginPackageUtil.isInstalled(context);
078            }
079    
080            @Override
081            public PluginPackage readPluginPackageProperties(
082                    String displayName, Properties properties) {
083    
084                    return PluginPackageUtil.readPluginPackageProperties(
085                            displayName, properties);
086            }
087    
088            @Override
089            public PluginPackage readPluginPackageXml(String xml) throws Exception {
090                    return PluginPackageUtil.readPluginPackageXml(xml);
091            }
092    
093            @Override
094            public void redeploy(String context) throws Exception {
095                    if (ServerDetector.isJetty()) {
096                            DeployUtil.redeployJetty(context);
097                    }
098                    else if (ServerDetector.isTomcat()) {
099                            DeployUtil.redeployTomcat(context);
100                    }
101            }
102    
103            @Override
104            public void undeploy(String context) throws Exception {
105                    File deployDir = new File(getDeployDir(), context);
106    
107                    DeployUtil.undeploy(ServerDetector.getServerId(), deployDir);
108            }
109    
110    }