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.collective.celos.CelosClientServerTest.java

@Test
public void testGetWorkflowListEmptyBeforeClearCache() throws Exception {
    Set<WorkflowID> workflowIDs = celosClient.getWorkflowList();
    Assert.assertTrue(workflowIDs.isEmpty());

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

    workflowIDs = celosClient.getWorkflowList();
    Assert.assertTrue(workflowIDs.isEmpty());

    celosClient.clearCache();/*from w  w w  . j a v  a  2  s  .c  o  m*/

    workflowIDs = celosClient.getWorkflowList();
    Assert.assertEquals(Sets.newHashSet(workflowIDs),
            Sets.newHashSet(new WorkflowID("workflow-1"), new WorkflowID("workflow-2"),
                    new WorkflowID("workflow-Itrntinliztin"), new WorkflowID("workflow-4")));
}

From source file:com.thoughtworks.go.mail.SmtpJes2MailSenderIntegrationTest.java

private void startJesServer() throws IOException, InterruptedException {
    File jesDir = new File("../tools/jes-2.0-beta2");
    FileUtils.deleteDirectory(new File(jesDir, "conf.run"));
    File runDir = new File(jesDir, "conf.run");
    runDir.mkdir();//from  w  w w  .ja v  a  2s  .  c  o  m
    FileUtils.copyDirectory(new File(jesDir, "conf.noauth"), new File(runDir, "conf"));
    FileUtils.copyDirectory(new File(jesDir, "security"), new File(runDir, "security"));

    SysOutStreamConsumer output = new SysOutStreamConsumer();
    CommandLine command = CommandLine.createCommandLine("/bin/bash").withWorkingDir(jesDir)
            .withArg("start-server.sh");
    System.out.println("command.toString() = " + command.toString());
    processWrapper = command.execute(output, new EnvironmentVariableContext(), null);
    RandomPort.waitForPort(2525, 20000L);
    RandomPort.waitForPort(1101, 20000L);
}

From source file:com.geewhiz.pacify.Replacer.java

private File createCopy() throws DefectException {
    try {//from www. j  a  v a2  s .c  o  m
        if (getCopyDestination().exists()) {
            if (!getCopyDestination().isDirectory()) {
                throw new DefectMessage("Destination directory [" + getCopyDestination().getAbsolutePath()
                        + "] is not a directory.");
            }
            if (getCopyDestination().list().length > 0) {
                throw new DefectMessage(
                        "Destination directory [" + getCopyDestination().getAbsolutePath() + "] is not empty.");
            }
            if (!getCopyDestination().canWrite()) {
                throw new DefectMessage("Destination directory [" + getCopyDestination().getAbsolutePath()
                        + "] is not writable.");
            }
        }
        FileUtils.copyDirectory(getPackagePath(), getCopyDestination());
        return getCopyDestination();
    } catch (IOException e) {
        logger.debug(e);
        throw new DefectMessage("Error while copy [" + getPackagePath().getAbsolutePath() + "] to ["
                + getCopyDestination().getAbsolutePath() + "].");
    }
}

From source file:de.jcup.egradle.other.GroovyParserSourceCollector.java

private void copyDirFull(File sourceDir, File targetDir, String subPath) throws IOException {
    File antlrPartsSource = new File(sourceDir, subPath);
    File antlrPartsTarget = new File(targetDir, subPath);
    antlrPartsTarget.getParentFile().mkdirs();
    System.out.println("copy dir:" + subPath);
    FileUtils.copyDirectory(antlrPartsSource, antlrPartsTarget);
}

From source file:co.runrightfast.vertx.orientdb.impl.embedded.EmbeddedOrientDBServiceWithSSLTest.java

@BeforeClass
public static void setUpClass() throws Exception {
    orientdbHome.mkdirs();//from   ww  w.j ava2 s  . c o  m
    FileUtils.cleanDirectory(orientdbHome);
    FileUtils.deleteDirectory(orientdbHome);
    log.logp(INFO, CLASS_NAME, "setUpClass",
            String.format("orientdbHome.exists() = %s", orientdbHome.exists()));

    final File configDirSrc = new File("src/test/resources/orientdb/config");
    final File configDirTarget = new File(orientdbHome, "config");
    FileUtils.copyFileToDirectory(new File(configDirSrc, "default-distributed-db-config.json"),
            configDirTarget);
    FileUtils.copyFileToDirectory(new File(configDirSrc, "hazelcast.xml"), configDirTarget);

    final File configCertDirSrc = new File("src/test/resources/orientdb/config/cert");
    final File configCertDirTarget = new File(orientdbHome, "config/cert");
    FileUtils.copyDirectory(configCertDirSrc, configCertDirTarget);

    final ApplicationId appId = ApplicationId.builder().group("co.runrightfast")
            .name("runrightfast-vertx-orientdb").version("1.0.0").build();
    final AppEventLogger appEventLogger = new AppEventJDKLogger(appId);

    final EmbeddedOrientDBServiceConfig config = EmbeddedOrientDBServiceConfig.builder()
            .orientDBRootDir(orientdbHome.toPath()).handler(new OGraphServerHandlerConfig())
            .handler(EmbeddedOrientDBServiceWithSSLTest::oHazelcastPlugin)
            .handler(EmbeddedOrientDBServiceWithSSLTest::oServerSideScriptInterpreter)
            .networkConfig(oServerNetworkConfiguration())
            .user(new OServerUserConfiguration(ROOT_USER, "root", "*"))
            .property(OGlobalConfiguration.DB_POOL_MIN, "1").property(OGlobalConfiguration.DB_POOL_MAX, "50")
            .databasePoolConfig(new OrientDBPoolConfig(CLASS_NAME, "remote:localhost/" + CLASS_NAME, "admin",
                    "admin", 10, ImmutableSet.of(() -> new SetCreatedOnAndUpdatedOn())))
            .lifecycleListener(() -> new RunRightFastOrientDBLifeCycleListener(appEventLogger)).build();

    service = new EmbeddedOrientDBService(config);
    ServiceUtils.start(service);
    initDatabase();
}

From source file:abs.backend.erlang.ErlApp.java

private void copyRuntime() throws IOException {
    InputStream is = null;/*from   ww w. ja va2 s  . c  o  m*/
    // TODO: this only works when the erlang compiler is invoked
    // from a jar file.  See http://stackoverflow.com/a/2993908 on
    // how to handle the other case.
    URLConnection resource = getClass().getResource("").openConnection();
    try {
        for (String f : RUNTIME_FILES) {
            if (f.endsWith("/*")) {
                String dirname = f.substring(0, f.length() - 2);
                String inname = RUNTIME_PATH + dirname;
                String outname = destDir + "/" + dirname;
                new File(outname).mkdirs();
                if (resource instanceof JarURLConnection) {
                    copyJarDirectory(((JarURLConnection) resource).getJarFile(), inname, outname);
                } else if (resource instanceof FileURLConnection) {
                    /* stolz: This at least works for the unit tests from within Eclipse */
                    File file = new File("src");
                    assert file.exists();
                    FileUtils.copyDirectory(new File("src/" + RUNTIME_PATH), destDir);
                } else {
                    throw new UnsupportedOperationException("File type: " + resource);
                }

            } else {
                is = ClassLoader.getSystemResourceAsStream(RUNTIME_PATH + f);
                if (is == null)
                    throw new RuntimeException("Could not locate Runtime file:" + f);
                String outputFile = f.replace('/', File.separatorChar);
                File file = new File(destDir, outputFile);
                file.getParentFile().mkdirs();
                ByteStreams.copy(is, Files.newOutputStreamSupplier(file));
            }
        }
    } finally {
        if (is != null)
            is.close();
    }
    for (String f : EXEC_FILES) {
        new File(destDir, f).setExecutable(true, false);
    }
}

From source file:asciidoc.maven.plugin.AsciiDocMojo.java

/**
 * Execute.//  w w  w.  j  a  va2 s .com
 */
public void execute() throws MojoExecutionException, MojoFailureException {
    if (getLog().isDebugEnabled())
        getLog().debug("asciiDocHome absolutePath: " + asciiDocHome.getAbsolutePath());
    PySystemState sys = Py.getSystemState();
    sys.path.append(new PyString(asciiDocHome.getAbsolutePath()));
    //
    PySystemObjectFactory asciidocFactory = new PySystemObjectFactory(sys, PyObject.class, "asciidocapi",
            "AsciiDocAPI");
    PyObject asciidoc = (PyObject) asciidocFactory.createObject();
    //
    if (outfile != null) {
        PyObject options = asciidoc.__getattr__("options");
        options.invoke("append", new PyString("--out-file"), new PyString(outfile.getAbsolutePath()));
        if (outdir == null) {
            outdir = outfile.getParentFile();
        }
    }
    if (outdir != null) {
        try {
            if (getLog().isDebugEnabled())
                getLog().debug("Copying " + asciiDocHome.getAbsolutePath() + "/images" + " to "
                        + outdir.getAbsolutePath() + "/images");
            FileUtils.copyDirectory(new File(asciiDocHome.getAbsolutePath(), "images"),
                    new File(outdir.getAbsolutePath(), "images"));
        } catch (IOException ioe) {
            getLog().error(ioe.getMessage(), ioe);
            // don't throw ioe;
        }
    }
    //
    if (backend != null) {
        PyObject options = asciidoc.__getattr__("options");
        options.invoke("append", new PyString("--backend"), new PyString(backend));
    }
    //
    if (lang != null) {
        PyDictionary attributes = (PyDictionary) asciidoc.__getattr__("attributes");
        attributes.__setitem__(new PyString("lang"), new PyString(lang));
    }
    //
    asciidoc.invoke("execute", new PyString(srcfile.getAbsolutePath()));
}

From source file:com.meltmedia.cadmium.core.git.DelayedGitServiceInitializer.java

/**
 * <p>Switches the current reference to point to a new remote git repository.</p>
 * <p>This method will block if the common reference has not been set or there are any threads currently using the referenced git service.</p>
 * /* www. j  a  v a2s  .c  o m*/
 * @param uri The uri to the remote repository.
 * @throws Exception
 */
public synchronized void switchRepository(String uri) throws Exception {
    File oldRepo = null;
    File gitDir = null;
    try {
        writeLock.lock();
        latch.await();
        if (!git.getRemoteRepository().equalsIgnoreCase(uri)) {
            logger.debug("Switching repo from {} to {}", git.getRemoteRepository(), uri);
            gitDir = new File(git.getBaseDirectory());
            IOUtils.closeQuietly(git);
            git = null;
            oldRepo = new File(gitDir.getParentFile(), "old-git-checkout");
            FileUtils.deleteQuietly(oldRepo);
            FileUtils.copyDirectory(gitDir, oldRepo);
            FileUtils.deleteDirectory(gitDir);
            git = GitService.cloneRepo(uri, gitDir.getAbsolutePath());
        }
    } catch (InterruptedException ie) {
        logger.warn("Thread interrupted, must be shutting down!", ie);
        throw ie;
    } catch (Exception e) {
        logger.warn("Failed to switch repository. Rolling back!");
        if (git != null) {
            IOUtils.closeQuietly(git);
            git = null;
        }
        FileUtils.deleteQuietly(gitDir);
        FileUtils.copyDirectory(oldRepo, gitDir);
        git = GitService.createGitService(gitDir.getAbsolutePath());
        throw e;
    } finally {
        FileUtils.deleteQuietly(oldRepo);
        writeLock.unlock();
    }
}

From source file:co.runrightfast.vertx.orientdb.impl.embedded.EmbeddedOrientDBServiceWithSSLWithClientAuthTest.java

@BeforeClass
public static void setUpClass() throws Exception {
    orientdbHome.mkdirs();/*  www.  ja  v  a  2  s. c om*/
    FileUtils.cleanDirectory(orientdbHome);
    FileUtils.deleteDirectory(orientdbHome);
    log.logp(INFO, CLASS_NAME, "setUpClass",
            String.format("orientdbHome.exists() = %s", orientdbHome.exists()));

    final File configDirSrc = new File("src/test/resources/orientdb/config");
    final File configDirTarget = new File(orientdbHome, "config");
    FileUtils.copyFileToDirectory(new File(configDirSrc, "default-distributed-db-config.json"),
            configDirTarget);
    FileUtils.copyFileToDirectory(new File(configDirSrc, "hazelcast.xml"), configDirTarget);

    final File configCertDirSrc = new File("src/test/resources/orientdb/config/cert");
    final File configCertDirTarget = new File(orientdbHome, "config/cert");
    FileUtils.copyDirectory(configCertDirSrc, configCertDirTarget);

    final ApplicationId appId = ApplicationId.builder().group("co.runrightfast")
            .name("runrightfast-vertx-orientdb").version("1.0.0").build();
    final AppEventLogger appEventLogger = new AppEventJDKLogger(appId);

    setSSLSystemProperties();
    final EmbeddedOrientDBServiceConfig config = EmbeddedOrientDBServiceConfig.builder()
            .orientDBRootDir(orientdbHome.toPath()).handler(new OGraphServerHandlerConfig(false))
            .handler(EmbeddedOrientDBServiceWithSSLWithClientAuthTest::oHazelcastPlugin)
            .handler(EmbeddedOrientDBServiceWithSSLWithClientAuthTest::oServerSideScriptInterpreter)
            .networkConfig(oServerNetworkConfiguration())
            .user(new OServerUserConfiguration(ROOT_USER, "root", "*"))
            .property(OGlobalConfiguration.DB_POOL_MIN, "1").property(OGlobalConfiguration.DB_POOL_MAX, "50")
            .databasePoolConfig(new OrientDBPoolConfig(CLASS_NAME, "remote:localhost/" + CLASS_NAME, "admin",
                    "admin", 10, ImmutableSet.of(() -> new SetCreatedOnAndUpdatedOn())))
            .lifecycleListener(() -> new RunRightFastOrientDBLifeCycleListener(appEventLogger)).build();

    service = new EmbeddedOrientDBService(config);
    ServiceUtils.start(service);
    initDatabase();
}

From source file:net.doubledoordev.backend.server.WorldManager.java

public void doBackup(File zip, File folder, FilenameFilter filter) {
    if (!folder.exists())
        return; // Prevent derp
    LOGGER.info(String.format("'%s' is making a backup from '%s' to '%s'", server.getID(), folder.getPath(),
            zip.getPath()));//from  ww w  .j a v  a2 s.  c o m
    if (server.getOnline()) {
        server.sendCmd("say Making backup....");
        server.sendCmd("save-off");
        server.sendCmd("save-all");
    }
    try {
        File tmp = new File(server.getBackupFolder(), "tmp");
        if (tmp.exists())
            FileUtils.deleteDirectory(tmp);
        tmp.mkdirs();
        FileUtils.copyDirectory(folder, tmp);
        zip.getParentFile().mkdirs();

        for (File delfolder : tmp.listFiles(filter))
            FileUtils.deleteDirectory(delfolder);

        if (tmp.list().length != 0) {
            ZipParameters parameters = new ZipParameters();
            parameters.setIncludeRootFolder(false);
            ZipFile zipFile = new ZipFile(zip);
            zipFile.createZipFileFromFolder(tmp, parameters, false, 0);
        }

        if (tmp.exists())
            FileUtils.deleteDirectory(tmp);
    } catch (IOException | ZipException e) {
        if (server.getOnline())
            server.sendCmd("say Error when making backup");
        server.error(e);
    }
    if (server.getOnline()) {
        server.sendCmd("save-on");
        server.sendCmd("save-all");
    }
}