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