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, FileFilter filter) throws IOException 

Source Link

Document

Copies a filtered directory to a new location preserving the file dates.

Usage

From source file:fr.acxio.tools.agia.io.AbstractFileOperations.java

protected void copyFile(Resource sOriginFile, Resource sDestinationFile) throws IOException {
    File aOrigineFile = sOriginFile.getFile();
    if (aOrigineFile.isFile()) {
        if (!isDirectory(sDestinationFile)) {
            FileUtils.copyFile(aOrigineFile, sDestinationFile.getFile(), preserveAttributes);
        } else {//  w w w. java2s.  co m
            FileUtils.copyFileToDirectory(aOrigineFile, sDestinationFile.getFile(), preserveAttributes);
        }
    } else {
        if (recursive) {
            FileUtils.copyDirectory(aOrigineFile, sDestinationFile.getFile(), preserveAttributes);
        } else {
            FileUtils.copyDirectory(aOrigineFile, sDestinationFile.getFile(), FileFileFilter.FILE,
                    preserveAttributes);
        }
    }
}

From source file:com.geewhiz.pacify.test.TestUtil.java

public static void removeOldTestResourcesAndCopyAgain(File fromFolder, File toFolder) {
    if (toFolder.exists()) {
        FileUtils.deleteQuietly(toFolder);
    }/*w  ww  . j  av  a  2 s. c  om*/

    try {
        FileUtils.copyDirectory(fromFolder, toFolder, true);
    } catch (IOException e) {
        throw new RuntimeException("error while copy test-resources", e);
    }

}

From source file:com.twinsoft.convertigo.engine.util.ProjectUtils.java

public static void copyIndexFile(String projectName) throws Exception {
    String projectRoot = Engine.PROJECTS_PATH + '/' + projectName;
    String templateBase = Engine.TEMPLATES_PATH + "/base";
    File indexPage = new File(projectRoot + "/index.html");
    if (!indexPage.exists()) {
        if (new File(projectRoot + "/sna.xsl").exists()) { /** webization javelin */
            if (new File(projectRoot + "/templates/status.xsl").exists()) /** not DKU / DKU */
                FileUtils.copyFile(new File(templateBase + "/index_javelin.html"), indexPage);
            else//from  w w  w  . j ava 2 s.  c  o m
                FileUtils.copyFile(new File(templateBase + "/index_javelinDKU.html"), indexPage);
        } else {
            FileFilter fileFilterNoSVN = new FileFilter() {
                public boolean accept(File pathname) {
                    String name = pathname.getName();
                    return !name.equals(".svn") || !name.equals("CVS");
                }
            };
            FileUtils.copyFile(new File(templateBase + "/index.html"), indexPage);
            FileUtils.copyDirectory(new File(templateBase + "/js"), new File(projectRoot + "/js"),
                    fileFilterNoSVN);
            FileUtils.copyDirectory(new File(templateBase + "/css"), new File(projectRoot + "/css"),
                    fileFilterNoSVN);
        }
    }
}

From source file:ch.mattrero.foldersync.FoldersSynchronizer.java

boolean syncAdded(final Path sourceItem) {
    try {//from  w  w  w.j  a v a  2 s.c o m
        if (Files.isDirectory(sourceItem)) {
            FileUtils.copyDirectory(sourceItem.toFile(), resolveBackupItemPath(sourceItem).toFile(), true);
            logger.debug("Added directory " + sourceItem);
        } else {
            Files.copy(sourceItem, resolveBackupItemPath(sourceItem), COPY_ATTRIBUTES, REPLACE_EXISTING);
            logger.debug("Added file " + sourceItem);
        }
    } catch (final IOException e) {
        logger.warn("Failed to create " + resolveBackupItemPath(sourceItem), e);
        return false;
    }

    return true;
}

From source file:com.funambol.server.config.ConfigurationTest.java

/**
 * Test of plugin handling/*from w w  w.  j a  v  a2s  . c om*/
 * @throws Exception
 */
public void testPlugin_1() throws Exception {

    Configuration.getConfiguration().initializeEngineComponents();

    Boolean b = (Boolean) PrivateAccessor.getField(Configuration.getConfiguration(),
            "engineComponentsInitialized");

    assertTrue("The engine components should be initialized", b.booleanValue());

    PluginHandler pluginHandler = (PluginHandler) PrivateAccessor.getField(Configuration.getConfiguration(),
            "pluginHandler");

    Map<String, Plugin> plugins = (Map<String, Plugin>) PrivateAccessor.getField(pluginHandler, "plugins");

    assertEquals("wrong expected plugin number:", 2, plugins.size());

    //
    // Deleting plugin 3
    //
    FileUtils.forceDelete(
            new File(Configuration.getConfigPath() + "/com/funambol/server/plugin/dummy-plugin-3.xml"));
    File dirTest1 = new File(funambolHome, "com/funambol/server/config/Configuration/plugin/test-1");

    FileUtils.copyDirectory(dirTest1, runtimePluginDir, new WildcardFileFilter("*.xml"));

    // Waiting for automatic change detection
    Thread.sleep(15 * 1000);

    pluginHandler = (PluginHandler) PrivateAccessor.getField(Configuration.getConfiguration(), "pluginHandler");
    plugins = (Map<String, Plugin>) PrivateAccessor.getField(pluginHandler, "plugins");

    assertEquals("wrong expected plugin number:", 2, plugins.size());

    System.out.println("Plugins: " + plugins);
    assertNotNull(plugins.get("dummy-plugin-1.xml"));
    assertNotNull(plugins.get("dummy-plugin-5.xml"));

    Plugin plugin1 = plugins.get("dummy-plugin-1.xml");
    assertEquals("Wrong plugin name", "test-plugin-1-updated", ((DummyPlugin) plugin1).getName());
}

From source file:controllers.Uploads.java

public static void publish(Long id) throws IOException {
    models.Upload upload = getUpload(id);
    File uploadsDir = Util.getUploadDir(id);
    User user = getUser();//from   w  w  w .  j a  v a 2  s .c  o  m
    UploadInfo uploadInfo = getUploadInfo(upload, uploadsDir, user);

    if (!uploadInfo.isPublishable()) {
        Validation.addError(null, "Upload is not valid, cannot publish. Fix errors first.");
        prepareForErrorRedirect();
        view(id);
    }

    for (Module module : uploadInfo.modules) {
        models.Module mod = models.Module.find("name = ?", module.name).first();
        if (mod == null) {
            mod = new models.Module();
            mod.name = module.name;
            mod.owner = user;
            mod.create();
        }

        models.ModuleVersion modVersion = new models.ModuleVersion();
        modVersion.module = mod;
        modVersion.version = module.version;
        modVersion.isCarPresent = module.hasCar;
        modVersion.isJarPresent = module.hasJar;
        modVersion.isJsPresent = module.hasJs;
        modVersion.isSourcePresent = module.hasSource;
        modVersion.isAPIPresent = module.hasDocs;
        modVersion.isRunnable = module.isRunnable;
        modVersion.ceylonMajor = module.ceylonMajor;
        modVersion.ceylonMinor = module.ceylonMinor;
        modVersion.published = Util.currentTimeInUTC();
        modVersion.doc = module.doc;
        modVersion.license = module.license;
        if (module.authors != null) {
            for (String author : module.authors) {
                modVersion.authors.add(Author.findOrCreate(author));
            }
        }
        modVersion.create();

        for (Import imp : module.dependencies)
            modVersion.addDependency(imp.name, imp.version, imp.optional, imp.export);
    }

    FileUtils.copyDirectory(uploadsDir, Util.getRepoDir(), NonEmptyDirectoryFilter);
    FileUtils.deleteDirectory(uploadsDir);
    upload.delete();

    MyCache.evictUploadsForOwner(user);
    MyCache.evictModulesForOwner(user);

    flash("message", "Repository published");
    index();
}

From source file:com.adguard.compiler.FileUtil.java

private static void copyDirectory(File source, File dest) throws IOException {
    FileUtils.copyDirectory(source, dest, new FileFilter() {
        public boolean accept(File pathname) {
            return !pathname.getName().startsWith(".");
        }//from   ww  w  .ja v  a 2 s  .com
    });
}

From source file:com.virtualparadigm.packman.processor.JPackageManagerBU.java

public static boolean createPackage(String packageName, String packageVersion, File packageOutputFile,
        File oldStateDir, File newStateDir, File licenseFile, File autorunInstallDir, File autorunUninstallDir,
        boolean developmentMode) {
    logger.info(/* www  .ja v  a2s.  c o  m*/
            "PackageManager::createPackage - creating package: " + packageName + " version: " + packageVersion);
    boolean status = false;
    if (packageName != null && packageVersion != null) {
        File tempDir = new File(TEMP_CREATE_PACKAGE_DIR_NAME);
        File tempMetadataDir = new File(
                JPackageManagerBU.TEMP_CREATE_PACKAGE_DIR_NAME + "/" + JPackageManagerBU.METADATA_DIR_NAME);
        File tempPatchDir = new File(
                JPackageManagerBU.TEMP_CREATE_PACKAGE_DIR_NAME + "/" + JPackageManagerBU.PATCH_DIR_NAME);
        File tempPatchFilesDir = new File(JPackageManagerBU.TEMP_CREATE_PACKAGE_DIR_NAME + "/"
                + JPackageManagerBU.PATCH_DIR_NAME + "/" + JPackageManagerBU.PATCH_FILES_DIR_NAME);

        File tempAutorunDir = new File(
                JPackageManagerBU.TEMP_CREATE_PACKAGE_DIR_NAME + "/" + JPackageManagerBU.AUTORUN_DIR_NAME);
        File tempAutorunInstallDir = new File(JPackageManagerBU.TEMP_CREATE_PACKAGE_DIR_NAME + "/"
                + JPackageManagerBU.AUTORUN_DIR_NAME + "/" + JPackageManagerBU.INSTALL_DIR_NAME);
        File tempAutorunUninstallDir = new File(JPackageManagerBU.TEMP_CREATE_PACKAGE_DIR_NAME + "/"
                + JPackageManagerBU.AUTORUN_DIR_NAME + "/" + JPackageManagerBU.UNINSTALL_DIR_NAME);

        tempMetadataDir.mkdirs();
        tempPatchFilesDir.mkdirs();
        tempAutorunInstallDir.mkdirs();
        tempAutorunUninstallDir.mkdirs();

        try {
            FileUtils.copyFileToDirectory(licenseFile, tempMetadataDir, true);

            FileUtils.copyDirectory(autorunInstallDir, tempAutorunInstallDir, true);
            FileUtils.copyDirectory(autorunUninstallDir, tempAutorunUninstallDir, true);

            String strPackageProperties = JPackageManagerBU.PACKAGE_NAME_KEY + "=" + packageName + "\n"
                    + JPackageManagerBU.PACKAGE_VERSION_KEY + "=" + packageVersion;
            FileUtils.writeStringToFile(new File(
                    tempMetadataDir.getAbsolutePath() + "/" + JPackageManagerBU.PACKAGE_PROPERTIES_FILE_NAME),
                    strPackageProperties, "UTF-8");

            JPatchManager directoryPatchManager = new JPatchManager();
            //                directoryPatchManager.makePatch(newStateDir, oldStateDir, new File(tempPatchDir.getAbsolutePath() + "/" + JPackageManagerBU.PATCH_FILE_NAME), tempPatchFilesDir);
            directoryPatchManager.makePatch(oldStateDir, newStateDir, new File(tempPatchDir.getAbsolutePath()),
                    null);

            if (packageOutputFile == null) {
                packageOutputFile = new File(packageName + "-" + packageVersion + ".zip");
            }
            ZipUtils.createZipFile(packageOutputFile.getAbsolutePath(),
                    new File[] { tempAutorunDir, tempMetadataDir, tempPatchDir }, 1024);

            status = true;
        } catch (Exception e) {
            logger.error("", e);
            //                e.printStackTrace();
        }

        if (!developmentMode) {
            JPackageManagerBU.cleanup(tempDir);
        }

    }
    return status;
}

From source file:com.virtualparadigm.packman.processor.JPackageManagerOld.java

public static boolean createPackage(String packageName, String packageVersion, File packageOutputFile,
        File oldStateDir, File newStateDir, File licenseFile, File autorunInstallDir, File autorunUninstallDir,
        File tempDir, boolean developmentMode) {
    logger.info(//  w  w w  .  j  a  v  a 2  s .com
            "PackageManager::createPackage - creating package: " + packageName + " version: " + packageVersion);
    boolean status = false;
    if (packageName != null && packageVersion != null) {
        if (tempDir == null) {
            tempDir = new File(TEMP_CREATE_PACKAGE_DIR_NAME);
        }

        File tempMetadataDir = new File(tempDir.getAbsolutePath() + "/" + JPackageManagerOld.METADATA_DIR_NAME);
        File tempPatchDir = new File(tempDir.getAbsolutePath() + "/" + JPackageManagerOld.PATCH_DIR_NAME);
        File tempPatchFilesDir = new File(tempDir.getAbsolutePath() + "/" + JPackageManagerOld.PATCH_DIR_NAME
                + "/" + JPackageManagerOld.PATCH_FILES_DIR_NAME);

        File tempAutorunDir = new File(tempDir.getAbsolutePath() + "/" + JPackageManagerOld.AUTORUN_DIR_NAME);
        File tempAutorunInstallDir = new File(tempDir.getAbsolutePath() + "/"
                + JPackageManagerOld.AUTORUN_DIR_NAME + "/" + JPackageManagerOld.INSTALL_DIR_NAME);
        File tempAutorunUninstallDir = new File(tempDir.getAbsolutePath() + "/"
                + JPackageManagerOld.AUTORUN_DIR_NAME + "/" + JPackageManagerOld.UNINSTALL_DIR_NAME);

        tempMetadataDir.mkdirs();
        tempPatchFilesDir.mkdirs();
        tempAutorunInstallDir.mkdirs();
        tempAutorunUninstallDir.mkdirs();

        try {
            FileUtils.copyFileToDirectory(licenseFile, tempMetadataDir, true);

            FileUtils.copyDirectory(autorunInstallDir, tempAutorunInstallDir, true);
            FileUtils.copyDirectory(autorunUninstallDir, tempAutorunUninstallDir, true);

            String strPackageProperties = JPackageManagerOld.PACKAGE_NAME_KEY + "=" + packageName + "\n"
                    + JPackageManagerOld.PACKAGE_VERSION_KEY + "=" + packageVersion;
            FileUtils.writeStringToFile(new File(
                    tempMetadataDir.getAbsolutePath() + "/" + JPackageManagerOld.PACKAGE_PROPERTIES_FILE_NAME),
                    strPackageProperties, "UTF-8");

            JPatchManager directoryPatchManager = new JPatchManager();
            //                directoryPatchManager.makePatch(oldStateDir, newStateDir, new File(tempPatchDir.getAbsolutePath() + "/" + JPackageManager.PATCH_FILE_NAME), tempPatchFilesDir);
            directoryPatchManager.makePatch(oldStateDir, newStateDir, new File(tempPatchDir.getAbsolutePath()),
                    null);

            if (packageOutputFile == null) {
                packageOutputFile = new File(packageName + "-" + packageVersion + ".zip");
            }
            ZipUtils.createZipFile(packageOutputFile.getAbsolutePath(),
                    new File[] { tempAutorunDir, tempMetadataDir, tempPatchDir }, 1024);

            status = true;
        } catch (Exception e) {
            logger.error("", e);
        }

        if (!developmentMode) {
            JPackageManagerOld.cleanup(tempDir);
        }

    }
    return status;
}

From source file:com.virtualparadigm.packman.processor.JPackageManager.java

public static boolean createPackage(String packageName, String packageVersion, File packageOutputFile,
        File oldStateDir, File newStateDir, File licenseFile, File autorunInstallDir, File autorunUninstallDir,
        File tempDir, boolean developmentMode) {
    logger.info(//from  www . java  2 s .c om
            "PackageManager::createPackage - creating package: " + packageName + " version: " + packageVersion);
    boolean status = false;
    if (packageName != null && packageVersion != null) {
        if (tempDir == null) {
            tempDir = new File(TEMP_CREATE_PACKAGE_DIR_NAME);
        }

        File tempMetadataDir = new File(tempDir.getAbsolutePath() + "/" + JPackageManager.METADATA_DIR_NAME);
        File tempPatchDir = new File(tempDir.getAbsolutePath() + "/" + JPackageManager.PATCH_DIR_NAME);
        File tempPatchFilesDir = new File(tempDir.getAbsolutePath() + "/" + JPackageManager.PATCH_DIR_NAME + "/"
                + JPackageManager.PATCH_FILES_DIR_NAME);

        File tempAutorunDir = new File(tempDir.getAbsolutePath() + "/" + JPackageManager.AUTORUN_DIR_NAME);
        File tempAutorunInstallDir = new File(tempDir.getAbsolutePath() + "/" + JPackageManager.AUTORUN_DIR_NAME
                + "/" + JPackageManager.INSTALL_DIR_NAME);
        File tempAutorunUninstallDir = new File(tempDir.getAbsolutePath() + "/"
                + JPackageManager.AUTORUN_DIR_NAME + "/" + JPackageManager.UNINSTALL_DIR_NAME);

        tempMetadataDir.mkdirs();
        tempPatchFilesDir.mkdirs();
        tempAutorunInstallDir.mkdirs();
        tempAutorunUninstallDir.mkdirs();

        try {
            FileUtils.copyFileToDirectory(licenseFile, tempMetadataDir, true);

            FileUtils.copyDirectory(autorunInstallDir, tempAutorunInstallDir, true);
            FileUtils.copyDirectory(autorunUninstallDir, tempAutorunUninstallDir, true);

            String strPackageProperties = JPackageManager.PACKAGE_NAME_KEY + "=" + packageName + "\n"
                    + JPackageManager.PACKAGE_VERSION_KEY + "=" + packageVersion;
            FileUtils.writeStringToFile(new File(
                    tempMetadataDir.getAbsolutePath() + "/" + JPackageManager.PACKAGE_PROPERTIES_FILE_NAME),
                    strPackageProperties, "UTF-8");

            JPatchManager directoryPatchManager = new JPatchManager();
            //                directoryPatchManager.makePatch(oldStateDir, newStateDir, new File(tempPatchDir.getAbsolutePath() + "/" + JPackageManager.PATCH_FILE_NAME), tempPatchFilesDir);
            directoryPatchManager.makePatch(oldStateDir, newStateDir, new File(tempPatchDir.getAbsolutePath()),
                    null);

            if (packageOutputFile == null) {
                packageOutputFile = new File(packageName + "-" + packageVersion + ".zip");
            }
            ZipUtils.createZipFile(packageOutputFile.getAbsolutePath(),
                    new File[] { tempAutorunDir, tempMetadataDir, tempPatchDir }, 1024);

            status = true;
        } catch (Exception e) {
            logger.error("", e);
        }

        if (!developmentMode) {
            JPackageManager.cleanup(tempDir);
        }

    }
    return status;
}