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.WebDeployer;
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 Jorge Ferrer
035     */
036    public class WebAutoDeployer extends WebDeployer implements AutoDeployer {
037    
038            public WebAutoDeployer() {
039                    try {
040                            baseDir = PrefsPropsUtil.getString(
041                                    PropsKeys.AUTO_DEPLOY_DEPLOY_DIR,
042                                    PropsValues.AUTO_DEPLOY_DEPLOY_DIR);
043                            destDir = DeployUtil.getAutoDeployDestDir();
044                            appServerType = ServerDetector.getServerId();
045                            unpackWar = PrefsPropsUtil.getBoolean(
046                                    PropsKeys.AUTO_DEPLOY_UNPACK_WAR,
047                                    PropsValues.AUTO_DEPLOY_UNPACK_WAR);
048                            filePattern = StringPool.BLANK;
049                            jbossPrefix = PrefsPropsUtil.getString(
050                                    PropsKeys.AUTO_DEPLOY_JBOSS_PREFIX,
051                                    PropsValues.AUTO_DEPLOY_JBOSS_PREFIX);
052                            tomcatLibDir = PrefsPropsUtil.getString(
053                                    PropsKeys.AUTO_DEPLOY_TOMCAT_LIB_DIR,
054                                    PropsValues.AUTO_DEPLOY_TOMCAT_LIB_DIR);
055    
056                            List<String> jars = new ArrayList<String>();
057    
058                            addExtJar(jars, "ext-util-java.jar");
059                            addRequiredJar(jars, "util-java.jar");
060    
061                            this.jars = jars;
062    
063                            checkArguments();
064                    }
065                    catch (Exception e) {
066                            _log.error(e);
067                    }
068            }
069    
070            public void autoDeploy(File file, String context)
071                    throws AutoDeployException {
072    
073                    List<String> wars = new ArrayList<String>();
074    
075                    wars.add(file.getName());
076    
077                    this.wars = wars;
078    
079                    try {
080                            deployFile(file, context);
081                    }
082                    catch (Exception e) {
083                            throw new AutoDeployException(e);
084                    }
085            }
086    
087            private static Log _log = LogFactoryUtil.getLog(WebAutoDeployer.class);
088    
089    }