Example usage for org.apache.commons.io FileUtils moveToDirectory

List of usage examples for org.apache.commons.io FileUtils moveToDirectory

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils moveToDirectory.

Prototype

public static void moveToDirectory(File src, File destDir, boolean createDestDir) throws IOException 

Source Link

Document

Moves a file or directory to the destination directory.

Usage

From source file:org.zend.php.zendserver.deployment.core.sdk.ProductionPackageBuilder.java

/**
 * Executes the ZF Deploy tool on the temporary directory.
 *//* w ww  . j ava  2s  .  co m*/
@Override
protected void finishOutputFile(File zpkFile) throws IOException {
    File appDir = new File(zpkTempDir, getAppdirName(configLocation));

    // make sure the .gitignore file is copied if any
    File srcGitIgnore = new File(container, GITIGNORE);
    File destGitIgnore = new File(appDir, GITIGNORE);
    if (srcGitIgnore.exists() && !destGitIgnore.exists()) {
        FileUtils.copyFile(srcGitIgnore, destGitIgnore);
    }

    // move everything but the app dir into the zpkdata directory
    File zpkDataDir = new File(zpkTempDir, ZPK_DATA_DIR);
    for (File file : zpkTempDir.listFiles()) {
        if (!file.getName().equals(getAppdirName(configLocation))) {
            FileUtils.moveToDirectory(file, zpkDataDir, true);
        }
    }

    // construct the command to execute the zf-deploy tool
    String zpkFilePath = zpkFile.getPath();
    String projectPath = appDir.getPath();
    String zpkDataPath = zpkDataDir.getPath();
    String[] command = new String[] { findPhpExePath(), getDeployPharPath(), BUILD_COMMAND, zpkFilePath,
            TARGET_OPTION, projectPath, ZPK_DATA_OPTION, zpkDataPath, CONFIGS_OPTION, appConfigsPath };

    // delete any previous instance of the result ZPK file
    new File(zpkFilePath).delete();

    // execute the ZF Deploy tool
    try {
        Process process = new ProcessBuilder(command).start();
        // wait for the process to finish
        int exitCode = process.waitFor();
        if (exitCode != 0) {
            String message = NLS.bind(Messages.ProductionPackageBuilder_ErrorZFDeployTool, exitCode,
                    IOUtils.toString(process.getInputStream()));
            throw new IOException(message);
        }
    } catch (InterruptedException e) {
        DeploymentCore.log(e);
    }

    // delete the temporary directory
    FileUtils.deleteDirectory(zpkTempDir);
}

From source file:slavetest.TestStoreCopy.java

/**
 * Checks that leftovers in the sandbox directory are discarded on store
 * copy./*from   w ww .j  ava2 s .co m*/
 *
 * @throws Exception
 */
@Test
public void sandboxIsOverwritten() throws Exception {
    slave.shutdown();

    Transaction secondMasterTx = master.beginTx();
    Node n = master.getNodeById(nodeId);
    n.setProperty("foo2", "bar2");
    secondMasterTx.success();
    secondMasterTx.finish();

    File sandboxed = new File(slaveDir, HighlyAvailableGraphDatabase.COPY_FROM_MASTER_TEMP);
    FileUtils.moveToDirectory(new File(slaveDir, "neostore"), sandboxed, false);
    FileUtils.moveToDirectory(new File(slaveDir, "neostore.propertystore.db"), sandboxed, false);
    Assert.assertEquals(3, sandboxed.listFiles().length);

    startSlave();

    Assert.assertEquals("bar", slave.getNodeById(nodeId).getProperty("foo"));
    Assert.assertEquals("bar2", slave.getNodeById(nodeId).getProperty("foo2"));
}