List of usage examples for org.apache.commons.io FileUtils moveDirectory
public static void moveDirectory(File srcDir, File destDir) throws IOException
From source file:de.uzk.hki.da.cb.RestartIngestWorkflowAction.java
/** * Leaves only the representation with the SIP content. * * @author Daniel M. de Oliveira/* w w w .j av a2 s .c om*/ * @throws IOException */ private void revertDataFolderToSIPContent() throws IOException { List<String> filesC = Arrays.asList(object.getDataPath().toFile().list()); Collections.sort(filesC, Collections.reverseOrder()); String newestRep = filesC.iterator().next(); if (newestRep.endsWith("+b")) { FileUtils.deleteDirectory(Path.makeFile(object.getDataPath(), newestRep)); newestRep = newestRep.replace("+b", "+a"); } File sipContent = Path.makeFile(object.getDataPath(), newestRep); File sipTemp = Path.makeFile(object.getPath(), "___sipContent"); FileUtils.moveDirectory(sipContent, sipTemp); FileUtils.deleteDirectory(object.getDataPath().toFile()); FileUtils.moveDirectory(sipTemp, object.getDataPath().toFile()); }
From source file:com.qualinsight.mojo.cobertura.core.AbstractCleaningReportMojo.java
private void cleanupFileSystem(final File classesDirectory, final File backupClassesDirectory, final File baseDataFile, final File destinationDataFile) throws MojoExecutionException { getLog().debug("Cleaning up file system after Cobertura report generation"); try {//from w w w. j a v a 2 s . c o m FileUtils.forceDelete(classesDirectory); FileUtils.moveDirectory(backupClassesDirectory, classesDirectory); FileUtils.moveFile(baseDataFile, destinationDataFile); } catch (final IOException e) { final String message = "An error occurred during file system cleanup: "; getLog().error(message, e); throw new MojoExecutionException(message, e); } }
From source file:com.diffplug.gradle.CmdLine.java
/** Removes the given file or directory. */ public void mv(File src, File dst) { run(() -> {/* ww w.ja v a 2 s . c o m*/ if (!src.exists()) { throw new IllegalArgumentException("mv failed: " + src.getAbsolutePath() + " does not exist."); } if (src.isDirectory()) { FileUtils.moveDirectory(src, dst); } else { FileUtils.moveFile(src, dst); } }); }
From source file:de.uzk.hki.da.cb.FetchPIPsAction.java
@Override public boolean implementation() throws FileNotFoundException, IOException { deletePreviousPIPs(); // Must be done at the beginning to make sure rollback() can act properly // TODO check if source exists distributedConversionAdapter.replicateToLocalNode(makeRelativePIPSourceFolder(WorkArea.PUBLIC).toString(), n);/* w ww . java2s.c om*/ distributedConversionAdapter .replicateToLocalNode(makeRelativePIPSourceFolder(WorkArea.WA_INSTITUTION).toString(), n); boolean validLicense = (canIgnoreLicenseValidation() || (o.getLicense_flag() != C.LICENSEFLAG_NO_LICENSE && o.getLicense_flag() != C.LICENSEFLAG_UNDEFINED)); if (validLicense) { //create and fill WorkArea.PUBLIC-Dir only if license metadata is acceptable if (makePIPSourceFolder(WorkArea.PUBLIC).exists()) { logger.info(INFO_MSG_REPLICATED_SUCESSFULLY + makePIPSourceFolder(WorkArea.PUBLIC)); // The rename is necessary because at the moment we donl't have another possibility to delete or trim the irods // collections on specific resources. FileUtils.moveDirectory(makePIPSourceFolder(WorkArea.PUBLIC), makePIPFolder(WorkArea.PUBLIC)); } } if (makePIPSourceFolder(WorkArea.WA_INSTITUTION).exists()) { logger.info(INFO_MSG_REPLICATED_SUCESSFULLY + makePIPSourceFolder(WorkArea.WA_INSTITUTION)); FileUtils.moveDirectory(makePIPSourceFolder(WorkArea.WA_INSTITUTION), makePIPFolder(WorkArea.WA_INSTITUTION)); } distributedConversionAdapter.remove(makeRelativePIPSourceFolder(WorkArea.PUBLIC).toString()); distributedConversionAdapter.remove(makeRelativePIPSourceFolder(WorkArea.WA_INSTITUTION).toString()); return true; }
From source file:com.sangupta.shire.site.SiteBackup.java
/** * Method that creates the backup of the _site folder, if present. * /* w ww .jav a 2s. c o m*/ */ public void backupOlderSite() { File siteFolder = new File(options.getParentFolder(), options.getSiteFolderName()); if (!siteFolder.exists()) { return; } if (!siteFolder.isDirectory()) { return; } backupFolder = new File(siteFolder.getAbsolutePath() + BACKUP_FOLDER_EXTENSION); try { FileUtils.moveDirectory(siteFolder, backupFolder); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.digitalgeneralists.assurance.model.merge.TargetMergeEngine.java
@Override public void mergeResult(ComparisonResult result, IProgressMonitor monitor) throws AssuranceNullFileReferenceException { File sourceFile = result.getSource().getFile(); File targetFile = result.getTarget().getFile(); if ((sourceFile == null) || (targetFile == null)) { throw new AssuranceNullFileReferenceException("The source or target file is null."); }// ww w.ja v a 2 s.com if (monitor != null) { StringBuilder message = new StringBuilder(512); monitor.publish(message.append("Merging ").append(targetFile.toString()).append(" to ") .append(sourceFile.toString()).toString()); message.setLength(0); message = null; } if (targetFile.exists()) { try { if (targetFile.isDirectory()) { FileUtils.copyDirectory(targetFile, sourceFile); } else { FileUtils.copyFile(targetFile, sourceFile); } result.setResolution(AssuranceResultResolution.REPLACE_SOURCE); } catch (IOException e) { logger.error("An error occurred when replacing the source with the target."); result.setResolution(AssuranceResultResolution.PROCESSING_ERROR_ENCOUNTERED); result.setResolutionError(e.getMessage()); } } else { if (sourceFile.exists()) { File scanDeletedItemsLocation = result .getSourceDeletedItemLocation(getApplicationDeletedItemsLocation()); if (scanDeletedItemsLocation == null) { StringBuilder deletedFilePath = new StringBuilder(512); scanDeletedItemsLocation = new File( deletedFilePath.append(this.getDefaultDeletedItemsLocation()).append(File.separator) .append(sourceFile.getName()).toString()); deletedFilePath.setLength(0); } try { if (sourceFile.isDirectory()) { FileUtils.moveDirectory(sourceFile, scanDeletedItemsLocation); } else { FileUtils.moveFile(sourceFile, scanDeletedItemsLocation); } result.setResolution(AssuranceResultResolution.DELETE_SOURCE); } catch (IOException e) { StringBuffer message = new StringBuffer(512); logger.error(message.append("Could not move item to deleted items location ") .append(sourceFile.getPath())); message.setLength(0); message = null; result.setResolution(AssuranceResultResolution.PROCESSING_ERROR_ENCOUNTERED); result.setResolutionError(e.getMessage()); } scanDeletedItemsLocation = null; } } sourceFile = null; targetFile = null; }
From source file:com.digitalgeneralists.assurance.model.merge.SourceMergeEngine.java
@Override public void mergeResult(ComparisonResult result, IProgressMonitor monitor) throws AssuranceNullFileReferenceException { File sourceFile = result.getSource().getFile(); File targetFile = result.getTarget().getFile(); if ((sourceFile == null) || (targetFile == null)) { throw new AssuranceNullFileReferenceException("The source or target file is null."); }/*from ww w. j a va2 s . c om*/ if (monitor != null) { StringBuilder message = new StringBuilder(512); monitor.publish(message.append("Merging ").append(sourceFile.toString()).append(" to ") .append(targetFile.toString()).toString()); message.setLength(0); message = null; } if (sourceFile.exists()) { try { if (sourceFile.isDirectory()) { FileUtils.copyDirectory(sourceFile, targetFile); } else { FileUtils.copyFile(sourceFile, targetFile); } result.setResolution(AssuranceResultResolution.REPLACE_TARGET); } catch (IOException e) { logger.error("An error occurred when replacing the target with the source."); result.setResolution(AssuranceResultResolution.PROCESSING_ERROR_ENCOUNTERED); result.setResolutionError(e.getMessage()); } } else { if (targetFile.exists()) { File scanDeletedItemsLocation = result .getTargetDeletedItemLocation(getApplicationDeletedItemsLocation()); if (scanDeletedItemsLocation == null) { StringBuilder deletedItemPath = new StringBuilder(512); scanDeletedItemsLocation = new File( deletedItemPath.append(this.getDefaultDeletedItemsLocation()).append(File.separator) .append(targetFile.getName()).toString()); deletedItemPath.setLength(0); deletedItemPath = null; } try { if (targetFile.isDirectory()) { FileUtils.moveDirectory(targetFile, scanDeletedItemsLocation); } else { FileUtils.moveFile(targetFile, scanDeletedItemsLocation); } result.setResolution(AssuranceResultResolution.DELETE_TARGET); } catch (IOException e) { StringBuffer message = new StringBuffer(512); logger.warn(message.append("Could not move item to deleted items location ") .append(sourceFile.getPath())); message.setLength(0); message = null; result.setResolution(AssuranceResultResolution.PROCESSING_ERROR_ENCOUNTERED); result.setResolutionError(e.getMessage()); } scanDeletedItemsLocation = null; } } sourceFile = null; targetFile = null; }
From source file:com.adguard.compiler.FileUtil.java
private static void copyFirefoxFiles(File source, File dest) throws Exception { File firefoxBase = new File(source, FIREFOX_FOLDER); copyDirectory(firefoxBase, dest);//from w ww . j a va 2 s . c om copyCommonFiles(source, dest, Browser.FIREFOX); //move processed html pages to data/content folder File sourcePagesDir = new File(dest, "pages"); File destPagesDir = new File(dest, "data/content"); copyDirectory(sourcePagesDir, destPagesDir); FileUtils.deleteQuietly(sourcePagesDir); //move js pages files to data/content/pages folder File sourceJsPagesDir = new File(dest, "lib/pages"); File destJsPagesDir = new File(dest, "data/content/pages"); FileUtils.moveDirectory(sourceJsPagesDir, destJsPagesDir); //move lib/content-script folder to data/content/content-script folder File sourceContentScript = new File(dest, "lib/content-script"); File destContentScript = new File(dest, "data/content/content-script"); copyDirectory(sourceContentScript, destContentScript); FileUtils.deleteQuietly(sourceContentScript); //move third-party js files to data/content folder File sourceLibsDir = new File(dest, "lib/libs"); File destLibsDir = new File(dest, "data/content/libs"); FileUtils.moveDirectory(sourceLibsDir, destLibsDir); //TODO: optimize //Remove deferred.min.js file, cause use only in chrome and safari extension FileUtils.deleteQuietly(new File(destLibsDir, "deferred.min.js")); //convert chrome style locales to firefox style File sourceLocalesDir = new File(dest, "_locales"); File destLocalesDir = new File(dest, "locale"); LocaleUtils.convertFromChromeToFirefoxLocales(sourceLocalesDir); //rename folder FileUtils.moveDirectory(sourceLocalesDir, destLocalesDir); //move filters folder to data folder File sourceFiltersDire = new File(dest, "filters"); File destFiltersDir = new File(dest, "data/filters"); FileUtils.moveDirectory(sourceFiltersDire, destFiltersDir); }
From source file:de.uzk.hki.da.cb.FetchPIPsAction.java
@Override public void rollback() throws Exception { if (makePIPFolder(WorkArea.PUBLIC).exists()) { logger.info(INFO_MSG_MOVED_BACK_PIP + makePIPSourceFolder(WorkArea.PUBLIC)); FileUtils.moveDirectory(makePIPFolder(WorkArea.PUBLIC), makePIPSourceFolder(WorkArea.PUBLIC)); // we know that this is possible to write to this location since we cleared it at beginning of implementation() }//from ww w. ja va2s .c o m if (makePIPFolder(WorkArea.WA_INSTITUTION).exists()) { logger.info(INFO_MSG_MOVED_BACK_PIP + makePIPSourceFolder(WorkArea.WA_INSTITUTION)); FileUtils.moveDirectory(makePIPFolder(WorkArea.WA_INSTITUTION), makePIPSourceFolder(WorkArea.WA_INSTITUTION)); } }
From source file:com.esofthead.mycollab.module.file.service.impl.FileRawContentServiceImpl.java
@Override public void movePath(String oldPath, String destinationPath) { try {/* w w w . j a v a2 s. co m*/ File src = new File(baseFolder + "/" + oldPath); File dest = new File(baseFolder + "/" + destinationPath); if (!src.exists()) { LOG.debug("Source: {} is not existed", src.getPath()); return; } if (dest.exists()) { FileUtils.deleteQuietly(dest); } if (src.isFile()) { FileUtils.moveFile(src, dest); } else { FileUtils.moveDirectory(src, dest); } } catch (IOException e) { throw new MyCollabException(e); } }