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

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

Introduction

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

Prototype

public static void moveDirectory(File srcDir, File destDir) throws IOException 

Source Link

Document

Moves a directory.

Usage

From source file:org.specrunner.webdriver.result.WritableWebDriver.java

/**
 * Move files/directory./*from   w ww. j av a 2s. co  m*/
 * 
 * @param from
 *            The original file/directory.
 * @param to
 *            The target file/directory.
 * @throws IOException
 *             On move errors.
 * @throws ResultException
 *             On action errors.
 */
protected void move(File from, File to) throws IOException, ResultException {
    if (to.exists()) {
        if (!to.delete()) {
            throw new ResultException("Could not remove resources '" + to + "'.");
        }
    }
    if (UtilLog.LOG.isDebugEnabled()) {
        UtilLog.LOG.debug("Moving " + from + " to " + to + ".");
    }
    if (from.isDirectory()) {
        FileUtils.moveDirectory(from, to);
    } else {
        FileUtils.moveFile(from, to);
    }
}

From source file:org.syncany.operations.down.actions.FileSystemAction.java

protected void moveToConflictFile(NormalizedPath conflictingPath) throws IOException {
    if (!FileUtil.exists(conflictingPath.toFile())) {
        logger.log(Level.INFO,/*  w  ww  .  j a v  a2  s  .  com*/
                "     - Creation of conflict file not necessary. Locally conflicting file vanished from "
                        + conflictingPath);
        return;
    }

    int attempts = 0;

    while (attempts++ < 10) {
        NormalizedPath conflictedCopyPath = null;

        try {
            conflictedCopyPath = findConflictFilename(conflictingPath);
            logger.log(Level.INFO, "     - Local version conflicts, moving local file " + conflictingPath
                    + " to " + conflictedCopyPath + " ...");

            if (conflictingPath.toFile().isDirectory()) {
                FileUtils.moveDirectory(conflictingPath.toFile(), conflictedCopyPath.toFile());
            } else {
                FileUtils.moveFile(conflictingPath.toFile(), conflictedCopyPath.toFile());
            }

            // Success!
            break;
        } catch (FileExistsException e) {
            logger.log(Level.SEVERE, "     - Cannot create conflict file; attempt = " + attempts + " for file: "
                    + conflictedCopyPath, e);
        } catch (FileNotFoundException e) {
            logger.log(Level.INFO, "     - Conflict file vanished. Don't care!", e);
        } catch (Exception e) {
            throw new RuntimeException("What to do here?", e);
        }
    }
}

From source file:org.syncany.tests.integration.scenarios.framework.MoveFolderWithinFolder.java

@Override
public void execute() throws Exception {
    File fromFolder = pickFolder(3123);
    File toFolder = new File(fromFolder + "-ren" + fromFolder.hashCode());

    log(this, fromFolder + " -> " + toFolder);
    FileUtils.moveDirectory(fromFolder, toFolder);
}

From source file:org.syncany.tests.util.TestClient.java

public void moveFile(String fileFrom, String fileTo) throws Exception {
    File fromLocalFile = getLocalFile(fileFrom);
    File toLocalFile = getLocalFile(fileTo);

    try {//  w  w  w  .  j a  va 2  s .c om
        if (fromLocalFile.isDirectory()) {
            FileUtils.moveDirectory(fromLocalFile, toLocalFile);
        } else {
            FileUtils.moveFile(fromLocalFile, toLocalFile);
        }
    } catch (Exception e) {
        throw new Exception("Move failed: " + fileFrom + " --> " + fileTo, e);
    }
}

From source file:org.talend.dataprep.folder.store.file.FileSystemFolderRepository.java

@Override
public Folder renameFolder(String folderId, String newName) {

    final Folder folder = getFolderById(folderId);

    if (folder == null) {
        throw new IllegalArgumentException("Cannot rename a folder that cannot be found");
    }/*from ww  w.j a  va2 s . c  om*/

    FolderPath folderToMovePath = FolderPath.deserializeFromString(folder.getPath());

    if (folderToMovePath.isRoot()) {
        throw new IllegalArgumentException("Cannot rename home folder");
    }

    if (newName.contains(PATH_SEPARATOR.toString())) {
        throw new TDPException(ILLEGAL_FOLDER_NAME, build().put("name", newName));
    }

    FolderPath targetFolderPath = new FolderPath(folderToMovePath.getParent(), newName);
    Path folderPath = pathsConverter.toPath(folderToMovePath);
    Path newFolderPath = pathsConverter.toPath(targetFolderPath);

    try {
        FileUtils.moveDirectory(folderPath.toFile(), newFolderPath.toFile());
    } catch (IOException e) {
        throw new TDPException(UNABLE_TO_RENAME_FOLDER, e, build().put("path", folder.getPath()));
    }

    return getFolderById(toId(pathsConverter.toFolderPath(newFolderPath)));
}

From source file:org.tolven.assembler.admin.AdminAssembler.java

private void deleteDir(File dir) {
    String tmpDirname = dir.getAbsolutePath() + ".tmp";
    File tmpDir = new File(tmpDirname);
    try {//from w w w .  ja  v  a 2  s. c  om
        FileUtils.deleteDirectory(tmpDir);
        if (dir.exists()) {
            FileUtils.moveDirectory(dir, tmpDir);
        }
        FileUtils.deleteDirectory(tmpDir);
    } catch (IOException ex) {
        throw new RuntimeException("Could not delete the directory: " + dir, ex);
    } finally {
        try {
            FileUtils.deleteDirectory(tmpDir);
        } catch (IOException ex) {
            throw new RuntimeException("Could not delete build directory: " + tmpDir, ex);
        }
    }
}

From source file:org.tolven.plugin.repository.RepositoryUpgrade.java

private void deleteBuildDir() {
    info("Deleting " + getConfigPluginsWrapper().getBuildDir());
    if (!isNoop()) {
        String tmpDirname = getConfigPluginsWrapper().getBuildDir().getAbsolutePath() + ".tmp";
        File tmpDir = new File(tmpDirname);
        try {/*from  www .ja va 2  s  .  c o  m*/
            FileUtils.deleteDirectory(tmpDir);
            if (getConfigPluginsWrapper().getBuildDir().exists()) {
                FileUtils.moveDirectory(getConfigPluginsWrapper().getBuildDir(), tmpDir);
            }
        } catch (IOException ex) {
            throw new RuntimeException(
                    "Could not delete build directory: " + getConfigPluginsWrapper().getBuildDir(), ex);
        } finally {
            try {
                FileUtils.deleteDirectory(tmpDir);
            } catch (IOException ex) {
                throw new RuntimeException("Could not delete build directory: " + tmpDir, ex);
            }
        }
    }
}

From source file:org.wso2.carbon.esb.samples.test.miscellaneous.Sample650TestCase.java

@BeforeClass(alwaysRun = true)
public void uploadSynapseConfig() throws Exception {

    super.init();
    serverManager = new ServerConfigurationManager(context);

    File existingDir = new File(FrameworkPathUtil.getCarbonHome() + File.separator + "repository"
            + File.separator + "samples" + File.separator + "synapse_sample_650.xml");

    File newDir = new File(FrameworkPathUtil.getCarbonHome() + File.separator + "repository" + File.separator
            + "samples" + File.separator + "default");

    File targetDir = new File(FrameworkPathUtil.getCarbonHome() + File.separator + "repository" + File.separator
            + "samples" + File.separator + "synapse_sample_650.xml" + File.separator + "default");

    FileUtils.moveDirectory(existingDir, newDir);

    FileUtils.moveDirectory(newDir, targetDir);

    serverManager.applyConfiguration(new File(
            TestConfigurationProvider.getResourceLocation() + File.separator + "artifacts" + File.separator
                    + "ESB" + File.separator + "miscellaneous" + File.separator + "axis2.xml"));

    // serverManager.restartGracefully();
    super.init();

    endPointAdminClient = new EndPointAdminClient(contextUrls.getBackEndUrl(), getSessionCookie());

    localEntriesAdminClient = new LocalEntriesAdminClient(contextUrls.getBackEndUrl(), getSessionCookie());

    sequenceAdminServiceClient = new SequenceAdminServiceClient(contextUrls.getBackEndUrl(),
            getSessionCookie());/* w ww  .  j  a v a  2  s. co  m*/

    taskAdminClient = new TaskAdminClient(contextUrls.getBackEndUrl(), getSessionCookie());
}

From source file:org.xwiki.contrib.repository.npm.internal.NpmExtensionFile.java

private void copyJsLibraries(File unPackedPackage, File jsLibrariesDirectory) throws IOException {
    unPackedPackage = new File(unPackedPackage.getAbsolutePath() + File.separator + "package");
    jsLibrariesDirectory.delete(); // this is required by FileUtils.moveDirectory
    // TODO: 08.08.2017 perhaps there should be some selection of copied js libraries
    FileUtils.moveDirectory(unPackedPackage, jsLibrariesDirectory);
}

From source file:org.xwiki.store.filesystem.internal.migration.R1000000XWIKI14758DataMigration.java

private File migrate(File file, boolean caseInsensitive) throws IOException {
    File newFile = encode(file, caseInsensitive);

    if (!newFile.equals(file)) {
        this.logger.info("Renaming folder [{}] into [{}]", file, newFile);

        // Rename the file if needed
        if (file.isDirectory()) {
            FileUtils.moveDirectory(file, newFile);
        } else {/*from   ww  w .ja v a 2 s .c  o m*/
            FileUtils.moveFile(file, newFile);
        }

        return newFile;
    }

    return file;
}