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.github.hadoop.maven.plugin.pack.PackMojo.java

/**
 * Create the hadoop deploy artifacts//from  ww w.  ja  v  a 2s.  co m
 * 
 * @throws IOException
 * @return File that contains the root of jar file to be packed.
 * @throws InvalidDependencyVersionException
 * @throws ArtifactNotFoundException
 * @throws ArtifactResolutionException
 */
private File createHadoopDeployArtifacts() throws IOException {
    FileUtils.deleteDirectory(outputDirectory);
    final File rootDir = new File(outputDirectory.getAbsolutePath() + File.separator + "root");
    FileUtils.forceMkdir(rootDir);

    final File jarlibdir = new File(rootDir.getAbsolutePath() + File.separator + "lib");
    FileUtils.forceMkdir(jarlibdir);

    final File classesdir = new File(project.getBuild().getDirectory() + File.separator + "classes");
    FileUtils.copyDirectory(classesdir, rootDir);
    final Set<Artifact> filteredArtifacts = this.filterArtifacts(this.artifacts);
    getLog().info("");
    getLog().info("Dependencies of this project independent of hadoop classpath " + filteredArtifacts);
    getLog().info("");
    for (final Artifact artifact : filteredArtifacts) {
        FileUtils.copyFileToDirectory(artifact.getFile(), jarlibdir);
    }
    return rootDir;
}

From source file:com.collective.celos.CelosClientServerTest.java

@Test
public void testGetWorkflowStatusWaiting() throws Exception {
    File src = new File(Thread.currentThread().getContextClassLoader()
            .getResource("com/collective/celos/client/wf-list").toURI());
    FileUtils.copyDirectory(src, workflowsDir);

    List<SlotState> slotStates = celosClient.getWorkflowStatus(new WorkflowID("workflow-2")).getSlotStates();
    Assert.assertEquals(slotStates.size(), SLOTS_IN_CELOS_SERVER_SLIDING_WINDOW);

    for (SlotState slotState : slotStates) {
        Assert.assertEquals(slotState.getStatus(), SlotState.Status.WAITING);
        Assert.assertEquals(slotState.getExternalID(), null);
        Assert.assertEquals(slotState.getRetryCount(), 0);
    }//from   w  ww .  jav  a  2 s. co m
}

From source file:com.blurengine.blur.modules.maploading.MapLoaderModule.java

public WorldBlurSession createSessionFromDirectory(File file) throws MapLoadException {
    String worldName = GENERATED_WORLD_DIRECTORY_PREFIX + file.getName();

    File worldDir = new File(Bukkit.getWorldContainer(), worldName);
    try {//from   w w w .  j a  v a 2s .co m
        FileUtils.copyDirectory(file, worldDir);
    } catch (IOException e) {
        throw new MapLoadException("Failed to duplicate " + file.getPath(), e);
    }

    World world = WorldCreator.name(worldDir.getName()).createWorld();

    // Load map config
    YamlDataSource yaml;
    try {
        File mapFile = new File(worldDir, MAP_FILE_NAME);
        if (!mapFile.exists()) {
            throw new MapLoadException(MAP_FILE_NAME + " is missing in " + file.toString());
        }
        yaml = SerializationUtils.yaml(mapFile).build();
    } catch (IOException e) {
        throw new MapLoadException("Failed to read " + MAP_FILE_NAME, e);
    }
    BlurConfig config = new BlurConfig();
    SerializationUtils.loadOrCreateProperties(getLogger(), yaml, config);

    // Create and load map config
    WorldBlurSession newSession = getSession().addChildSession(new WorldBlurSession(getSession(), world));
    sessions.add(newSession);
    newSession.setName(file.getName());
    newSession.getModuleManager().getModuleLoader().load(config.getModules());
    return newSession;
}

From source file:com.amazonaws.eclipse.android.sdk.newproject.NewAndroidProjectWizard.java

@Override
@SuppressWarnings("restriction")
public boolean performFinish() {
    if (getContainer() instanceof WizardDialog) {
        setRunnableContext((WizardDialog) getContainer());
    }//  ww w  .j  a  v  a2s  .co  m

    try {
        NewProjectWizardState newProjectWizardState = new NewProjectWizardState(Mode.ANY);
        newProjectWizardState.projectName = dataModel.getProjectName();
        newProjectWizardState.applicationName = "AWS Android Application";
        newProjectWizardState.packageName = dataModel.getPackageName();
        newProjectWizardState.target = dataModel.getAndroidTarget();
        newProjectWizardState.createActivity = false;

        new NewProjectCreator(newProjectWizardState, runnableContext).createAndroidProjects();
        IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(dataModel.getProjectName());

        IJavaProject javaProject = JavaCore.create(project);
        AndroidSdkInstall awsAndroidSdk = AndroidSdkManager.getInstance().getDefaultSdkInstall();
        awsAndroidSdk.writeMetadataToProject(javaProject);
        AwsAndroidSdkClasspathUtils.addAwsAndroidSdkToProjectClasspath(javaProject, awsAndroidSdk);

        AndroidManifestFile androidManifestFile = new AndroidManifestFile(project);
        androidManifestFile.initialize();
        copyProguardPropertiesFile(project);

        if (dataModel.isSampleCodeIncluded()) {
            // copy sample code files over
            Bundle bundle = Platform.getBundle(AndroidSDKPlugin.PLUGIN_ID);
            URL url = FileLocator.find(bundle, new Path("resources/S3_Uploader/"), null);
            try {
                File sourceFile = new File(FileLocator.resolve(url).toURI());
                File projectFolder = project.getLocation().toFile();
                File projectSourceFolder = new File(projectFolder, "src");

                for (File file : sourceFile.listFiles()) {
                    File destinationFile = new File(project.getLocation().toFile(), file.getName());
                    if (file.isDirectory())
                        FileUtils.copyDirectory(file, destinationFile);
                    else
                        FileUtils.copyFile(file, destinationFile);
                }

                // move *.java files to new src dir
                String s = dataModel.getPackageName().replace(".", File.separator) + File.separator;
                for (File file : projectSourceFolder.listFiles()) {
                    if (file.isDirectory())
                        continue;
                    File destinationFile = new File(projectSourceFolder, s + file.getName());
                    FileUtils.moveFile(file, destinationFile);

                    // update package lines with regex
                    // replace "com.amazonaws.demo.s3uploader" with dataModel.getPackageName()
                    List<String> lines = FileUtils.readLines(destinationFile);
                    ArrayList<String> outLines = new ArrayList<String>();
                    for (String line : lines) {
                        outLines.add(line.replace("com.amazonaws.demo.s3uploader", dataModel.getPackageName()));
                    }
                    FileUtils.writeLines(destinationFile, outLines);
                }

                // update android manifest file
                androidManifestFile.addSampleActivity();
            } catch (Exception e) {
                IStatus status = new Status(IStatus.ERROR, AndroidSDKPlugin.PLUGIN_ID,
                        "Unable to update AWS SDK with sample app for Android project setup", e);
                StatusManager.getManager().handle(status, StatusManager.SHOW | StatusManager.LOG);
            }
        }

        // refresh the workspace to pick up the changes we just made
        project.refreshLocal(IResource.DEPTH_INFINITE, null);
    } catch (Exception e) {
        IStatus status = new Status(IStatus.ERROR, AndroidSDKPlugin.PLUGIN_ID,
                "Unable to create new AWS Android project", e);
        StatusManager.getManager().handle(status, StatusManager.SHOW | StatusManager.LOG);
        return false;
    }

    return true;
}

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

/**
 * //from  www  .  java  2  s  .co  m
 * @param templateProject
 */
@SuppressWarnings("unchecked")
public static void createRooApplication(final File ecoreProject, final File busProject,
        final File templateProject) {
    File imbProject;
    File editProject;
    String pluginContent;
    String pomContent;
    String tomcatConfiguration;
    Collection<File> pluginFiles;

    try {
        editProject = new File(ecoreProject.getParent(), ecoreProject.getName() + ".edit");
        imbProject = new File(editProject, "/imb/");
        FileUtils.deleteDirectory(imbProject);

        // Create the roo application
        FileUtils.copyFile(new File(templateProject, "/templates/install.roo"),
                new File(imbProject, "install.roo"));
        EcoreImbEditor.executeCommand("roo script --file install.roo", imbProject);

        // Update libraries
        pomContent = FileUtils.readFileToString(new File(imbProject, "pom.xml"));
        pomContent = pomContent.replaceFirst("</dependencies>",
                FileUtils.readFileToString(new File(templateProject, "/templates/pom.xml")));
        FileUtils.writeStringToFile(new File(imbProject, "pom.xml"), pomContent);

        // IMB types configuration
        FileUtils.copyDirectory(new File(busProject, "/src/main/java/imb"),
                new File(imbProject, "/src/main/java/imb"));
        FileUtils.copyFile(new File(busProject, "/src/main/resources/schema.xsd"),
                new File(imbProject, "/src/main/resources/schema.xsd"));

        FileUtils.copyFile(
                new File(busProject,
                        "/src/main/resources/META-INF/spring/applicationContext-contentresolver.xml"),
                new File(imbProject,
                        "/src/main/resources/META-INF/spring/applicationContext-contentresolver.xml"));

        // Update the plugin configuration
        pluginFiles = FileUtils.listFiles(new File(editProject, "/src"), new IOFileFilter() {
            @Override
            public boolean accept(File file) {
                return (file.getName().endsWith("Plugin.java"));
            }

            @Override
            public boolean accept(File dir, String file) {
                return (file.endsWith("Plugin.java"));
            }
        }, TrueFileFilter.INSTANCE);
        for (File plugin : pluginFiles) {
            pluginContent = FileUtils.readFileToString(plugin);
            pluginContent = pluginContent.substring(0,
                    pluginContent.indexOf("public static class Implementation extends EclipsePlugin"));

            // Tomcat configuration
            tomcatConfiguration = FileUtils
                    .readFileToString(new File(templateProject, "/templates/Plugin.txt"));
            tomcatConfiguration = tomcatConfiguration.replace("${imbProject}", imbProject.getPath());

            FileUtils.writeStringToFile(plugin, pluginContent + tomcatConfiguration);
            break;
        }

    } catch (Exception e) {
        e.printStackTrace();
        System.out.println("Error while configuring Roo application: " + e.getMessage());
    }
}

From source file:com.ibm.liberty.starter.service.test.api.v1.ProviderEndpoint.java

@GET
@Path("packages/prepare")
public String prepareDynamicPackages(@QueryParam("path") String techWorkspaceDir,
        @QueryParam("options") String options, @QueryParam("techs") String techs) throws IOException {
    if (techWorkspaceDir != null && !techWorkspaceDir.trim().isEmpty()) {
        FileUtils.deleteQuietly(new File(techWorkspaceDir + "/package"));

        File techWorkspace = new File(techWorkspaceDir);
        if (techs != null && options != null && !options.trim().isEmpty()) {
            String[] techOptions = options.split(",");
            String testOptionOne = techOptions.length >= 1 ? techOptions[0] : null;

            if ("testoption1".equals(testOptionOne) && techs.contains("test")) {
                String packageTargetDirPath = techWorkspaceDir + "/package";
                File packageTargetDir = new File(packageTargetDirPath);
                FileUtils.copyDirectory(techWorkspace, packageTargetDir);
                return "success";
            }/*from  ww  w  .j a v  a  2s .c o  m*/
        }
    }
    return "failure";
}

From source file:com.talis.entity.db.babudb.bulk.BabuDbEntityDatabaseBuilder.java

private void copyIndexFiles(File source, File target, String indexName) throws IOException {
    FileUtils.copyDirectory(source, new File(target, indexName));
}

From source file:com.photon.phresco.framework.win8.util.Win8MetroCofigFileParser.java

private static void copyLibFolder(ApplicationInfo info, File path) throws IOException {
    File srcDir = new File(path + File.separator + info.getName());
    if (srcDir.exists()) {
        File destDir = new File(path + File.separator + HELLOWORLD);
        FileUtils.copyDirectory(srcDir, destDir);
        FileUtils.deleteDirectory(srcDir);
    }/* w  w w .j ava 2s  .co m*/
}

From source file:com.sonar.it.scanner.msbuild.TestUtils.java

public static Path projectDir(TemporaryFolder temp, String projectName) throws IOException {
    Path projectDir = Paths.get("projects").resolve(projectName);
    FileUtils.deleteDirectory(new File(temp.getRoot(), projectName));
    Path tmpProjectDir = temp.newFolder(projectName).toPath();
    FileUtils.copyDirectory(projectDir.toFile(), tmpProjectDir.toFile());
    return tmpProjectDir;
}

From source file:com.mindquarry.desktop.workspace.conflict.DeleteWithModificationConflict.java

public void beforeUpdate() throws ClientException, IOException {
    // NOTE: here we could implement a fast-path avoiding the download
    // of the new files by simply deleting the folder on the server
    // before we run the update
    // if (action == Action.DELETE) {
    // nothing to do here, we have to wait for the update and delete
    // the folder again (svn will recreate it due to the remote mods)
    // }/*from   ww w .  java2 s.  c o  m*/

    if (action == Action.REVERTDELETE) {
        if (localDelete) {
            // revert local delete
            log.info("beforeUpdate (localDelete), reverting " + status.getPath());
            client.revert(status.getPath(), true);
        } else {
            // make a local copy of the file/dir
            File source = new File(status.getPath());

            // temp file prefix is required to be at least 3 chars long, so add another prefix:
            String tmpPrefix = TEMP_FILE_PREFIX + source.getName();
            if (source.isFile()) {
                tempCopy = File.createTempFile(tmpPrefix, null, source.getParentFile());
                FileUtils.copyFile(source, tempCopy);
            } else {
                tempCopy = createTempDir(tmpPrefix, null, source.getParentFile());
                FileUtils.copyDirectory(source, tempCopy);
            }

            // remove .svn directories from copy (if there are any)
            removeDotSVNDirectories(tempCopy.getPath());

            // revert all local changes to file/dir
            log.info("beforeUpdate, reverting " + status.getPath());
            client.revert(status.getPath(), true);

            // TODO: really delete folder before svn copy
            // We will do a svn copy of an old version into this folder
            // after the update. To do this, the folder must not exist
            // anymore locally, and should not be seen as 'missing'.
            // Otherwise svn is forced to overwrite some existing, versioned
            // folder, which fails with errors like:
            // - 'Revision 1 doesn't match existing revision 2'
            //     if the folder is removed ('missing')
            // - 'path refers to directory or read access is denied'
            //     if the folder exists, but is 'unversioned'

            // it has to be in normal state, so that during the update it
            // gets deleted through the remote changes - the deletion will
            // then be reverted through the svn copy from the last version
            // before the deletion

            // TODO: this is wrong, only delete unversioned files
            // Delete complete file/dir as the update operation will leave
            // unversioned copies of files that were locally modified.
            FileUtils.forceDelete(source);
        }
    }
}