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, FileFilter filter) throws IOException 

Source Link

Document

Copies a filtered directory to a new location preserving the file dates.

Usage

From source file:com.appunity.ant.InitProjectTask.java

private void getSource(ProjectProfile.Project project) throws IOException {
    if (project.disk != null) {
        System.out.println("project.disk : " + project.disk);
        FileUtils.copyDirectory(new File(project.disk.url), new File(workDir, project.name),
                ProjectFileFilter.IgnoreVCSFile);
    } else if (project.git != null) {
        throw new UnsupportedOperationException(" GIT");
    } else if (project.hg != null) {
        throw new UnsupportedOperationException(" HG");
    } else if (project.svn != null) {
        System.out.println("project.svn : " + project.svn);
        SubversionHelper helper = new SubversionHelper();
        helper.execute(this, workDir, project);
    }// w w w  . j  a  v a 2s. c  o  m
}

From source file:mobac.program.EnvironmentSetup.java

/**
 * In case the <tt>mapsources</tt> directory has been moved by configuration (directories.ini or settings.xml) we
 * need to copy the existing map packs into the configured directory
 *///from w w w  .jav  a  2 s . c  om
public static void copyMapPacks() {
    File userMapSourcesDir = Settings.getInstance().getMapSourcesDirectory();
    File progMapSourcesDir = new File(DirectoryManager.programDir, "mapsources");
    if (userMapSourcesDir.equals(progMapSourcesDir))
        return; // no user specific directory configured
    if (userMapSourcesDir.isDirectory())
        return; // directory already exists - map packs should have been already copied
    try {
        Utilities.mkDirs(userMapSourcesDir);
        FileUtils.copyDirectory(progMapSourcesDir, userMapSourcesDir, new FileExtFilter(".jar"));
    } catch (IOException e) {
        log.error(e);
        JOptionPane.showMessageDialog(null, "Error on initializing mapsources directory:\n" + e.getMessage(),
                "Error", JOptionPane.ERROR_MESSAGE);
        System.exit(1);
    }
}

From source file:kr.co.leem.system.FileSystemUtils.java

/**
 *  ./*w  ww. j av a2 s  .  co  m*/
 *
 * @param srcDir ?  .
 * @param destDir   .
 * @param preserveFileDate  .
 * @see FileUtils#copyDirectory(File, File, boolean)
 */
public static void copyDirectory(final String srcDir, final String destDir, final boolean preserveFileDate) {
    processIO(new IOCallback<Object>() {
        public Object doInProcessIO() throws IOException, NullPointerException {
            FileUtils.copyDirectory(new File(srcDir), new File(destDir), preserveFileDate);
            return null;
        }
    });
}

From source file:com.funambol.server.config.ConfigurationTest.java

@Override
protected void setUp() throws Exception {
    File initialPlugin = new File(funambolHome,
            "com/funambol/server/config/Configuration/plugin/initial-plugins");

    FileUtils.forceMkdir(runtimePluginDir);
    FileUtils.cleanDirectory(runtimePluginDir);
    FileUtils.copyDirectory(initialPlugin, runtimePluginDir, new WildcardFileFilter("*.xml"));

    //// w w  w  .ja va2 s .  c o  m
    // This is required since if the plugin xml files used in the tests are 
    // downloaded from SVN repository, they have the same timestamp so the changes
    // are not correctly detected by the DirectoryMonitor. In this way we are sure
    // the timestamp is different (touch uses the current timestamp and of course the
    // files - in src/test/data/com/funambol/server/config/Configuration/pluging/test-1 -
    // are downloaded previously)
    //
    File[] files = runtimePluginDir.listFiles();
    for (File file : files) {
        FileUtils.touch(file);
    }

    Configuration.getConfiguration();
}

From source file:com.github.blindpirate.gogradle.util.IOUtils.java

public static void copyDependencies(final File srcDir, final File destDir, final Set<String> subpackages) {
    try {/*from  w w w.java 2s  .  c o m*/
        Assert.isTrue(dirIsEmpty(destDir));
        DependencyInstallFileFilter filter = DependencyInstallFileFilter.subpackagesFilter(srcDir, subpackages);
        FileUtils.copyDirectory(srcDir, destDir, filter);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}

From source file:de.renew.workflow.connector.internal.cases.ScenarioCompatibilityHelper.java

public static boolean ensureBackwardsCompatibility(final ScenarioHandlingProjectNature nature) {
    // FIXME: this is dirty fix only for this release 2.3
    // should be implemented in other way, we just do not have any time now
    try {//  w ww.j av  a  2 s. c  o m
        if (nature == null
                || !nature.getProject().hasNature("org.kalypso.kalypso1d2d.pjt.Kalypso1D2DProjectNature")) //$NON-NLS-1$
            return true;

        // FIXME: the whole code here does not belong to this place -> this is a hidden dependency to 1d2d: bad!
        // TODO: instead implement an extension point mechanism
        final ProjectTemplate[] lTemplate = EclipsePlatformContributionsExtensions
                .getProjectTemplates("org.kalypso.kalypso1d2d.pjt.projectTemplate"); //$NON-NLS-1$
        try {
            // FIXME: this very probably does not work correctly or any more at all!

            /* Unpack project from template */
            final File destinationDir = nature.getProject().getLocation().toFile();
            final URL data = lTemplate[0].getData();
            final String location = data.toString();
            final String extension = FilenameUtils.getExtension(location);
            if ("zip".equalsIgnoreCase(extension)) //$NON-NLS-1$
            {
                // TODO: this completely overwrite the old project content, is this intended?
                ZipUtilities.unzip(data.openStream(), destinationDir, false);
            } else {
                final URL fileURL = FileLocator.toFileURL(data);
                final File dataDir = FileUtils.toFile(fileURL);
                if (dataDir == null) {
                    return false;
                }

                // FIXME: this only fixes the basic scenario, is this intended?

                final IOFileFilter lFileFilter = new WildcardFileFilter(new String[] { "wind.gml" }); //$NON-NLS-1$
                final IOFileFilter lDirFilter = TrueFileFilter.INSTANCE;
                final Collection<?> windFiles = FileUtils.listFiles(destinationDir, lFileFilter, lDirFilter);

                if (dataDir.isDirectory() && (windFiles == null || windFiles.size() == 0)) {
                    final WildcardFileFilter lCopyFilter = new WildcardFileFilter(
                            new String[] { "*asis", "models", "wind.gml" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                    FileUtils.copyDirectory(dataDir, destinationDir, lCopyFilter);
                } else {
                    return true;
                }
            }
        } catch (final Throwable t) {
            t.printStackTrace();
            return false;
        }

        nature.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
    } catch (final CoreException e) {
        // FIXME: this is no error handling; the users are not informed and will stumble over following errors caued by
        // this problem

        WorkflowConnectorPlugin.getDefault().getLog().log(e.getStatus());
        e.printStackTrace();
        return false;
    }

    return true;
}

From source file:com.jayway.maven.plugins.android.phase09package.Apklib2Mojo.java

protected File createPrecompiledApkLibraryFile() throws MojoExecutionException {
    final File apklibrary = new File(project.getBuild().getDirectory(),
            project.getBuild().getFinalName() + "." + APKLIB_PRECOMPILED);

    final File apklibRoot = new File(project.getBuild().getDirectory(), APKLIB_PRECOMPILED + "-dir");
    final File apklibBin = new File(apklibRoot, "bin");
    final File apklibRes = new File(apklibBin, "res");

    FileUtils.deleteQuietly(apklibrary);
    FileUtils.deleteQuietly(apklibRoot);

    try {/*w w  w .  j av  a 2 s  .c o m*/

        if (!apklibRoot.exists()) {
            boolean mkdir = apklibRoot.mkdirs();
            if (!mkdir) {
                throw new MojoExecutionException(
                        "Can't create " + apklibRoot.getAbsolutePath() + " directory.");
            }
        }

        FileUtils.copyDirectory(resourceDirectory, apklibRes, NOT_PNG);

        crunchResources(resourceDirectory, apklibRes);
        createClassesJar(apklibBin);
        File buildXml = createFakeBuildXml(apklibRoot);
        File projProps = createPropertiesFile(apklibRoot);

        ZipArchiver zipArchiver = new ZipArchiver();
        zipArchiver.setDestFile(apklibrary);

        zipArchiver.addFile(androidManifestFile, "AndroidManifest.xml");
        addDirectory(zipArchiver, assetsDirectory, "assets");
        addDirectory(zipArchiver, apklibBin, "bin");
        zipArchiver.addFile(projProps, "project.properties");
        zipArchiver.addFile(buildXml, "build.xml");

        // Lastly, add any native libraries
        addNativeLibraries(zipArchiver);

        zipArchiver.createArchive();
    } catch (ArchiverException e) {
        throw new MojoExecutionException("ArchiverException while creating ." + APKLIB_PRECOMPILED + " file.",
                e);
    } catch (IOException e) {
        throw new MojoExecutionException("IOException while creating ." + APKLIB_PRECOMPILED + " file.", e);
    }

    return apklibrary;
}

From source file:es.uvigo.ei.sing.gc.model.entities.User.java

public void changeEmail(String email) throws IOException, NullPointerException, IllegalStateException {
    if (email == null)
        throw new NullPointerException("email");
    if (this.isGuest())
        throw new IllegalStateException("guest users email can not be changed");

    // If it is a directory change.
    if (this.email != null) {
        FileUtils.copyDirectory(this.getUserDirectory(), User.getUserDirectory(email), true);
    }/*from   w w w.jav a  2s.c o m*/

    this.email = email;
}

From source file:com.funambol.server.cleanup.ClientLogCleanUpAgentTest.java

@Override
protected void setUp() throws Exception {
    super.setUp();

    agent = new ClientLogCleanUpAgent(clientsLogDir, targetArchivationDirectory, activationThreshold,
            maxNumberOfArchivedFiles, numberOfArchivedFilesToDelete, timeToRest, lockName);

    try {//from   ww  w .j a  va2s  .  c  om
        FileUtils.forceMkdir(new File(TARGET_DIR));
        FileUtils.cleanDirectory(new File(TARGET_DIR));
        FileUtils.copyDirectory(new File(BASE_DIR), new File(TARGET_DIR),
                new NotFileFilter(new SuffixFileFilter(".svn")));
    } catch (IOException e) {
        assertTrue("Unable to handle target dir", true);
    }
}

From source file:com.serena.rlc.provider.filesystem.client.FilesystemClient.java

public void localCopy(String srcFolderPath, String destFolderPath, boolean preserveDates)
        throws FilesystemClientException {
    File source = new File(srcFolderPath);
    File destination = new File(destFolderPath);

    try {/*from w  w  w.ja v  a  2 s.co  m*/
        if (!source.exists()) {
            throw new FilesystemClientException("Source directory " + srcFolderPath + " does not exist");
        }

        if (!destination.exists()) {
            logger.debug("Target directory " + destFolderPath + " does not exist, but it will be created...");
        }

        FileUtils.copyDirectory(source, destination, preserveDates);

    } catch (IOException e) {
        logger.debug(e.getLocalizedMessage());
        throw new FilesystemClientException(e.getLocalizedMessage());
    }

}