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:ml.shifu.shifu.actor.PostTrainActorTest.java

public void testActor() throws IOException, InterruptedException {
    File tmpModels = new File("models");
    File tmpCommon = new File("common");

    File models = new File("src/test/resources/example/cancer-judgement/ModelStore/ModelSet1/models");

    FileUtils.copyDirectory(models, tmpModels);

    ActorRef postTrainRef = actorSystem.actorOf(new Props(new UntypedActorFactory() {
        private static final long serialVersionUID = 6777309320338075269L;

        public UntypedActor create() {
            return new PostTrainActor(modelConfig, columnConfigList, new AkkaExecStatus(true));
        }//from w  ww.j ava2  s.c  o m
    }), "post-trainer");

    List<Scanner> scanners = ShifuFileUtils.getDataScanners(
            "src/test/resources/example/cancer-judgement/DataStore/DataSet1", SourceType.LOCAL);
    postTrainRef.tell(new AkkaActorInputMessage(scanners), postTrainRef);

    while (!postTrainRef.isTerminated()) {
        Thread.sleep(5000);
    }

    File file = new File("./ColumnConfig.json");
    Assert.assertTrue(file.exists());

    FileUtils.deleteQuietly(file);
    FileUtils.deleteDirectory(tmpModels);
    FileUtils.deleteDirectory(tmpCommon);
}

From source file:com.digitalgeneralists.assurance.model.merge.TargetMergeEngine.java

@Override
public void mergeResult(ComparisonResult result, IProgressMonitor monitor)
        throws AssuranceNullFileReferenceException {
    File sourceFile = result.getSource().getFile();
    File targetFile = result.getTarget().getFile();

    if ((sourceFile == null) || (targetFile == null)) {
        throw new AssuranceNullFileReferenceException("The source or target file is null.");
    }/*from   w w  w. ja v a 2 s.co  m*/

    if (monitor != null) {
        StringBuilder message = new StringBuilder(512);
        monitor.publish(message.append("Merging ").append(targetFile.toString()).append(" to ")
                .append(sourceFile.toString()).toString());
        message.setLength(0);
        message = null;
    }

    if (targetFile.exists()) {
        try {
            if (targetFile.isDirectory()) {
                FileUtils.copyDirectory(targetFile, sourceFile);
            } else {
                FileUtils.copyFile(targetFile, sourceFile);
            }
            result.setResolution(AssuranceResultResolution.REPLACE_SOURCE);
        } catch (IOException e) {
            logger.error("An error occurred when replacing the source with the target.");
            result.setResolution(AssuranceResultResolution.PROCESSING_ERROR_ENCOUNTERED);
            result.setResolutionError(e.getMessage());
        }
    } else {
        if (sourceFile.exists()) {
            File scanDeletedItemsLocation = result
                    .getSourceDeletedItemLocation(getApplicationDeletedItemsLocation());
            if (scanDeletedItemsLocation == null) {
                StringBuilder deletedFilePath = new StringBuilder(512);
                scanDeletedItemsLocation = new File(
                        deletedFilePath.append(this.getDefaultDeletedItemsLocation()).append(File.separator)
                                .append(sourceFile.getName()).toString());
                deletedFilePath.setLength(0);
            }
            try {
                if (sourceFile.isDirectory()) {
                    FileUtils.moveDirectory(sourceFile, scanDeletedItemsLocation);
                } else {
                    FileUtils.moveFile(sourceFile, scanDeletedItemsLocation);
                }
                result.setResolution(AssuranceResultResolution.DELETE_SOURCE);
            } catch (IOException e) {
                StringBuffer message = new StringBuffer(512);
                logger.error(message.append("Could not move item to deleted items location ")
                        .append(sourceFile.getPath()));
                message.setLength(0);
                message = null;
                result.setResolution(AssuranceResultResolution.PROCESSING_ERROR_ENCOUNTERED);
                result.setResolutionError(e.getMessage());
            }
            scanDeletedItemsLocation = null;
        }
    }

    sourceFile = null;
    targetFile = null;
}

From source file:com.digitalgeneralists.assurance.model.merge.SourceMergeEngine.java

@Override
public void mergeResult(ComparisonResult result, IProgressMonitor monitor)
        throws AssuranceNullFileReferenceException {
    File sourceFile = result.getSource().getFile();
    File targetFile = result.getTarget().getFile();

    if ((sourceFile == null) || (targetFile == null)) {
        throw new AssuranceNullFileReferenceException("The source or target file is null.");
    }//ww w  . ja v  a2  s  . c o  m

    if (monitor != null) {
        StringBuilder message = new StringBuilder(512);
        monitor.publish(message.append("Merging ").append(sourceFile.toString()).append(" to ")
                .append(targetFile.toString()).toString());
        message.setLength(0);
        message = null;
    }

    if (sourceFile.exists()) {
        try {
            if (sourceFile.isDirectory()) {
                FileUtils.copyDirectory(sourceFile, targetFile);
            } else {
                FileUtils.copyFile(sourceFile, targetFile);
            }
            result.setResolution(AssuranceResultResolution.REPLACE_TARGET);
        } catch (IOException e) {
            logger.error("An error occurred when replacing the target with the source.");
            result.setResolution(AssuranceResultResolution.PROCESSING_ERROR_ENCOUNTERED);
            result.setResolutionError(e.getMessage());
        }
    } else {
        if (targetFile.exists()) {
            File scanDeletedItemsLocation = result
                    .getTargetDeletedItemLocation(getApplicationDeletedItemsLocation());
            if (scanDeletedItemsLocation == null) {
                StringBuilder deletedItemPath = new StringBuilder(512);
                scanDeletedItemsLocation = new File(
                        deletedItemPath.append(this.getDefaultDeletedItemsLocation()).append(File.separator)
                                .append(targetFile.getName()).toString());
                deletedItemPath.setLength(0);
                deletedItemPath = null;
            }
            try {
                if (targetFile.isDirectory()) {
                    FileUtils.moveDirectory(targetFile, scanDeletedItemsLocation);
                } else {
                    FileUtils.moveFile(targetFile, scanDeletedItemsLocation);
                }
                result.setResolution(AssuranceResultResolution.DELETE_TARGET);
            } catch (IOException e) {
                StringBuffer message = new StringBuffer(512);
                logger.warn(message.append("Could not move item to deleted items location ")
                        .append(sourceFile.getPath()));
                message.setLength(0);
                message = null;
                result.setResolution(AssuranceResultResolution.PROCESSING_ERROR_ENCOUNTERED);
                result.setResolutionError(e.getMessage());
            }
            scanDeletedItemsLocation = null;
        }
    }

    sourceFile = null;
    targetFile = null;
}

From source file:edu.si.services.beans.cameratrap.CameraTrapIngestManifestSchemaValidationTest.java

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

    //The Location of the Input dir in the project
    File inputSrcDirLoc = new File("../../Routes/Camera Trap/Input");

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

From source file:com.github.ipaas.ideploy.agent.handler.RollbackCodeHandler.java

@Override
public void execute(String flowId, String cmd, Map<String, Object> params, BundleContext bundleContext)
        throws Exception {

    String doingCodeVerPath = (String) params.get("doingCodeVerPath");
    String usingCodeVerPath = (String) params.get("usingCodeVerPath");

    String deployPath = (String) params.get("deployPath");
    logger.debug(" params:" + JsonUtil.toJson(params));
    if (StringUtil.isNullOrBlank(usingCodeVerPath)) {// ,???,?
        File localBkFile = new File(String.valueOf(params.get("localBkPath")));
        File appRootFile = new File(deployPath);
        if (appRootFile.exists()) {
            FileUtils.cleanDirectory(appRootFile);// ?
        }//from   w ww. j  av  a 2 s  .  c o m
        if (!localBkFile.exists()) {
            logger.error("?:" + localBkFile.getAbsolutePath());
            throw new Exception("?,?!");
        }
        FileUtils.copyDirectory(localBkFile, appRootFile);
        logger.debug("??");
        return;
    }

    String savePath = String.valueOf(params.get("savePath"));
    long headRev = SVNRevision.HEAD.getNumber();

    Integer hostStatus = Integer.valueOf("" + params.get("hostStatus"));

    if (hostStatus == 1) {// ,??SVN?
        SVNUtil.getDeta4UpdateAll(usingCodeVerPath, headRev, savePath);
    } else {
        // ?? ?
        SVNUtil.getDelta(doingCodeVerPath, headRev, usingCodeVerPath, headRev, savePath);
    }

    // ?
    UpdateCodeUtil.updateCode(savePath, deployPath);
}

From source file:com.michaelfitzmaurice.devtools.HeaderToolTest.java

@Before
public void setUpDirectories() throws IOException {

    // ensure test data exists as expected
    File runtimeDirectory = new File(System.getProperty("user.dir"));
    File testDataRoot = new File(runtimeDirectory, "src/test/data/");
    assertTestDataDirValid(testDataRoot);

    // copy test data to a temp directory
    TMP_ROOT_DIRECTORY = new File(FileUtils.getTempDirectory(),
            "header_tool_tests_" + System.currentTimeMillis());
    FileUtils.forceMkdir(TMP_ROOT_DIRECTORY);
    TMP_ROOT_DIRECTORY.deleteOnExit();//from w  w  w  .  j  av a  2  s.  c  o m
    FileUtils.copyDirectory(testDataRoot, TMP_ROOT_DIRECTORY);
    Collection<File> tmpDirContents = FileUtils.listFilesAndDirs(TMP_ROOT_DIRECTORY, TrueFileFilter.INSTANCE,
            TrueFileFilter.INSTANCE);
    assertFileListsEqual(expectedTestDirContents(TMP_ROOT_DIRECTORY), tmpDirContents,
            "Temp dir does not contain expected contents");

    HEADER_FILE = new File(testDataRoot, HEADER_FILENAME);
    HEADER_CONTENT = fileContents(HEADER_FILE);
    assertTrue("Header file was empty", HEADER_CONTENT.length() > 0);
}

From source file:com.wavemaker.tools.project.LauncherHelper.java

/**
 * NOTE: this method is called from the Launcher. DO NOT CHANGE TO NEW RESOURCE API.
 * /*from   w ww  .j  av a2 s  .com*/
 * @param waveMakerHome
 * @throws IOException
 */
public static void doUpgrade(java.io.File waveMakerHomeFile) throws IOException {
    Resource waveMakerHome = new FileSystemResource(waveMakerHomeFile);
    VersionInfo vi = LocalStudioConfiguration.getCurrentVersionInfo();
    LocalStudioConfiguration.setRegisteredVersionInfo(vi);

    Resource oldWMHome = LocalStudioConfiguration.staticGetWaveMakerHome();
    if (0 != oldWMHome.getFile().compareTo(waveMakerHome.getFile())) {
        FileUtils.copyDirectory(oldWMHome.getFile(), waveMakerHome.getFile());
        LocalStudioConfiguration.setWaveMakerHome(waveMakerHome);
    }
}

From source file:com.canoo.webtest.util.WebtestEmbeddingUtil.java

/**
 * Copies WebTest resources (ie webtest.xml, tools/*, the XSLs, CSSs and pictures, ...) package in WebTest jar file
 * into the provide folder. Indeed different Ant tasks can't work with resources in a jar file.
 * @param targetFolder the folder in which resources should be copied to
 * @throws java.io.IOException if the resources can be accessed or copied
 *//*from   ww  w .java2s .  c  o  m*/
static void copyWebTestResources(final File targetFolder) throws IOException {
    final String resourcesPrefix = "com/canoo/webtest/resources/";
    final URL webtestXmlUrl = WebtestEmbeddingUtil.class.getClassLoader()
            .getResource(resourcesPrefix + "webtest.xml");

    if (webtestXmlUrl == null) {
        throw new IllegalStateException("Can't find resource " + resourcesPrefix + "webtest.xml");
    } else if (webtestXmlUrl.toString().startsWith("jar:file")) {
        final String urlJarFileName = webtestXmlUrl.toString().replaceFirst("^jar:file:([^\\!]*).*$", "$1");
        final String jarFileName = URLDecoder.decode(urlJarFileName, Charset.defaultCharset().name());
        final JarFile jarFile = new JarFile(jarFileName);
        final String urlPrefix = StringUtils.removeEnd(webtestXmlUrl.toString(), "webtest.xml");

        for (final Enumeration<JarEntry> entries = jarFile.entries(); entries.hasMoreElements();) {
            final JarEntry jarEntry = entries.nextElement();
            if (jarEntry.getName().startsWith(resourcesPrefix)) {
                final String relativeName = StringUtils.removeStart(jarEntry.getName(), resourcesPrefix);
                final URL url = new URL(urlPrefix + relativeName);
                final File targetFile = new File(targetFolder, relativeName);
                FileUtils.forceMkdir(targetFile.getParentFile());
                FileUtils.copyURLToFile(url, targetFile);
            }
        }
    } else if (webtestXmlUrl.toString().startsWith("file:")) {
        // we're probably developing and/or have a custom version of the resources in classpath
        final File webtestXmlFile = FileUtils.toFile(webtestXmlUrl);
        final File resourceFolder = webtestXmlFile.getParentFile();

        FileUtils.copyDirectory(resourceFolder, targetFolder);
    } else {
        throw new IllegalStateException(
                "Resource " + resourcesPrefix + "webtest.xml is not in a jar file: " + webtestXmlUrl);
    }
}

From source file:minecrunch_launcher.Server.java

public void run() {
    // Install selected server
    if (os.contains("Windows")) {
        minecrunchDir = home + "\\minecrunch\\";
    } else {/* w  w  w  .j a v  a2  s  .  co  m*/
        minecrunchDir = home + "/minecrunch/";
    }
    wd.setVisible(true);

    // create directory in users home folder server
    File dir = new File(minecrunchDir + name + "_server");
    if (!dir.exists()) {
        if (dir.mkdir()) {
            String console = "Server directory created.";
            System.out.println(console);
        } else {
            String console = "Server directory already exists.";
            System.out.println(console);
        }
    }
    // download file from server
    URL url = null;
    try {
        url = new URL("http://www.minecrunch.net/download/" + name + "/server_install.zip");
    } catch (MalformedURLException ex) {
        System.out.println(ex);
    }
    File file = new File(minecrunchDir + "server_install.zip");
    try {
        FileUtils.copyURLToFile(url, file);
    } catch (IOException ex) {
        System.out.println(ex);
    }

    // unzip file in users home folder and extract it to server
    try {
        ZipFile zipFile = new ZipFile(minecrunchDir + "server_install.zip");
        zipFile.extractAll(minecrunchDir + name + "_server");
    } catch (ZipException e) {
    }
    File dir2 = new File(minecrunchDir + name + "_server\\server_install");
    File dir3 = new File(minecrunchDir + name + "_server");
    try {
        FileUtils.copyDirectory(dir2, dir3);
        FileUtils.deleteDirectory(dir2);
    } catch (IOException ex) {
        System.out.println(ex);
    }

    // clean up and delete zip file that was downloaded
    file.delete();
    wd.setVisible(false);
}

From source file:com.vmware.photon.controller.deployer.configuration.ServiceConfiguratorTest.java

@Test
public void testApplyDynamicParameters() throws Exception {
    FileUtils.copyDirectory(new File(configPath), new File(TMP_DIR));
    ServiceConfigurator serviceConfigurator = new ServiceConfigurator();
    ContainersConfig containersConfig = serviceConfigurator.generateContainersConfig(configPath);
    serviceConfigurator.applyDynamicParameters(TMP_DIR, ContainersConfig.ContainerType.PhotonControllerCore,
            containersConfig.getContainerSpecs().get(ContainersConfig.ContainerType.PhotonControllerCore.name())
                    .getDynamicParameters());

    Map<String, Object> dynamicParameters = new HashMap<>();
    List<LoadBalancerServer> list = new ArrayList<>();
    list.add(new LoadBalancerServer("server-1", "0.0.0.0"));
    list.add(new LoadBalancerServer("server-2", "1.1.1.1"));
    dynamicParameters.put("MGMT_API_HTTP_SERVERS", list);
    serviceConfigurator.applyDynamicParameters(TMP_DIR, ContainersConfig.ContainerType.LoadBalancer,
            dynamicParameters);//from   www .j a  v a 2 s  .  com
    File file = new File(TMP_DIR + "haproxy/haproxy.cfg");
    String haproxyCfg = FileUtils.readFileToString(file);
    assertThat(haproxyCfg.contains("server server-1 0.0.0.0 check"), is(true));
    assertThat(haproxyCfg.contains("server server-2 1.1.1.1 check"), is(true));

    FileUtils.deleteDirectory(new File(TMP_DIR));
}