com.github.ipaas.ideploy.agent.handler.BackupCodeHandler.java Source code

Java tutorial

Introduction

Here is the source code for com.github.ipaas.ideploy.agent.handler.BackupCodeHandler.java

Source

/**
 * Licensed under the Apache License, Version 2.0 (the "License");  * you may not use this file except in compliance with the License.  * You may obtain a copy of the License at  *    *      http://www.apache.org/licenses/LICENSE-2.0  *    * Unless required by applicable law or agreed to in writing, software  * distributed under the License is distributed on an "AS IS" BASIS,  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  * See the License for the specific language governing permissions and  * limitations under the License..
 */

package com.github.ipaas.ideploy.agent.handler;

import java.io.File;
import java.util.Map;

import org.apache.commons.io.FileUtils;
import org.osgi.framework.BundleContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.github.ipaas.ideploy.agent.CrsCmdHandlerWithFeed;

/**
 * ?
 * 
 * @author wudg
 */

public class BackupCodeHandler extends CrsCmdHandlerWithFeed {

    private static Logger logger = LoggerFactory.getLogger(BackupCodeHandler.class);

    @Override
    public void execute(String flowId, String cmd, Map<String, Object> params, BundleContext bundleContext)
            throws Exception {
        logger.debug("?  flowId:" + flowId + "  cmd:" + cmd + "  params:" + params);

        String srcPath = String.valueOf(params.get("srcPath"));
        String targetPath = String.valueOf(params.get("targetPath"));

        File srcDir = new File(srcPath);

        // ?
        if (!srcDir.exists()) {
            return;
        }

        File destDir = new File(targetPath);

        // 
        if (destDir.exists() || destDir.getParentFile().exists()) {
            FileUtils.cleanDirectory(destDir.getParentFile());
        } else {
            FileUtils.forceMkdir(destDir);
        }

        // 
        FileUtils.copyDirectory(srcDir, destDir);

        logger.debug("??...");
    }

}