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:com.fiveamsolutions.nci.commons.mojo.copywebfiles.CopyWebFilesMojo.java

/**
 * @param latestDeployDirectory//w w  w  . ja  v  a2 s  .  com
 * @param fileFilter
 * @throws MojoExecutionException
 */
@SuppressWarnings("rawtypes")
private void copyFiles(File latestDeployDirectory, IOFileFilter fileFilter) throws MojoExecutionException {
    try {
        for (File srcDir : srcDirectories) {
            Collection filesToCopy = FileUtils.listFiles(srcDir, fileFilter, TrueFileFilter.INSTANCE);
            int count = 0;
            for (Object o : filesToCopy) {
                File src = (File) o;
                String relativePath = StringUtils.removeStart(src.getAbsolutePath(), srcDir.getAbsolutePath());
                File dest = new File(latestDeployDirectory.getAbsoluteFile() + relativePath);
                if (src.lastModified() > dest.lastModified()) {
                    getLog().debug("Copying " + src.getAbsolutePath() + " to " + dest.getAbsolutePath());
                    FileUtils.copyFile(src, dest);
                    count++;
                }
            }
            getLog().info("Copied " + count + " files from " + srcDir.getAbsolutePath() + " to "
                    + latestDeployDirectory.getAbsolutePath());
            FileUtils.copyDirectory(srcDir, latestDeployDirectory, fileFilter);
        }
    } catch (IOException e) {
        throw new MojoExecutionException("Failed to copy web files", e);
    }
}

From source file:com.jayway.maven.plugins.android.common.BuildHelper.java

private void copyFolder(File sourceFolder, File targetFolder, FileFilter filter) throws MojoExecutionException {
    if (!sourceFolder.exists()) {
        return;/*from  www .  j  av  a2s  . co  m*/
    }

    try {
        log.debug("Copying " + sourceFolder + " to " + targetFolder);
        if (!targetFolder.exists()) {
            if (!targetFolder.mkdirs()) {
                throw new MojoExecutionException("Could not create target directory " + targetFolder);
            }
        }
        FileUtils.copyDirectory(sourceFolder, targetFolder, filter);
    } catch (IOException e) {
        throw new MojoExecutionException("Could not copy source folder to target folder", e);
    }
}

From source file:de.tarent.maven.plugins.pkg.packager.IzPackPackager.java

/**
 * Creates the temporary and package base directory.
 * //from  w  w  w .j a v  a2 s  .  co m
 * @param l
 * @param basePkgDir
 * @throws MojoExecutionException
 */
private void prepareDirectories(Log l, File tempRoot, File izPackEmbeddedRoot, File srcDir,
        File tempDescriptorRoot, File libraryRoot) throws MojoExecutionException {
    l.info("creating temporary directory: " + tempRoot.getAbsolutePath());

    if (!tempRoot.exists() && !tempRoot.mkdirs()) {
        throw new MojoExecutionException("Could not create temporary directory.");
    }
    l.info("cleaning the temporary directory");
    try {
        FileUtils.cleanDirectory(tempRoot);
    } catch (IOException ioe) {
        throw new MojoExecutionException("Exception while cleaning temporary directory.", ioe);
    }

    l.info("creating IzPack base directory: " + izPackEmbeddedRoot.getAbsolutePath());
    if (!izPackEmbeddedRoot.mkdirs()) {
        throw new MojoExecutionException("Could not create directory for the embedded IzPack installation.");
    }
    if (!tempDescriptorRoot.mkdirs()) {
        throw new MojoExecutionException("Could not create base directory for the IzPack descriptor.");
    }
    l.info("copying IzPack descriptor data");
    try {
        FileUtils.copyDirectory(srcDir, tempDescriptorRoot, Utils.FILTER);
    } catch (IOException ioe) {
        throw new MojoExecutionException("IOException while copying IzPack descriptor data.", ioe);
    }

    l.info("creating directory for dependencies: " + libraryRoot.getAbsolutePath());
    if (!libraryRoot.mkdirs()) {
        throw new MojoExecutionException("Could not create directory for the dependencies.");
    }
}

From source file:com.isomorphic.maven.mojo.AbstractPackagerMojo.java

/**
 * Provides some initialization and validation steps around the collection and transformation of an Isomorphic SDK. 
 * //from  ww  w.ja v a2  s.  c  o  m
 * @throws MojoExecutionException When any fatal error occurs.
 * @throws MojoFailureException When any non-fatal error occurs. 
 */
public void execute() throws MojoExecutionException, MojoFailureException {

    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    dateFormat.setLenient(false);
    if (buildDate == null) {
        buildDate = dateFormat.format(new Date());
    }
    try {
        dateFormat.parse(buildDate);
    } catch (ParseException e) {
        throw new MojoExecutionException(
                String.format("buildDate '%s' must take the form yyyy-MM-dd.", buildDate));
    }

    LOGGER.debug("buildDate set to '{}'", buildDate);

    String buildNumberFormat = "\\d.*\\.\\d.*[d|p]";
    if (!buildNumber.matches(buildNumberFormat)) {
        throw new MojoExecutionException(
                String.format("buildNumber '%s' must take the form [major].[minor].[d|p].  e.g., 4.1d",
                        buildNumber, buildNumberFormat));
    }

    File basedir = FileUtils.getFile(workdir, product.toString(), license.toString(), buildNumber, buildDate);

    //add optional modules to the list of downloads
    List<License> licenses = new ArrayList<License>();
    licenses.add(license);
    if (license == POWER || license == ENTERPRISE) {
        if (includeAnalytics) {
            licenses.add(ANALYTICS_MODULE);
        }
        if (includeMessaging) {
            licenses.add(MESSAGING_MODULE);
        }
    }

    //collect the maven artifacts and send them along to the abstract method
    Set<Module> artifacts = collect(licenses, basedir);

    File bookmarkable = new File(basedir.getParent(), "latest");
    LOGGER.info("Copying distribution to '{}'", bookmarkable.getAbsolutePath());
    try {
        FileUtils.forceMkdir(bookmarkable);
        FileUtils.cleanDirectory(bookmarkable);
        FileUtils.copyDirectory(basedir, bookmarkable,
                FileFilterUtils.notFileFilter(FileFilterUtils.nameFileFilter("zip")));
    } catch (IOException e) {
        throw new MojoFailureException("Unable to copy distribution contents", e);
    }

    String[] executables = { "bat", "sh", "command" };
    Collection<File> scripts = FileUtils.listFiles(basedir, executables, true);
    scripts.addAll(FileUtils.listFiles(bookmarkable, executables, true));
    for (File script : scripts) {
        script.setExecutable(true);
        LOGGER.debug("Enabled execute permissions on file '{}'", script.getAbsolutePath());
    }
    doExecute(artifacts);

}

From source file:de.pksoftware.springstrap.fs.service.LocalFileSystemService.java

@Override
public void copyFolder(ItemVisibility visibility, FileSystemBucket bucket, IFileSystemPath srcPath,
        IFileSystemPath destPath, String[] excludeAntPattern)
        throws NotAFolderException, FSIOException, NoSuchFolderException {
    File srcFolder = getItem(visibility, bucket, srcPath);

    if (!srcFolder.exists()) {
        throw new NoSuchFolderException(bucket, srcPath);
    }//  w  ww  . j ava2 s .  c o m

    if (!srcFolder.isDirectory()) {
        throw new NotAFolderException(bucket, srcPath);
    }

    File destFolder = getItem(visibility, bucket, destPath);

    if (destFolder.exists() && !destFolder.isDirectory()) {
        throw new NotAFolderException(bucket, destPath);
    }

    try {
        FileUtils.copyDirectory(srcFolder, destFolder, new FileFilter() {

            @Override
            public boolean accept(File pathname) {
                for (String antPattern : excludeAntPattern) {
                    String absAntPattern = srcFolder.getAbsolutePath() + "/" + antPattern;

                    //logger.info("Testing {} against {}", absAntPattern, pathname.getAbsolutePath());

                    if (antPathMatcher.match(absAntPattern, pathname.getAbsolutePath())) {
                        return false;
                    }
                }

                return true;
            }

        });
    } catch (IOException e) {
        throw new FSIOException(bucket, srcPath, "copyFolder", e);
    }

}

From source file:eu.qualimaster.easy.extension.modelop.ModelModifier.java

/**
 * Creates a copy of the build model and place the files parallel to the copied variability model files.
 * @return The root folder of the copied model files.
 *///from w w  w. j  a  v  a  2  s .c  om
private File copyBuildModel() {
    File srcFolder = new File(baseLocation, "EASy");
    File vilFolder = new File(targetFolder, COPIED_MODELS_LOCATION);
    vilFolder.mkdirs();
    try {
        FileUtils.copyDirectory(srcFolder, vilFolder, new FileFilter() {

            @Override
            public boolean accept(File pathname) {
                String fileName = pathname.getName();
                return pathname.isDirectory() || fileName.endsWith("vil") || fileName.endsWith("vtl")
                        || fileName.endsWith("rtvtl");
            }
        });
    } catch (IOException e) {
        Bundle.getLogger(ModelModifier.class).exception(e);
    }
    return vilFolder;
}

From source file:com.ephesoft.gxt.foldermanager.server.FolderManagerServiceImpl.java

@Override
public List<String> copyFiles(List<String> copyFilesList, String currentFolderPath) throws UIException {
    List<String> resultList = new ArrayList<String>();
    for (String filePath : copyFilesList) {
        try {// ww  w.ja  v  a2s . c  om
            File srcFile = new File(filePath);
            if (srcFile.exists()) {
                String fileName = srcFile.getName();
                File copyFile = new File(currentFolderPath + File.separator + fileName);
                if (copyFile.exists()) {
                    if (copyFile.equals(srcFile)) {
                        int counter = 0;
                        while (copyFile.exists()) {
                            String newFileName;
                            if (counter == 0) {
                                newFileName = FolderManagementConstants.COPY + FolderManagementConstants.SPACE
                                        + FolderManagementConstants.OF + FolderManagementConstants.SPACE
                                        + fileName;
                            } else {
                                newFileName = FolderManagementConstants.COPY + FolderManagementConstants.SPACE
                                        + FolderManagementConstants.OPENING_BRACKET + counter
                                        + FolderManagementConstants.CLOSING_BRACKET
                                        + FolderManagementConstants.SPACE + FolderManagementConstants.OF
                                        + FolderManagementConstants.SPACE + fileName;
                            }
                            counter++;
                            copyFile = new File(currentFolderPath + File.separator + newFileName);
                        }
                    } else {
                        resultList.add(fileName);
                    }
                }
                if (srcFile.isFile()) {
                    FileUtils.copyFile(srcFile, copyFile, false);
                } else {
                    FileUtils.forceMkdir(copyFile);
                    FileUtils.copyDirectory(srcFile, copyFile, false);
                }
            } else {
                resultList.add(srcFile.getName());
            }
        } catch (IOException e) {
            throw new UIException(
                    FolderManagementMessages.EXCEPTION_OCCURRED_WHILE_COPY_PASTE_OPERATION_COULD_NOT_COMPLETE_OPERATION);
        }
    }
    return resultList;
}

From source file:com.bluexml.tools.miscellaneous.PrepareSIDEModulesMigration.java

protected static File copyDir(File workspaceFile, File srcDir) {

    File destDir0 = new File(workspaceFile, MIGRATION_FOLDER);
    File destDir = new File(destDir0, srcDir.getName());
    try {//ww w.j  a v a  2 s  .  c  o m
        FileUtils.copyDirectory(srcDir, destDir, new FileFilter() {

            public boolean accept(File pathname) {
                String name = pathname.getName();
                boolean equals = name.equals(".svn") || name.equals("target");

                return !equals;
            }
        });
        return destDir;
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}

From source file:edu.stolaf.cs.wmrserver.TransformProcessor.java

private void copyLibraryFiles(SubnodeConfiguration languageConf, File jobTransformDir) throws IOException {
    // Get the library directory, returning if not specified
    File libDir = getLibraryDirectory(languageConf);
    if (libDir == null)
        return;/*from www . j  ava  2  s.c o  m*/

    // Get the file extension appropriate for the language
    String scriptExtension = languageConf.getString("extension", "");
    if (!scriptExtension.isEmpty())
        scriptExtension = "." + scriptExtension;

    // Create a file filter to exclude prefix/suffix files
    String pattern = "^(mapper|reducer)-(prefix|suffix)" + Pattern.quote(scriptExtension) + "$";
    FileFilter libFilter = new NotFileFilter(new RegexFileFilter(pattern));

    // Copy filtered contents of library directory
    FileUtils.copyDirectory(libDir, jobTransformDir, libFilter);
}

From source file:com.taobao.android.builder.tools.solib.NativeSoUtils.java

/**
 * @param localNativeLibrariesDirectory/*from  ww  w  .j  a v a2 s  .c  o  m*/
 * @param destinationDirectory
 * @param supportAbis                   ??
 * @param removeSoFiles
 */
public static void copyLocalNativeLibraries(final File localNativeLibrariesDirectory,
        final File destinationDirectory, Set<String> supportAbis, Set<String> removeSoFiles) {
    sLogger.info("Copying existing native libraries from " + localNativeLibrariesDirectory + " to "
            + destinationDirectory);
    try {
        IOFileFilter filter = new NativeSoFilter(supportAbis, removeSoFiles);
        // ????????
        Collection<File> files = FileUtils.listFiles(localNativeLibrariesDirectory, filter,
                TrueFileFilter.TRUE);
        List<String> dumpFiles = new ArrayList<String>();
        for (File file : files) {
            String relativePath = getRelativePath(localNativeLibrariesDirectory, file);
            File destFile = new File(destinationDirectory, relativePath);
            if (destFile.exists()) {
                String orgFileMd5 = MD5Util.getFileMD5(file);
                String destFileMd5 = MD5Util.getFileMD5(destFile);
                if (!orgFileMd5.equals(destFileMd5)) {
                    dumpFiles.add(file.getAbsolutePath() + " to " + destFile.getAbsolutePath());
                }
            }
        }
        if (dumpFiles.size() > 0) {
            throw new RuntimeException(
                    "Copy native so error,duplicate file exist!:\n" + StringUtils.join(dumpFiles, "\n"));
        }
        FileUtils.copyDirectory(localNativeLibrariesDirectory, destinationDirectory, filter);
    } catch (IOException e) {
        throw new RuntimeException("Could not copy native dependency.", e);
    }
}