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

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

Introduction

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

Prototype

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

Source Link

Document

Copies a whole directory to a new location preserving the file dates.

Usage

From source file:com.enderville.enderinstaller.util.InstallScript.java

/**
 * Make backup copies of important files/folders in case the backup fails.
 *
 * @throws IOException//from   w ww.  ja  v a  2s  . c  om
 */
private static void createBackup() throws IOException {
    //TODO what other folders to backup?
    FileUtils.copyFile(new File(InstallerConfig.getMinecraftJar()),
            new File(InstallerConfig.getMinecraftJar() + ".backup"));
    File mods = new File(InstallerConfig.getMinecraftModsFolder());
    File modsBackup = new File(InstallerConfig.getMinecraftModsFolder() + "_backup/");
    if (modsBackup.exists()) {
        FileUtils.deleteDirectory(modsBackup);
    }
    if (mods.exists()) {
        FileUtils.copyDirectory(mods, modsBackup);
    }

    for (String name : otherThingsToBackup) {
        String fname = FilenameUtils
                .normalize(FilenameUtils.concat(InstallerConfig.getMinecraftFolder(), name));
        String fnameBackup = fname + "_backup";
        File f = new File(fname);
        File backup = new File(fnameBackup);
        if (backup.exists()) {
            FileUtils.deleteDirectory(backup);
        }
        if (f.exists()) {
            FileUtils.copyDirectory(f, backup);
        }
    }
}

From source file:com.arcusys.liferay.vaadinplugin.VaadinUpdater.java

public void restoreFromBackup() throws IOException {

    outputLog.log("Restore old vaadin files from " + backupPath);

    String vaadinResourcePath = ControlPanelPortletUtil.getVaadinResourceDir();
    File vaadinResource = new File(vaadinResourcePath);
    outputLog.log("Restore old vaadin resources : " + vaadinResourcePath + " to " + backupPath);
    String backupreSourcesPath = backupDir.getPath() + "/resources";
    File backupreSourcesDir = new File(backupreSourcesPath);
    if (!backupreSourcesDir.exists()) {
        outputLog.log("Can't restore resources. Can't find directory " + backupreSourcesPath);
    } else {/*from   w  w w.  ja v a  2 s .  c o  m*/
        FileUtils.copyDirectory(backupreSourcesDir, vaadinResource);
    }

    //        File vaadin6Version = ControlPanelPortletUtil.get6VersionVaadinJarLocation();
    //        if (vaadin6Version.exists()) {
    //            outputLog.log("Backup vaadin.jar : " + vaadin6Version.getAbsolutePath());
    //            FileUtils.copyFile(vaadin6Version, backupDir);
    //        }

    String backupFilesPath = backupPath + "/";

    VaadinVersion currentVaadinInfo = VaadinVersion.getVaadinVersion(currentVaadinVersion);
    Collection<VaadinFileInfo> vaadinFileInfos = currentVaadinInfo.getVaadinFilesInfo();

    StringBuffer sb = new StringBuffer();
    Boolean isExistsNotBackuped = false;

    for (VaadinFileInfo fileInfo : vaadinFileInfos) {
        try {
            replaceFile(backupFilesPath, fileInfo.getPlace(), fileInfo.getName());
        } catch (Exception ex) {
            sb.append(fileInfo.getName()).append(", ");
            isExistsNotBackuped = true;
        }
    }

    if (isExistsNotBackuped) {
        outputLog.log("Can't restore next files : " + sb.toString());
    }
}

From source file:com.goodformobile.build.mobile.RIMPackageMojoTest.java

@Test
public void testExecuteOnProguardPreverifiedClasses() throws Exception {

    File projectDirectory = getRelativeFile("projects/maven-test-app-preverified-with-proguard/pom.xml")
            .getParentFile();//from w w w. ja va 2s .  c  o m

    File workProjectDirectory = new File(getBasedir(), "target/temp/project");
    if (workProjectDirectory.exists()) {
        FileUtils.cleanDirectory(workProjectDirectory);
    }
    FileUtils.copyDirectory(projectDirectory, workProjectDirectory);

    RIMPackageMojo mojo = setupMojo();

    MavenProject project = getProject(mojo);

    setupProject(workProjectDirectory, project);

    mojo.execute();

    // Ensure a jad is generated.
    File targetDirectory = new File(workProjectDirectory, "target");
    File expectedJad = new File(targetDirectory.getAbsoluteFile() + File.separator + "deliverables"
            + File.separator + "maven_test_app.jad");
    assertTrue("Unable to find generated jad: " + expectedJad.getAbsolutePath(), expectedJad.exists());

    // Ensure a cod file is generated.
    File expectedCod = new File(targetDirectory.getAbsoluteFile() + File.separator + "deliverables"
            + File.separator + "maven_test_app.cod");
    assertTrue("Unable to find generated cod: " + expectedCod.getAbsolutePath(), expectedCod.exists());

}

From source file:com.twinsoft.convertigo.beans.core.MobileApplication.java

private void checkFolder() {
    File folder = getResourceFolder();
    if (!folder.exists()) {
        try {/*from  w  w w. j a v a2 s  .c  om*/
            File templateFolder = new File(Engine.TEMPLATES_PATH, "base/DisplayObjects/mobile");
            FileUtils.copyDirectory(templateFolder, folder);
        } catch (IOException e) {
            Engine.logBeans.warn("(MobileApplication) The folder '" + folder.getAbsolutePath()
                    + "' doesn't exist and cannot be created", e);
        }
    }
}

From source file:com.genericworkflownodes.knime.nodegeneration.NodeGenerator.java

private void copyContributingPlugins() {
    for (ContributingPluginMeta contributingPluginMeta : contributingPluginMetas) {
        try {//from w  w w .  j a  va 2  s.  co m
            // TODO: Handle compiled classes in bin/ or build/ (maybe check
            // build.properties for output folder)
            FileUtils.copyDirectory(contributingPluginMeta.getContributingPluginDirectory(), new File(
                    baseBinaryDirectory, contributingPluginMeta.getContributingPluginDirectory().getName()));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:edu.ur.file.db.FileSystemManager.java

/**
 * Move the directory from one location to another.  It currently
 * does this by a copy and delete./*from   ww  w .  j ava  2  s . co  m*/
 * 
 * @param currentPath path including the directory name
 * @param destPath path including the new directory name.
 * 
 * @return true if the directory is moved
 * 
 * @throws Illegal state exception if the currentPath does not exist
 * @throws Illegal state exception if the destintation path exists
 *         meaning an overwrite is occuring.
 * @throws RuntimeExcpetion if the file cannot be moved
 */
static boolean copyDirectory(String currentPath, String destPath) {
    if (log.isDebugEnabled()) {
        log.debug("Copying " + currentPath + " to " + destPath);
    }

    boolean copied = false;
    File current = new File(currentPath);

    if (!current.exists()) {
        throw new IllegalStateException("Current directory does not exist " + current.getAbsolutePath());
    }

    File dest = new File(destPath);

    if (dest.exists()) {
        throw new IllegalStateException(
                "Destination " + dest.getAbsolutePath() + " already exists cannot overwrite. "
                        + " current directory must be copied to a non-existent directory");
    }

    try {
        FileUtils.copyDirectory(current, dest);
        copied = dest.exists();
    } catch (IOException io) {
        throw new RuntimeException(io);
    }

    return copied;
}

From source file:com.collective.celos.CelosClientServerTest.java

@Test
public void testGetWorkflowStatusTransitionToSuccess() throws Exception {

    File src = new File(Thread.currentThread().getContextClassLoader()
            .getResource("com/collective/celos/client/wf-list").toURI());
    FileUtils.copyDirectory(src, workflowsDir);

    celosClient.iterateScheduler();/*w  w w .ja  v  a2s.c o  m*/
    celosClient.iterateScheduler();
    celosClient.iterateScheduler();

    List<SlotState> slotStates = celosClient.getWorkflowStatus(new WorkflowID("workflow-2")).getSlotStates();
    Assert.assertEquals(slotStates.size(), SLOTS_IN_CELOS_SERVER_SLIDING_WINDOW);

    SlotState slotStateLst = slotStates.get(slotStates.size() - 1);
    Assert.assertEquals(slotStateLst.getStatus(), SlotState.Status.SUCCESS);
    Assert.assertNotNull(slotStateLst.getExternalID());
    Assert.assertEquals(slotStateLst.getRetryCount(), 0);

    slotStates = slotStates.subList(0, slotStates.size() - 1);
    for (SlotState slotState : slotStates) {
        Assert.assertEquals(slotState.getStatus(), SlotState.Status.READY);
        Assert.assertNull(slotState.getExternalID());
        Assert.assertEquals(slotState.getRetryCount(), 0);
    }
}

From source file:bioLockJ.AppController.java

/**
 * If user prop indicates they need a copy of the input files, copy them to the project dir.
 *
 * @throws Exception//from  ww w. j av  a  2 s  .c  o  m
 */
private static void copyInputDirs(final File targetDir) throws Exception {

    if ((targetDir == null) || !targetDir.isDirectory()) {
        throw new Exception("Unable to copy input files.  Parameter \"targetDir\" is not a directory: "
                + ((targetDir == null) ? "null" : targetDir.getAbsolutePath()));
    }

    final File startedFlag = new File(targetDir.getAbsolutePath() + File.separator + Constants.BLJ_STARTED);
    if (startedFlag.exists()) {
        recursiveFileDelete(targetDir);
    }

    if (!targetDir.exists()) {
        targetDir.mkdirs();
    }

    for (final File dir : Config.requireExistingDirectories(Config.INPUT_DIRS)) {
        Log.out.info("Copying input files from " + dir + " to " + targetDir);
        FileUtils.copyDirectory(dir, targetDir);
    }

    final File completeFlag = new File(targetDir.getAbsolutePath() + File.separator + Constants.BLJ_COMPLETE);
    final FileWriter writer = new FileWriter(completeFlag);
    writer.close();
    if (!completeFlag.exists()) {
        throw new Exception("Unable to create " + completeFlag.getAbsolutePath());
    }
}

From source file:com.mycompany.projecta.CommonTasks.java

@Override
public String DirectoryToDirectory(String source, String target) throws Exception {

    try {/*ww w . j a v  a 2s .  c om*/

        File Source = new File(source);
        File Target = new File(target);

        FileUtils.copyDirectory(Source, Target);
        FileUtils.cleanDirectory(Source);
    }

    catch (Exception ex) {
        ex.printStackTrace(System.out);
        return ex.toString();
    }

    return "passed";
}

From source file:com.enderville.enderinstaller.util.InstallScript.java

/**
 * If the install fails, restore everything that we backed up.
 *
 * @throws IOException/*from  ww w . j  a  va 2 s.co m*/
 */
private static void restoreBackup() throws IOException {
    //TODO what other folders to restore?
    FileUtils.copyFile(new File(InstallerConfig.getMinecraftJar() + ".backup"),
            new File(InstallerConfig.getMinecraftJar()));
    File mods = new File(InstallerConfig.getMinecraftModsFolder());
    File modsBackup = new File(InstallerConfig.getMinecraftModsFolder() + "_backup");
    if (modsBackup.exists()) {
        FileUtils.deleteDirectory(mods);
        FileUtils.copyDirectory(modsBackup, mods);
    }
    for (String name : otherThingsToBackup) {
        String fname = FilenameUtils
                .normalize(FilenameUtils.concat(InstallerConfig.getMinecraftFolder(), name));
        String fnameBackup = fname + "_backup";
        File f = new File(fname);
        File backup = new File(fnameBackup);
        if (backup.exists()) {
            FileUtils.copyDirectory(backup, f);
        }
    }
}