001    /**
002     * Copyright (c) 2000-present 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.kernel.deploy.auto;
016    
017    import com.liferay.portal.kernel.deploy.auto.context.AutoDeploymentContext;
018    import com.liferay.portal.kernel.log.Log;
019    import com.liferay.portal.kernel.log.LogFactoryUtil;
020    
021    import java.io.File;
022    
023    /**
024     * @author Ivica Cardic
025     * @author Brian Wing Shun Chan
026     * @author Ryan Park
027     * @author Manuel de la Peña
028     */
029    public abstract class BaseAutoDeployListener implements AutoDeployListener {
030    
031            @Override
032            public final int deploy(AutoDeploymentContext autoDeploymentContext)
033                    throws AutoDeployException {
034    
035                    File file = autoDeploymentContext.getFile();
036    
037                    if (_log.isDebugEnabled()) {
038                            _log.debug("Invoking deploy for " + file.getPath());
039                    }
040    
041                    if (_log.isInfoEnabled()) {
042                            _log.info(getPluginPathInfoMessage(file));
043                    }
044    
045                    AutoDeployer autoDeployer = buildAutoDeployer();
046    
047                    int code = autoDeployer.autoDeploy(autoDeploymentContext);
048    
049                    if ((code == AutoDeployer.CODE_DEFAULT) && _log.isInfoEnabled()) {
050                            _log.info(
051                                    getSuccessMessage(file) +
052                                            ". Deployment will start in a few seconds.");
053                    }
054    
055                    return code;
056            }
057    
058            @Override
059            public boolean isDeployable(AutoDeploymentContext autoDeploymentContext)
060                    throws AutoDeployException {
061    
062                    return isDeployable(autoDeploymentContext.getFile());
063            }
064    
065            protected abstract AutoDeployer buildAutoDeployer()
066                    throws AutoDeployException;
067    
068            protected abstract String getPluginPathInfoMessage(File file);
069    
070            protected abstract String getSuccessMessage(File file);
071    
072            protected abstract boolean isDeployable(File file)
073                    throws AutoDeployException;
074    
075            private static final Log _log = LogFactoryUtil.getLog(
076                    BaseAutoDeployListener.class);
077    
078    }