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.splunk.shuttl.testutil.TUtilsBucket.java

private static void copyDirectory(File from, File to) {
    try {//from w w w . j  a v  a2  s  .  c  o  m
        FileUtils.copyDirectory(from, to);
    } catch (IOException e) {
        TUtilsTestNG.failForException("Couldn't copy: " + from + ", to: " + to, e);
    }
}

From source file:net.sf.mavenjython.JythonMojo.java

/**
 * Strategy A: include jython in plugin. Extract on the run.
 * /*from   w  w w  .  j  a v  a2s .  c  o m*/
 * Strategy B: Project also has dependency on jython. We find that jar and
 * extract it and work from there.
 * 
 * B has the benefit that we don't have to update this plugin for every
 * version and the user needs the jython dependency anyway to call the
 * Python Console
 */
public void execute() throws MojoExecutionException {
    setupVariables();

    extractJarToDirectory(jythonArtifact.getFile(), temporaryBuildDirectory);

    // now what? we have the jython content, now we need
    // easy_install
    getLog().info("installing easy_install ...");
    try {
        if (OVERRIDE || !setuptoolsJar.exists()) {
            FileUtils.copyInputStreamToFile(setuptoolsResource.openStream(), setuptoolsJar);
        }
    } catch (IOException e) {
        throw new MojoExecutionException("copying setuptools failed", e);
    }
    extractJarToDirectory(setuptoolsJar, new File(sitepackagesdir, SETUPTOOLS_EGG));
    try {
        IOUtils.write("./" + SETUPTOOLS_EGG + "\n",
                new FileOutputStream(new File(sitepackagesdir, "setuptools.pth")));
    } catch (IOException e) {
        throw new MojoExecutionException("writing path entry for setuptools failed", e);
    }
    getLog().info("installing easy_install done");

    if (libraries == null) {
        getLog().info("no python libraries requested");
    } else {
        getLog().info("installing requested python libraries");
        // then we need to call easy_install to install the other
        // dependencies.
        runJythonScriptOnInstall(temporaryBuildDirectory,
                getEasyInstallArgs("Lib/site-packages/" + SETUPTOOLS_EGG + "/easy_install.py"));
        getLog().info("installing requested python libraries done");
    }

    getLog().info("copying requested libraries");
    /**
     * we installed the packages into our temporary build directory now we
     * want to move these libraries into outputDirectory/Lib
     * 
     * <pre>
     * mv --no-override temporaryBuildDirectory/Lib/site-packages/*.egg/* outputDirectory/Lib/
     * </pre>
     */
    for (File i : sitepackagesdir.listFiles(
            (FileFilter) new AndFileFilter(DirectoryFileFilter.INSTANCE, new SuffixFileFilter(".egg")))) {
        getLog().info("copying " + i + " into " + new File(outputDirectory, "Lib"));
        try {
            FileUtils.deleteDirectory(new File(installlibdir, i.getName()));
        } catch (IOException e) {
        }
        try {
            FileUtils.copyDirectory(i, installlibdir);
        } catch (IOException e) {
            throw new MojoExecutionException(
                    "copying " + i + " to " + new File(outputDirectory, "Lib") + " failed", e);
        }
    }

    /**
     * Setuptools installs a site.py for every package. This might conflict
     * with the jython installation. All it does anyway is help look for
     * eggs, so it wouldn't help us. Errors are ignored here.
     */
    new File(installlibdir, "site.py").delete();
    new File(installlibdir, "site$py.class").delete();
    getLog().info("copying requested libraries done");

    /**
     * If the project does not want its python sources to be in Lib/ it
     * needs to call
     * 
     * PySystemState.addPaths(path, jarFileName + "/myLibFolder");
     * 
     * before starting Python up.
     */
}

From source file:de.uzk.hki.da.cb.PrepareSendToPresenterAction.java

/**
 * The xIP (in case PUBLIC right is set) contains converted files that are 
 * meant only to be presented in a portal but not to be archived. So to prevent these files
 * get into the archive we extract the derivate before we build a tar file around the xIP.
 * /*w  w  w .  j a v a 2 s  .  c o m*/
 * Moves 
 * <li>from work/[csn]/[oid]/data/temp_pips/public -> dip/public/[csn]/[oid]
 * <li>from work/[csn]/[oid]/data/temp_pips/institution -> dip/institution/[csn]/[oid]
 * 
 * @param dipName has the form urn_pkgid
 * @throws IOException 
 */
private void copyPIPSforReplication() throws IOException {

    if (Path.makeFile(wa.dataPath(), WorkArea.TMP_PIPS, WorkArea.PUBLIC).exists()) {
        logger.info("Copying public datastreams to "
                + wa.pipSourceFolderPath(WorkArea.PUBLIC).toFile().getAbsolutePath());
        if (wa.pipSourceFolderPath(WorkArea.PUBLIC).toFile().exists())
            FolderUtils.deleteDirectorySafe(wa.pipSourceFolderPath(WorkArea.PUBLIC).toFile());
        FileUtils.copyDirectory(Path.make(wa.dataPath(), WorkArea.TMP_PIPS, WorkArea.PUBLIC).toFile(),
                wa.pipSourceFolderPath(WorkArea.PUBLIC).toFile());
    }
    if (Path.makeFile(wa.dataPath(), WorkArea.TMP_PIPS, WorkArea.WA_INSTITUTION).exists()) {
        logger.info("Copying institution datastreams to " + wa.pipSourceFolderPath(WorkArea.WA_INSTITUTION));
        if (wa.pipSourceFolderPath(WorkArea.WA_INSTITUTION).toFile().exists())
            FolderUtils.deleteDirectorySafe(wa.pipSourceFolderPath(WorkArea.WA_INSTITUTION).toFile());
        FileUtils.copyDirectory(Path.make(wa.dataPath(), WorkArea.TMP_PIPS, WorkArea.PUBLIC).toFile(),
                wa.pipSourceFolderPath(WorkArea.WA_INSTITUTION).toFile());
    }
}

From source file:de.fosd.jdime.common.FileArtifact.java

@Override
public final void copyArtifact(final FileArtifact destination) throws IOException {
    assert (destination != null);

    if (destination.isFile()) {
        if (isFile()) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Copying file " + this + " to file " + destination);
                LOG.debug("Destination already exists overwriting: " + destination.exists());
            }//from   w  w w .  j  av  a  2 s.c om

            FileUtils.copyFile(file, destination.file);
        } else {
            throw new UnsupportedOperationException(
                    "When copying to a file, " + "the source must also be a file.");
        }
    } else if (destination.isDirectory()) {
        if (isFile()) {
            assert (destination.exists()) : "Destination directory does not exist: " + destination;
            if (LOG.isDebugEnabled()) {
                LOG.debug("Copying file " + this + " to directory " + destination);
            }
            FileUtils.copyFileToDirectory(file, destination.file);
        } else if (isDirectory()) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Copying directory " + this + " to directory " + destination);
                LOG.debug("Destination already exists overwriting: " + destination.exists());
            }
            FileUtils.copyDirectory(file, destination.file);
        }
    } else {
        LOG.fatal("Failed copying " + this + " to " + destination);
        LOG.fatal("isDirectory(" + this + ") = " + isDirectory());
        LOG.fatal("isDirectory(" + destination + ") = " + destination.isDirectory());
        throw new NotYetImplementedException("Only copying files and directories is supported.");
    }
}

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

@Test
public void testGetWorkflowStatusTransitionToReady() throws Exception {

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

    celosClient.iterateScheduler();/*from   w w  w  . j a va 2  s  .c om*/
    List<SlotState> slotStates = celosClient.getWorkflowStatus(new WorkflowID("workflow-2")).getSlotStates();
    Assert.assertEquals(slotStates.size(), SLOTS_IN_CELOS_SERVER_SLIDING_WINDOW);

    for (SlotState slotState : slotStates) {
        Assert.assertEquals(slotState.getStatus(), SlotState.Status.READY);
        Assert.assertEquals(slotState.getExternalID(), null);
        Assert.assertEquals(slotState.getRetryCount(), 0);
    }
}

From source file:hu.bme.mit.sette.tools.catg.CatgGenerator.java

private void copyTool(EclipseProject eclipseProject) throws IOException, SetteConfigurationException {
    FileUtils.copyDirectory(getTool().getToolDirectory(), getRunnerProjectSettings().getBaseDirectory());

    // edit build.xml
    // TODO make better

    File buildXml = new File(getRunnerProjectSettings().getBaseDirectory(), "build.xml");
    List<String> newLines = new ArrayList<>();

    InputStream fis = null;//from  www. ja v a  2s .c o  m
    try {
        fis = new FileInputStream(buildXml);
        List<String> lines = IOUtils.readLines(fis);

        for (String line : lines) {
            if (line.contains("[SETTE]")) {
                String indent = "";

                for (int i = 0; i < line.length(); i++) {
                    char ch = line.charAt(i);

                    if (ch == ' ' || ch == '\t') {
                        indent += ch;
                    } else {
                        break;
                    }
                }

                line = line.trim();
                if (line.equals("<!-- [SETTE][Libraries] -->")) {
                    for (EclipseClasspathEntry entry : eclipseProject.getClasspathDescriptor()
                            .classpathEntries()) {
                        if (entry.getKind().equals(Kind.LIBRARY)) {
                            newLines.add(
                                    String.format("%s<pathelement location=\"%s\"/>", indent, entry.getPath()));
                        }
                    }
                } else if (line.equals("<!-- [SETTE][Sources] -->")) {
                    for (EclipseClasspathEntry entry : eclipseProject.getClasspathDescriptor()
                            .classpathEntries()) {
                        if (entry.getKind().equals(Kind.SOURCE)) {
                            newLines.add(String.format("%s<src path=\"%s\"/>", indent, entry.getPath()));
                        }
                    }
                } else {
                    throw new SetteConfigurationException(
                            "Invalid SETTE command (XML comment) in CATG build.xml: " + line);
                }
            } else {
                newLines.add(line);
            }
        }
    } finally {
        IOUtils.closeQuietly(fis);
    }

    FileOutputStream fos = null;
    try {
        fos = new FileOutputStream(buildXml);
        IOUtils.writeLines(newLines, null, fos);
    } finally {
        IOUtils.closeQuietly(fos);
    }
}

From source file:io.treefarm.plugins.haxe.TestCompileMojo.java

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    super.execute();

    if (munitCompiler.getHasRequirements()) {

        if (openflIsActive() && testTargets != null && testClasspath != null) {
            String logInfo = "Compiling tests for MassiveUnit using OpenFL ";
            logInfo += (testCoverage ? "WITH code coverage" : "WITHOUT code coverage") + ".";
            if (testDebug) {
                logInfo += "\n *** with debug, so only tests with @TestDebug will be built ***";
            }/* w  w w  .j a v  a  2 s. c  om*/
            getLog().info(logInfo);

            Set<String> classPaths = new HashSet<String>();
            String cleanClassPathList = "";
            try {
                List<String> displayHxml = openflCompiler.displayHxml(project, testTargets.iterator().next(),
                        nmml, null, null, null);
                for (String line : displayHxml) {
                    String classPath = StringUtils.substringAfter(line, "-cp ");
                    if (classPath.length() > 0) {
                        classPaths.add(classPath);
                    }
                }
            } catch (Exception e) {
                throw new MojoFailureException("Tests compilation failed", e);
            }

            compilerFlags = new ArrayList<String>();
            compilerFlags.add("-lib munit");
            compilerFlags.add("-lib hamcrest");
            if (testCoverage && classPaths.size() > 0) {
                compilerFlags.add("-lib mcover");
                compilerFlags.add("-D MCOVER");

                /*String mCoverDirective = "--macro mcover.MCover.coverage\\([\\'\\'],[\\'";
                //String mCoverDirective = "--macro mcover.MCover.coverage([''],['";
                Iterator<String> it = classPaths.iterator();
                String classPath;
                while(it.hasNext()) {
                classPath = it.next();
                if (!StringUtils.contains(classPath, ",")
                        && StringUtils.indexOf(classPath, "/") != 0) {
                    if (cleanClassPathList.length() > 0) {
                        cleanClassPathList += ",";
                    }
                    cleanClassPathList += classPath;
                }
                }
                        
                mCoverDirective += cleanClassPathList + "\\']\\)";
                //mCoverDirective += cleanClassPathList + "'],[''])";
                compilerFlags.add(mCoverDirective);
                getLog().info("mcover call: " + mCoverDirective);*/
            }
            compilerFlags.add("-cp " + testClasspath);

            try {
                if (testRunner == null) {
                    testRunner = TEST_RUNNER;
                }
                if (testHxml == null) {
                    testHxml = TEST_HXML;
                }

                List<String> displayHxml = openflCompiler.displayHxml(project, testTargets, nmml, compilerFlags,
                        testMain, testRunner);

                String hxmlDump = "";
                for (String hxmlLine : displayHxml) {
                    hxmlDump += hxmlLine + "\n";
                }

                File hxmlFile = new File(outputDirectory, testHxml);
                if (hxmlFile.exists()) {
                    FileUtils.deleteQuietly(hxmlFile);
                }
                hxmlFile.createNewFile();
                FileWriter fw = new FileWriter(hxmlFile.getAbsoluteFile());
                BufferedWriter bw = new BufferedWriter(fw);
                bw.write(hxmlDump);
                bw.close();

                if (testResources != null) {
                    File resourcesFile = new File(outputDirectory.getParentFile(), testResources);
                    File tmpResourcesFile = new File(outputDirectory, "tmp_resources");
                    tmpResourcesFile.mkdirs();
                    FileUtils.copyDirectory(resourcesFile, new File(tmpResourcesFile, resourcesFile.getName()));
                    testResources = tmpResourcesFile.getAbsolutePath();
                }

                if (testBinPath == null) {
                    testBinPath = TEST_BIN_PATH;
                }
                File testBinFile = new File(outputDirectory, testBinPath);
                testBinPath = testBinFile.getAbsolutePath();

                munitCompiler.config(testClasspath, testBinPath, testBinPath, cleanClassPathList,
                        hxmlFile.getAbsolutePath(), testResources, testTemplates);
                openflCompiler.initialize(debug, verbose, false, false, true, testDebug);
                openflCompiler.compile(project, testTargets, nmml, compilerFlags, testMain, testRunner, true,
                        false, false);
            } catch (Exception e) {
                throw new MojoFailureException("Tests compilation failed", e);
            }
        } else {
            getLog().info("Compiling tests using MassiveUnit.");

            try {
                munitCompiler.initialize(testDebug, false);
                munitCompiler.setOutputDirectory(outputDirectory);
                munitCompiler.compile(project, null);
            } catch (Exception e) {
                throw new MojoFailureException("Tests compilation failed", e);
            }
        }
    } else {
        getLog().info("Compiling tests using standard Haxe unit testing.");

        if (testRunner == null || project.getTestCompileSourceRoots().size() == 0) {
            getLog().info("No test sources to compile");
            return;
        }

        String output = OutputNamesHelper.getTestOutput(project);
        EnumMap<CompileTarget, String> targets = new EnumMap<CompileTarget, String>(CompileTarget.class);
        targets.put(CompileTarget.neko, output);

        try {
            haxeCompiler.compile(project, targets, testRunner, true, true, verbose);
        } catch (Exception e) {
            throw new MojoFailureException("Tests compilation failed", e);
        }
    }
}

From source file:hudson.model.UserIdMigratorTest.java

static void copyTestDataIfExists(Class clazz, TestName testName, File tempDirectory) throws IOException {
    File resourcesDirectory = new File(BASE_RESOURCE_PATH + clazz.getSimpleName(), testName.getMethodName());
    if (resourcesDirectory.exists()) {
        FileUtils.copyDirectory(resourcesDirectory, tempDirectory);
    }/*  ww  w .j a  va2s .c o  m*/
}

From source file:com.teotigraphix.caustk.utils.RuntimeUtils.java

public static final void copyDirectory(File src, File dest) throws IOException {
    FileUtils.copyDirectory(src, dest);
}

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

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

    if (!newRuntimeLocation.toFile().exists()) {
        FileUtils.copyDirectory(getLiferayRuntimeDir().toFile(), newRuntimeLocation.toFile());
    }/*  ww  w  .  j av  a2 s .co  m*/

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

    final NullProgressMonitor npm = new NullProgressMonitor();

    IRuntime runtime = ServerCore.findRuntime(name);

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

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

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

    ServerCore.getRuntimes();
    assertNotNull(runtime);

    return runtime;
}