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.hangum.tadpole.engine.initialize.TadpoleSystemInitializer.java

/**
 * initialize jdbc driver/*  w  w  w.  j  a v a  2 s . com*/
 */
private static void initJDBCDriver() {
    final String strJDBCDir = ApplicationArgumentUtils.JDBC_RESOURCE_DIR;
    File jdbcLocationDir = new File(strJDBCDir);
    logger.info("######### TDB JDBC Driver local Path : " + strJDBCDir);
    if (!jdbcLocationDir.exists()) {
        logger.info("\t##### Copying initialize JDBC Driver........");
        try {
            jdbcLocationDir.mkdirs();

            File fileEngine = FileLocator.getBundleFile(TadpoleEngineActivator.getDefault().getBundle());
            String filePath = fileEngine.getAbsolutePath() + "/libs/driver";
            logger.info("##### TDB JDBC URI: " + filePath);

            FileUtils.copyDirectory(new File(filePath), new File(strJDBCDir));
        } catch (Exception e) {
            logger.error("Initialize JDBC driver file", e);
        }
    }

    // driver loading
    try {
        JDBCDriverLoader.addJARDir(strJDBCDir);
    } catch (Exception e) {
        logger.error("JDBC driver loading", e);
    }
}

From source file:com.uwsoft.editor.proxy.SceneDataManager.java

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

From source file:com.osbitools.ws.shared.prj.utils.BasicTextDemoFileUtils.java

/**
 * Copy all demo maps into physical directory
 * //from   w  w  w  .jav a 2  s. c o  m
 * @param base Top root directory to copy files
 * @param dir Sub-directory from top resource tree 
 * @throws IOException
 * @throws URISyntaxException
 */
@Override
public void copyDemoProj(String dest, String dir) throws IOException {
    String sdir = Utils.isEmpty(dir) ? "" : File.separator + dir;
    FileUtils.copyDirectory(new File(getProjSrcDir() + sdir), new File(dest + sdir));
}

From source file:de.uzk.hki.da.model.WorkArea.java

/**
 * Copies a SIP to the ingest area/*from   ww w. jav  a  2  s.  c o  m*/
 * @param makeFile
 * @throws IOException 
 */
public void ingestSIP(File sip) throws IOException {
    if (!sip.exists())
        throw new IllegalArgumentException("Missing file: " + sip);
    if (sip.isFile())
        FileUtils.copyFile(sip, sipFile());
    else
        FileUtils.copyDirectory(sip, sipFile());
}

From source file:energy.usef.environment.tool.util.FileUtil.java

public static void copyFolder(String fromFolder, String toFolder) throws IOException {
    if (!isFolderExists(fromFolder)) {
        LOGGER.error("Folder {} can not be found and therefor can not be copied to {}.", fromFolder, toFolder);
        throw new RuntimeException("Folder " + fromFolder
                + " can not be found and therefor can not be copied to " + toFolder + ".");
    }//from   ww  w . j  a  va  2  s.  co m

    LOGGER.info("Copy folder from {} to {}.", fromFolder, toFolder);
    File src = new File(fromFolder);
    File dest = new File(toFolder);
    FileUtils.copyDirectory(src, dest);
}

From source file:com.github.hadoop.maven.plugin.PackMojo.java

/**
 * Create the hadoop deploy artifacts//from w w  w  . j  ava  2  s  .  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);
    File rootDir = new File(outputDirectory.getAbsolutePath() + File.separator + "root");
    FileUtils.forceMkdir(rootDir);

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

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

From source file:com.badlogicgames.packr.Packr.java

public void pack(Config config) throws IOException {
    // create output dir
    File out = new File(config.outDir);
    File target = out;/* w  w  w .j  a  v a 2  s .co  m*/
    if (out.exists()) {
        if (new File(".").equals(out)) {
            System.out.println("Output directory equals working directory, aborting");
            System.exit(-1);
        }

        System.out.println("Output directory '" + out.getAbsolutePath() + "' exists, deleting");
        FileUtils.deleteDirectory(out);
    }
    out.mkdirs();

    Map<String, String> values = new HashMap<String, String>();
    values.put("${executable}", config.executable);
    values.put("${bundleIdentifier}", "com.yourcompany.identifier"); // FIXME add as a param

    // if this is a mac build, let's create the app bundle structure
    if (config.platform == Platform.mac) {
        new File(out, "Contents").mkdirs();
        FileUtils.writeStringToFile(new File(out, "Contents/Info.plist"),
                readResourceAsString("/Info.plist", values));
        target = new File(out, "Contents/MacOS");
        target.mkdirs();
        new File(out, "Contents/Resources").mkdirs();
        // FIXME copy icons
    }

    // write jar, exe and config to target folder
    byte[] exe = null;
    String extension = "";
    switch (config.platform) {
    case windows:
        exe = readResource("/packr-windows.exe");
        extension = ".exe";
        break;
    case linux32:
        exe = readResource("/packr-linux");
        break;
    case linux64:
        exe = readResource("/packr-linux-x64");
        break;
    case mac:
        exe = readResource("/packr-mac");
        break;
    }
    FileUtils.writeByteArrayToFile(new File(target, config.executable + extension), exe);
    new File(target, config.executable + extension).setExecutable(true);
    FileUtils.copyFile(new File(config.jar), new File(target, new File(config.jar).getName()));
    writeConfig(config, new File(target, "config.json"));

    // add JRE from local or remote zip file
    File jdkFile = null;
    if (config.jdk.startsWith("http://") || config.jdk.startsWith("https://")) {
        System.out.println("Downloading JDK from '" + config.jdk + "'");
        jdkFile = new File(target, "jdk.zip");
        InputStream in = new URL(config.jdk).openStream();
        OutputStream outJdk = FileUtils.openOutputStream(jdkFile);
        IOUtils.copy(in, outJdk);
        in.close();
        outJdk.close();
    } else {
        jdkFile = new File(config.jdk);
    }
    File tmp = new File(target, "tmp");
    tmp.mkdirs();
    System.out.println("Unpacking JRE");
    ZipUtil.unpack(jdkFile, tmp);
    File jre = searchJre(tmp);
    if (jre == null) {
        System.out.println("Couldn't find JRE in JDK, see '" + tmp.getAbsolutePath() + "'");
        System.exit(-1);
    }
    FileUtils.copyDirectory(jre, new File(target, "jre"));
    FileUtils.deleteDirectory(tmp);
    if (config.jdk.startsWith("http://") || config.jdk.startsWith("https://")) {
        jdkFile.delete();
    }

    // copy resources
    System.out.println("copying resources");
    copyResources(target, config.resources);

    // perform tree shaking      
    if (config.minimizeJre != null) {
        minimizeJre(config, target);
    }

    System.out.println("Done!");
}

From source file:com.thoughtworks.go.config.GoRepoConfigDataSourceIntegrationTest.java

private String setupExternalConfigRepo(File configRepo, String configRepoTestResource) throws IOException {
    ClassPathResource resource = new ClassPathResource(configRepoTestResource);
    FileUtils.copyDirectory(resource.getFile(), configRepo);
    CommandLine.createCommandLine("git").withEncoding("utf-8").withArg("init")
            .withArg(configRepo.getAbsolutePath()).runOrBomb(null);
    CommandLine.createCommandLine("git").withEncoding("utf-8").withArgs("config", "commit.gpgSign", "false")
            .withWorkingDir(configRepo.getAbsoluteFile()).runOrBomb(null);
    gitAddDotAndCommit(configRepo);/*from ww  w  .j a v  a 2  s  .co m*/
    ConsoleResult consoleResult = CommandLine.createCommandLine("git").withEncoding("utf-8").withArg("log")
            .withArg("-1").withArg("--pretty=format:%h").withWorkingDir(configRepo).runOrBomb(null);

    return consoleResult.outputAsString();
}

From source file:com.photon.maven.plugins.android.AbstractAndroidMojoTestCase.java

/**
 * Copy the project specified into a temporary testing directory. Create the {@link MavenProject} and
 * {@link ManifestUpdateMojo}, configure it from the <code>plugin-config.xml</code> and return the created Mojo.
 * <p>//w  ww.jav a2 s  .c o  m
 * Note: only configuration entries supplied in the plugin-config.xml are presently configured in the mojo returned.
 * That means and 'default-value' settings are not automatically injected by this testing framework (or plexus
 * underneath that is suppling this functionality)
 * 
 * @param resourceProject
 *            the name of the goal to look for in the <code>plugin-config.xml</code> that the configuration will be
 *            pulled from.
 * @param resourceProject
 *            the resourceProject path (in src/test/resources) to find the example/test project.
 * @return the created mojo (unexecuted)
 * @throws Exception
 *             if there was a problem creating the mojo.
 */
protected T createMojo(String resourceProject) throws Exception {
    // Establish test details project example
    String testResourcePath = "src/test/resources/" + resourceProject;
    testResourcePath = FilenameUtils.separatorsToSystem(testResourcePath);
    File exampleDir = new File(getBasedir(), testResourcePath);
    Assert.assertTrue("Path should exist: " + exampleDir, exampleDir.exists());

    // Establish the temporary testing directory.
    String testingPath = "target/tests/" + this.getClass().getSimpleName() + "." + getName();
    testingPath = FilenameUtils.separatorsToSystem(testingPath);
    File testingDir = new File(getBasedir(), testingPath);

    if (testingDir.exists()) {
        FileUtils.cleanDirectory(testingDir);
    } else {
        Assert.assertTrue("Could not create directory: " + testingDir, testingDir.mkdirs());
    }

    // Copy project example into temporary testing directory
    // to avoid messing up the good source copy, as mojo can change
    // the AndroidManifest.xml file.
    FileUtils.copyDirectory(exampleDir, testingDir);

    // Prepare MavenProject
    final MavenProject project = new MojoProjectStub(testingDir);

    // Setup Mojo
    PlexusConfiguration config = extractPluginConfiguration("android-maven-plugin", project.getFile());
    @SuppressWarnings("unchecked")
    final T mojo = (T) lookupMojo(getPluginGoalName(), project.getFile());

    // Inject project itself
    setVariableValueToObject(mojo, "project", project);

    // Configure the rest of the pieces via the PluginParameterExpressionEvaluator
    //  - used for ${plugin.*}
    MojoDescriptor mojoDesc = new MojoDescriptor();
    // - used for error messages in PluginParameterExpressionEvaluator
    mojoDesc.setGoal(getPluginGoalName());
    MojoExecution mojoExec = new MojoExecution(mojoDesc);
    // - Only needed if we start to use expressions like ${settings.*}, ${localRepository}, ${reactorProjects}
    // MavenSession context = null; // Messy to declare, would rather avoid using it.
    // - Used for ${basedir} relative paths
    PathTranslator pathTranslator = new DefaultPathTranslator();
    // - Declared to prevent NPE from logging events in maven core
    Logger logger = new ConsoleLogger(Logger.LEVEL_DEBUG, mojo.getClass().getName());

    MavenSession context = createMock(MavenSession.class);

    expect(context.getExecutionProperties()).andReturn(project.getProperties());
    expect(context.getCurrentProject()).andReturn(project);
    replay(context);

    // Declare evalator that maven itself uses.
    ExpressionEvaluator evaluator = new PluginParameterExpressionEvaluator(context, mojoExec, pathTranslator,
            logger, project, project.getProperties());
    // Lookup plexus configuration component
    ComponentConfigurator configurator = (ComponentConfigurator) lookup(ComponentConfigurator.ROLE, "basic");
    // Configure mojo using above
    ConfigurationListener listener = new DebugConfigurationListener(logger);
    configurator.configureComponent(mojo, config, evaluator, getContainer().getContainerRealm(), listener);

    return mojo;
}

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

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

    celosClient.getWorkflowStatus(new WorkflowID("noid"));
}