List of usage examples for org.apache.commons.io FileUtils forceDelete
public static void forceDelete(File file) throws IOException
From source file:com.handcraftedbits.bamboo.plugin.go.task.test.GoTestTaskType.java
@NotNull @Override// www . jav a 2 s.co m public TaskResult execute(@NotNull final TaskContext taskContext) throws TaskException { final GoTestTaskConfiguration configuration = new GoTestTaskConfiguration(getTaskHelper(), taskContext); int i = 0; final File outputDirectory = new File(taskContext.getWorkingDirectory(), configuration.getLogOutputPath()); final List<GoArgumentList> packagesWithArguments = configuration .getPackagesWithArguments(GoTestTaskConfiguration.flagsToExclude); final ProcessHelper processHelper = getTaskHelper().createProcessHelper(taskContext); if (outputDirectory.exists()) { try { FileUtils.forceDelete(outputDirectory); } catch (final IOException e) { taskContext.getBuildLogger().addErrorLogEntry(getTaskHelper().getText( "task.test.error.directory." + "results.delete", outputDirectory.getAbsolutePath())); return TaskResultBuilder.newBuilder(taskContext).failedWithError().build(); } } if (!outputDirectory.mkdirs()) { taskContext.getBuildLogger().addErrorLogEntry(getTaskHelper() .getText("task.test.error.directory." + "results.create", outputDirectory.getAbsolutePath())); return TaskResultBuilder.newBuilder(taskContext).failedWithError().build(); } for (final GoArgumentList packageWithArguments : packagesWithArguments) { final LinkedList<String> commandLine = new LinkedList<>(); final FileOutputHandler fileOutputHandler = new FileOutputHandler( new File(outputDirectory, "goTestOutput" + (i++) + ".log")); final ExternalProcess process; commandLine.add(configuration.getGoExecutable()); commandLine.add("test"); commandLine.add("-v"); commandLine.addAll(packageWithArguments.getItems()); if (configuration.shouldLogOutputToBuild()) { process = processHelper.executeProcess(commandLine, configuration.getSourcePath(), configuration.getEnvironmentVariables(), new CompositeOutputHandler(taskContext.getBuildLogger(), processHelper.createStandardOutputHandler(), fileOutputHandler), new CompositeOutputHandler(taskContext.getBuildLogger(), processHelper.createStandardErrorHandler(), fileOutputHandler)); } else { process = processHelper.executeProcess(commandLine, configuration.getSourcePath(), configuration.getEnvironmentVariables(), fileOutputHandler, fileOutputHandler); } if (process.getHandler().getExitCode() != 0) { return TaskResultBuilder.newBuilder(taskContext).checkReturnCode(process, 0).build(); } } return TaskResultBuilder.newBuilder(taskContext).success().build(); }
From source file:com.webbfontaine.valuewebb.action.tt.AttDocFileHandler.java
private static void removeFile(UploadItem item) { try {//from w ww . j a va 2 s .com FileUtils.forceDelete(item.getFile()); } catch (Exception e) { LOGGER.error("Failed to remove uploaded file {0}", e, item.getFile().getAbsolutePath()); } }
From source file:backend.ProcessDratWrapper.java
public void reset() throws Exception { for (String dir : Utils.getResetDirectories()) { File file = new File(dir); try {/* ww w.ja v a 2 s .c om*/ FileUtils.forceDelete(new File(dir)); } catch (FileNotFoundException fnfe) { // do nothing, since if the file isn't found... don't need to delete it } } }
From source file:fr.sanofi.fcl4transmart.controllers.listeners.clinicalData.RemoveRawFileListener.java
@Override public void handleEvent(Event event) { Vector<File> files = this.selectRawFilesUI.getSelectedRemovedFile(); File cmf = ((ClinicalData) this.dataType).getCMF(); File wmf = ((ClinicalData) this.dataType).getWMF(); boolean confirm = this.selectRawFilesUI.confirm( "The column mapping file and the word mapping file will be updated or removed consequently.\nAre you sure to remove these files?"); for (File file : files) { if (file == null) { return; }//from w w w .j av a2 s . co m if (((ClinicalData) this.dataType).getRawFiles().size() == files.size()) { if (cmf != null || wmf != null) { if (confirm) { if (cmf != null) { ((ClinicalData) this.dataType).setCMF(null); try { FileUtils.forceDelete(cmf); } catch (IOException e) { // TODO Auto-generated catch block this.selectRawFilesUI.displayMessage("File error: " + e.getLocalizedMessage()); e.printStackTrace(); } } if (wmf != null) { ((ClinicalData) this.dataType).setWMF(null); try { FileUtils.forceDelete(wmf); } catch (IOException e) { // TODO Auto-generated catch block this.selectRawFilesUI.displayMessage("File error: " + e.getLocalizedMessage()); e.printStackTrace(); } } ((ClinicalData) this.dataType).getRawFiles().remove(file); FileUtils.deleteQuietly(file); UsedFilesPart.sendFilesChanged(dataType); } } else { if (confirm) { ((ClinicalData) this.dataType).getRawFiles().remove(file); FileUtils.deleteQuietly(file); UsedFilesPart.sendFilesChanged(dataType); } } } else {//several raw files: update cmf and wmf to remove lines for this raw file if (cmf != null || wmf != null) { if (confirm) { if (cmf != null) { File newCmf = new File(this.dataType.getPath().toString() + File.separator + this.dataType.getStudy().toString() + ".columns.tmp"); try { FileWriter fw = new FileWriter(newCmf); BufferedWriter out = new BufferedWriter(fw); try { BufferedReader br = new BufferedReader(new FileReader(cmf)); String line; while ((line = br.readLine()) != null) { if (line.split("\t", -1)[0].compareTo(file.getName()) != 0) { out.write(line + "\n"); } } br.close(); } catch (Exception e) { this.selectRawFilesUI.displayMessage("File error: " + e.getLocalizedMessage()); e.printStackTrace(); out.close(); } out.close(); String fileName = cmf.getName(); FileUtils.deleteQuietly(cmf); try { File fileDest = new File(this.dataType.getPath() + File.separator + fileName); FileUtils.moveFile(newCmf, fileDest); ((ClinicalData) this.dataType).setCMF(fileDest); } catch (Exception ioe) { this.selectRawFilesUI .displayMessage("File error: " + ioe.getLocalizedMessage()); return; } } catch (Exception e) { this.selectRawFilesUI.displayMessage("Error: " + e.getLocalizedMessage()); e.printStackTrace(); } } if (wmf != null) { File newWmf = new File(this.dataType.getPath().toString() + File.separator + this.dataType.getStudy().toString() + ".words.tmp"); try { FileWriter fw = new FileWriter(newWmf); BufferedWriter out = new BufferedWriter(fw); try { BufferedReader br = new BufferedReader(new FileReader(wmf)); String line; while ((line = br.readLine()) != null) { if (line.split("\t", -1)[0].compareTo(file.getName()) != 0) { out.write(line + "\n"); } } br.close(); } catch (Exception e) { this.selectRawFilesUI.displayMessage("Error: " + e.getLocalizedMessage()); e.printStackTrace(); out.close(); } out.close(); String fileName = wmf.getName(); FileUtils.deleteQuietly(wmf); try { File fileDest = new File(this.dataType.getPath() + File.separator + fileName); FileUtils.moveFile(newWmf, fileDest); ((ClinicalData) this.dataType).setWMF(fileDest); } catch (Exception ioe) { this.selectRawFilesUI .displayMessage("File error: " + ioe.getLocalizedMessage()); return; } } catch (Exception e) { this.selectRawFilesUI.displayMessage("Error: " + e.getLocalizedMessage()); e.printStackTrace(); } } ((ClinicalData) this.dataType).getRawFiles().remove(file); FileUtils.deleteQuietly(file); UsedFilesPart.sendFilesChanged(dataType); } } else { if (confirm) { ((ClinicalData) this.dataType).getRawFiles().remove(file); FileUtils.deleteQuietly(file); UsedFilesPart.sendFilesChanged(dataType); } } } } this.selectRawFilesUI.updateViewer(); WorkPart.updateSteps(); WorkPart.updateFiles(); }
From source file:com.asakusafw.testdriver.BatchTestDriver.java
/** * ?????????/*from w ww. j av a 2s .co m*/ * @param batchDescriptionClass ??? */ public void runTest(Class<? extends BatchDescription> batchDescriptionClass) { try { JobflowExecutor executor = new JobflowExecutor(driverContext); // ? executor.cleanWorkingDirectory(); // ???Excel??? storeDatabase(); setLastModifiedTimestamp(new Timestamp(0L)); // ??? BatchDriver batchDriver = BatchDriver.analyze(batchDescriptionClass); assertFalse(batchDriver.getDiagnostics().toString(), batchDriver.hasError()); File compileWorkDir = driverContext.getCompilerWorkingDirectory(); if (compileWorkDir.exists()) { FileUtils.forceDelete(compileWorkDir); } File compilerOutputDir = new File(compileWorkDir, "output"); File compilerLocalWorkingDir = new File(compileWorkDir, "build"); BatchInfo batchInfo = DirectBatchCompiler.compile(batchDescriptionClass, "test.batch", Location.fromPath(driverContext.getClusterWorkDir(), '/'), compilerOutputDir, compilerLocalWorkingDir, Arrays.asList(new File[] { DirectFlowCompiler.toLibraryPath(batchDescriptionClass) }), batchDescriptionClass.getClassLoader(), driverContext.getOptions()); for (JobflowInfo jobflowInfo : batchInfo.getJobflows()) { driverContext.prepareCurrentJobflow(jobflowInfo); executor.runJobflow(jobflowInfo); } // ???Excel??DB?? loadDatabase(); if (!testUtils.inspect()) { Assert.fail(testUtils.getCauseMessage()); } } catch (IOException e) { throw new RuntimeException(e); } finally { driverContext.cleanUpTemporaryResources(); } }
From source file:com.hp.autonomy.frontend.find.idol.configuration.IdolFindConfigFileServiceTest.java
@After public void tearDown() throws IOException { FileUtils.forceDelete(new File(TEST_DIR)); }
From source file:com.kegare.caveworld.plugin.mceconomy.MCEconomyPlugin.java
@Method(modid = MODID) public static void syncShopCfg() { if (shopCfg == null) { shopCfg = Config.loadConfig("shop"); } else {// w ww . j a va2s. c om ShopProductManager.instance().clearShopProducts(); } if (shopCfg.getCategoryNames().isEmpty()) { ShopProductManager.instance().addShopProduct(new ShopProduct(new ItemStack(Items.bread, 6), 30)); ShopProductManager.instance().addShopProduct(new ShopProduct(new ItemStack(Blocks.sapling, 1, 0), 15)); ShopProductManager.instance().addShopProduct(new ShopProduct(new ItemStack(Blocks.sapling, 1, 1), 15)); ShopProductManager.instance().addShopProduct(new ShopProduct(new ItemStack(Blocks.sapling, 1, 2), 15)); ShopProductManager.instance().addShopProduct(new ShopProduct(new ItemStack(Blocks.sapling, 1, 3), 15)); ShopProductManager.instance().addShopProduct(new ShopProduct(new ItemStack(Blocks.sapling, 1, 4), 18)); ShopProductManager.instance().addShopProduct(new ShopProduct(new ItemStack(Blocks.sapling, 1, 5), 18)); ShopProductManager.instance().addShopProduct(new ShopProduct(new ItemStack(Items.wheat_seeds, 10), 10)); ShopProductManager.instance().addShopProduct(new ShopProduct(new ItemStack(Items.bed), 100)); ShopProductManager.instance().addShopProduct(new ShopProduct(new ItemStack(Blocks.torch, 64), 50)); ShopProductManager.instance().addShopProduct(new ShopProduct(new ItemStack(Items.iron_sword), 100)); ShopProductManager.instance().addShopProduct(new ShopProduct(new ItemStack(Items.iron_pickaxe), 150)); ShopProductManager.instance().addShopProduct(new ShopProduct(new ItemStack(Items.iron_axe), 150)); ShopProductManager.instance().addShopProduct(new ShopProduct(new ItemStack(Items.iron_shovel), 50)); ShopProductManager.instance().addShopProduct(new ShopProduct(new ItemStack(Items.iron_hoe), 100)); if (Config.rope) { ShopProductManager.instance() .addShopProduct(new ShopProduct(new ItemStack(CaveBlocks.rope, 5), 10)); } } else { int i = 0; for (String name : shopCfg.getCategoryNames()) { if (NumberUtils.isNumber(name)) { ShopProductManager.instance().addShopProduct(null); } else ++i; } if (i > 0) { try { FileUtils.forceDelete(new File(shopCfg.toString())); ShopProductManager.instance().clearShopProducts(); shopCfg = null; syncShopCfg(); } catch (Exception e) { e.printStackTrace(); } } } if (shopCfg.hasChanged()) { shopCfg.save(); } }
From source file:Helpers.FileHelper.java
public void deleteDirectory(File path) { if (path.exists()) { try {//from www. j a va 2 s. c o m File f = path; FileUtils.cleanDirectory(f); //clean out directory (this is optional -- but good know) FileUtils.forceDelete(f); //delete directory FileUtils.forceMkdir(f); //create directory } catch (IOException e) { e.printStackTrace(); } } }
From source file:launcher.workflow.update.UpdateWorkflow.java
public static void begin(final Settings launcherCfg, final String license) { WorkflowStep prepare = new WorkflowStep("Preparing to launch the game", new WorkflowAction() { @Override//from w ww . j a va 2 s .co m public boolean act() { return true; } }); WorkflowStep checkLicense = new WorkflowStep("Checking to see if a license has been entered.", new WorkflowAction() { @Override public boolean act() throws Exception { if (license == null || license.isEmpty()) { LaunchLogger.error(LaunchLogger.Tab + "No valid license found."); return false; } WorkflowWindowManager.setProgressVisible(true); URL licenseCheckUrl = new URL(launcherCfg.licenseCall(license)); String response = IOUtils.toString(licenseCheckUrl.openStream()); WorkflowWindowManager.setProgressVisible(false); if (response.contains("true")) { LaunchLogger.info(LaunchLogger.Tab + "License is valid."); return true; } else { if (License.isCached()) { LaunchLogger .info("Invalid license was found. Deleting the locally cached license."); License.deleteCache(); return false; } } return false; } }); WorkflowStep checkVersion = new WorkflowStep("Checking for updates.", new WorkflowAction() { @Override public boolean act() throws Exception { File versionPath = new File("assets/data/version.dat"); String myVersion = "0.0.0"; if (versionPath.exists()) { myVersion = FileUtils.readFileToString(versionPath); LaunchLogger.info("Detected version: " + myVersion); } WorkflowWindowManager.setProgressVisible(true); URL versionCheckUrl = new URL(launcherCfg.versionCall(myVersion)); String result = IOUtils.toString(versionCheckUrl.openStream()); WorkflowWindowManager.setProgressVisible(false); if (result.contains("true")) { LaunchLogger.info(LaunchLogger.Tab + "Local copy of the game is out of date."); return true; } LaunchLogger.info(LaunchLogger.Tab + "Local copy of the game is up to date. No update required."); return false; } }); WorkflowStep downloadUpdate = new WorkflowStep("Preparing the update location", new WorkflowAction() { @Override public boolean act() throws Exception { if (UpdateWorkflowData.UpdateArchive.exists()) { FileUtils.forceDelete(UpdateWorkflowData.UpdateArchive); } int responseTimeoutMs = launcherCfg.responseTimeoutMilliseconds; int downloadTimeoutMs = launcherCfg.downloadTimeoutMilliseconds; LaunchLogger.info("Attempting to download an update using license: [" + license + "]"); WorkflowWindowManager.setProgressVisible(true); String downloadUrl = launcherCfg.downloadCall(license, "update"); LaunchLogger.info("Downloading latest stable edition"); FileUtils.copyURLToFile(new URL(downloadUrl), UpdateWorkflowData.UpdateArchive, responseTimeoutMs, downloadTimeoutMs); WorkflowWindowManager.setProgressVisible(false); LaunchLogger.info(LaunchLogger.Tab + "Update downloaded successfully."); return true; } }); WorkflowStep applyUpdate = new WorkflowStep("Unpacking update archive", new WorkflowAction() { @Override public boolean act() throws IOException { WorkflowWindowManager.setProgressVisible(true); Archive.unzip(UpdateWorkflowData.UpdateArchive, UpdateWorkflowData.UpdateWorkingDirectory); LaunchLogger.info("Replacing old content"); File game = new File(UpdateWorkflowData.UpdateWorkingDirectory + "/game.jar"); File gameTarget = new File("./"); LaunchLogger.info("Attempting to copy: " + game + " to " + gameTarget); FileUtils.copyFileToDirectory(game, gameTarget); File assets = new File(UpdateWorkflowData.UpdateWorkingDirectory + "/assets"); File assetsTarget = new File("./assets"); LaunchLogger.info("Attempting to copy: " + assets + " to " + assetsTarget); FileUtils.copyDirectory(assets, assetsTarget); WorkflowWindowManager.setProgressVisible(false); LaunchLogger.info(LaunchLogger.Tab + "Update applied successfully."); return true; } }); WorkflowStep clean = new WorkflowStep("Cleaning up temporary files", new WorkflowAction() { @Override public boolean act() throws IOException { if (UpdateWorkflowData.UpdateArchive.exists()) { FileUtils.forceDelete(UpdateWorkflowData.UpdateArchive); } if (UpdateWorkflowData.UpdateWorkingDirectory.exists()) { FileUtils.deleteDirectory(UpdateWorkflowData.UpdateWorkingDirectory); } return true; } }); prepare.setOnSuccess(checkLicense); checkLicense.setOnSuccess(checkVersion); checkVersion.setOnSuccess(downloadUpdate); downloadUpdate.setOnSuccess(applyUpdate); applyUpdate.setOnSuccess(clean); prepare.setOnFailure(clean); checkLicense.setOnFailure(clean); checkVersion.setOnFailure(clean); downloadUpdate.setOnFailure(clean); applyUpdate.setOnFailure(clean); prepare.execute(); }
From source file:gov.redhawk.sca.efs.tests.ScaFileStoreTest.java
/** * @throws java.lang.Exception/*from w ww.ja v a 2 s .c om*/ */ @After public void tearDown() throws Exception { this.fileSystem = null; this.rootFileStore = null; if (this.deleteFile != null && this.deleteFile.exists()) { if (!this.deleteFile.isDirectory()) { FileUtils.forceDelete(this.deleteFile); } else { FileUtils.deleteDirectory(this.deleteFile); } } if (this.inputStream != null) { this.inputStream.close(); this.inputStream = null; } if (this.outputStream != null) { this.outputStream.close(); this.outputStream = null; } }