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:ch.systemsx.cisd.openbis.generic.server.dataaccess.db.DatabaseAndIndexReplacer.java

public static void main(String[] args) {
    if (args.length != 4) {
        System.out.println("Usage: java " + DatabaseAndIndexReplacer.class.getName()
                + " <destination database kind> <destination index folder> "
                + "<source database kind> <source index folder>");
        System.exit(1);//from w w w  .  j a  v a 2s.  c  o  m
    }
    LogInitializer.init();
    String destinationDatabase = IndexCreationUtil.DATABASE_NAME_PREFIX + args[0];
    File destinationFolder = new File(args[1]);
    String sourceDatabase = IndexCreationUtil.DATABASE_NAME_PREFIX + args[2];
    File sourceFolder = new File(args[3]);

    boolean ok = IndexCreationUtil.duplicateDatabase(destinationDatabase, sourceDatabase);
    if (ok == false) {
        System.exit(1);
    }
    FileUtilities.deleteRecursively(destinationFolder);
    try {
        FileUtils.copyDirectory(sourceFolder, destinationFolder, true);
        operationLog
                .info("Index successfully copies from '" + sourceFolder + "' to '" + destinationFolder + "'.");
    } catch (IOException ex) {
        operationLog.error("Couldn't copy '" + sourceFolder + "' to '" + destinationFolder + "'.", ex);
    }

}

From source file:com.fizzed.stork.assembly.AssemblyUtils.java

static public void copyStandardProjectResources(File projectDir, File outputDir) throws IOException {
    FileUtils.copyDirectory(projectDir, outputDir, new FileFilter() {
        @Override/*from www.j a  v a  2 s  .c o  m*/
        public boolean accept(File pathname) {
            String name = pathname.getName().toLowerCase();
            if (name.startsWith("readme") || name.startsWith("changelog") || name.startsWith("release")
                    || name.startsWith("license")) {
                return true;
            } else {
                return false;
            }
        }
    });
}

From source file:com.arcbees.gwtpolymer.tasks.ComponentFilesCopier.java

@Override
public void process(PolymerComponent element) throws Exception {
    File componentDirectory = element.getComponentDirectory();
    File componentPublicDirectory = element.getComponentPublicDirectory();

    FileUtils.copyDirectory(componentDirectory, componentPublicDirectory, new CopyPolymerFilter());
}

From source file:fr.inria.atlanmod.neoemf.benchmarks.datastore.helper.BackendHelper.java

public static File copyStore(File sourceFile) throws IOException {
    File outputFile = Workspace.newTempDirectory().resolve(sourceFile.getName()).toFile();

    log.info("Copy {} to {}", sourceFile, outputFile);

    if (sourceFile.isDirectory()) {
        FileUtils.copyDirectory(sourceFile, outputFile, true);
    } else {/*from   w ww . j a va2  s . c o m*/
        FileUtils.copyFile(sourceFile, outputFile);
    }

    return outputFile;
}

From source file:atg.tools.dynunit.test.util.FileUtil.java

public static void copyDirectory(@NotNull String srcDir, @NotNull String dstDir,
        @NotNull final List<String> excludes) throws IOException {
    logger.entry(srcDir, dstDir, excludes);
    Validate.notEmpty(srcDir);/*from  w  ww .  j  a va2s  . c o  m*/
    Validate.notEmpty(dstDir);
    final File source = new File(srcDir);
    if (!source.exists()) {
        throw logger.throwing(new FileNotFoundException(srcDir));
    }
    final File destination = new File(dstDir);
    FileUtils.copyDirectory(source, destination, new FileFilter() {
        @Override
        public boolean accept(final File file) {
            return excludes.contains(file.getName());
        }
    });
    logger.exit();
}

From source file:citibob.licensor.MakeLauncher.java

/**
 * //  ww  w .j  a  va 2  s .  c o  m
 * @param version
 * @param configDir
 * @param outJar
 * @param spassword
 * @throws java.lang.Exception
 */
public static void makeLauncher(String version, File configDir, File outJar, String spassword)
        throws Exception {
    File oaDir = ClassPathUtils.getMavenProjectRoot();
    File oalaunchDir = new File(oaDir, "../oalaunch");
    File oasslDir = new File(oaDir, "../oassl");
    File keyDir = new File(oasslDir, "keys/client");
    File tmpDir = new File(".", "tmp");
    FileUtils.deleteDirectory(tmpDir);
    tmpDir.mkdirs();

    // Find the oalaunch JAR file
    File oalaunchJar = null;
    File[] files = new File(oalaunchDir, "target").listFiles();
    for (File f : files) {
        if (f.getName().startsWith("oalaunch") && f.getName().endsWith(".jar")) {
            oalaunchJar = f;
            break;
        }
    }

    // Unjar the oalaunch.jar file into the temporary directory
    exec(tmpDir, "jar", "xvf", oalaunchJar.getAbsolutePath());

    File tmpOalaunchDir = new File(tmpDir, "oalaunch");
    File tmpConfigDir = new File(tmpOalaunchDir, "config");

    // Read app.properties
    Properties props = new Properties();
    InputStream in = new FileInputStream(new File(configDir, "app.properties"));
    props.load(in);
    in.close();

    // Re-do the config dir
    FileUtils.deleteDirectory(tmpConfigDir);
    FileFilter ff = new FileFilter() {
        public boolean accept(File f) {
            if (f.getName().startsWith("."))
                return false;
            if (f.getName().endsWith("~"))
                return false;
            return true;
        }
    };
    FileUtils.copyDirectory(configDir, tmpConfigDir, ff);

    // Set up to encrypt
    char[] password = null;
    PBECrypt pbe = new PBECrypt();
    if (spassword != null)
        password = spassword.toCharArray();

    // Encrypt .properties files if needed
    if (password != null) {
        for (File fin : configDir.listFiles()) {
            if (fin.getName().endsWith(".properties") || fin.getName().endsWith(".jks")) {
                File fout = new File(tmpConfigDir, fin.getName());
                pbe.encrypt(fin, fout, password);
            }
        }
    }

    // Copy the appropriate key and certificate files
    String dbUserName = props.getProperty("db.user", null);
    File[] jksFiles = new File[] { new File(keyDir, dbUserName + "-store.jks"),
            new File(keyDir, dbUserName + "-trust.jks") };
    for (File fin : jksFiles) {
        if (!fin.exists()) {
            System.out.println("Missing jks file: " + fin.getName());
            continue;
        }
        File fout = new File(tmpConfigDir, fin.getName());
        if (password != null) {
            System.out.println("Encrypting " + fin.getName());
            pbe.encrypt(fin, fout, password);
        } else {
            System.out.println("Copying " + fin.getName());
            FileUtils.copyFile(fin, fout);
        }
    }

    // Use a downloaded JNLP file, not a static one.
    new File(tmpOalaunchDir, "offstagearts.jnlp").delete();

    // Open properties file, which we will write to...
    File oalaunchProperties = new File(tmpDir, "oalaunch/oalaunch.properties");
    Writer propertiesOut = new FileWriter(oalaunchProperties);
    propertiesOut.write(
            "jnlp.template.url = " + "http://offstagearts.org/releases/offstagearts/offstagearts_oalaunch-"
                    + version + ".jnlp.template\n");
    String configName = outJar.getName();
    int dot = configName.lastIndexOf(".jar");
    if (dot >= 0)
        configName = configName.substring(0, dot);
    propertiesOut.write("config.name = " + configName + "\n");
    propertiesOut.close();

    // Jar it back up
    exec(tmpDir, "jar", "cvfm", outJar.getAbsolutePath(), "META-INF/MANIFEST.MF", ".");

    //   // Sign it
    //   exec(null, "jarsigner", "-storepass", "keyst0re", outJar.getAbsolutePath(),
    //         "offstagearts");

    // Remove the tmp directory
    FileUtils.deleteDirectory(tmpDir);
}

From source file:com.github.k0zka.contentcompress.ContentGzipMojo.java

public void execute() throws MojoExecutionException {
    getLog().info("Compressing static resources with gzip...");
    try {//  w  ww.ja v a  2s .com
        if (!ObjectUtils.equals(webappDirectory, outputDirectory)) {
            FileUtils.copyDirectory(webappDirectory, outputDirectory, new DotNotFilter());
        }
        seekAndGzip(outputDirectory);
    } catch (IOException e) {
        throw new MojoExecutionException("IO exception when gzipping files", e);
    }
}

From source file:com.gettextresourcebundle.GettextResourceBundleControlTest.java

/**
 * test that PO files loaded from the file system will reload after 
 * cache timeout occurs and modified dates are different
 * @throws IOException// w  w  w.j  a v a  2  s . c  o  m
 */
@Test
public void testFileReloads() throws IOException {
    File localeDirectory = new File("./src/test/resources/locale");
    File localeNewDirectory = new File("./src/test/resources/localeNew");
    File targetDirectory = new File("./target/testLocales");
    targetDirectory.mkdirs();

    //unit test with 5 second cache time
    final long cacheTTL = 5 * 1000l;
    GettextResourceBundleControl.setCacheTTL(cacheTTL);

    FileUtils.copyDirectory(localeDirectory, targetDirectory, false);

    ResourceBundle en_US = ResourceBundle.getBundle(targetDirectory.getAbsolutePath(), Locale.US,
            GettextResourceBundleControl.getControl("test"));
    assertEquals("The locale key should be en_US for the en_US locale", "en_US", en_US.getString("locale"));

    ResourceBundle en_CA = ResourceBundle.getBundle(targetDirectory.getAbsolutePath(), Locale.CANADA,
            GettextResourceBundleControl.getControl("test"));
    assertEquals("The locale key should be en_CA for the en_CA locale", "en_CA", en_CA.getString("locale"));

    FileUtils.copyDirectory(localeNewDirectory, targetDirectory, false);

    en_US = ResourceBundle.getBundle(targetDirectory.getAbsolutePath(), Locale.US,
            GettextResourceBundleControl.getControl("test"));
    assertEquals("The locale key should be en_US for the en_US locale before cache expiry", "en_US",
            en_US.getString("locale"));

    en_CA = ResourceBundle.getBundle(targetDirectory.getAbsolutePath(), Locale.CANADA,
            GettextResourceBundleControl.getControl("test"));
    assertEquals("The locale key should be en_CA for the en_CA locale before cache expiry", "en_CA",
            en_CA.getString("locale"));

    //wait until cacheTTL passes so that cache expires
    long end = System.currentTimeMillis() + (cacheTTL);
    while (end > System.currentTimeMillis()) {
        try {
            Thread.sleep(end - System.currentTimeMillis());
        } catch (InterruptedException e) {

        }
    }

    en_US = ResourceBundle.getBundle(targetDirectory.getAbsolutePath(), Locale.US,
            GettextResourceBundleControl.getControl("test"));
    assertEquals("The locale key should be en_US #2 for the en_US locale before cache expiry", "en_US #2",
            en_US.getString("locale"));

    en_CA = ResourceBundle.getBundle(targetDirectory.getAbsolutePath(), Locale.CANADA,
            GettextResourceBundleControl.getControl("test"));
    assertEquals("The locale key should be en_CA #2 for the en_CA locale before cache expiry", "en_CA #2",
            en_CA.getString("locale"));
}

From source file:edu.kit.dama.util.release.GenerateSourceRelease.java

public static void copySources(File source, File destination, final ReleaseConfiguration config)
        throws IOException {
    for (String folder : config.getInputDirectories()) {
        File input = new File(source, folder);
        if (!input.exists()) {
            //warn
            continue;
        }/*  w  w w .  jav  a  2  s  .co  m*/
        new File(destination, folder).mkdirs();
        FileUtils.copyDirectory(input, new File(destination, folder), new FileFilter() {

            @Override
            public boolean accept(File pathname) {
                //check folders to ignore
                for (String folder : config.getDirectoriesToIgnore()) {
                    if (pathname.isDirectory() && folder.equals(pathname.getName())) {
                        return false;
                    }
                }

                //check files to ignore
                for (String file : config.getFilesToIgnore()) {
                    if (pathname.isFile() && new WildcardFileFilter(file).accept(pathname)) {
                        return false;
                    }
                }

                return true;
            }
        });
    }

    for (String file : config.getFilesToRemove()) {
        FileUtils.deleteQuietly(new File(destination, file));
    }

    for (String file : config.getInputFiles()) {
        File input = new File(source, file);
        if (input.exists()) {
            FileUtils.copyFile(new File(source, file), new File(destination, file));
        } else {
            //warn
        }
    }
}

From source file:com.hurence.logisland.documentation.DocGenerator.java

public static void main(String[] args) {
    DocGenerator.generate(new File("."), "rst");

    try {/*from  w w  w.  ja  v a  2 s . c  om*/
        FileUtils.copyDirectory(new File("."),
                new File("../logisland-core/logisland-framework/logisland-resources/src/main/resources/docs"),
                new WildcardFileFilter("*.rst"));

        FileUtils.copyDirectory(new File("tutorials"), new File(
                "../logisland-core/logisland-framework/logisland-resources/src/main/resources/docs/tutorials"),
                new WildcardFileFilter("*.rst"));

        FileUtils.copyDirectory(new File("_static"), new File(
                "../logisland-core/logisland-framework/logisland-resources/src/main/resources/docs/_static"));
    } catch (IOException e) {
        logger.error("I/O error", e);
    }
}