001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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.context.AutoDeploymentContext;
020    import com.liferay.portal.kernel.util.FileUtil;
021    import com.liferay.portal.tools.deploy.BaseDeployer;
022    import com.liferay.portal.util.PropsValues;
023    
024    import java.io.File;
025    import java.io.IOException;
026    
027    import org.apache.commons.io.FileUtils;
028    
029    /**
030     * @author Miguel Pastor
031     */
032    public class ModuleAutoDeployer extends BaseDeployer {
033    
034            @Override
035            public int deployFile(AutoDeploymentContext autoDeploymentContext)
036                    throws Exception {
037    
038                    String destDir = PropsValues.MODULE_FRAMEWORK_AUTO_DEPLOY_DIRS[0];
039    
040                    if (!FileUtil.exists(destDir)) {
041                            FileUtil.mkdirs(destDir);
042                    }
043    
044                    try {
045                            FileUtils.copyFileToDirectory(
046                                    autoDeploymentContext.getFile(), new File(destDir));
047                    }
048                    catch (IOException ioe) {
049                            throw new AutoDeployException(ioe);
050                    }
051    
052                    return AutoDeployer.CODE_DEFAULT;
053            }
054    
055    }