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:com.docdoku.server.storage.filesystem.FileStorageProvider.java

public void copySubResources(BinaryResource source, BinaryResource destination) throws StorageException {
    File subResourceFolder = getSubResourceFolder(source);
    if (subResourceFolder.exists()) {
        try {//from   ww  w.j  av  a2 s . c  o  m
            FileUtils.copyDirectory(subResourceFolder, getSubResourceFolder(destination));
        } catch (IOException e) {
            LOGGER.log(Level.WARNING, null, e);
            throw new StorageException("Can't copy subResourceFolder from " + source.getFullName() + " to "
                    + destination.getFullName(), e);
        }
    }
}

From source file:com.alibaba.jstorm.daemon.supervisor.SyncSupervisorEvent.java

private void downloadLocalStormCode(Map conf, String topologyId, String masterCodeDir)
        throws IOException, TException {

    // STORM-LOCAL-DIR/supervisor/stormdist/storm-id
    String stormroot = StormConfig.supervisor_stormdist_root(conf, topologyId);

    FileUtils.copyDirectory(new File(masterCodeDir), new File(stormroot));

    ClassLoader classloader = Thread.currentThread().getContextClassLoader();

    String resourcesJar = resourcesJar();

    URL url = classloader.getResource(StormConfig.RESOURCES_SUBDIR);

    String targetDir = stormroot + '/' + StormConfig.RESOURCES_SUBDIR;

    if (resourcesJar != null) {

        LOG.info("Extracting resources from jar at " + resourcesJar + " to " + targetDir);

        JStormUtils.extract_dir_from_jar(resourcesJar, StormConfig.RESOURCES_SUBDIR, stormroot);// extract dir
        // from jar;;
        // util.clj
    } else if (url != null) {

        LOG.info("Copying resources at " + url.toString() + " to " + targetDir);

        FileUtils.copyDirectory(new File(url.getFile()), (new File(targetDir)));

    }// ww  w  .  j  a  v a2  s  . co  m
}

From source file:fr.paris.lutece.plugins.updater.service.UpdateService.java

/**
 * Deploy a plugin (downloaded => deploy)
 * @param strPluginName The plugin name/*from  ww  w . j  ava2  s  .  co m*/
 * @param strVersion The update version
 */
@Override
public void deployPlugin(String strPluginName, String strVersion) {
    AppLogService.info("deploy plugin : " + strPluginName);

    try {
        // Copy the webapp folder
        File fileSource = new File(AppPathService.getWebAppPath() + PATH_DOWNLOADED + strPluginName + "/"
                + strVersion + FOLDER_WEBAPP);
        File fileDest = new File(PluginManagerService.getInstance().getDeployWebappPath(strPluginName));

        if (fileDest.exists()) {
            FileUtils.deleteDirectory(fileDest);
        }

        FileUtils.copyDirectory(fileSource, fileDest);

        // Copy the SQL folder
        fileSource = new File(AppPathService.getWebAppPath() + PATH_DOWNLOADED + strPluginName + "/"
                + strVersion + FOLDER_SQL);
        fileDest = new File(PluginManagerService.getInstance().getDeploySqlPath(strPluginName));

        if (fileDest.exists()) {
            FileUtils.deleteDirectory(fileDest);
        }

        FileUtils.copyDirectory(fileSource, fileDest);
    } catch (IOException ex) {
        AppLogService.error("error deploying plugin : ", ex);
    }
}

From source file:com.aspose.email.examples.outlook.pst.SplitAndMergePSTFile.java

public static void deleteAndRecopySampleFiles(String destFolder, String srcFolder) {

    try {/*  w  ww  . ja va2s.  c o  m*/
        deleteAllFilesInDirectory(new File(destFolder));
        File source = new File(srcFolder);
        File dest = new File(destFolder);
        FileUtils.copyDirectory(source, dest);
    } catch (IOException e) {
        System.out.println(e.getLocalizedMessage());
    }
}

From source file:com.qq.tars.maven.gensrc.TarsBuildMojo.java

public void execute() throws MojoExecutionException, MojoFailureException {
    getLog().info("Start run build...");
    try {// ww  w . j  a va  2  s .c o m
        if (platformName == null) {
            String osName = System.getProperty("os.name");
            if (osName.toLowerCase().contains(Platform.WINDOWS_NAME)) {
                platformName = Platform.WINDOWS_NAME;
            } else {
                platformName = Platform.UNIX_NAME;
            }
        }

        File targetDir = new File(project.getBuild().getDirectory());
        File tarsDir = new File(targetDir, "tars");
        if (tarsDir.exists()) {
            FileUtils.forceDelete(tarsDir);
        }
        tarsDir.mkdir();

        File binDir = new File(tarsDir, "bin");
        binDir.mkdir();

        File confDir = new File(tarsDir, "conf");
        confDir.mkdir();

        File dataDir = new File(tarsDir, "data");
        dataDir.mkdir();

        File binAppsDir = new File(binDir, "apps" + File.separator + "ROOT");
        binAppsDir.mkdir();
        FileUtils.copyDirectory(war, binAppsDir);

        File binConfDir = new File(binDir, "conf");
        binConfDir.mkdir();

        File binLogDir = new File(binDir, "log");
        binLogDir.mkdir();

        File libDir = new File(binDir, "lib");
        libDir.mkdir();

        String app = getApp();
        String server = getServer();

        if (app == null || server == null) {
            throw new MojoExecutionException("Failed to build app server is null.");
        }

        String configFileName = String.format("%s.%s.%s", app, server, "config.conf");
        File configFile = new File(confDir, configFileName);
        getLog().info(String.format("Create config file %s ", configFile.getCanonicalPath()));
        createConfigScript(binDir, dataDir, binLogDir, configFile);

        installLibDependency(libDir);

        getLog().info(String.format("Create platform %s start script...", platformName));
        Platform platform = Platform.getInstance(platformName);
        String binscript = createBinScript(platform, libDir, binDir, configFile);
        getLog().info("Start Script in " + binscript);
    } catch (Exception e) {
        getLog().error(e);
        throw new MojoExecutionException("Failed to tars build", e);
    }
}

From source file:it.greenvulcano.util.file.FileManager.java

/**
 * Copy the file/directory to a new one.<br>
 * The filePattern may be a regular expression: in this case, all the filenames
 * matching the pattern will be copied to the target directory.<br>
 * If a file, whose name matches the <code>filePattern</code> pattern, already
 * exists in the same target directory, it will be overwritten.<br>
 *
 * @param sourcePath/*from w w w  .  j  a  v a2  s  .  c  om*/
 *            Absolute pathname of the source file/directory.
 * @param targetPath
 *            Absolute pathname of the target file/directory.
 * @param filePattern
 *            A regular expression defining the name of the files to be copied. Used only if
 *            srcPath identify a directory. Null or "" disable file filtering.
 * @throws Exception
 */
public static void cp(String sourcePath, String targetPath, String filePattern) throws Exception {
    File src = new File(sourcePath);
    if (!src.isAbsolute()) {
        throw new IllegalArgumentException("The pathname of the source file is NOT absolute: " + sourcePath);
    }
    File target = new File(targetPath);
    if (!target.isAbsolute()) {
        throw new IllegalArgumentException("The pathname of the target file is NOT absolute: " + targetPath);
    }

    if (src.isDirectory()) {
        if ((filePattern == null) || filePattern.equals("") || filePattern.equals(".*")) {
            logger.debug(
                    "Copying directory " + src.getAbsolutePath() + " to directory " + target.getAbsolutePath());
            FileUtils.copyDirectory(src, new File(targetPath));
        } else {
            Set<FileProperties> files = ls(sourcePath, filePattern);
            for (FileProperties file : files) {
                logger.debug("Copying file " + file.getName() + " from directory " + src.getAbsolutePath()
                        + " to directory " + target.getAbsolutePath());
                if (file.isDirectory()) {
                    FileUtils.copyDirectoryToDirectory(new File(src, file.getName()), target);
                } else {
                    FileUtils.copyFileToDirectory(new File(src, file.getName()), target);
                }
            }
        }
    } else {
        if (target.isDirectory()) {
            logger.debug("Copying file " + src.getAbsolutePath() + " to directory " + target.getAbsolutePath());
            FileUtils.copyFileToDirectory(src, target);
        } else {
            logger.debug("Copying file " + src.getAbsolutePath() + " to " + target.getAbsolutePath());
            FileUtils.copyFile(src, target);
        }
    }
}

From source file:mx.itesm.imb.EcoreImbEditor.java

/**
 * //from   w w w  .  j  ava  2s.  c om
 * @param ecoreProject
 * @param busProject
 * @param templateProject
 */
@SuppressWarnings("unchecked")
public static void configureRestTemplate(final File ecoreProject, final File busProject,
        final File templateProject) {
    File manifestFile;
    String configuration;
    String exportPackage;
    String bundleActivator;
    String templateContent;
    String oxmConfiguration;

    try {
        // Copy lib
        FileUtils.copyDirectory(new File(templateProject, "/lib.rest"),
                new File(ecoreProject.getParent(), ecoreProject.getName() + ".edit/lib"));
        FileUtils.copyDirectory(new File(templateProject, "/lib.rest"),
                new File(ecoreProject.getParent(), ecoreProject.getName() + ".editor/lib"));
        FileUtils.copyDirectory(new File(templateProject, "/lib.jdom"),
                new File(ecoreProject.getParent(), ecoreProject.getName() + ".editor/lib"));

        // Add rest configuration
        templateContent = FileUtils.readFileToString(new File(templateProject, "/templates/beans.xml"));
        configuration = FileUtils.readFileToString(new File(busProject,
                "/src/main/resources/META-INF/spring/applicationContext-contentresolver.xml"));
        oxmConfiguration = configuration.substring(configuration.indexOf("<oxm:"),
                configuration.indexOf("</oxm:jaxb2-marshaller>") + "</oxm:jaxb2-marshaller>".length());
        templateContent = templateContent.replace("<!-- oxm -->", oxmConfiguration);
        FileUtils.writeStringToFile(
                new File(ecoreProject.getParent(), ecoreProject.getName() + ".edit/beans.xml"),
                templateContent);
        FileUtils.writeStringToFile(
                new File(ecoreProject.getParent(), ecoreProject.getName() + ".editor/beans.xml"),
                templateContent);

        // Copy imb types
        FileUtils.copyDirectory(new File(busProject, "/src/main/java/imb"),
                new File(ecoreProject.getParent(), ecoreProject.getName() + ".edit/src/imb"));
        FileUtils.copyDirectory(new File(busProject, "/src/main/java/imb"),
                new File(ecoreProject.getParent(), ecoreProject.getName() + ".editor/src/imb"));

        // Update classpath
        FileUtils.copyFile(new File(templateProject, "templates/classpath.xml"),
                new File(ecoreProject.getParent(), ecoreProject.getName() + ".edit/.classpath"));
        FileUtils.copyFile(new File(templateProject, "templates/classpath.editor.xml"),
                new File(ecoreProject.getParent(), ecoreProject.getName() + ".editor/.classpath"));
        templateContent = FileUtils.readFileToString(new File(templateProject, "/templates/project.xml"));
        FileUtils.writeStringToFile(
                new File(ecoreProject.getParent(), ecoreProject.getName() + ".edit/.project"),
                templateContent.replace("${projectName}", ecoreProject.getName()));
        FileUtils.writeStringToFile(
                new File(ecoreProject.getParent(), ecoreProject.getName() + ".editor/.project"),
                templateContent.replace("${projectName}", ecoreProject.getName()));

        // Update Manifest
        bundleActivator = null;
        exportPackage = null;

        // edit project
        manifestFile = new File(ecoreProject.getParent(),
                ecoreProject.getName() + ".edit/META-INF/MANIFEST.MF");
        for (String line : (List<String>) FileUtils.readLines(manifestFile)) {
            if (line.startsWith("Bundle-Activator")) {
                bundleActivator = line.replace("Bundle-Activator: ", "");
            } else if (line.startsWith("Export-Package: ")) {
                exportPackage = line.replace("Export-Package: ", "");
            }
        }
        templateContent = FileUtils.readFileToString(new File(templateProject, "/templates/manifest.MF"));
        templateContent = templateContent.replaceAll("\\$\\{projectName\\}", ecoreProject.getName());
        templateContent = templateContent.replace("${bundleActivator}", bundleActivator);
        templateContent = templateContent.replace("${exportPackage}", exportPackage);
        FileUtils.writeStringToFile(manifestFile, templateContent);

        // editor project
        manifestFile = new File(ecoreProject.getParent(),
                ecoreProject.getName() + ".editor/META-INF/MANIFEST.MF");
        for (String line : (List<String>) FileUtils.readLines(manifestFile)) {
            if (line.startsWith("Bundle-Activator")) {
                bundleActivator = line.replace("Bundle-Activator: ", "");
            } else if (line.startsWith("Export-Package: ")) {
                exportPackage = line.replace("Export-Package: ", "");
            }
        }
        templateContent = FileUtils
                .readFileToString(new File(templateProject, "/templates/manifest.editor.MF"));
        templateContent = templateContent.replaceAll("\\$\\{projectName\\}", ecoreProject.getName());
        templateContent = templateContent.replace("${bundleActivator}", bundleActivator);
        templateContent = templateContent.replace("${exportPackage}", exportPackage);
        FileUtils.writeStringToFile(manifestFile, templateContent);

    } catch (Exception e) {
        System.out.println("Error while configuring Rest template: " + e.getMessage());
    }
}

From source file:it.analysis.IssuesModeTest.java

@Test
public void only_scan_changed_files_on_change() throws IOException {
    restoreProfile("one-issue-per-line.xml");
    orchestrator.getServer().provisionProject("sample", "xoo-sample");
    orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "one-issue-per-line");

    SonarScanner runner = configureRunner("shared/xoo-sample", "sonar.verbose", "true");
    BuildResult result = orchestrator.executeBuild(runner);

    // change QP//from   w ww  . ja va2s  .com
    restoreProfile("with-many-rules.xml");
    orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "with-many-rules");

    // now change file hash in a temporary location
    File tmpProjectDir = temp.newFolder();
    FileUtils.copyDirectory(ItUtils.projectDir("shared/xoo-sample"), tmpProjectDir);
    File srcFile = new File(tmpProjectDir, "src/main/xoo/sample/Sample.xoo");
    FileUtils.write(srcFile, "\n", StandardCharsets.UTF_8, true);

    // scan again, with different QP
    runner = SonarScanner.create(tmpProjectDir, "sonar.working.directory", temp.newFolder().getAbsolutePath(),
            "sonar.analysis.mode", "issues", "sonar.report.export.path", "sonar-report.json", "sonar.userHome",
            temp.newFolder().getAbsolutePath(), "sonar.verbose", "true", "sonar.scanChangedFilesOnly", "true");
    result = orchestrator.executeBuild(runner);
    assertThat(result.getLogs()).contains("Scanning only changed files");
    assertThat(result.getLogs())
            .doesNotContain("'One Issue Per Line' skipped because there is no related file in current project");
    ItUtils.assertIssuesInJsonReport(result, 3, 0, 17);
}

From source file:im.bci.gamesitekit.GameSiteKitMain.java

private void copyMedias() throws IOException {
    Path mediaOutputDir = outputDir.resolve("media");
    FileUtils.copyDirectory(templateDir.resolve("media").toFile(), mediaOutputDir.toFile());
    FileUtils.copyDirectory(inputDir.resolve("media").toFile(), mediaOutputDir.toFile());
}

From source file:com.liferay.ide.project.core.tests.ProjectCoreBase.java

protected SDK createNewSDK() throws Exception {
    final IPath newSDKLocation = new Path(getLiferayPluginsSdkDir().toString() + "-new");

    if (!newSDKLocation.toFile().exists()) {
        FileUtils.copyDirectory(getLiferayPluginsSdkDir().toFile(), newSDKLocation.toFile());
    }/*from www .  j  av a 2s. com*/

    assertEquals(true, newSDKLocation.toFile().exists());

    SDK newSDK = SDKUtil.createSDKFromLocation(newSDKLocation);

    if (newSDK == null) {
        FileUtils.copyDirectory(getLiferayPluginsSdkDir().toFile(), newSDKLocation.toFile());
        newSDK = SDKUtil.createSDKFromLocation(newSDKLocation);
    }

    SDKManager.getInstance().addSDK(newSDK);

    return newSDK;
}