List of usage examples for org.apache.commons.io FileUtils cleanDirectory
public static void cleanDirectory(File directory) throws IOException
From source file:com.github.ipaas.ideploy.agent.util.SVNUtil.java
/** * ??"?"/*from w w w . j av a 2 s. c o m*/ * @param repository * @param remoteRoot * @param logs * @param savePath * @throws Exception */ private static void getDelta4Add(SVNRepository repository, String remoteRoot, Collection<SVNLog> logs, String savePath) throws Exception { SVNNodeKind nodeKind = null; if (logs == null || logs.isEmpty()) { return; } File localRoot = new File(savePath); // if (localRoot.exists()) { FileUtils.cleanDirectory(localRoot); } else { localRoot.mkdirs(); } String remotePath = null; String localPath = null; File localEntry = null; for (SVNLog l : logs) { if (l.getType() == SVNLog.TYPE_DEL) { continue; } remotePath = remoteRoot + l.getPath(); localPath = savePath + l.getPath(); nodeKind = repository.checkPath(remotePath, l.getRevision()); if (nodeKind == SVNNodeKind.DIR) { localEntry = new File(localPath); if (!localEntry.exists()) { localEntry.mkdirs(); } } if (nodeKind == SVNNodeKind.FILE) { localEntry = new File(localPath); getFile(repository, remotePath, localEntry, l.getRevision()); } } }
From source file:com.ibm.util.merge.IntegrationTestingCsvProvider.java
@After public void teardown() throws IOException { FileUtils.cleanDirectory(outputDir); }
From source file:com.att.aro.core.fileio.impl.FileManagerImpl.java
@Override public boolean directoryDeleteInnerFiles(String directoryPath) { if ((Util.isWindowsOS() && ("C:\\".equals(directoryPath) || "C:".equals(directoryPath))) || "/".equals(directoryPath)) { logger.error("Illegal attempt to delete files in " + directoryPath); return false; }//from w ww. j a va 2 s . c o m try { File directory = new File(directoryPath); if (!directory.exists()) { return false; } FileUtils.cleanDirectory(directory); } catch (IOException ex) { return false; } return true; }
From source file:biz.gabrys.lesscss.extended.compiler.storage.DataStorageImpl.java
/** * {@inheritDoc}//from w w w .j av a2s . co m * @throws DataStorageException if an I/O error occurred. * @since 1.0 */ public void deleteAll() { synchronized (mutex) { try { FileUtils.cleanDirectory(directory); } catch (final IOException e) { throw new DataStorageException(e); } } }
From source file:com.withbytes.tentaculo.traverser.windows.WindowsTraverserTest.java
/** * Test of backup method, of class WindowsTraverser. *///from w w w .java 2s.c om @Test public void testBackup() throws Exception { //Create folder to use as destination File destination = new File(TestsConfiguration.RESOURCES_PATH + "test"); destination.delete(); destination.mkdir(); IPathTranslator translator = mock(WindowsPathTranslator.class); WindowsTraverser instance = new WindowsTraverser(); File probe; //Test cases String sourceFile = TestsConfiguration.RESOURCES_PATH + "two\\2.yml"; String sourceDirectory = TestsConfiguration.RESOURCES_PATH + "two"; String sourceNonExistant = TestsConfiguration.RESOURCES_PATH + "falsepath"; when(translator.translatePath(anyString())).thenReturn(sourceFile).thenReturn(sourceDirectory) .thenReturn(sourceNonExistant); //Checking file copy assertEquals(true, instance.backup(sourceFile, translator, destination.getAbsolutePath())); probe = new File(destination.getAbsolutePath(), "2.yml"); assertEquals(true, probe.exists()); FileUtils.cleanDirectory(destination); //Checking directory copy assertEquals(true, instance.backup(sourceDirectory, translator, destination.getAbsolutePath())); probe = new File(destination.getAbsolutePath(), "two"); assertEquals(true, probe.exists()); probe = new File(destination.getAbsolutePath(), "two\\1.yml"); assertEquals(true, probe.exists()); FileUtils.cleanDirectory(destination); //Checking source doesn't exists assertEquals(false, instance.backup(sourceNonExistant, translator, destination.getAbsolutePath())); assertEquals(0, FileUtils.sizeOfDirectory(destination)); //Verify mock verify(translator, times(3)).translatePath(anyString()); //Remove existent destination folder and files FileUtils.deleteQuietly(destination); }
From source file:com.codejumble.opentube.downloader.DownloadManager.java
@Override protected Object doInBackground() throws Exception { try {/*from ww w .ja v a 2s.c o m*/ logger.info("Starting the download queue..."); for (int i = 0; i < downloads.size(); i++) { logger.info("Starting download number {}", i); currentOnGoingDownload = i + 1;// We want to show 1/1, not 0/0 Download e = downloads.get(i); //Update status mainFrame.changeStatus("Downloading"); mainFrame.updateDownloadQueueStatus(currentOnGoingDownload, downloadQueueSize); e.addPropertyChangeListener(mainFrame); //And start downloading in another thread e.execute(); //Refresh the progress every 800 ms while (e.getProgress() < 100) { e.refreshProgress(); try { Thread.sleep(800); } catch (InterruptedException ex) { //TODO } } //TODO format converting // if (!e.getEndFormat().equals("mp4")) { // //if conversion needs to be performed // mainFrame.changeStatus("Converting"); // String tmp = e.getTargetFile().getAbsolutePath(); // String tmp2 = tmpFolder.getAbsolutePath() + File.separator + e.getTargetFile().getName().replace("mp4", e.getEndFormat()); // // IMediaReader reader = ToolFactory.makeReader(tmp); // reader.addListener(ToolFactory.makeWriter(tmp2, reader)); // while (reader.readPacket() == null) // ; // } //Move downloaded file to final destination logger.info("Moving file to downloads folder..."); mainFrame.changeStatus("Locating"); File currentDownload = e.getTargetFile(); FileUtils.copyFile(currentDownload, new File(downloadFolder + File.separator + currentDownload.getName())); //Clear tmp folder logger.info("Cleaning cached elements"); FileUtils.cleanDirectory(tmpFolder); } } catch (Exception e) { } downloads.clear(); return null; }
From source file:controller.servlet.AllDataDelete.java
/** * Mtodo deleteServerFiles, permite eliminar los ficheros del servidor. *///from w w w. j a v a 2s.com private void deleteServerFiles() { // Bsqueda y borrado de los ficheros en las carpetas del servidor. String path = this.getServletContext().getRealPath(""); path += File.separator + Path.UPLOADEDFILES_FOLDER; File directory = new File(path); if (directory.exists()) { try { FileUtils.cleanDirectory(directory); try { Files.delete(Paths.get(path)); } catch (IOException ex) { Logger.getLogger(AllDataDelete.class.getName()).log(Level.SEVERE, null, ex); } } catch (IOException ex) { Logger.getLogger(AllDataDelete.class.getName()).log(Level.SEVERE, null, ex); } } path = this.getServletContext().getRealPath(""); path += File.separator + Path.POIS_FOLDER; directory = new File(path); if (directory.exists()) { try { FileUtils.cleanDirectory(directory); try { Files.delete(Paths.get(path)); } catch (IOException ex) { Logger.getLogger(AllDataDelete.class.getName()).log(Level.SEVERE, null, ex); } } catch (IOException ex) { Logger.getLogger(AllDataDelete.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:com.agiletec.plugins.jpavatar.apsadmin.avatar.TestAvatarAction.java
@Override protected void tearDown() throws Exception { FileUtils.cleanDirectory(new File(this._avatarManager.getAvatarDiskFolder() + "avatar")); super.tearDown(); }
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>//from www .j a v 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.agiletec.plugins.jpavatar.aps.system.services.avatar.TestAvatarManager.java
@Override protected void tearDown() throws Exception { super.tearDown(); FileUtils.cleanDirectory(new File(this._avatarManager.getAvatarDiskFolder() + "avatar")); this._userManager.removeUser("jpavatarTestUser"); }