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

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

Introduction

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

Prototype

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

Source Link

Document

Copies a directory to within another directory preserving the file dates.

Usage

From source file:org.apache.parquet.tools.submit.FileFormat.java

public void CopyFiles(String srcDir, String dstDir) throws IOException {
    File source = new File(srcDir);
    File dest = new File(dstDir);

    if (source.isFile()) {
        FileUtils.copyFileToDirectory(source, dest);
    } else if (source.isDirectory()) {
        FileUtils.copyDirectoryToDirectory(source, dest);

    }//  w  ww.  j  a  v  a 2s . c  o  m
}

From source file:org.apache.rya.accumulo.mr.merge.util.AccumuloInstanceDriver.java

/**
 * Copies the HADOOP_HOME bin directory to the {@link MiniAccumuloCluster} temp directory.
 * {@link MiniAccumuloCluster} expects to find bin/winutils.exe in the MAC temp
 * directory instead of HADOOP_HOME for some reason.
 * @throws IOException/*from   w  w  w.  j  av a  2 s.  com*/
 */
private void copyHadoopHomeToTemp() throws IOException {
    if (IS_COPY_HADOOP_HOME_ENABLED && SystemUtils.IS_OS_WINDOWS) {
        final String hadoopHomeEnv = System.getenv("HADOOP_HOME");
        if (hadoopHomeEnv != null) {
            final File hadoopHomeDir = new File(hadoopHomeEnv);
            if (hadoopHomeDir.exists()) {
                final File binDir = Paths.get(hadoopHomeDir.getAbsolutePath(), "/bin").toFile();
                if (binDir.exists()) {
                    FileUtils.copyDirectoryToDirectory(binDir, tempDir);
                } else {
                    log.warn("The specified path for the Hadoop bin directory does not exist: "
                            + binDir.getAbsolutePath());
                }
            } else {
                log.warn("The specified path for HADOOP_HOME does not exist: "
                        + hadoopHomeDir.getAbsolutePath());
            }
        } else {
            log.warn("The HADOOP_HOME environment variable was not found.");
        }
    }
}

From source file:org.apache.solr.client.solrj.SolrSchemalessExampleTest.java

@BeforeClass
public static void beforeClass() throws Exception {
    File tempSolrHome = createTempDir().toFile();
    // Schemaless renames schema.xml -> schema.xml.bak, and creates + modifies conf/managed-schema,
    // which violates the test security manager's rules, which disallow writes outside the build dir,
    // so we copy the example/example-schemaless/solr/ directory to a new temp dir where writes are allowed.
    FileUtils.copyFileToDirectory(new File(ExternalPaths.SERVER_HOME, "solr.xml"), tempSolrHome);
    File collection1Dir = new File(tempSolrHome, "collection1");
    FileUtils.forceMkdir(collection1Dir);
    FileUtils.copyDirectoryToDirectory(new File(ExternalPaths.SCHEMALESS_CONFIGSET), collection1Dir);
    Properties props = new Properties();
    props.setProperty("name", "collection1");
    OutputStreamWriter writer = null;
    try {//from w  ww .ja  v a 2 s  . c  o  m
        writer = new OutputStreamWriter(FileUtils.openOutputStream(new File(collection1Dir, "core.properties")),
                "UTF-8");
        props.store(writer, null);
    } finally {
        if (writer != null) {
            try {
                writer.close();
            } catch (Exception ignore) {
            }
        }
    }
    createJetty(tempSolrHome.getAbsolutePath());
}

From source file:org.ballerinalang.test.observability.tracing.TracingTestCase.java

@BeforeGroups(value = "tracing-test", alwaysRun = true)
private void setup() throws Exception {
    int[] requiredPorts = new int[] { 9090, 9091, 9092 };

    serverInstance = new BServerInstance(balServer);

    copyFile(new File(System.getProperty(TEST_NATIVES_JAR)),
            new File(serverInstance.getServerHome() + DEST_FUNCTIONS_JAR));

    FileUtils.copyDirectoryToDirectory(
            new File(BASEDIR + File.separator + "target" + File.separator + "lib" + File.separator + "repo"
                    + File.separator + "ballerina" + File.separator + "testobserve"),
            new File(serverInstance.getServerHome() + File.separator + "lib" + File.separator + "repo"
                    + File.separator + "ballerina"));

    String basePath = new File("src" + File.separator + "test" + File.separator + "resources" + File.separator
            + "observability" + File.separator + "tracing").getAbsolutePath();

    String configFile = new File(RESOURCE_LOCATION + "ballerina.conf").getAbsolutePath();
    String[] args = new String[] { "--config", configFile };
    serverInstance.startServer(basePath, "tracingservices", args, requiredPorts);
}

From source file:org.cloudifysource.esc.shell.commands.BootstrapCloud.java

@Override
protected Object doExecute() throws Exception {

    if (this.existingManagersFile != null) {
        if (!this.existingManagersFile.exists() || !this.existingManagersFile.isFile()) {
            throw new CLIStatusException(CloudifyErrorMessages.FILE_NOT_EXISTS.getName(),
                    this.existingManagersFile.getAbsolutePath());
        }/*  w w w  .  j a v  a 2  s  .c o m*/
    }

    if (cloudOverrides != null) {
        if (cloudOverrides.length() >= TEN_K) {
            throw new CLIStatusException(CloudifyErrorMessages.CLOUD_OVERRIDES_TO_LONG.getName());
        }
    }

    final RecipePathResolver pathResolver = new RecipePathResolver();

    File providerDirectory = null;
    if (pathResolver.resolveCloud(new File(getCloudProvider()))) {
        providerDirectory = pathResolver.getResolved();
    } else {
        throw new CLIStatusException("cloud_driver_file_doesnt_exist",
                StringUtils.join(pathResolver.getPathsLooked().toArray(), ", "));
    }

    final File tempFolder = createTempFolder();
    FileUtils.copyDirectoryToDirectory(providerDirectory, tempFolder);
    providerDirectory = new File(tempFolder, providerDirectory.getName());

    defaultSecurityTargetFile = new File(
            providerDirectory + PATH_SEPARATOR + CloudifyConstants.SECURITY_FILE_NAME);

    setSecurityMode();
    copySecurityFiles(providerDirectory.getAbsolutePath());

    // load the cloud file
    final File cloudFile = findCloudFile(providerDirectory);

    // load properties file
    final File cloudPropertiesFile = new File(providerDirectory,
            cloudFile.getName().split("\\.")[0] + DSLUtils.PROPERTIES_FILE_SUFFIX);

    // check for overrides file
    Cloud cloud = null;
    if (cloudOverrides == null) {
        cloud = ServiceReader.readCloud(cloudFile);
    } else {

        // read cloud with overrides properties so they reflect during bootstrap.
        cloud = ServiceReader.readCloudFromDirectory(providerDirectory.getAbsolutePath(),
                FileUtils.readFileToString(cloudOverrides));

        // append the overrides file to the existing properties file
        final FileAppender appender = new FileAppender(cloudPropertiesFile);
        appender.append("Overrides File Properties", cloudOverrides);
        appender.flush();
    }

    // start the installer
    final CloudGridAgentBootstrapper installer = new CloudGridAgentBootstrapper();
    installer.setProviderDirectory(providerDirectory);
    if (this.adminFacade != null) {
        installer.setAdminFacade(this.adminFacade);
    } else {
        installer.setAdminFacade((AdminFacade) session.get(Constants.ADMIN_FACADE));
    }
    installer.setProgressInSeconds(PROGRESS_INTERVAL_SECONDS);
    installer.setVerbose(verbose);
    installer.setCloud(cloud);
    installer.setCloudFile(cloudFile);
    installer.setNoWebServices(noWebServices);
    installer.setUseExisting(this.useExistingManagers);
    installer.setExistingManagersFile(this.existingManagersFile);
    // Bootstrap!

    // Note: The cloud driver may be very verbose. This is EXTEREMELY useful
    // when debugging ESM
    // issues, but can also clutter up the CLI display. It makes more sense to temporarily raise the log level here,
    // so that all of these
    // messages will not be displayed on the console.
    limitLoggingLevel();
    logger.info(getFormattedMessage("bootstrapping_cloud", getCloudProvider()));
    try {
        // TODO: Create the event listeners here and pass them to the installer.
        installer.bootstrapCloudAndWait(securityProfile, username, password, keystorePassword, !skipValidation,
                getTimeoutInMinutes(), TimeUnit.MINUTES);
        return getFormattedMessage("cloud_started_successfully", getCloudProvider());
    } finally {
        // if an overrides file was passed, then the properties file is dirty. delete it.
        if (cloudOverrides != null) {
            cloudPropertiesFile.delete();
        }
        FileUtils.deleteQuietly(tempFolder);
        installer.close();
        restoreLoggingLevel();
    }

}

From source file:org.cloudifysource.esc.shell.commands.GetCloudManagers.java

@Override
protected Object doExecute() throws Exception {

    if (cloudOverrides != null) {
        if (cloudOverrides.length() >= TEN_K) {
            throw new CLIStatusException(CloudifyErrorMessages.CLOUD_OVERRIDES_TO_LONG.getName());
        }//from   w ww.  ja v a2s  . c  o  m
    }

    final RecipePathResolver pathResolver = new RecipePathResolver();

    File providerDirectory = null;
    if (pathResolver.resolveCloud(this.getCloudProvider())) {
        providerDirectory = pathResolver.getResolved();
    } else {
        throw new CLIStatusException("cloud_driver_file_doesnt_exist",
                StringUtils.join(pathResolver.getPathsLooked().toArray(), ", "));
    }

    final File tempFolder = createTempFolder();
    FileUtils.copyDirectoryToDirectory(providerDirectory, tempFolder);
    providerDirectory = new File(tempFolder, providerDirectory.getName());

    // load the cloud file
    final File cloudFile = findCloudFile(providerDirectory);

    // load properties file
    final File cloudPropertiesFile = new File(providerDirectory,
            cloudFile.getName().split("\\.")[0] + DSLUtils.PROPERTIES_FILE_SUFFIX);

    // check for overrides file
    Cloud cloud = null;
    if (cloudOverrides == null) {
        cloud = ServiceReader.readCloud(cloudFile);
    } else {

        // read cloud with overrides properties so they reflect during bootstrap.
        cloud = ServiceReader.readCloudFromDirectory(providerDirectory.getAbsolutePath(),
                FileUtils.readFileToString(cloudOverrides));

        // append the overrides file to the existing properties file
        final FileAppender appender = new FileAppender(cloudPropertiesFile);
        appender.append("Overrides File Properties", cloudOverrides);
        appender.flush();
    }

    // start the installer
    final CloudGridAgentBootstrapper installer = new CloudGridAgentBootstrapper();
    installer.setProviderDirectory(providerDirectory);
    if (this.adminFacade != null) {
        installer.setAdminFacade(this.adminFacade);
    } else {
        installer.setAdminFacade((AdminFacade) session.get(Constants.ADMIN_FACADE));
    }
    installer.setVerbose(verbose);
    installer.setCloud(cloud);
    installer.setCloudFile(cloudFile);

    // logger.info(getFormattedMessage("bootstrapping_cloud", getCloudProvider()));

    try {
        MachineDetails[] managers = installer.getCloudManagers();
        if (managers.length == 0) {
            return getFormattedMessage(CloudifyErrorMessages.MANAGEMENT_SERVERS_NOT_LOCATED.getName());
        }
        final StringBuilder sb = new StringBuilder();
        final String newline = System.getProperty("line.separator");
        for (MachineDetails manager : managers) {
            sb.append(getFormattedMessage(CloudifyErrorMessages.MANAGEMENT_SERVERS_DETAILS.getName(),
                    normalizeDetailsString(manager.getMachineId()),
                    normalizeDetailsString(manager.getPrivateAddress()),
                    normalizeDetailsString(manager.getPublicAddress())));
            sb.append(newline);
        }
        return sb.toString();
    } finally {
        // if an overrides file was passed, then the properties file is dirty. delete it.
        if (cloudOverrides != null) {
            cloudPropertiesFile.delete();
        }
        FileUtils.deleteDirectory(tempFolder);
        installer.close();
    }

}

From source file:org.codehaus.tycho.eclipsepackaging.ProductExportMojo.java

/**
 * @param rootFileEntry files and directories seperated by semicolons, the syntax is:
 *            <ul>// w w w  .  ja v a 2 s  . c  o  m
 *            <li>for a relative file: file:license.html,...</li>
 *            <li>for a absolute file: absolute:file:/eclipse/about.html,...</li>
 *            <li>for a relative folder: rootfiles,...</li>
 *            <li>for a absolute folder: absolute:/eclipse/rootfiles,...</li>
 *            </ul>
 * @param subFolder the sub folder to which the root file entries are copied to
 */
private void handleRootEntry(File target, String rootFileEntries, String subFolder) {
    StringTokenizer t = new StringTokenizer(rootFileEntries, ",");
    File destination = target;
    if (subFolder != null) {
        destination = new File(target, subFolder);
    }
    while (t.hasMoreTokens()) {
        String rootFileEntry = t.nextToken();
        String fileName = rootFileEntry.trim();
        boolean isAbsolute = false;
        if (fileName.startsWith("absolute:")) {
            isAbsolute = true;
            fileName = fileName.substring("absolute:".length());
        }
        if (fileName.startsWith("file")) {
            fileName = fileName.substring("file:".length());
        }
        File source = null;
        if (!isAbsolute) {
            source = new File(project.getBasedir(), fileName);
        } else {
            source = new File(fileName);
        }
        if (source.isFile()) {
            try {
                FileUtils.copyFileToDirectory(source, destination);
            } catch (IOException e) {
                e.printStackTrace();
            }
        } else if (source.isDirectory()) {
            try {
                FileUtils.copyDirectoryToDirectory(source, destination);
            } catch (IOException e) {
                e.printStackTrace();
            }
        } else {
            getLog().warn("Skipping root entry " + rootFileEntry);
        }
    }
}

From source file:org.codehaus.tycho.eclipsepackaging.ProductExportMojo.java

private void copyToDirectory(File source, File targetFolder) throws MojoExecutionException {
    try {//  w ww.j  a  va 2s.  c  o m
        if (source.isFile()) {
            FileUtils.copyFileToDirectory(source, targetFolder);
        } else if (source.isDirectory()) {
            FileUtils.copyDirectoryToDirectory(source, targetFolder);
        } else {
            getLog().warn("Skipping bundle " + source.getAbsolutePath());
        }
    } catch (IOException e) {
        throw new MojoExecutionException("Unable to copy " + source.getName(), e);
    }
}

From source file:org.domainmath.gui.update.UpdateFrame.java

/**
 * Back up contents to a folder./*ww w.j a  v a  2s  .  c  o m*/
 * @return backup folder
 */
private File backup() {
    // make an unique folder to store backup files.
    Long n = new Random().nextLong();
    File backupDir = new File(System.getProperty("user.dir") + File.separator + "backup_" + n.toString());
    backupDir.mkdir();

    // get files list.
    List<File> fileList = getFileList(
            new File(System.getProperty("user.dir") + File.separator + "files_backup.ini"));

    // backup.
    for (File file : fileList) {

        // copy folders.
        if (file.isDirectory()) {
            try {
                FileUtils.copyDirectoryToDirectory(file, backupDir);
                FileUtils.deleteDirectory(file);
            } catch (IOException ex) {

            }
        } else if (file.isFile()) {
            try {
                FileUtils.copyFileToDirectory(file, backupDir);
                FileUtils.forceDelete(file);
            } catch (IOException ex) {

            }
        }
    }
    return backupDir;
}

From source file:org.domainmath.gui.update.UpdateFrame.java

/**
 * Move files to src dir./*from w  w  w  .j a  v  a2 s.c  om*/
 * @param file_list
 * @param srcDir 
 */
private void moveFile(File[] file_list, File srcDir) {
    for (File file : file_list) {

        // copy folders.
        if (file.isDirectory()) {
            try {
                FileUtils.copyDirectoryToDirectory(file, srcDir);
                FileUtils.deleteDirectory(file);
            } catch (IOException ex) {

            }
        } else if (file.isFile()) {
            try {
                FileUtils.copyFileToDirectory(file, srcDir);
                FileUtils.forceDelete(file);
            } catch (IOException ex) {

            }
        }
    }
}