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.auto;
016    
017    import com.liferay.portal.deploy.DeployUtil;
018    import com.liferay.portal.kernel.deploy.auto.AutoDeployException;
019    import com.liferay.portal.kernel.log.Log;
020    import com.liferay.portal.kernel.log.LogFactoryUtil;
021    import com.liferay.portal.kernel.util.PropsKeys;
022    import com.liferay.portal.kernel.util.ServerDetector;
023    import com.liferay.portal.kernel.util.StringPool;
024    import com.liferay.portal.tools.deploy.PortletDeployer;
025    import com.liferay.portal.util.PrefsPropsUtil;
026    import com.liferay.portal.util.PropsValues;
027    
028    import java.io.File;
029    
030    import java.util.ArrayList;
031    import java.util.List;
032    
033    /**
034     * @author Ivica Cardic
035     * @author Brian Wing Shun Chan
036     */
037    public class PortletAutoDeployer
038            extends PortletDeployer implements AutoDeployer {
039    
040            public PortletAutoDeployer() {
041                    try {
042                            baseDir = PrefsPropsUtil.getString(
043                                    PropsKeys.AUTO_DEPLOY_DEPLOY_DIR,
044                                    PropsValues.AUTO_DEPLOY_DEPLOY_DIR);
045                            destDir = DeployUtil.getAutoDeployDestDir();
046                            appServerType = ServerDetector.getServerId();
047                            auiTaglibDTD = DeployUtil.getResourcePath("aui.tld");
048                            portletTaglibDTD = DeployUtil.getResourcePath(
049                                    "liferay-portlet.tld");
050                            portletExtTaglibDTD = DeployUtil.getResourcePath(
051                                    "liferay-portlet-ext.tld");
052                            securityTaglibDTD = DeployUtil.getResourcePath(
053                                    "liferay-security.tld");
054                            themeTaglibDTD = DeployUtil.getResourcePath("liferay-theme.tld");
055                            uiTaglibDTD = DeployUtil.getResourcePath("liferay-ui.tld");
056                            utilTaglibDTD = DeployUtil.getResourcePath("liferay-util.tld");
057                            unpackWar = PrefsPropsUtil.getBoolean(
058                                    PropsKeys.AUTO_DEPLOY_UNPACK_WAR,
059                                    PropsValues.AUTO_DEPLOY_UNPACK_WAR);
060                            filePattern = StringPool.BLANK;
061                            jbossPrefix = PrefsPropsUtil.getString(
062                                    PropsKeys.AUTO_DEPLOY_JBOSS_PREFIX,
063                                    PropsValues.AUTO_DEPLOY_JBOSS_PREFIX);
064                            tomcatLibDir = PrefsPropsUtil.getString(
065                                    PropsKeys.AUTO_DEPLOY_TOMCAT_LIB_DIR,
066                                    PropsValues.AUTO_DEPLOY_TOMCAT_LIB_DIR);
067    
068                            List<String> jars = new ArrayList<String>();
069    
070                            addExtJar(jars, "ext-util-bridges.jar");
071                            addExtJar(jars, "ext-util-java.jar");
072                            addExtJar(jars, "ext-util-taglib.jar");
073                            addRequiredJar(jars, "util-bridges.jar");
074                            addRequiredJar(jars, "util-java.jar");
075                            addRequiredJar(jars, "util-taglib.jar");
076    
077                            this.jars = jars;
078    
079                            checkArguments();
080                    }
081                    catch (Exception e) {
082                            _log.error(e);
083                    }
084            }
085    
086            public void autoDeploy(File file, String context)
087                    throws AutoDeployException {
088    
089                    List<String> wars = new ArrayList<String>();
090    
091                    wars.add(file.getName());
092    
093                    this.wars = wars;
094    
095                    try {
096                            deployFile(file, context);
097                    }
098                    catch (Exception e) {
099                            throw new AutoDeployException(e);
100                    }
101            }
102    
103            private static Log _log = LogFactoryUtil.getLog(PortletAutoDeployer.class);
104    
105    }