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.util.ShifuCLITest.java

@Test
public void testPostTrainModel() throws Exception {
    File originModel = new File(
            "src/test/resources/example/cancer-judgement/ModelStore/ModelSet1/ModelConfig.json");
    File tmpModel = new File("ModelConfig.json");

    File originColumn = new File(
            "src/test/resources/example/cancer-judgement/ModelStore/ModelSet1/ColumnConfig.json");
    File tmpColumn = new File("ColumnConfig.json");

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

    FileUtils.copyFile(originModel, tmpModel);
    FileUtils.copyFile(originColumn, tmpColumn);
    FileUtils.copyDirectory(modelsDir, tmpModelsDir);

    long timestamp = tmpColumn.lastModified();
    // run post-train
    ShifuCLI.initializeModel();//from w ww .java2s  . c  om
    ShifuCLI.calModelStats();
    ShifuCLI.selectModelVar();
    ShifuCLI.normalizeTrainData();
    ShifuCLI.postTrainModel();
    Assert.assertTrue(tmpColumn.lastModified() > timestamp);

    FileUtils.deleteQuietly(tmpModel);
    FileUtils.deleteQuietly(tmpColumn);
    FileUtils.deleteDirectory(new File("tmp"));
    FileUtils.deleteDirectory(new File("models"));
}

From source file:azkaban.test.jobtype.JobTypeManagerTest.java

/**
 * Test out reloading properties/*from   www.  j a v a 2  s . co  m*/
 * @throws Exception
 */
@Test
public void testResetPlugins() throws Exception {
    // Add a plugins file to the anothertestjob folder
    File anothertestfolder = new File(TEST_PLUGIN_DIR + "/anothertestjob");
    Props pluginProps = new Props();
    pluginProps.put("test1", "1");
    pluginProps.put("test2", "2");
    pluginProps.put("pluginprops3", "4");
    pluginProps.storeFlattened(new File(anothertestfolder, "plugin.properties"));

    // clone the testjob folder
    File testFolder = new File(TEST_PLUGIN_DIR + "/testjob");
    FileUtils.copyDirectory(testFolder, new File(TEST_PLUGIN_DIR + "/newtestjob"));

    // change the common properties
    Props commonPlugin = new Props(null, TEST_PLUGIN_DIR + "/common.properties");
    commonPlugin.put("commonprop1", "1");
    commonPlugin.put("newcommonprop1", "2");
    commonPlugin.removeLocal("commonprop2");
    commonPlugin.storeFlattened(new File(TEST_PLUGIN_DIR + "/common.properties"));

    // change the common properties
    Props commonPrivate = new Props(null, TEST_PLUGIN_DIR + "/commonprivate.properties");
    commonPrivate.put("commonprivate1", "1");
    commonPrivate.put("newcommonprivate1", "2");
    commonPrivate.removeLocal("commonprivate2");
    commonPrivate.storeFlattened(new File(TEST_PLUGIN_DIR + "/commonprivate.properties"));

    // change testjob private property
    Props loadProps = new Props(null, TEST_PLUGIN_DIR + "/testjob/private.properties");
    loadProps.put("privatetest", "test");

    /*
     * Reload the plugins here!!
     */
    manager.loadPlugins();

    // Checkout common props
    JobTypePluginSet pluginSet = manager.getJobTypePluginSet();
    Props commonProps = pluginSet.getCommonPluginJobProps();
    assertEquals("1", commonProps.get("commonprop1"));
    assertEquals("commonprop3", commonProps.get("commonprop3"));
    assertEquals("2", commonProps.get("newcommonprop1"));
    assertNull(commonProps.get("commonprop2"));

    // Checkout common private
    Props commonPrivateProps = pluginSet.getCommonPluginLoadProps();
    assertEquals("1", commonPrivateProps.get("commonprivate1"));
    assertEquals("commonprivate3", commonPrivateProps.get("commonprivate3"));
    assertEquals("2", commonPrivateProps.get("newcommonprivate1"));
    assertNull(commonPrivateProps.get("commonprivate2"));

    // Verify anothertestjob changes
    Class<? extends Job> atjClass = pluginSet.getPluginClass("anothertestjob");
    assertEquals("azkaban.test.jobtype.FakeJavaJob", atjClass.getName());
    Props ajobProps = pluginSet.getPluginJobProps("anothertestjob");
    assertEquals("1", ajobProps.get("test1"));
    assertEquals("2", ajobProps.get("test2"));
    assertEquals("4", ajobProps.get("pluginprops3"));
    assertEquals("commonprop3", ajobProps.get("commonprop3"));

    Props aloadProps = pluginSet.getPluginLoaderProps("anothertestjob");
    assertEquals("1", aloadProps.get("commonprivate1"));
    assertNull(aloadProps.get("commonprivate2"));
    assertEquals("commonprivate3", aloadProps.get("commonprivate3"));

    // Verify testjob changes
    Class<? extends Job> tjClass = pluginSet.getPluginClass("testjob");
    assertEquals("azkaban.test.jobtype.FakeJavaJob2", tjClass.getName());
    Props tjobProps = pluginSet.getPluginJobProps("testjob");
    assertEquals("1", tjobProps.get("commonprop1"));
    assertEquals("2", tjobProps.get("newcommonprop1"));
    assertEquals("1", tjobProps.get("pluginprops1"));
    assertEquals("2", tjobProps.get("pluginprops2"));
    assertEquals("3", tjobProps.get("pluginprops3"));
    assertEquals("pluginprops", tjobProps.get("commonprop3"));
    assertNull(tjobProps.get("commonprop2"));

    Props tloadProps = pluginSet.getPluginLoaderProps("testjob");
    assertNull(tloadProps.get("jobtype.classpath"));
    assertEquals("azkaban.test.jobtype.FakeJavaJob2", tloadProps.get("jobtype.class"));
    assertEquals("1", tloadProps.get("commonprivate1"));
    assertNull(tloadProps.get("commonprivate2"));
    assertEquals("private3", tloadProps.get("commonprivate3"));

    // Verify newtestjob
    Class<? extends Job> ntPluginClass = pluginSet.getPluginClass("newtestjob");
    assertEquals("azkaban.test.jobtype.FakeJavaJob2", ntPluginClass.getName());
    Props ntjobProps = pluginSet.getPluginJobProps("newtestjob");
    Props ntloadProps = pluginSet.getPluginLoaderProps("newtestjob");

    // Loader props
    assertNull(ntloadProps.get("jobtype.classpath"));
    assertEquals("azkaban.test.jobtype.FakeJavaJob2", ntloadProps.get("jobtype.class"));
    assertEquals("1", ntloadProps.get("commonprivate1"));
    assertNull(ntloadProps.get("commonprivate2"));
    assertEquals("private3", ntloadProps.get("commonprivate3"));
    assertEquals("0", ntloadProps.get("testprivate"));
    // Job props
    assertEquals("1", ntjobProps.get("commonprop1"));
    assertNull(ntjobProps.get("commonprop2"));
    assertEquals("1", ntjobProps.get("pluginprops1"));
    assertEquals("2", ntjobProps.get("pluginprops2"));
    assertEquals("3", ntjobProps.get("pluginprops3"));
    assertEquals("pluginprops", ntjobProps.get("commonprop3"));
}

From source file:android.databinding.compilationTest.BaseCompilationTest.java

protected void prepareApp(Map<String, String> replacements) throws IOException, URISyntaxException {
    replacements = addDefaults(replacements);
    // how to get build folder, pass from gradle somehow ?
    FileUtils.forceMkdir(testFolder);//from   ww w  . jav a  2s .  com
    copyResourceTo("/AndroidManifest.xml", new File(testFolder, "app/src/main/AndroidManifest.xml"),
            replacements);
    copyResourceTo("/project_build.gradle", new File(testFolder, "build.gradle"), replacements);
    copyResourceTo("/app_build.gradle", new File(testFolder, "app/build.gradle"), replacements);
    copyResourceTo("/settings.gradle", new File(testFolder, "settings.gradle"), replacements);
    File localProperties = new File("../local.properties");
    if (localProperties.exists()) {
        FileUtils.copyFile(localProperties, new File(testFolder, "local.properties"));
    }
    FileUtils.copyFile(new File("../propLoader.gradle"), new File(testFolder, "propLoaderClone.gradle"));
    FileUtils.copyFile(new File("../gradlew"), new File(testFolder, "gradlew"));
    FileUtils.copyDirectory(new File("../gradle"), new File(testFolder, "gradle"));
}

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

@Test
public void testGetWorkflowStatusWithInfo() throws Exception {

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

    celosClient.iterateScheduler();/*  w  ww  .j a v  a2  s  . c  om*/
    WorkflowStatus status = celosClient.getWorkflowStatus(new WorkflowID("workflow-2"));

    Assert.assertEquals(new URL("http://collective.com"), status.getInfo().getUrl());
    Assert.assertEquals(1, status.getInfo().getContacts().size());
    Assert.assertEquals("John Doe", status.getInfo().getContacts().get(0).getName());
    Assert.assertEquals(URI.create("john.doe@collective.com"),
            status.getInfo().getContacts().get(0).getEmail());
}

From source file:im.bci.gamesitekit.GameSiteKitMain.java

private void copyStyle() throws IOException {
    FileUtils.copyDirectory(styleInputDir.toFile(), styleOutputDir.toFile());
}

From source file:im.bci.gamesitekit.GameSiteKitMain.java

private void copyScripts() throws IOException {
    FileUtils.copyDirectory(scriptsInputDir.toFile(), scriptsOutputDir.toFile());
}

From source file:azkaban.jobtype.JobTypeManagerTest.java

/**
 * Test out reloading properties//from  ww  w .j a v a 2s .  com
 *
 * @throws Exception
 */
@Test
public void testResetPlugins() throws Exception {
    // Add a plugins file to the anothertestjob folder
    File anothertestfolder = new File(testPluginDirPath + "/anothertestjob");
    Props pluginProps = new Props();
    pluginProps.put("test1", "1");
    pluginProps.put("test2", "2");
    pluginProps.put("pluginprops3", "4");
    pluginProps.storeFlattened(new File(anothertestfolder, "plugin.properties"));

    // clone the testjob folder
    File testFolder = new File(testPluginDirPath + "/testjob");
    FileUtils.copyDirectory(testFolder, new File(testPluginDirPath + "/newtestjob"));

    // change the common properties
    Props commonPlugin = new Props(null, testPluginDirPath + "/common.properties");
    commonPlugin.put("commonprop1", "1");
    commonPlugin.put("newcommonprop1", "2");
    commonPlugin.removeLocal("commonprop2");
    commonPlugin.storeFlattened(new File(testPluginDirPath + "/common.properties"));

    // change the common properties
    Props commonPrivate = new Props(null, testPluginDirPath + "/commonprivate.properties");
    commonPrivate.put("commonprivate1", "1");
    commonPrivate.put("newcommonprivate1", "2");
    commonPrivate.removeLocal("commonprivate2");
    commonPrivate.storeFlattened(new File(testPluginDirPath + "/commonprivate.properties"));

    // change testjob private property
    Props loadProps = new Props(null, testPluginDirPath + "/testjob/private.properties");
    loadProps.put("privatetest", "test");

    // Reload the plugins here!!
    manager.loadPlugins();

    // Checkout common props
    JobTypePluginSet pluginSet = manager.getJobTypePluginSet();
    Props commonProps = pluginSet.getCommonPluginJobProps();
    assertEquals("1", commonProps.get("commonprop1"));
    assertEquals("commonprop3", commonProps.get("commonprop3"));
    assertEquals("2", commonProps.get("newcommonprop1"));
    assertNull(commonProps.get("commonprop2"));

    // Checkout common private
    Props commonPrivateProps = pluginSet.getCommonPluginLoadProps();
    assertEquals("1", commonPrivateProps.get("commonprivate1"));
    assertEquals("commonprivate3", commonPrivateProps.get("commonprivate3"));
    assertEquals("2", commonPrivateProps.get("newcommonprivate1"));
    assertNull(commonPrivateProps.get("commonprivate2"));

    // Verify anothertestjob changes
    Class<? extends Job> atjClass = pluginSet.getPluginClass("anothertestjob");
    assertEquals("azkaban.jobtype.FakeJavaJob", atjClass.getName());
    Props ajobProps = pluginSet.getPluginJobProps("anothertestjob");
    assertEquals("1", ajobProps.get("test1"));
    assertEquals("2", ajobProps.get("test2"));
    assertEquals("4", ajobProps.get("pluginprops3"));
    assertEquals("commonprop3", ajobProps.get("commonprop3"));

    Props aloadProps = pluginSet.getPluginLoaderProps("anothertestjob");
    assertEquals("1", aloadProps.get("commonprivate1"));
    assertNull(aloadProps.get("commonprivate2"));
    assertEquals("commonprivate3", aloadProps.get("commonprivate3"));

    // Verify testjob changes
    Class<? extends Job> tjClass = pluginSet.getPluginClass("testjob");
    assertEquals("azkaban.jobtype.FakeJavaJob2", tjClass.getName());
    Props tjobProps = pluginSet.getPluginJobProps("testjob");
    assertEquals("1", tjobProps.get("commonprop1"));
    assertEquals("2", tjobProps.get("newcommonprop1"));
    assertEquals("1", tjobProps.get("pluginprops1"));
    assertEquals("2", tjobProps.get("pluginprops2"));
    assertEquals("3", tjobProps.get("pluginprops3"));
    assertEquals("pluginprops", tjobProps.get("commonprop3"));
    assertNull(tjobProps.get("commonprop2"));

    Props tloadProps = pluginSet.getPluginLoaderProps("testjob");
    assertNull(tloadProps.get("jobtype.classpath"));
    assertEquals("azkaban.jobtype.FakeJavaJob2", tloadProps.get("jobtype.class"));
    assertEquals("1", tloadProps.get("commonprivate1"));
    assertNull(tloadProps.get("commonprivate2"));
    assertEquals("private3", tloadProps.get("commonprivate3"));

    // Verify newtestjob
    Class<? extends Job> ntPluginClass = pluginSet.getPluginClass("newtestjob");
    assertEquals("azkaban.jobtype.FakeJavaJob2", ntPluginClass.getName());
    Props ntjobProps = pluginSet.getPluginJobProps("newtestjob");
    Props ntloadProps = pluginSet.getPluginLoaderProps("newtestjob");

    // Loader props
    assertNull(ntloadProps.get("jobtype.classpath"));
    assertEquals("azkaban.jobtype.FakeJavaJob2", ntloadProps.get("jobtype.class"));
    assertEquals("1", ntloadProps.get("commonprivate1"));
    assertNull(ntloadProps.get("commonprivate2"));
    assertEquals("private3", ntloadProps.get("commonprivate3"));
    assertEquals("0", ntloadProps.get("testprivate"));
    // Job props
    assertEquals("1", ntjobProps.get("commonprop1"));
    assertNull(ntjobProps.get("commonprop2"));
    assertEquals("1", ntjobProps.get("pluginprops1"));
    assertEquals("2", ntjobProps.get("pluginprops2"));
    assertEquals("3", ntjobProps.get("pluginprops3"));
    assertEquals("pluginprops", ntjobProps.get("commonprop3"));
}

From source file:fr.paris.lutece.plugins.updater.service.PluginManagerService.java

/**
 * Restore a plugin (backup => webapp)
 * @param strPluginName The plugin name/*w ww  .j  av a  2 s .c  o m*/
 */
public void restorePlugin(String strPluginName) {
    _logger.info("restore plugin : " + strPluginName);

    try {
        File fileSource = new File(getWebAppPath() + PATH_BACKUP + strPluginName + FOLDER_WEBAPP);
        File fileDest = new File(getWebAppPath());

        FileUtils.copyDirectory(fileSource, fileDest);
    } catch (IOException ex) {
        _logger.error("error restoring plugin : ", ex);
    }
}

From source file:com.arcusys.liferay.vaadinplugin.VaadinUpdater.java

private void backupOldFiles() throws IOException {
    outputLog.log("Backup old vaadin files to " + backupPath);

    String vaadinResourcePath = ControlPanelPortletUtil.getVaadinResourceDir();
    File vaadinResource = new File(vaadinResourcePath);
    outputLog.log("Backup old vaadin resources : " + vaadinResourcePath + " to " + backupPath);
    String backupreSourcesPath = backupDir.getPath() + fileSeparator + "resources";
    File backupreSourcesDir = new File(backupreSourcesPath);
    if (backupreSourcesDir.exists())
        FileUtils.deleteDirectory(backupreSourcesDir);
    if (!backupreSourcesDir.mkdir()) {
        outputLog.log("Can't backup resources. Can't create directory " + backupreSourcesPath);
    } else {/*from   w w w. jav a  2 s. c o m*/
        FileUtils.copyDirectory(vaadinResource, backupreSourcesDir);
    }

    String backupFilesPath = backupPath + fileSeparator;

    File vaadin6Version = ControlPanelPortletUtil.get6VersionVaadinJarLocation();
    if (vaadin6Version.exists()) {
        outputLog.log("Backup vaadin.jar : " + vaadin6Version.getAbsolutePath());
        replaceFile(vaadin6Version.getParent() + fileSeparator, backupFilesPath, vaadin6Version.getName());
    }

    VaadinVersion currentVaadinInfo = VaadinVersion.getVaadinVersion(currentVaadinVersion);
    Collection<VaadinFileInfo> vaadinFileInfos = currentVaadinInfo.getVaadinFilesInfo();

    StringBuffer sb = new StringBuffer();
    Boolean isExistsNotBackuped = false;

    for (VaadinFileInfo fileInfo : vaadinFileInfos) {
        try {
            replaceFile(fileInfo.getPlace(), backupFilesPath, fileInfo.getName());
        } catch (Exception ex) {
            sb.append(fileInfo.getName()).append(", ");
            isExistsNotBackuped = true;
        }
    }

    if (isExistsNotBackuped) {
        outputLog.log("Can't backup next files : " + sb.toString());
    }
}

From source file:ml.shifu.shifu.ShifuCLITest.java

public void testPostTrainModel() throws Exception {
    File originModel = new File(
            "src/test/resources/example/cancer-judgement/ModelStore/ModelSet1/ModelConfig.json");
    File tmpModel = new File("ModelConfig.json");

    File originColumn = new File(
            "src/test/resources/example/cancer-judgement/ModelStore/ModelSet1/ColumnConfig.json");
    File tmpColumn = new File("ColumnConfig.json");

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

    FileUtils.copyFile(originModel, tmpModel);
    FileUtils.copyFile(originColumn, tmpColumn);
    FileUtils.copyDirectory(modelsDir, tmpModelsDir);

    long timestamp = tmpColumn.lastModified();
    // run post-train
    ShifuCLI.initializeModel();/*w  w  w  . ja v  a  2 s .c om*/
    ShifuCLI.calModelStats(null);
    ShifuCLI.normalizeTrainData();
    ShifuCLI.selectModelVar(null);
    ShifuCLI.postTrainModel();
    Assert.assertTrue(tmpColumn.lastModified() > timestamp);

    FileUtils.deleteQuietly(tmpModel);
    FileUtils.deleteQuietly(tmpColumn);
    FileUtils.deleteDirectory(new File("tmp"));
    FileUtils.deleteDirectory(new File("models"));
}