Example usage for org.apache.commons.io FileUtils copyFileToDirectory

List of usage examples for org.apache.commons.io FileUtils copyFileToDirectory

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils copyFileToDirectory.

Prototype

public static void copyFileToDirectory(File srcFile, File destDir) throws IOException 

Source Link

Document

Copies a file to a directory preserving the file date.

Usage

From source file:com.virtualparadigm.packman.processor.JPackageManager.java

private static void archivePackage(Package installPackage, File packageManagerDataDir) {
    // create "archive" dir if it doesnt exist
    // create package archive dir (<package name>_v_<package version>)
    // copy contents of package metadata, autorun and patch file to archive dir
    try {/* w  w  w. ja  v a 2s .co m*/
        File archiveDir = new File(packageManagerDataDir.getAbsolutePath() + "/" + ARCHIVE_DIR_NAME);
        File archivePackageDir = new File(archiveDir.getAbsolutePath() + "/" + installPackage.getName() + "_v_"
                + installPackage.getVersion());
        //            if(!archivePackageDir.exists())
        //            {
        //                archivePackageDir.mkdirs();
        //            }

        File archivePackageInstallDir = new File(
                archivePackageDir.getAbsolutePath() + "/" + JPackageManager.INSTALL_DIR_NAME);
        if (!archivePackageInstallDir.exists()) {
            archivePackageInstallDir.mkdirs();
        }

        File archivePackageUninstallDir = new File(
                archivePackageDir.getAbsolutePath() + "/" + JPackageManager.UNINSTALL_DIR_NAME);
        if (!archivePackageUninstallDir.exists()) {
            archivePackageUninstallDir.mkdirs();
        }

        // metadata archive dir
        FileUtils.copyDirectory(
                new File(packageManagerDataDir.getAbsolutePath() + "/" + TEMP_INSTALL_DIR_NAME + "/"
                        + JPackageManager.METADATA_DIR_NAME),
                new File(archivePackageDir.getAbsolutePath() + "/" + JPackageManager.METADATA_DIR_NAME));

        // install archive dir
        FileUtils.copyDirectory(
                new File(packageManagerDataDir.getAbsolutePath() + "/" + TEMP_INSTALL_DIR_NAME + "/"
                        + JPackageManager.AUTORUN_DIR_NAME + "/" + JPackageManager.INSTALL_DIR_NAME),
                new File(archivePackageInstallDir.getAbsolutePath() + "/" + JPackageManager.AUTORUN_DIR_NAME));

        FileUtils.copyFileToDirectory(
                new File(packageManagerDataDir.getAbsolutePath() + "/" + TEMP_INSTALL_DIR_NAME + "/"
                        + JPackageManager.PATCH_DIR_NAME + "/" + JPackageManager.PATCH_FILE_NAME),
                new File(archivePackageInstallDir.getAbsolutePath() + "/" + JPackageManager.PATCH_DIR_NAME));

        // uninstall archive dir
        FileUtils.copyDirectory(
                new File(packageManagerDataDir.getAbsolutePath() + "/" + TEMP_INSTALL_DIR_NAME + "/"
                        + JPackageManager.AUTORUN_DIR_NAME + "/" + JPackageManager.UNINSTALL_DIR_NAME),
                new File(
                        archivePackageUninstallDir.getAbsolutePath() + "/" + JPackageManager.AUTORUN_DIR_NAME));

        FileUtils.copyFileToDirectory(
                new File(packageManagerDataDir.getAbsolutePath() + "/" + TEMP_INSTALL_DIR_NAME + "/"
                        + JPackageManager.PATCH_DIR_NAME + "/" + JPackageManager.PATCH_FILE_NAME),
                new File(archivePackageUninstallDir.getAbsolutePath() + "/" + JPackageManager.PATCH_DIR_NAME));

    } catch (Exception e) {
        logger.error("", e);
    }
}

From source file:com.taobao.android.builder.tools.proguard.BundleProguarder.java

private static void cacheProguard(AppVariantContext appVariantContext, Input input, Result result)
        throws FileCacheException, IOException {

    AwbBundle awbBundle = input.getAwbBundles().get(0).getAwbBundle();
    File tmpDir = new File(appVariantContext.getScope().getGlobalScope().getIntermediatesDir(),
            "progurad-cache/" + awbBundle.getName());
    tmpDir.mkdirs();//w  w w  .jav  a 2s.c o m

    for (AwbTransform awbTransform : input.getAwbBundles()) {
        for (File file : awbTransform.getInputFiles()) {
            if (file.exists()) {
                String md5 = input.proguardJarMap.get(file);
                if (StringUtils.isNoneEmpty(md5)) {
                    FileUtils.copyFile(file, new File(tmpDir, md5 + ".jar"));
                } else {
                    FileUtils.copyFileToDirectory(file, tmpDir);
                }
            } else {
                new File(tmpDir, file.getName()).createNewFile();
            }
        }
    }

    //Keep cache. Json
    File keepFile = awbBundle.getKeepProguardFile();
    if (null != keepFile && keepFile.exists()) {
        FileUtils.copyFileToDirectory(keepFile, tmpDir);
    }

    File proguardCfg = new File(null != input.proguardOutputDir ? input.proguardOutputDir
            : appVariantContext.getAwbProguardDir(awbBundle), "proguard.cfg");
    if (!proguardCfg.exists()) {
        proguardCfg = input.printConfiguration;
    }
    if (null != proguardCfg && proguardCfg.exists()) {
        FileUtils.copyFileToDirectory(proguardCfg, tmpDir);
    }

    File usageCfg = new File(null != input.proguardOutputDir ? input.proguardOutputDir
            : appVariantContext.getAwbProguardDir(awbBundle), "usage.cfg");
    if (!usageCfg.exists()) {
        usageCfg = input.printUsage;
    }
    if (null != usageCfg && usageCfg.exists()) {
        FileUtils.copyFileToDirectory(usageCfg, tmpDir);
    }

    FileCacheCenter.cacheFile(CACHE_TYPE, result.key, tmpDir,
            AtlasBuildContext.sBuilderAdapter.pushCacheToNetwork && isRemoteCacheEnabled(appVariantContext));

}

From source file:hudson.FilePathTest.java

@Issue("JENKINS-10629")
@Test//  w ww  . j  av  a 2 s  . c o m
public void testEOFbrokenFlush() throws IOException, InterruptedException {
    final File srcFolder = temp.newFolder("src");
    // simulate magic structure with magic sizes:
    // |- dir/pom.xml   (2049)
    // |- pom.xml       (2049)
    // \- small.tar     (1537)
    final File smallTar = new File(srcFolder, "small.tar");
    givenSomeContentInFile(smallTar, 1537);
    final File dir = new File(srcFolder, "dir");
    dir.mkdirs();
    final File pomFile = new File(dir, "pom.xml");
    givenSomeContentInFile(pomFile, 2049);
    FileUtils.copyFileToDirectory(pomFile, srcFolder);

    final File archive = temp.newFile("archive.tar");

    // Compress archive
    final FilePath tmpDirPath = new FilePath(srcFolder);
    int tarred = tmpDirPath.tar(new FileOutputStream(archive), "**");
    assertEquals("One file should have been compressed", 3, tarred);

    // Decompress
    final File dstFolder = temp.newFolder("dst");
    dstFolder.mkdirs();
    FilePath outDir = new FilePath(dstFolder);
    // and now fail when flush is bad!
    tmpDirPath.child("../" + archive.getName()).untar(outDir, TarCompression.NONE);
}

From source file:com.taobao.android.TPatchTool.java

/**
 * ?bundlepatch//from ww w .j  a v  a 2  s  .co m
 *
 * @param newBundleFile
 * @param baseBundleFile
 * @param patchTmpDir
 * @param diffTxtFile
 */
private void processBundleFiles(File newBundleFile, File baseBundleFile, File patchTmpDir)
        throws IOException, RecognitionException, PatchException {
    String bundleName = FilenameUtils.getBaseName(newBundleFile.getName());
    File destPatchBundleDir = new File(patchTmpDir, bundleName);
    final File newBundleUnzipFolder = new File(newBundleFile.getParentFile(), bundleName);
    final File baseBundleUnzipFolder = new File(baseBundleFile.getParentFile(), bundleName);

    if (null != baseBundleFile
            && baseBundleFile.isFile() && baseBundleFile.exists() && !noPatchBundles.contains(baseBundleFile
                    .getName().replace("_", ".").substring(3, baseBundleFile.getName().length() - 3))
            && diffBundleDex) {
        // 
        // dex
        ZipUtils.unzip(newBundleFile, newBundleUnzipFolder.getAbsolutePath());
        ZipUtils.unzip(baseBundleFile, baseBundleUnzipFolder.getAbsolutePath());
        File destDex = new File(destPatchBundleDir, DEX_NAME);
        File tmpDexFolder = new File(patchTmpDir, bundleName + "-dex");
        createBundleDexPatch(newBundleUnzipFolder, baseBundleUnzipFolder, destDex, tmpDexFolder, false);

        // ?
        Collection<File> newBundleResFiles = FileUtils.listFiles(newBundleUnzipFolder, new IOFileFilter() {

            @Override
            public boolean accept(File file) {
                // ?dex
                if (file.getName().endsWith(".dex")) {
                    return false;
                }
                String relativePath = PathUtils.toRelative(newBundleUnzipFolder, file.getAbsolutePath());
                if (null != notIncludeFiles && pathMatcher.match(notIncludeFiles, relativePath)) {
                    return false;
                }
                return true;
            }

            @Override
            public boolean accept(File file, String s) {
                return accept(new File(file, s));
            }
        }, TrueFileFilter.INSTANCE);

        for (File newBundleResFile : newBundleResFiles) {
            String resPath = PathUtils.toRelative(newBundleUnzipFolder, newBundleResFile.getAbsolutePath());
            File baseBundleResFile = new File(baseBundleUnzipFolder, resPath);
            File destResFile = new File(destPatchBundleDir, resPath);
            if (baseBundleResFile.exists()) {
                if (isFileModify(newBundleResFile, baseBundleResFile, bundleName, resPath)) { // ?
                    FileUtils.copyFile(newBundleResFile, destResFile);
                }
            } else {// ?
                FileUtils.copyFile(newBundleResFile, destResFile);
            }
        }
    } else { // bundle?
        FileUtils.copyFileToDirectory(newBundleFile, patchTmpDir);
    }
    if (!isModifyBundle(newBundleFile.getName()) && !createAll) {
        FileUtils.deleteDirectory(destPatchBundleDir);
        Iterator<BundleDiffResult> iterator = patchInfos.iterator();
        while (iterator.hasNext()) {
            BundleDiffResult bundleDiffResult = iterator.next();
            if (bundleDiffResult.getBundleName().equals(bundleName.substring(3).replace("_", "."))) {
                iterator.remove();
            }
        }
    }
}

From source file:de.uzk.hki.da.cli.Cli.java

/**
 * Copies the files listed in a SIP list to a single directory
 * //from ww  w  .  j  a  v a 2 s.c  om
 * @param fileListFile The SIP list file
 * @return The path to the directory containing the files
 */
private String copySipListContentToFolder(File sipListFile) {

    CliProgressManager progressManager = new CliProgressManager();

    String tempFolderName = getTempFolderName();

    XMLReader xmlReader = null;
    SAXParserFactory spf = SAXParserFactory.newInstance();
    try {
        xmlReader = spf.newSAXParser().getXMLReader();
    } catch (Exception e) {
        logger.error("Failed to create SAX parser", e);
        System.out.println("Fehler beim Einlesen der SIP-Liste: SAX-Parser konnte nicht erstellt werden.");
        return "";
    }
    xmlReader.setErrorHandler(new ErrorHandler() {

        @Override
        public void error(SAXParseException e) throws SAXException {
            throw new SAXException("Beim Einlesen der SIP-Liste ist ein Fehler aufgetreten.", e);
        }

        @Override
        public void fatalError(SAXParseException e) throws SAXException {
            throw new SAXException("Beim Einlesen der SIP-Liste ist ein schwerer Fehler aufgetreten.", e);
        }

        @Override
        public void warning(SAXParseException e) throws SAXException {
            logger.warn("Warning while parsing siplist", e);
            System.out.println("\nWarnung:\n" + e.getMessage());
        }
    });

    InputStream inputStream;
    try {
        inputStream = new FileInputStream(sipListFile);

        Reader reader = new InputStreamReader(inputStream, "UTF-8");
        Builder parser = new Builder(xmlReader);
        Document doc = parser.build(reader);
        reader.close();

        Element root = doc.getRootElement();
        Elements sipElements = root.getChildElements("sip");

        long files = 0;
        for (int i = 0; i < sipElements.size(); i++) {
            Elements fileElements = sipElements.get(i).getChildElements("file");
            if (fileElements != null)
                files += fileElements.size();
        }
        progressManager.setTotalSize(files);

        for (int i = 0; i < sipElements.size(); i++) {
            Element sipElement = sipElements.get(i);
            String sipName = sipElement.getAttributeValue("name");

            File tempDirectory = new File(tempFolderName + File.separator + sipName);
            if (tempDirectory.exists()) {
                FolderUtils.deleteQuietlySafe(new File(tempFolderName));
                System.out.println("\nDie SIP-Liste enthlt mehrere SIPs mit dem Namen " + sipName + ". "
                        + "Bitte vergeben Sie fr jedes SIP einen eigenen Namen.");
                return "";
            }
            tempDirectory.mkdirs();

            Elements fileElements = sipElement.getChildElements("file");

            for (int j = 0; j < fileElements.size(); j++) {
                Element fileElement = fileElements.get(j);
                String filepath = fileElement.getValue();

                File file = new File(filepath);
                if (!file.exists()) {
                    logger.error("File " + file.getAbsolutePath() + " is referenced in siplist, "
                            + "but does not exist");
                    System.out.println("\nDie in der SIP-Liste angegebene Datei " + file.getAbsolutePath()
                            + " existiert nicht.");
                    FolderUtils.deleteQuietlySafe(new File(tempFolderName));
                    return "";
                }

                try {
                    if (file.isDirectory())
                        FileUtils.copyDirectoryToDirectory(file, tempDirectory);
                    else
                        FileUtils.copyFileToDirectory(file, tempDirectory);
                    progressManager.copyFilesFromListProgress();
                } catch (IOException e) {
                    logger.error("Failed to copy file " + file.getAbsolutePath() + " to folder "
                            + tempDirectory.getAbsolutePath(), e);
                    System.out.println("\nDie in der SIP-Liste angegebene Datei " + file.getAbsolutePath()
                            + " konnte nicht kopiert werden.");
                    FolderUtils.deleteQuietlySafe(new File(tempFolderName));
                    return "";
                }
            }
        }
    } catch (Exception e) {
        logger.error("Failed to read siplist " + sipListFile.getAbsolutePath(), e);
        System.out.println("\nBeim Lesen der SIP-Liste ist ein Fehler aufgetreten. ");
        return "";
    }

    return (new File(tempFolderName).getAbsolutePath());
}

From source file:com.taobao.android.TPatchTool.java

/**
 * ?bundle??/*from ww w  .  ja va  2 s. c  o  m*/
 *
 * @param newApkUnzipFolder
 * @param baseApkUnzipFolder
 * @param patchTmpDir
 * @throws IOException
 */
private void copyMainBundleResources(final File newApkUnzipFolder, final File baseApkUnzipFolder,
        File patchTmpDir) throws IOException {
    boolean resoureModified = false;

    Collection<File> retainFiles = FileUtils.listFiles(newApkUnzipFolder, new IOFileFilter() {

        @Override
        public boolean accept(File file) {
            String relativePath = PathUtils.toRelative(newApkUnzipFolder, file.getAbsolutePath());
            if (pathMatcher.match(DEFAULT_NOT_INCLUDE_RESOURCES, relativePath)) {
                return false;
            }
            if (null != notIncludeFiles && pathMatcher.match(notIncludeFiles, relativePath)) {
                return false;
            }
            return true;
        }

        @Override
        public boolean accept(File file, String s) {
            return accept(new File(file, s));
        }
    }, TrueFileFilter.INSTANCE);

    for (File retainFile : retainFiles) {
        String relativePath = PathUtils.toRelative(newApkUnzipFolder, retainFile.getAbsolutePath());
        File baseFile = new File(baseApkUnzipFolder, relativePath);
        if (isFileModify(retainFile, baseFile)) {
            resoureModified = true;
            File destFile = new File(patchTmpDir, relativePath);
            FileUtils.copyFile(retainFile, destFile);
        }
    }
    if (resoureModified) {
        File AndroidMenifestFile = new File(newApkUnzipFolder, ANDROID_MANIFEST);
        FileUtils.copyFileToDirectory(AndroidMenifestFile, patchTmpDir);
    }
}

From source file:display.containers.FileManager.java

/**
 * Deplace les fichiers / repertoire selectionnees vers le dossier dir
 * @param currentDir2//w ww  .  ja v a2  s .c o  m
 * @throws IOException 
 */
public void copySelectedFilesTo(File dir) throws IOException {
    // Recupere les lignes selectionnees
    int[] indices = table.getSelectedRows();
    // On recupere les fichiers correspondants
    ArrayList<File> files = new ArrayList<File>();
    for (int i = 0; i < indices.length; i++) {
        int row = table.convertRowIndexToModel(indices[i]);
        File fi = ((FileTableModel) table.getModel()).getFile(row);
        if (!continueAction) {
            continueAction = true;
            return;
        }
        if (!fi.getName().contains("..")) {
            if (fi.isDirectory())
                FileUtils.copyDirectoryToDirectory(fi, dir);
            else
                FileUtils.copyFileToDirectory(fi, dir);
        }
    }
}

From source file:com.virtualparadigm.packman.processor.JPackageManagerOld.java

private static void archivePackage(Package installPackage, File packageManagerDataDir) {
    // create "archive" dir if it doesnt exist
    // create package archive dir (<package name>_v_<package version>)
    // copy contents of package metadata, autorun and patch file to archive dir
    try {//from  w w  w  . ja v a2  s.c o  m
        File archiveDir = new File(packageManagerDataDir.getAbsolutePath() + "/" + ARCHIVE_DIR_NAME);
        File archivePackageDir = new File(archiveDir.getAbsolutePath() + "/" + installPackage.getName() + "_v_"
                + installPackage.getVersion());
        //            if(!archivePackageDir.exists())
        //            {
        //                archivePackageDir.mkdirs();
        //            }

        File archivePackageInstallDir = new File(
                archivePackageDir.getAbsolutePath() + "/" + JPackageManagerOld.INSTALL_DIR_NAME);
        if (!archivePackageInstallDir.exists()) {
            archivePackageInstallDir.mkdirs();
        }

        File archivePackageUninstallDir = new File(
                archivePackageDir.getAbsolutePath() + "/" + JPackageManagerOld.UNINSTALL_DIR_NAME);
        if (!archivePackageUninstallDir.exists()) {
            archivePackageUninstallDir.mkdirs();
        }

        // metadata archive dir
        FileUtils.copyDirectory(
                new File(packageManagerDataDir.getAbsolutePath() + "/" + TEMP_INSTALL_DIR_NAME + "/"
                        + JPackageManagerOld.METADATA_DIR_NAME),
                new File(archivePackageDir.getAbsolutePath() + "/" + JPackageManagerOld.METADATA_DIR_NAME));

        // install archive dir
        FileUtils.copyDirectory(
                new File(packageManagerDataDir.getAbsolutePath() + "/" + TEMP_INSTALL_DIR_NAME + "/"
                        + JPackageManagerOld.AUTORUN_DIR_NAME + "/" + JPackageManagerOld.INSTALL_DIR_NAME),
                new File(archivePackageInstallDir.getAbsolutePath() + "/"
                        + JPackageManagerOld.AUTORUN_DIR_NAME));

        FileUtils.copyFileToDirectory(
                new File(packageManagerDataDir.getAbsolutePath() + "/" + TEMP_INSTALL_DIR_NAME + "/"
                        + JPackageManagerOld.PATCH_DIR_NAME + "/" + JPackageManagerOld.PATCH_FILE_NAME),
                new File(archivePackageInstallDir.getAbsolutePath() + "/" + JPackageManagerOld.PATCH_DIR_NAME));

        // uninstall archive dir
        FileUtils.copyDirectory(
                new File(packageManagerDataDir.getAbsolutePath() + "/" + TEMP_INSTALL_DIR_NAME + "/"
                        + JPackageManagerOld.AUTORUN_DIR_NAME + "/" + JPackageManagerOld.UNINSTALL_DIR_NAME),
                new File(archivePackageUninstallDir.getAbsolutePath() + "/"
                        + JPackageManagerOld.AUTORUN_DIR_NAME));

        FileUtils.copyFileToDirectory(
                new File(packageManagerDataDir.getAbsolutePath() + "/" + TEMP_INSTALL_DIR_NAME + "/"
                        + JPackageManagerOld.PATCH_DIR_NAME + "/" + JPackageManagerOld.PATCH_FILE_NAME),
                new File(archivePackageUninstallDir.getAbsolutePath() + "/"
                        + JPackageManagerOld.PATCH_DIR_NAME));

    } catch (Exception e) {
        logger.error("", e);
    }
}

From source file:de.blizzy.documentr.page.PageStore.java

@Override
public void relocatePage(final String projectName, final String branchName, final String path,
        String newParentPagePath, User user) throws IOException {

    Assert.hasLength(projectName);//from  w w  w  .j  a v  a2  s  . c  om
    Assert.hasLength(branchName);
    Assert.hasLength(path);
    Assert.hasLength(newParentPagePath);
    Assert.notNull(user);
    // check if pages exist by trying to load them
    getPage(projectName, branchName, path, false);
    getPage(projectName, branchName, newParentPagePath, false);

    ILockedRepository repo = null;
    List<String> oldPagePaths;
    List<String> deletedPagePaths;
    List<String> newPagePaths;
    List<PagePathChangedEvent> pagePathChangedEvents;
    try {
        repo = globalRepositoryManager.getProjectBranchRepository(projectName, branchName);
        String pageName = path.contains("/") ? StringUtils.substringAfterLast(path, "/") : path; //$NON-NLS-1$ //$NON-NLS-2$
        final String newPagePath = newParentPagePath + "/" + pageName; //$NON-NLS-1$

        File workingDir = RepositoryUtil.getWorkingDir(repo.r());

        File oldSubPagesDir = Util.toFile(new File(workingDir, DocumentrConstants.PAGES_DIR_NAME), path);
        oldPagePaths = listPagePaths(oldSubPagesDir, true);
        oldPagePaths = Lists.newArrayList(Lists.transform(oldPagePaths, new Function<String, String>() {
            @Override
            public String apply(String p) {
                return path + "/" + p; //$NON-NLS-1$
            }
        }));
        oldPagePaths.add(path);

        File deletedPagesSubDir = Util.toFile(new File(workingDir, DocumentrConstants.PAGES_DIR_NAME),
                newPagePath);
        deletedPagePaths = listPagePaths(deletedPagesSubDir, true);
        deletedPagePaths = Lists.newArrayList(Lists.transform(deletedPagePaths, new Function<String, String>() {
            @Override
            public String apply(String p) {
                return newPagePath + "/" + p; //$NON-NLS-1$
            }
        }));
        deletedPagePaths.add(newPagePath);

        Git git = Git.wrap(repo.r());
        AddCommand addCommand = git.add();

        for (String dirName : Sets.newHashSet(DocumentrConstants.PAGES_DIR_NAME,
                DocumentrConstants.ATTACHMENTS_DIR_NAME)) {
            File dir = new File(workingDir, dirName);

            File newSubPagesDir = Util.toFile(dir, newPagePath);
            if (newSubPagesDir.exists()) {
                git.rm().addFilepattern(dirName + "/" + newPagePath).call(); //$NON-NLS-1$
            }
            File newPageFile = Util.toFile(dir, newPagePath + DocumentrConstants.PAGE_SUFFIX);
            if (newPageFile.exists()) {
                git.rm().addFilepattern(dirName + "/" + newPagePath + DocumentrConstants.PAGE_SUFFIX).call(); //$NON-NLS-1$
            }
            File newMetaFile = Util.toFile(dir, newPagePath + DocumentrConstants.META_SUFFIX);
            if (newMetaFile.exists()) {
                git.rm().addFilepattern(dirName + "/" + newPagePath + DocumentrConstants.META_SUFFIX).call(); //$NON-NLS-1$
            }

            File newParentPageDir = Util.toFile(dir, newParentPagePath);
            File subPagesDir = Util.toFile(dir, path);
            if (subPagesDir.exists()) {
                FileUtils.copyDirectoryToDirectory(subPagesDir, newParentPageDir);
                git.rm().addFilepattern(dirName + "/" + path).call(); //$NON-NLS-1$
                addCommand.addFilepattern(dirName + "/" + newParentPagePath + "/" + pageName); //$NON-NLS-1$ //$NON-NLS-2$
            }
            File pageFile = Util.toFile(dir, path + DocumentrConstants.PAGE_SUFFIX);
            if (pageFile.exists()) {
                FileUtils.copyFileToDirectory(pageFile, newParentPageDir);
                git.rm().addFilepattern(dirName + "/" + path + DocumentrConstants.PAGE_SUFFIX).call(); //$NON-NLS-1$
                addCommand.addFilepattern(
                        dirName + "/" + newParentPagePath + "/" + pageName + DocumentrConstants.PAGE_SUFFIX); //$NON-NLS-1$ //$NON-NLS-2$
            }
            File metaFile = Util.toFile(dir, path + DocumentrConstants.META_SUFFIX);
            if (metaFile.exists()) {
                FileUtils.copyFileToDirectory(metaFile, newParentPageDir);
                git.rm().addFilepattern(dirName + "/" + path + DocumentrConstants.META_SUFFIX).call(); //$NON-NLS-1$
                addCommand.addFilepattern(
                        dirName + "/" + newParentPagePath + "/" + pageName + DocumentrConstants.META_SUFFIX); //$NON-NLS-1$ //$NON-NLS-2$
            }
        }

        addCommand.call();
        PersonIdent ident = new PersonIdent(user.getLoginName(), user.getEmail());
        git.commit().setAuthor(ident).setCommitter(ident)
                .setMessage("move " + path + " to " + newParentPagePath + "/" + pageName) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                .call();
        git.push().call();

        newPagePaths = Lists.transform(oldPagePaths, new Function<String, String>() {
            @Override
            public String apply(String p) {
                return newPagePath + StringUtils.removeStart(p, path);
            }
        });

        pagePathChangedEvents = Lists.transform(oldPagePaths, new Function<String, PagePathChangedEvent>() {
            @Override
            public PagePathChangedEvent apply(String oldPath) {
                String newPath = newPagePath + StringUtils.removeStart(oldPath, path);
                return new PagePathChangedEvent(projectName, branchName, oldPath, newPath);
            }
        });

        PageUtil.updateProjectEditTime(projectName);
    } catch (GitAPIException e) {
        throw new IOException(e);
    } finally {
        Closeables.closeQuietly(repo);
    }

    Set<String> allDeletedPagePaths = Sets.newHashSet(oldPagePaths);
    allDeletedPagePaths.addAll(deletedPagePaths);
    eventBus.post(new PagesDeletedEvent(projectName, branchName, allDeletedPagePaths));

    for (String newPath : newPagePaths) {
        eventBus.post(new PageChangedEvent(projectName, branchName, newPath));
    }

    for (PagePathChangedEvent event : pagePathChangedEvents) {
        eventBus.post(event);
    }
}

From source file:io.snappydata.hydra.cluster.SnappyTest.java

protected void copyConfigData(String fileName) {
    if (doneCopying)
        return;// w  ww  . ja v a 2s .  co m
    String filePath = productConfDirPath + fileName;
    File srcFile = new File(filePath);
    try {
        File destDir = new File(".");
        FileUtils.copyFileToDirectory(srcFile, destDir);
        Log.getLogWriter().info(
                "Done copying " + fileName + " file from " + srcFile + " to " + destDir.getAbsolutePath());
    } catch (IOException e) {
        throw new TestException(
                "Error occurred while copying data from file: " + srcFile + "\n " + e.getMessage());
    }
    doneCopying = true;
}