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:brooklyn.util.io.FileUtil.java

public static void copyDir(File srcDir, File destDir) throws IOException, InterruptedException {
    if (!Os.isMicrosoftWindows()) {
        String cmd = "cp -R '" + srcDir.getAbsolutePath() + "' '" + destDir.getAbsolutePath() + "'";
        Process proc = Runtime.getRuntime().exec(cmd);
        proc.waitFor();/*ww  w  .j  a v a  2  s . c om*/
        if (proc.exitValue() == 0)
            return;
    }

    FileUtils.copyDirectory(srcDir, destDir);
}

From source file:minecrunch_launcher.Client.java

public void run() {
    // Reading modpack profile XML file and getting profile parameters
    if (os.contains("Windows")) {
        minecraftDir = home + "\\AppData\\Roaming\\.minecraft\\";
        tempDir = home + "\\AppData\\temp\\";
        clientInstall = tempDir + "client_install\\";
        modinstallDir = home + "\\AppData\\Roaming\\.minecraft\\minecrunch\\";
    }/*from w ww .  j a  v  a  2  s  . c om*/

    if (os.contains("Linux")) {
        minecraftDir = home + "/.minecraft/";
        tempDir = home + "/temp/";
        clientInstall = tempDir + "client_install/";
        modinstallDir = home + "/.minecraft/minecrunch/";
    }

    if (os.contains("Mac")) {
        minecraftDir = home + "/Library/Application Support/minecraft/";
        tempDir = home + "/temp/";
        clientInstall = tempDir + "client_install/";
        modinstallDir = home + "/Library/Application Support/minecraft/minecrunch/";
    }

    try {
        Modprofile();
    } catch (ParserConfigurationException | SAXException | IOException | XPathExpressionException ex) {
        Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex);
    }

    // Install selected modpack
    wd.setVisible(true);
    System.out.println("Modpack picked: " + name);
    System.out.println("Gamename is: " + gamename);
    File dir = new File(tempDir);
    if (!dir.exists()) {
        if (dir.mkdir()) {
            String console = "Temporary directory created.";
            System.out.println(console);
        } else {
            String console = "Temporary directory already exists.";
            System.out.println(console);
        }
    }
    URL url = null;
    try {
        url = new URL("http://www.minecrunch.net/download/" + name + "/client_install.zip");
    } catch (MalformedURLException ex) {
        System.out.println(ex);
    }
    File file = new File(tempDir + "client_install.zip");
    try {
        FileUtils.copyURLToFile(url, file);
    } catch (IOException ex) {
        System.out.println(ex);
    }
    try {
        ZipFile zipFile = new ZipFile(tempDir + "client_install.zip");
        zipFile.extractAll(tempDir);
    } catch (ZipException e) {
    }
    file.delete();

    File newlib = new File(clientInstall + "libraries");
    File oldlib = new File(minecraftDir + "libraries");
    try {
        FileUtils.copyDirectory(newlib, oldlib);
        System.out.println("Copied libraries directory.");
        FileUtils.deleteDirectory(newlib);
        System.out.println("Deleted libraries directory.");
    } catch (IOException ex) {
        System.out.println(ex);
    }

    File newver = new File(clientInstall + "versions");
    File oldver = new File(minecraftDir + "versions");
    try {
        FileUtils.copyDirectory(newver, oldver);
        System.out.println("Copied version directory.");
        FileUtils.deleteDirectory(newver);
        System.out.println("Deleted version directory.");
    } catch (IOException ex) {
        System.out.println(ex);
    }

    File newmods = new File(clientInstall);
    File oldmods = new File(modinstallDir + name + "\\");
    try {
        FileUtils.copyDirectory(newmods, oldmods);
        System.out.println("Copied all other directories.");
    } catch (IOException ex) {
        System.out.println(ex);
    }

    try {
        // delete temporary directory
        FileUtils.deleteDirectory(dir);
    } catch (IOException ex) {
        System.out.println(ex);
    }

    // Setup profile
    String profile = gamename;
    String gamedir = modinstallDir + name;
    String filePath = minecraftDir + "launcher_profiles.json";
    JSONParser parser = new JSONParser();
    Object obj = null;
    try {
        obj = parser.parse(new FileReader(filePath));
    } catch (IOException | ParseException ex) {
    }
    JSONObject jsonObject = (JSONObject) obj;
    JSONObject profiles = (JSONObject) jsonObject.get("profiles");
    String selectedProfile = profile;
    String clientToken = (String) jsonObject.get("clientToken");
    JSONObject authenticationDatabase = (JSONObject) jsonObject.get("authenticationDatabase");
    JSONObject params = new JSONObject();
    params.put("name", profile);
    params.put("gameDir", gamedir);
    params.put("lastVersionId", version);
    params.put("javaArgs", java);
    profiles.put(profile, params);
    JSONObject update = new JSONObject();
    update.put("profiles", profiles);
    update.put("selectedProfile", selectedProfile);
    update.put("clientToken", clientToken);
    update.put("authenticationDatabase", authenticationDatabase);
    try (FileWriter newfile = new FileWriter(filePath)) {
        newfile.write(update.toJSONString());
        newfile.flush();
    } catch (IOException ex) {
        System.out.println(ex);
    }
    wd.setVisible(false);
}

From source file:com.planet57.gshell.internal.FileSystemAccessImpl.java

@Override
public void copyDirectory(final File source, final File target) throws IOException {
    checkNotNull(source);//from w  w w  . ja  v a  2  s . c om
    checkNotNull(target);
    log.debug("Copy directory: {} -> {}", source, target);
    FileUtils.copyDirectory(source, target);
}

From source file:bboss.org.artofsolving.jodconverter.office.OfficeProcess.java

private void prepareInstanceProfileDir() throws OfficeException {
    if (instanceProfileDir.exists()) {
        logger.warn(String.format("profile dir '%s' already exists; deleting", instanceProfileDir));
        deleteProfileDir();/*w  w  w . j a  va 2s  . co m*/
    }
    if (templateProfileDir != null) {
        try {
            FileUtils.copyDirectory(templateProfileDir, instanceProfileDir);
        } catch (IOException ioException) {
            throw new OfficeException("failed to create profileDir", ioException);
        }
    }
}

From source file:net.sourceforge.cobertura.test.ParentChildStaticFieldTest.java

@Test
public void parentChildStaticFieldShouldWorkAfterInstrumentalizationTest() throws Exception {
    /*/* ww w  .j  a  va  2  s  . c  o  m*/
     * Use a temporary directory and create a few sources files.
     */
    File tempDir = TestUtils.getTempDir();
    File srcDir = new File(tempDir, "src");
    File instrumentDir = new File(tempDir, "instrument");

    File mainSourceFile = new File(srcDir, "mypackage/ParentChildStaticField.java");
    File datafile = new File(srcDir, "cobertura.ser");
    mainSourceFile.getParentFile().mkdirs();

    byte[] encoded = Files.readAllBytes(Paths.get(
            "src/test/resources/examples/basic/src/com/example/simple/ParentChildStaticFieldExample.java"));

    FileUtils.write(mainSourceFile, new String(encoded, "utf8"));

    TestUtils.compileSource(ant, srcDir);

    TestUtils.instrumentClasses(ant, srcDir, datafile, instrumentDir);

    //moving instrumented classes so we don't have to change classpaths
    FileUtils.copyDirectory(instrumentDir, srcDir);

    /*
     * Kick off the Main (instrumented) class.
     */
    Java java = new Java();
    java.setProject(TestUtils.project);
    java.setClassname("mypackage.ParentChildStaticField");
    java.setDir(srcDir);
    java.setFork(true);
    java.setFailonerror(true);
    java.setClasspath(TestUtils.getCoberturaDefaultClasspath());
    java.execute();

}

From source file:com.ibm.util.merge.web.InitializeServlet.java

private void setup(String folder, ServletContext servletContext) {
    log.info("Setting up idmu folders");
    ArrayList<String> folders = new ArrayList<String>();
    folders.add("database");
    folders.add("logs");
    folders.add("output");
    folders.add("packages");
    folders.add("properties");
    folders.add("templates");
    folders.add("autoload");
    for (String aFolder : folders) {
        File theSource = new File(servletContext.getRealPath("/WEB-INF" + File.separator + aFolder));
        File theTarget = new File(folder + File.separator + aFolder);
        try {/*from   w  w  w  . j a  va 2  s.c  o m*/
            if (!theTarget.exists())
                theTarget.mkdirs();
            FileUtils.copyDirectory(theSource, theTarget);
            log.info("Copied files to " + theTarget.getAbsolutePath());
        } catch (IOException e) {
            throw new RuntimeException("SETUP ERROR! - Unable to copy files from " + theSource + " to "
                    + theTarget + ":" + e.getMessage());
        }
    }
}

From source file:com.photon.phresco.service.dependency.impl.DependencyUtils.java

public static void copyFilesTo(File[] files, File destPath) throws IOException {
    if (isDebugEnabled) {
        S_LOGGER.debug("Entering Method DependencyUtils.copyFilesTo(File[] files, File destPath)");
        S_LOGGER.error(" copyFilesTo() Destination Filepath =" + destPath.getPath());
    }//w w  w .  j a v  a  2 s . c  o  m
    if (files == null || destPath == null) {
        return; //nothing to copy
    }
    for (File file : files) {
        if (file.isDirectory()) {
            FileUtils.copyDirectory(file, destPath);
        } else {
            FileUtils.copyFileToDirectory(file, destPath);
        }
    }

}

From source file:com.o2d.pkayjava.editor.proxy.SceneDataManager.java

public void buildScenes(String targetPath) {
    ProjectManager projectManager = facade.retrieveProxy(ProjectManager.NAME);
    String srcPath = projectManager.getCurrentWorkingPath() + "/" + projectManager.currentProjectVO.projectName
            + "/scenes";
    FileHandle scenesDirectoryHandle = Gdx.files.absolute(srcPath);
    File fileTarget = new File(targetPath + "/" + scenesDirectoryHandle.name());
    try {/*from  ww  w.  j a v  a2s.  c  o m*/
        FileUtils.copyDirectory(scenesDirectoryHandle.file(), fileTarget);
    } catch (IOException e) {
        e.printStackTrace();
    }
    //copy project dt
    try {
        FileUtils.copyFile(
                new File(projectManager.getCurrentWorkingPath() + "/"
                        + projectManager.currentProjectVO.projectName + "/project.dt"),
                new File(targetPath + "/project.dt"));
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.qualinsight.mojo.cobertura.core.AbstractInstrumentationMojo.java

private void prepareDirectories(final File classesDirectory, final File backupClassesDirectory,
        final File baseDataFile) throws MojoExecutionException {
    getLog().debug("Preparing Cobertura instrumentation directories");
    try {//from  w  w w .j a va2  s . co m
        if (backupClassesDirectory.exists()) {
            FileUtils.forceDelete(backupClassesDirectory);
        }
        FileUtils.copyDirectory(classesDirectory, backupClassesDirectory);
        if (baseDataFile.exists() && !FileUtils.deleteQuietly(baseDataFile)) {
            final String message = "Could not delete baseDataFile: " + baseDataFile.getAbsolutePath();
            getLog().error(message);
            throw new MojoExecutionException(message);
        }
    } catch (final IOException e) {
        final String message = "An error occured during directories preparation:";
        getLog().error(message, e);
        throw new MojoExecutionException(message, e);
    }
}

From source file:com.twosigma.beakerx.kernel.magic.command.ClasspathAddMvnDepsCellMagicCommandTest.java

private static void prepareLocalMavenRepository() throws IOException {
    FileUtils.copyDirectory(new File(SRC_TEST_RESOURCES_TEST_MVN_CACHE), new File(BUILD_PATH));
    unzipRepo();//from   w  ww  .  j  a v a 2 s .c  o m
}