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.LayoutTemplateDeployer;
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 LayoutTemplateAutoDeployer
038            extends LayoutTemplateDeployer implements AutoDeployer {
039    
040            public LayoutTemplateAutoDeployer() {
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                            unpackWar = PrefsPropsUtil.getBoolean(
048                                    PropsKeys.AUTO_DEPLOY_UNPACK_WAR,
049                                    PropsValues.AUTO_DEPLOY_UNPACK_WAR);
050                            filePattern = StringPool.BLANK;
051                            jbossPrefix = PrefsPropsUtil.getString(
052                                    PropsKeys.AUTO_DEPLOY_JBOSS_PREFIX,
053                                    PropsValues.AUTO_DEPLOY_JBOSS_PREFIX);
054                            unpackWar = PrefsPropsUtil.getBoolean(
055                                    PropsKeys.AUTO_DEPLOY_UNPACK_WAR,
056                                    PropsValues.AUTO_DEPLOY_UNPACK_WAR);
057    
058                            List<String> jars = new ArrayList<String>();
059    
060                            this.jars = jars;
061    
062                            checkArguments();
063                    }
064                    catch (Exception e) {
065                            _log.error(e);
066                    }
067            }
068    
069            public void autoDeploy(File file, String context)
070                    throws AutoDeployException {
071    
072                    List<String> wars = new ArrayList<String>();
073    
074                    wars.add(file.getName());
075    
076                    this.wars = wars;
077    
078                    try {
079                            deployFile(file, context);
080                    }
081                    catch (Exception e) {
082                            throw new AutoDeployException(e);
083                    }
084            }
085    
086            private static Log _log = LogFactoryUtil.getLog(
087                    LayoutTemplateAutoDeployer.class);
088    
089    }