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.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.kernel.util.PropsKeys;
022    import com.liferay.portal.tools.deploy.BaseDeployer;
023    import com.liferay.portal.util.PropsUtil;
024    
025    import java.io.File;
026    import java.io.IOException;
027    
028    import org.apache.commons.io.FileUtils;
029    
030    /**
031     * @author Miguel Pastor
032     * @author Gregory Amerson
033     */
034    public class ModuleAutoDeployer extends BaseDeployer {
035    
036            @Override
037            public int deployFile(AutoDeploymentContext autoDeploymentContext)
038                    throws Exception {
039    
040                    String[] moduleFrameworkAutoDeployDirs = PropsUtil.getArray(
041                            PropsKeys.MODULE_FRAMEWORK_AUTO_DEPLOY_DIRS);
042    
043                    String destDir = null;
044    
045                    for (String moduleFrameworkAutoDeployDir :
046                                    moduleFrameworkAutoDeployDirs) {
047    
048                            if (moduleFrameworkAutoDeployDir.endsWith("modules")) {
049                                    destDir = moduleFrameworkAutoDeployDir;
050                            }
051                    }
052    
053                    FileUtil.mkdirs(destDir);
054    
055                    try {
056                            FileUtils.copyFileToDirectory(
057                                    autoDeploymentContext.getFile(), new File(destDir));
058                    }
059                    catch (IOException ioe) {
060                            throw new AutoDeployException(ioe);
061                    }
062    
063                    return AutoDeployer.CODE_DEFAULT;
064            }
065    
066    }