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(getSuccessMessage(file));
051                    }
052    
053                    return code;
054            }
055    
056            @Override
057            public boolean isDeployable(AutoDeploymentContext autoDeploymentContext)
058                    throws AutoDeployException {
059    
060                    return isDeployable(autoDeploymentContext.getFile());
061            }
062    
063            protected abstract AutoDeployer buildAutoDeployer()
064                    throws AutoDeployException;
065    
066            protected abstract String getPluginPathInfoMessage(File file);
067    
068            protected abstract String getSuccessMessage(File file);
069    
070            protected abstract boolean isDeployable(File file)
071                    throws AutoDeployException;
072    
073            private static final Log _log = LogFactoryUtil.getLog(
074                    BaseAutoDeployListener.class);
075    
076    }