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.auto;
016    
017    import com.liferay.portal.kernel.deploy.auto.AutoDeployException;
018    import com.liferay.portal.kernel.deploy.auto.AutoDeployer;
019    import com.liferay.portal.kernel.deploy.auto.BaseAutoDeployListener;
020    import com.liferay.portal.kernel.deploy.auto.context.AutoDeploymentContext;
021    import com.liferay.portal.kernel.log.Log;
022    import com.liferay.portal.kernel.log.LogFactoryUtil;
023    
024    import java.io.File;
025    
026    /**
027     * @author Ivica Cardic
028     * @author Brian Wing Shun Chan
029     */
030    public class ThemeAutoDeployListener extends BaseAutoDeployListener {
031    
032            public ThemeAutoDeployListener() {
033                    _autoDeployer = new ThemeAutoDeployer();
034            }
035    
036            @Override
037            public int deploy(AutoDeploymentContext autoDeploymentContext)
038                    throws AutoDeployException {
039    
040                    File file = autoDeploymentContext.getFile();
041    
042                    if (_log.isDebugEnabled()) {
043                            _log.debug("Invoking deploy for " + file.getPath());
044                    }
045    
046                    if (!isThemePlugin(file)) {
047                            return AutoDeployer.CODE_NOT_APPLICABLE;
048                    }
049    
050                    if (_log.isInfoEnabled()) {
051                            _log.info("Copying themes for " + file.getPath());
052                    }
053    
054                    int code = _autoDeployer.autoDeploy(autoDeploymentContext);
055    
056                    if ((code == AutoDeployer.CODE_DEFAULT) && _log.isInfoEnabled()) {
057                            _log.info(
058                                    "Themes for " + file.getPath() + " copied successfully. " +
059                                            "Deployment will start in a few seconds.");
060                    }
061    
062                    return code;
063            }
064    
065            private static Log _log = LogFactoryUtil.getLog(
066                    ThemeAutoDeployListener.class);
067    
068            private AutoDeployer _autoDeployer;
069    
070    }