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:Implement.Service.AdminServiceImpl.java

@Override
public boolean approveTemporaryPackage(int packageID) throws Exception {
    DateTime now = new DateTime();
    String startDateStr = now.toString("MM/dd/yyyy");
    int newPackageID = packageDAO.approveTemporaryPackage(packageID, startDateStr);
    //Insert create image folder
    String path = System.getProperty("catalina.base");
    File folderPackage = new File(path + "/webapps/Images/TemporaryPackages/" + packageID);
    if (!folderPackage.exists()) {
        folderPackage.mkdirs();//from  w  ww . j av  a 2 s  .c  om
    }

    //Copy image to new folder
    File sourceImageFolder = new File(path + "/webapps/Images/PrimaryPackages/" + newPackageID);
    if (!sourceImageFolder.exists()) {
        sourceImageFolder.mkdirs();
    }

    FileUtils.copyDirectory(folderPackage, sourceImageFolder);
    folderPackage.delete();
    //Update database
    for (final File fileEntry : sourceImageFolder.listFiles()) {
        String fileName = fileEntry.getName();
        String fileExtension = fileName.substring(fileName.lastIndexOf(".") + 1);
        if (fileName.contains("cover")) {
            packageDAO.updateCoverAfterApprove(newPackageID,
                    "/Images/PrimaryPackages/" + newPackageID + "/cover." + fileExtension);
        } else {
            packageDAO.updateAdditionalAfterApprove(newPackageID, "%" + fileName + "%",
                    "/Images/PrimaryPackages/" + newPackageID + "/" + fileName);
        }
    }
    return true;
}

From source file:net.continuumsecurity.runner.StoryRunner.java

private void copyResultsToStampedReportsDir() throws IOException {
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy.MM.dd-HH.mm.ss", Locale.getDefault());
    File dirName = new File(REPORTS_DIR + File.separator + formatter.format(new Date()));
    FileUtils.forceMkdir(dirName);//w  w  w.  ja  v a2s .c  o  m
    FileUtils.copyDirectory(new File(LATEST_REPORTS), dirName);
}

From source file:com.kylinolap.job.engine.GenericJobEngineTest.java

@BeforeClass
public static void beforeClass() throws Exception {

    FileUtils.forceMkdir(new File("/tmp/kylin/logs/"));

    FileUtils.deleteDirectory(new File(tempTestMetadataUrl));
    FileUtils.copyDirectory(new File("../examples/test_case_data"), new File(tempTestMetadataUrl));
    System.setProperty(KylinConfig.KYLIN_CONF, tempTestMetadataUrl);

    // deploy files to hdfs
    SSHClient hadoopCli = new SSHClient(getHadoopCliHostname(), getHadoopCliUsername(), getHadoopCliPassword(),
            null);/*from ww  w  .j  ava2s  .co m*/
    scpFilesToHdfs(hadoopCli, new String[] { "src/test/resources/json/dummy_jobinstance.json" }, mrInputDir);
    // deploy sample java jar
    hadoopCli.scpFileToRemote("src/test/resources/jarfile/SampleJavaProgram.jarfile", "/tmp");
    hadoopCli.scpFileToRemote("src/test/resources/jarfile/SampleBadJavaProgram.jarfile", "/tmp");

    // create log dir
    hadoopCli.execCommand("mkdir -p /tmp/kylin/logs/");
    KylinConfig kylinConfig = KylinConfig.getInstanceFromEnv();
    kylinConfig.setMetadataUrl(tempTestMetadataUrl);

    jobManager = new JobManager("GenericJobEngineTest", new JobEngineConfig(KylinConfig.getInstanceFromEnv()));

    jobDAO = JobDAO.getInstance(KylinConfig.getInstanceFromEnv());

    jobDAO.updateJobInstance(createARunningJobInstance("a_running_job"));

    jobManager.startJobEngine(2);
    Thread.sleep(2000);
}

From source file:com.googlecode.t7mp.steps.deployment.ResolveTomcatStep.java

private void copyToTomcatDirectory(File unpackDirectory) throws IOException {
    File[] files = unpackDirectory.listFiles(new FileFilter() {
        @Override//from  w ww . j a  v  a 2 s.c om
        public boolean accept(File file) {
            return file.isDirectory();
        }
    });
    // should only be one
    FileUtils.copyDirectory(files[0], this.mojo.getCatalinaBase());
}

From source file:azkaban.execapp.FlowRunnerTestUtil.java

/**
 * Initialize the project with the flow definitions stored in the given source directory. Also
 * copy the source directory to the working directory.
 *
 * @param project project to initialize//from  w w w . j ava 2s .  c  o  m
 * @param sourceDir the source dir
 * @param workingDir the working dir
 * @return the flow name to flow map
 * @throws ProjectManagerException the project manager exception
 * @throws IOException the io exception
 */
public static Map<String, Flow> prepareProject(final Project project, final File sourceDir,
        final File workingDir) throws ProjectManagerException, IOException {
    final FlowLoaderFactory loaderFactory = new FlowLoaderFactory(new Props(null));
    final FlowLoader loader = loaderFactory.createFlowLoader(sourceDir);

    loader.loadProjectFlow(project, sourceDir);
    if (!loader.getErrors().isEmpty()) {
        for (final String error : loader.getErrors()) {
            System.out.println(error);
        }
        throw new RuntimeException(String.format(
                "Errors found in loading flows into a project ( %s ). From the directory: ( %s ).",
                project.getName(), sourceDir));
    }

    final Map<String, Flow> flowMap = loader.getFlowMap();
    project.setFlows(flowMap);
    FileUtils.copyDirectory(sourceDir, workingDir);
    return flowMap;
}

From source file:de.egore911.versioning.deployer.performer.PerformCheckout.java

private static void performSvn(String target, String url) {
    String tmp = target + File.separatorChar + "checkout";
    try {//w  w w.  j a v  a  2s. c  o m
        File tmpDir = new File(tmp);
        SVNURL svnurl = SVNURL.parseURIEncoded(url);
        SvnOperationFactory svnOperationFactory = new SvnOperationFactory();
        try {
            SvnCheckout checkout = svnOperationFactory.createCheckout();
            checkout.setSingleTarget(SvnTarget.fromFile(tmpDir));
            checkout.setSource(SvnTarget.fromURL(svnurl));
            checkout.run();
        } finally {
            svnOperationFactory.dispose();
        }
        FileUtils.copyDirectory(tmpDir, new File(target));
        FileUtils.deleteDirectory(tmpDir);
    } catch (SVNException | IOException e) {
        LOG.error(e.getMessage(), e);
    }
}

From source file:com.liferay.maven.plugins.ThemeMergeMojo.java

protected void doExecute() throws Exception {
    if (!workDir.exists()) {
        workDir.mkdirs();/*from  w  ww.  j  a v a  2s  .c  o m*/
    }

    String parentThemeGroupId = "liferay.portal";
    String parentThemeArtifactId = "portal-web";
    String parentThemeVersion = liferayVersion;

    String[] excludes = { "html/themes/classic/_diffs/**", "html/themes/control_panel/_diffs/**" };

    String[] includes = { "html/themes/_unstyled/**", "html/themes/_styled/**", "html/themes/classic/**",
            "html/themes/control_panel/**" };

    if (!parentTheme.equals("_styled") && !parentTheme.equals("_unstyled") && !parentTheme.equals("classic")
            && !parentTheme.equals("control_panel")) {

        String[] parentThemeArray = parentTheme.split(":");

        parentThemeGroupId = parentThemeArray[0];
        parentThemeArtifactId = parentThemeArray[1];
        parentThemeVersion = parentThemeArray[2];

        excludes = new String[] { "WEB-INF/**" };

        includes = null;
    }

    Artifact artifact = artifactFactory.createArtifact(parentThemeGroupId, parentThemeArtifactId,
            parentThemeVersion, "", "war");

    artifactResolver.resolve(artifact, remoteArtifactRepositories, localArtifactRepository);

    UnArchiver unArchiver = archiverManager.getUnArchiver(artifact.getFile());

    unArchiver.setDestDirectory(workDir);
    unArchiver.setSourceFile(artifact.getFile());

    IncludeExcludeFileSelector includeExcludeFileSelector = new IncludeExcludeFileSelector();

    includeExcludeFileSelector.setExcludes(excludes);
    includeExcludeFileSelector.setIncludes(includes);

    unArchiver.setFileSelectors(new FileSelector[] { includeExcludeFileSelector });

    unArchiver.extract();

    webappDirectory.mkdirs();

    if (parentThemeArtifactId.equals("portal-web")) {
        FileUtils.copyDirectory(new File(workDir, "html/themes/_unstyled"), webappDirectory);

        getLog().info("Copying html/themes/_unstyled to " + webappDirectory);

        if (!"_unstyled".equals(parentTheme)) {
            FileUtils.copyDirectory(new File(workDir, "html/themes/_styled"), webappDirectory);

            getLog().info("Copying html/themes/_styled to " + webappDirectory);
        }

        if (!"_unstyled".equals(parentTheme) && !"_styled".equals(parentTheme)) {

            FileUtils.copyDirectory(new File(workDir, "html/themes/" + parentTheme), webappDirectory);

            getLog().info("Copying html/themes/" + parentTheme + " to " + webappDirectory);
        }
    } else {
        FileUtils.copyDirectory(workDir, webappDirectory);
    }

    File initFile = new File(webappDirectory, "templates/init." + themeType);

    FileUtils.deleteQuietly(initFile);

    File templatesDirectory = new File(webappDirectory, "templates/");

    String[] extensions = null;

    if (themeType.equals("ftl")) {
        extensions = new String[] { "vm" };
    } else {
        extensions = new String[] { "ftl" };
    }

    Iterator<File> itr = FileUtils.iterateFiles(templatesDirectory, extensions, false);

    while (itr.hasNext()) {
        File file = itr.next();

        FileUtils.deleteQuietly(file);
    }
}

From source file:com.github.ithildir.liferay.mobile.go.GoSDKBuilder.java

protected void copyResource(String name, String destination) throws IOException {

    File destinationDir = new File(destination);

    destinationDir = new File(destinationDir.getAbsoluteFile(), CharPool.SLASH + name);

    URL sourceURL = getClass().getResource(CharPool.SLASH + name);
    URLConnection sourceConnection = sourceURL.openConnection();

    if (sourceConnection instanceof JarURLConnection) {
        copyJarResource((JarURLConnection) sourceConnection, destinationDir);
    } else {/*from w  ww .  j  av a  2s .com*/
        File sourceDir = new File(sourceURL.getPath());

        FileUtils.copyDirectory(sourceDir, destinationDir);
    }

    Iterator<File> itr = FileUtils.iterateFiles(destinationDir, new String[] { "copy" }, true);

    while (itr.hasNext()) {
        File file = itr.next();

        String cleanPath = FilenameUtils.removeExtension(file.getAbsolutePath());

        File cleanFile = new File(cleanPath);

        if (!cleanFile.exists()) {
            FileUtils.moveFile(file, new File(cleanPath));
        } else {
            file.delete();
        }
    }
}

From source file:ch.cyberduck.core.preferences.SecurityApplicationGroupSupportDirectoryFinder.java

@Override
public Local find() {
    final NSFileManager manager = NSFileManager.defaultManager();
    if (manager.respondsToSelector(Foundation.selector("containerURLForSecurityApplicationGroupIdentifier:"))) {
        final NSURL group = manager.containerURLForSecurityApplicationGroupIdentifier(identifier);
        if (null == group) {
            log.warn("Missing com.apple.security.application-groups in sandbox entitlements");
        } else {//from   ww  w .  j a v a2 s.c  o m
            // You should organize the contents of this directory in the same way that any other Library folder is organized
            final String application = PreferencesFactory.get().getProperty("application.container.name");
            final Local folder = LocalFactory.get(String.format("%s/Library/Application Support", group.path()),
                    application);
            try {
                // In previous versions of OS X, although the group container directory is part of your sandbox,
                // the directory itself is not created automatically.
                if (!folder.exists()) {
                    log.info(String.format("Create shared security application group folder %s", folder));
                    folder.mkdir();
                }
                log.info(String.format(
                        "Shared security application group folder %s is empty. Attempt to migrate support directory.",
                        folder));
                final Local previous = new ApplicationSupportDirectoryFinder().find();
                if (previous.exists()) {
                    log.warn(String.format("Migrate application support folder from %s to %s", previous,
                            folder));
                    // Rename folder recursively
                    try {
                        FileUtils.copyDirectory(new File(previous.getAbsolute()),
                                new File(folder.getAbsolute()));
                        log.warn(String.format("Move application support folder %s to Trash", previous));
                        try {
                            final Trash trash = LocalTrashFactory.get();
                            trash.trash(previous);
                            final Symlink symlink = LocalSymlinkFactory.get();
                            symlink.symlink(previous, folder.getAbsolute());
                        } catch (LocalAccessDeniedException e) {
                            log.warn(String.format(
                                    "Failure cleaning up previous application support directory. %s",
                                    e.getMessage()));
                        }
                    } catch (IOException e) {
                        log.warn(String.format(
                                "Failure migrating %s to security application group directory %s. %s", previous,
                                folder, e.getMessage()));
                    }
                } else {
                    log.debug(String.format("No previous application support folder found in %s", previous));
                }
                return folder;
            } catch (AccessDeniedException e) {
                log.warn(String.format("Failure creating security application group directory. %s",
                        e.getMessage()));
            }
        }
    }
    log.warn("Missing support for security application groups. Default to application support directory");
    // Fallback for 10.7 and earlier
    return new ApplicationSupportDirectoryFinder().find();
}

From source file:com.liferay.mobile.sdk.windows.WindowsSDKBuilder.java

protected void copyResource(String name, String destination) throws IOException {

    File destinationDir = new File(destination);

    destinationDir = destinationDir.getAbsoluteFile();

    URL sourceURL = getClass().getResource(CharPool.SLASH + name);
    URLConnection sourceConnection = sourceURL.openConnection();

    if (sourceConnection instanceof JarURLConnection) {
        copyJarResource((JarURLConnection) sourceConnection, destinationDir);
    } else {/*from  w ww  . ja  v  a  2 s .com*/
        File sourceDir = new File(sourceURL.getPath());

        FileUtils.copyDirectory(sourceDir, destinationDir);
    }

    Iterator<File> itr = FileUtils.iterateFiles(destinationDir, new String[] { "copy" }, true);

    while (itr.hasNext()) {
        File file = itr.next();

        String cleanPath = FilenameUtils.removeExtension(file.getAbsolutePath());

        File cleanFile = new File(cleanPath);

        if (!cleanFile.exists()) {
            FileUtils.moveFile(file, new File(cleanPath));
        } else {
            file.delete();
        }
    }
}