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:de.tarent.maven.plugins.pkg.Utils.java

/**
 * Copies the <code>AuxFile</code> instances contained within the set. It
 * takes the <code>srcAuxFilesDir</code> and <code>auxFileDstDir</code>
 * arguments into account to specify the parent source and destination
 * directory of the files./*from w ww.j  a va  2s . c  om*/
 * 
 * By default files are copied into directories. If the <code>rename</code>
 * property of the <code>AuxFile</code> instance is set however the file is
 * copied and renamed to the last part of the path.
 * 
 * The return value is the amount of copied bytes.
 * 
 * @param l
 * @param srcAuxFilesDir
 * @param dstDir
 * @param auxFiles
 * @param makeExecutable
 * @return
 * @throws MojoExecutionException
 */
public static long copyFiles(Log l, File srcDir, File dstDir, List<? extends AuxFile> auxFiles, String type,
        boolean makeExecutable) throws MojoExecutionException {
    long size = 0;

    Iterator<? extends AuxFile> ite = auxFiles.iterator();
    while (ite.hasNext()) {
        AuxFile af = (AuxFile) ite.next();
        File from = new File(srcDir, af.from);
        File to = new File(dstDir, af.to);

        l.info("copying " + type + ": " + from.toString());
        l.info("destination: " + to.toString());

        if (!from.exists()) {
            throw new MojoExecutionException("File to copy does not exist: " + from.toString());
        }
        createParentDirs(to, type);

        try {
            if (from.isDirectory()) {
                to = new File(to, from.getName());
                FileUtils.copyDirectory(from, to, FILTER);
                for (final Iterator<File> files = FileUtils.iterateFiles(from, FILTER, FILTER); files
                        .hasNext();) {
                    final File nextFile = files.next();
                    size += nextFile.length();
                }
            } else if (af.isRename()) {
                FileUtils.copyFile(from, to);
                size += from.length();

                if (makeExecutable) {
                    makeExecutable(l, to.getAbsolutePath());
                }
            } else {
                FileUtils.copyFileToDirectory(from, to);
                size += from.length();

                if (makeExecutable) {
                    makeExecutable(l, to.getAbsolutePath() + File.separator + from.getName());
                }
            }
        } catch (IOException ioe) {
            throw new MojoExecutionException("IOException while copying " + type, ioe);
        }
    }

    return size;
}

From source file:hd3gtv.mydmam.metadata.RenderedFile.java

public static void copyMoveAllMetadataContent(String metadata_reference_id_from,
        String metadata_reference_id_dest, boolean copy) throws IOException {
    if (metadata_reference_id_from == null) {
        throw new NullPointerException("\"metadata_reference_id_from\" can't to be null");
    }/*from  w  ww  . j  a  va 2s  . com*/
    if (metadata_reference_id_dest == null) {
        throw new NullPointerException("\"metadata_reference_id_dest\" can't to be null");
    }
    if (local_directory == null) {
        throw new IOException("No configuration is set !");
    }
    if (local_directory.exists() == false) {
        throw new IOException("Invalid configuration is set !");
    }

    StringBuilder sb_from_directory = new StringBuilder();
    sb_from_directory.append(local_directory.getCanonicalPath());
    sb_from_directory.append(File.separator);
    sb_from_directory.append(metadata_reference_id_from.substring(0, 6));
    sb_from_directory.append(File.separator);
    sb_from_directory.append(metadata_reference_id_from.substring(6));

    StringBuilder sb_dest_directory = new StringBuilder();
    sb_dest_directory.append(local_directory.getCanonicalPath());
    sb_dest_directory.append(File.separator);
    sb_dest_directory.append(metadata_reference_id_dest.substring(0, 6));
    sb_dest_directory.append(File.separator);
    sb_dest_directory.append(metadata_reference_id_dest.substring(6));

    File from_dir = new File(sb_from_directory.toString()).getCanonicalFile();
    File dest_dir = new File(sb_dest_directory.toString()).getCanonicalFile();

    Log2Dump dump = new Log2Dump();
    dump.add("from", from_dir);
    dump.add("to", dest_dir);
    Log2.log.debug("Prepare operation", dump);

    /**
     * Create sub directories.
     */
    FileUtils.forceMkdir(dest_dir);
    FileUtils.deleteDirectory(dest_dir);

    if (copy == false) {
        FileUtils.moveDirectory(from_dir, dest_dir);
    } else {
        FileUtils.copyDirectory(from_dir, dest_dir, true);
    }
}

From source file:com.amazonaws.eclipse.elasticbeanstalk.webproject.CreateNewAwsJavaWebProjectRunnable.java

private void addSessionManagerConfigurationFiles(IProject project) throws IOException, CoreException {
    Bundle bundle = ElasticBeanstalkPlugin.getDefault().getBundle();
    URL url = FileLocator.resolve(bundle.getEntry("/"));
    IPath templateRoot = new Path(url.getFile(), "templates");

    FileUtils.copyDirectory(templateRoot.append("dynamodb-session-manager").toFile(),
            project.getLocation().toFile(), new SvnMetadataFilter());

    // Add the user's credentials to context.xml
    File localContextXml = project.getLocation().append(".ebextensions").append("context.xml").toFile();
    AccountInfo accountInfo = AwsToolkitCore.getDefault().getAccountManager()
            .getAccountInfo(dataModel.getAccountId());
    String contextContents = FileUtils.readFileToString(localContextXml);
    contextContents = contextContents.replace("{ACCESS_KEY}", accountInfo.getAccessKey());
    contextContents = contextContents.replace("{SECRET_KEY}", accountInfo.getSecretKey());
    FileUtils.writeStringToFile(localContextXml, contextContents);

    project.refreshLocal(IResource.DEPTH_INFINITE, null);

    // Update the J2EE Deployment Assembly by creating a link from the '/.ebextensions'
    // folder to the '/WEB-INF/.ebextensions' folder in the web assembly mapping for WTP
    IVirtualComponent rootComponent = ComponentCore.createComponent(project);
    IVirtualFolder rootFolder = rootComponent.getRootFolder();
    try {//w w w .j a  v a  2 s. c  o m
        Path source = new Path("/.ebextensions");
        Path target = new Path("/WEB-INF/.ebextensions");
        IVirtualFolder subFolder = rootFolder.getFolder(target);
        subFolder.createLink(source, 0, null);
    } catch (CoreException ce) {
        String message = "Unable to configure deployment assembly to map .ebextension directory";
        AwsToolkitCore.getDefault().logException(message, ce);
    }
}