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.ericsson.eiffel.remrem.semantics.clone.PrepareLocalEiffelSchemas.java

/**
 * This method is used to copy eiffeloperations schemas to eiffelrepo schemas location
 * //from   w  w  w  .ja  v a  2  s .  co  m
 * @param operationsRepoPath
 *            local operations repository url
 * @param eiffelRepoPath
 *            local eiffel repository url
 */
private void copyOperationSchemas(final String operationsRepoPath, final String eiffelRepoPath) {
    final File operationSchemas = new File(
            operationsRepoPath + File.separator + EiffelConstants.SCHEMA_LOCATION);
    final File eiffelSchemas = new File(eiffelRepoPath + File.separator + EiffelConstants.SCHEMA_LOCATION);
    if (operationSchemas.isDirectory()) {
        try {
            FileUtils.copyDirectory(operationSchemas, eiffelSchemas);
        } catch (IOException e) {
            System.out.println(
                    "Exception occurred while copying schemas from operations repository to eiffel repository");
            e.printStackTrace();
        }
    }
}

From source file:com.liferay.ide.project.core.tests.UpgradeLiferayProjectsOpTests.java

protected IRuntime createNewRuntime620(final String name) throws Exception {
    final IPath newRuntimeLocation = new Path(getLiferayRuntimeDir620().toString() + "-new");

    if (!newRuntimeLocation.toFile().exists()) {
        FileUtils.copyDirectory(getLiferayRuntimeDir620().toFile(), newRuntimeLocation.toFile());
    }/*from  w w w .j a  v a 2s .c  o  m*/

    assertEquals(true, newRuntimeLocation.toFile().exists());

    final NullProgressMonitor npm = new NullProgressMonitor();

    IRuntime runtime = ServerCore.findRuntime(name);

    if (runtime == null) {
        final IRuntimeWorkingCopy runtimeWC = ServerCore.findRuntimeType(getRuntimeId620()).createRuntime(name,
                npm);

        runtimeWC.setName(name);
        runtimeWC.setLocation(newRuntimeLocation);

        runtime = runtimeWC.save(true, npm);
    }

    ServerCore.getRuntimes();
    assertNotNull(runtime);

    return runtime;
}

From source file:com.doplgangr.secrecy.FileSystem.Vault.java

public Vault rename(String name) {
    if (wrongPass)
        return null; //bye
    java.io.File folder = new java.io.File(path);
    java.io.File newFoler = new java.io.File(folder.getParent(), name);
    try {//from   w w  w  .ja va  2s  . c om
        FileUtils.copyDirectory(folder, newFoler);
    } catch (IOException e) {
        // New Folder should be cleared. Only preserver old folder
        try {
            FileUtils.deleteDirectory(newFoler);
        } catch (IOException ignored) {
            //ignore
        }
        return null;
    }
    try {
        FileUtils.deleteDirectory(folder);
    } catch (IOException ignored) {
        //ignored
    }
    return new Vault(name, key);
}

From source file:com.streamsets.datacollector.MiniSDCTestingUtility.java

/**
 * Start mini SDC//from  w  w  w  .  j a v a  2 s  . co m
 * @param executionMode the Execution mode - could be standalone or cluster
 * @return
 * @throws Exception
 */
public MiniSDC createMiniSDC(ExecutionMode executionMode) throws Exception {
    Properties miniITProps = new Properties();
    File miniITProperties = new File(Resources.getResource("miniIT.properties").toURI());
    InputStream sdcInStream = new FileInputStream(miniITProperties);
    miniITProps.load(sdcInStream);
    String sdcDistRoot = (String) miniITProps.get(SDC_DIST_DIR);
    File sdcDistFile = new File(sdcDistRoot);
    if (!sdcDistFile.exists()) {
        throw new RuntimeException("SDC dist root dir " + sdcDistFile.getAbsolutePath() + "doesn't exist");
    }
    LOG.info("SDC dist root at " + sdcDistFile.getAbsolutePath());
    sdcInStream.close();

    File target = getDataTestDir();
    String targetRoot = target.getAbsolutePath();
    File etcTarget = new File(target, "etc");
    File resourcesTarget = new File(target, "resources");
    FileUtils.copyDirectory(new File(sdcDistRoot + "/etc"), etcTarget);
    FileUtils.copyDirectory(new File(sdcDistRoot + "/resources"), resourcesTarget);
    FileUtils.copyDirectory(new File(sdcDistRoot + "/libexec"), new File(target, "libexec"));
    // Set execute permissions back on script
    Set<PosixFilePermission> set = new HashSet<PosixFilePermission>();
    set.add(PosixFilePermission.OWNER_EXECUTE);
    set.add(PosixFilePermission.OWNER_READ);
    set.add(PosixFilePermission.OWNER_WRITE);
    set.add(PosixFilePermission.OTHERS_READ);
    Files.setPosixFilePermissions(new File(target, "libexec" + "/_cluster-manager").toPath(), set);
    File staticWebDir = new File(target, "static-web");
    staticWebDir.mkdir();

    setExecutePermission(new File(target, "libexec" + "/_cluster-manager").toPath());
    File log4jProperties = new File(etcTarget, "sdc-log4j.properties");
    if (log4jProperties.exists()) {
        log4jProperties.delete();
    }
    Files.copy(Paths.get(Resources.getResource("log4j.properties").toURI()), log4jProperties.toPath());

    File sdcProperties = new File(etcTarget, "sdc.properties");
    System.setProperty("sdc.conf.dir", etcTarget.getAbsolutePath());
    System.setProperty("sdc.resources.dir", resourcesTarget.getAbsolutePath());
    System.setProperty("sdc.libexec.dir", targetRoot + "/libexec");
    System.setProperty("sdc.static-web.dir", targetRoot + "/static-web");
    rewriteProperties(sdcProperties, executionMode);
    this.miniSDC = new MiniSDC(sdcDistRoot);
    return this.miniSDC;
}

From source file:com.amazonaws.eclipse.dynamodb.testtool.TestToolManager.java

/**
 * Install the given version of the test tool.
 *
 * @param version The version of the test tool to install.
 * @param monitor A progress monitor to keep updated.
 *//*from w w  w .ja  v a 2s.  c  o  m*/
public void installVersion(final TestToolVersion version, final IProgressMonitor monitor) {

    if (version.isInstalled()) {
        return;
    }

    try {

        File tempFile = File.createTempFile("dynamodb_local_", "");
        tempFile.delete();
        if (!tempFile.mkdirs()) {
            throw new RuntimeException("Failed to create temporary " + "directory for download");
        }

        File zipFile = new File(tempFile, "dynamodb_local.zip");

        download(version.getDownloadKey(), zipFile, monitor);

        File unzipped = new File(tempFile, "unzipped");
        if (!unzipped.mkdirs()) {
            throw new RuntimeException("Failed to create temporary " + "directory for unzipping");
        }

        unzip(zipFile, unzipped);

        File versionDir = getVersionDirectory(version.getName());
        FileUtils.copyDirectory(unzipped, versionDir);

    } catch (IOException exception) {
        throw new RuntimeException("Error installing DynamoDB Local: " + exception.getMessage(), exception);
    } finally {
        monitor.done();
        installing.remove(version.getName());
    }
}

From source file:com.amazonaws.eclipse.sdk.ui.AbstractSdkManager.java

/**
 * Copies the SDK given into the workspace's private state storage for this
 * plugin.//from w ww .j  av a  2  s  .c  o  m
 */
private void copySdk(AbstractSdkInstall install, IProgressMonitor monitor) {
    monitor.subTask("Copying SDK to workspace metadata");
    try {
        File sdkDir = getSDKInstallDir();
        File versionDir = new File(sdkDir, install.getVersion());

        if (versionDir.exists() && sdkInstallFactory.createSdkInstallFromDisk(versionDir).isValidSdkInstall())
            return;
        if (!versionDir.exists() && !versionDir.mkdirs())
            throw new Exception("Couldn't make SDK directory " + versionDir);

        FileUtils.copyDirectory(install.getRootDirectory(), versionDir);
        monitor.worked(20);
    } catch (IllegalStateException e) {
        JavaSdkPlugin.getDefault().getLog()
                .log(new Status(Status.WARNING, JavaSdkPlugin.PLUGIN_ID, "No state directory to cache SDK", e));
    } catch (Exception e) {
        JavaSdkPlugin.getDefault().getLog()
                .log(new Status(Status.ERROR, JavaSdkPlugin.PLUGIN_ID, e.getMessage(), e));
    }
}

From source file:edu.si.services.sidora.rest.batch.BatchTitleTest.java

/**
 * Sets up the Temp directories used by the
 * route./*from  w  ww .ja  v  a2  s .  c  o  m*/
 * @throws IOException
 */
@BeforeClass
public static void setupSysPropsTempResourceDir() throws IOException {
    //Create and Copy the Input dir xslt, etc. files used in the route
    tempInputDirectory = new File("Input");
    if (!tempInputDirectory.exists()) {
        tempInputDirectory.mkdir();
    }

    //The Location of the Input dir in the project
    File inputSrcDirLoc = new File("../Routes/Sidora-Batch/Karaf-config/Input");

    //Copy the Input src files so the camel route can find them
    FileUtils.copyDirectory(inputSrcDirLoc, tempInputDirectory);
}

From source file:com.magnet.plugin.generator.Generator.java

public void makeFilePerformance(ProgressIndicator progressIndicator) {
    progressIndicator.setFraction(0.1);//from  ww  w.ja va 2 s. c o m
    try {
        File cachedSourceFolder = cacheManager.getControllerSourceFolder();

        // copy test files
        File generatedTestFiles = new File(cachedSourceFolder, CacheManager.RELATIVE_TEST_DIR);
        File targetTestFolder = ProjectManager.getTestSourceFolderFile(project);
        if (generatedTestFiles.exists()) {
            if (targetTestFolder != null && targetTestFolder.exists()) {
                // if test filename exists, copy the test into a fileName_latest.java test
                List<String> testFiles = FileHelper.getCommonTestFiles(project, controllerName, packageName);
                String fileName = testFiles == null || testFiles.size() == 0 ? null : testFiles.get(0); // assuming one test class
                if (fileName == null || !fileName.endsWith(".java")) {
                    FileUtils.copyDirectory(generatedTestFiles, targetTestFolder);
                } else {
                    String newFileName = fileName + ".latest";
                    String header = Rest2MobileMessages.getMessage(Rest2MobileMessages.LATEST_TEST_CLASS_HEADER,
                            fileName.substring(fileName.lastIndexOf('/') + 1));
                    File newFile = new File(generatedTestFiles, newFileName);
                    File oldFile = new File(generatedTestFiles, fileName);
                    String content = FileUtils.readFileToString(oldFile);
                    FileUtils.write(newFile, header);
                    FileUtils.write(newFile, content, true);
                    FileUtils.forceDelete(oldFile);
                    FileUtils.copyDirectory(generatedTestFiles, targetTestFolder);
                }
            }
            // TODO: the src directory can be confusing, it should be called test,or tests as with ios.
            File rootTestDirectory = new File(cachedSourceFolder, "src");
            FileUtils.deleteDirectory(rootTestDirectory);
        }

        // copy others
        FileUtils.copyDirectory(cachedSourceFolder, ProjectManager.getSourceFolderFile(project));
        ControllerHistoryManager.saveController(project, cacheManager.getControllerFolder().getName());
        File controllerFile = ProjectManager.getControllerFile(project, packageName, controllerName);
        if (null != controllerFile) {
            showControllerFile(controllerFile);
        }
        //displayIndicatorMessage(progressIndicator, "Completed generation", 100);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.magnet.plugin.r2m.generator.Generator.java

public void makeFilePerformance(ProgressIndicator progressIndicator) {
    progressIndicator.setFraction(0.1);//from w w w.  j  a  va 2s.c  o m
    try {
        File cachedSourceFolder = cacheManager.getControllerSourceFolder();

        // copy test files
        File generatedTestFiles = new File(cachedSourceFolder, CacheManager.RELATIVE_TEST_DIR);
        File targetTestFolder = ProjectManager.getTestSourceFolderFile(project);
        if (generatedTestFiles.exists()) {
            if (targetTestFolder != null && targetTestFolder.exists()) {
                // if test filename exists, copy the test into a fileName_latest.java test
                List<String> testFiles = FileHelper.getCommonTestFiles(project, controllerName, packageName);
                String fileName = testFiles == null || testFiles.size() == 0 ? null : testFiles.get(0); // assuming one test class
                if (fileName == null || !fileName.endsWith(".java")) {
                    FileUtils.copyDirectory(generatedTestFiles, targetTestFolder);
                } else {
                    String newFileName = fileName + ".latest";
                    String header = R2MMessages.getMessage("LATEST_TEST_CLASS_HEADER",
                            fileName.substring(fileName.lastIndexOf('/') + 1));
                    File newFile = new File(generatedTestFiles, newFileName);
                    File oldFile = new File(generatedTestFiles, fileName);
                    String content = FileUtils.readFileToString(oldFile);
                    FileUtils.write(newFile, header);
                    FileUtils.write(newFile, content, true);
                    FileUtils.forceDelete(oldFile);
                    FileUtils.copyDirectory(generatedTestFiles, targetTestFolder);
                }
            }
            // TODO: the src directory can be confusing, it should be called test,or tests as with ios.
            File rootTestDirectory = new File(cachedSourceFolder, "src");
            FileUtils.deleteDirectory(rootTestDirectory);
        }

        // copy others
        FileUtils.copyDirectory(cachedSourceFolder, ProjectManager.getSourceFolderFile(project));
        ControllerHistoryManager.saveController(project, cacheManager.getControllerFolder().getName());
        File controllerFile = ProjectManager.getControllerFile(project, packageName, controllerName);
        if (null != controllerFile) {
            showControllerFile(controllerFile);
        }
        //displayIndicatorMessage(progressIndicator, "Completed generation", 100);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.github.jengelman.gradle.plugins.integration.TestFile.java

public void copyTo(File target) {
    if (isDirectory()) {
        try {/*from  ww  w  . j a va  2  s  . c o  m*/
            FileUtils.copyDirectory(this, target);
        } catch (IOException e) {
            throw new RuntimeException(
                    String.format("Could not copy test directory '%s' to '%s'", this, target), e);
        }
    } else {
        try {
            FileUtils.copyFile(this, target);
        } catch (IOException e) {
            throw new RuntimeException(String.format("Could not copy test file '%s' to '%s'", this, target), e);
        }
    }
}