Java Code Examples for org.codehaus.plexus.util.FileUtils#deleteDirectory()
The following examples show how to use
org.codehaus.plexus.util.FileUtils#deleteDirectory() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RawXJC2Mojo.java From maven-jaxb2-plugin with BSD 2-Clause "Simplified" License | 6 votes |
protected void setupDirectories() { final File generateDirectory = getGenerateDirectory(); if (getRemoveOldOutput() && generateDirectory.exists()) { try { FileUtils.deleteDirectory(this.getGenerateDirectory()); } catch (IOException ex) { getLog().warn("Failed to remove old generateDirectory [" + generateDirectory + "].", ex); } } // Create the destination path if it does not exist. if (generateDirectory != null && !generateDirectory.exists()) { generateDirectory.mkdirs(); } final File episodeFile = getEpisodeFile(); if (getEpisode() && episodeFile != null) { final File parentFile = episodeFile.getParentFile(); parentFile.mkdirs(); } }
Example 2
Source File: DirectoryWatcherTest.java From directory-watcher with Apache License 2.0 | 6 votes |
@Test public void validateOsxDirectoryWatcherNoHashing() throws Exception { Assume.assumeTrue(System.getProperty("os.name").toLowerCase().contains("mac")); File directory = new File(new File("").getAbsolutePath(), "target/directory"); FileUtils.deleteDirectory(directory); directory.mkdirs(); runWatcher( directory.toPath(), new MacOSXListeningWatchService( new MacOSXListeningWatchService.Config() { @Override public FileHasher fileHasher() { return null; } }), false); }
Example 3
Source File: MonkeyTest.java From tomee with Apache License 2.0 | 6 votes |
@Test public void run() throws Exception { final File tomee = prepareProject(); try { invoke(tomee); // invalid, should fail } catch (final ClassFormatError cfe) { // ok, we created an invalid jar } new Monkey(tomee).run(); final File[] libs = new File(tomee, "lib").listFiles(new FilenameFilter() { @Override public boolean accept(final File dir, final String name) { return name.endsWith(".jar"); } }); assertEquals(1, libs.length); final File jar = libs[0]; assertTrue(jar.getName().contains("tomee-monkey-")); assertEquals(2, invoke(tomee)); FileUtils.deleteDirectory(tomee.getParentFile().getParentFile()); }
Example 4
Source File: DefaultIOUtil.java From webstart with MIT License | 6 votes |
/** * {@inheritDoc} */ public void removeDirectory( File dir ) throws MojoExecutionException { if ( dir != null ) { if ( dir.exists() && dir.isDirectory() ) { getLogger().debug( "Deleting directory " + dir.getAbsolutePath() ); try { FileUtils.deleteDirectory( dir ); } catch ( IOException e ) { throw new MojoExecutionException( "Could not delete directory: " + dir, e ); } } } }
Example 5
Source File: AbstractAppAssemblerMojo.java From appassembler with MIT License | 6 votes |
protected void removeDirectory( File directory ) throws MojoExecutionException { if ( directory.exists() ) { try { this.getLog().info( "Removing " + directory ); FileUtils.deleteDirectory( directory ); } catch ( IOException e ) { throw new MojoExecutionException( e.getMessage(), e ); } } }
Example 6
Source File: CompilerMojoTestBase.java From aspectj-maven-plugin with MIT License | 5 votes |
/** * Clean up targetarea after a testcase is run. * So we make shure, we don't get sideeffects between testruns. */ protected void tearDown() throws Exception { super.tearDown(); try { FileUtils.deleteDirectory( project.getBuild().getDirectory() ); } catch ( Exception ex ) { ;// Only a problem on windows. we really do not care.. if we cant delete the file // It is probably not there } }
Example 7
Source File: BasicSupport.java From ci.maven with Apache License 2.0 | 5 votes |
protected void deleteApplication(File parent, String filename) throws IOException { File application = new File(parent, filename); if (application.isDirectory()) { // application can be installed with expanded format FileUtils.deleteDirectory(application); } else { application.delete(); } }
Example 8
Source File: CLIEmbedServerTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Test public void testLogDirProperty() throws IOException, InterruptedException { String currBaseDir = null; final String newStandalone = "CLIEmbedServerTestCaseStandaloneTmp"; assertFalse(cli.isConnected()); try { // save the current value currBaseDir = WildFlySecurityManager.getPropertyPrivileged(JBOSS_SERVER_BASE_DIR, null); CLIEmbedUtil.copyServerBaseDir(ROOT, "standalone", newStandalone, true); String newBaseDir = ROOT + File.separator + newStandalone; setProperties(newBaseDir); String line = "embed-server --std-out=echo " + JBOSS_HOME; cli.sendLine(line); assertTrue(cli.isConnected()); assertPath(JBOSS_SERVER_BASE_DIR, ROOT + File.separator + newStandalone); assertPath(JBOSS_SERVER_CONFIG_DIR, ROOT + File.separator + newStandalone + File.separator + "configuration"); assertPath(JBOSS_SERVER_DATA_DIR, ROOT + File.separator + newStandalone + File.separator + "data"); assertPath(JBOSS_SERVER_LOG_DIR, ROOT + File.separator + newStandalone + File.separator + "log"); assertPath(JBOSS_SERVER_TEMP_DIR, ROOT + File.separator + newStandalone + File.separator + "tmp"); assertPath(JBOSS_CONTROLLER_TEMP_DIR, ROOT + File.separator + newStandalone + File.separator + "tmp"); } finally { cli.sendLine("stop-embedded-server"); // restore the original setProperties(currBaseDir); FileUtils.deleteDirectory(new File(ROOT + File.separator + newStandalone)); } }
Example 9
Source File: RemoveLocalArtifactMojo.java From build-helper-maven-plugin with MIT License | 5 votes |
public void execute() throws MojoFailureException { File localArtifactFile = new File( localRepository.getBasedir(), localRepository.pathOf( project.getArtifact() ) ); File localArtifactDirectory = localArtifactFile.getParentFile(); if ( removeAll ) { localArtifactDirectory = localArtifactDirectory.getParentFile(); } try { FileUtils.deleteDirectory( localArtifactDirectory ); if ( getLog().isInfoEnabled() ) { getLog().info( localArtifactDirectory.getAbsolutePath() + " removed." ); } } catch ( IOException e ) { final String failureMessage = "Cannot delete " + localArtifactDirectory; if ( failOnError ) { throw new MojoFailureException( failureMessage ); } else { getLog().warn( failureMessage ); } } }
Example 10
Source File: GitWagon.java From opoopress with Apache License 2.0 | 5 votes |
private void removeCheckoutDirectory() throws ConnectionException { if (checkoutDirectory == null) { return; // Silently return. } try { FileUtils.deleteDirectory(checkoutDirectory); } catch (IOException e) { throw new ConnectionException("Unable to cleanup checkout directory", e); } }
Example 11
Source File: NativeSourcesTest.java From maven-native with MIT License | 5 votes |
@Override protected void setUp() throws Exception { super.setUp(); workDirectory = new File( getBasedir(), "/target/NativeSourceTest" ); if ( workDirectory.exists() ) { FileUtils.deleteDirectory( workDirectory ); } workDirectory.mkdirs(); }
Example 12
Source File: GolangCleanMojo.java From mvn-golang with Apache License 2.0 | 5 votes |
private void deleteStoreFolder() throws MojoFailureException { try { final File goStoreFolder = new File(getStoreFolder()); if (goStoreFolder.isDirectory()) { getLog().info("Deleting the Store Folder : " + goStoreFolder); FileUtils.deleteDirectory(goStoreFolder); } else { getLog().info("The Store Folder does not found : " + goStoreFolder); } } catch (IOException ex) { throw new MojoFailureException("Can't delete the Store Folder", ex); } }
Example 13
Source File: DirectoryWatcherTest.java From directory-watcher with Apache License 2.0 | 5 votes |
@Test public void validateJdkDirectoryWatcher() throws Exception { // The JDK watch service is basically unusable on mac since it polls every 10s Assume.assumeFalse(System.getProperty("os.name").toLowerCase().contains("mac")); File directory = new File(new File("").getAbsolutePath(), "target/directory"); FileUtils.deleteDirectory(directory); directory.mkdirs(); runWatcher(directory.toPath(), FileSystems.getDefault().newWatchService()); }
Example 14
Source File: AnnotationProcessingTest.java From takari-lifecycle with Eclipse Public License 1.0 | 5 votes |
@Test public void testProc_nonIncrementalProcessor() throws Exception { Assume.assumeTrue(CompilerJdt.ID.equals(compilerId)); File processor = compileAnnotationProcessor(); File basedir = resources.getBasedir("compile-proc/proc"); File target = new File(basedir, "target"); processAnnotations(basedir, Proc.proc, processor, newProcessors("processor.NonIncrementalProcessor")); mojos.assertBuildOutputs(target, // "classes/proc/Source.class", // "generated-sources/annotations/proc/NonIncrementalSource.java", // "classes/proc/NonIncrementalSource.class"); FileUtils.deleteDirectory(target); processAnnotations(basedir, Proc.only, processor, newProcessors("processor.NonIncrementalProcessor")); mojos.assertBuildOutputs(target, // "generated-sources/annotations/proc/NonIncrementalSource.java"); FileUtils.deleteDirectory(target); processAnnotations(basedir, Proc.proc, processor, newProcessors("processor.NonIncrementalProcessor")); mojos.assertBuildOutputs(target, // "classes/proc/Source.class", // "generated-sources/annotations/proc/NonIncrementalSource.java", // "classes/proc/NonIncrementalSource.class"); FileUtils.deleteDirectory(target); processAnnotations(basedir, Proc.only, processor, newProcessors("processor.NonIncrementalProcessor")); mojos.assertBuildOutputs(target, // "generated-sources/annotations/proc/NonIncrementalSource.java"); }
Example 15
Source File: DirectoryWatcherTest.java From directory-watcher with Apache License 2.0 | 5 votes |
@Test public void validateOsxDirectoryWatcherRelativePath() throws Exception { Assume.assumeTrue(System.getProperty("os.name").toLowerCase().contains("mac")); File directory = new File(new File("").getAbsolutePath(), "target/directory"); FileUtils.deleteDirectory(directory); directory.mkdirs(); runWatcher(Paths.get("target/directory"), new MacOSXListeningWatchService()); }
Example 16
Source File: DirectoryWatcherTest.java From directory-watcher with Apache License 2.0 | 5 votes |
@Test public void validateOsxDirectoryWatcher() throws Exception { Assume.assumeTrue(System.getProperty("os.name").toLowerCase().contains("mac")); File directory = new File(new File("").getAbsolutePath(), "target/directory"); FileUtils.deleteDirectory(directory); directory.mkdirs(); runWatcher(directory.toPath(), new MacOSXListeningWatchService()); }
Example 17
Source File: DirectoryWatcherTest.java From directory-watcher with Apache License 2.0 | 5 votes |
@Test public void validateOsxWatchKeyOverflow() throws Exception { Assume.assumeTrue(System.getProperty("os.name").toLowerCase().contains("mac")); File directory = new File(new File("").getAbsolutePath(), "target/directory"); FileUtils.deleteDirectory(directory); directory.mkdirs(); MacOSXListeningWatchService service = new MacOSXListeningWatchService(); MacOSXWatchKey key = new MacOSXWatchKey(service, ImmutableList.of(ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY), 16); int totalEvents = 0; for (int i = 0; i < 10; i++) { Path toSignal = Paths.get(directory.toPath().toAbsolutePath().toString() + "/" + i); key.signalEvent(ENTRY_CREATE, toSignal); key.signalEvent(ENTRY_MODIFY, toSignal); key.signalEvent(ENTRY_DELETE, toSignal); totalEvents += 3; } int overflowCount = 0; List<WatchEvent<?>> events = key.pollEvents(); for (WatchEvent<?> event : events) { if (event.kind() == OVERFLOW) { overflowCount = event.count(); break; } } assertTrue("OVERFLOW event must exist", overflowCount > 0); assertTrue( "Overflow count must equal number of missing events", totalEvents == events.size() + overflowCount - 1); }
Example 18
Source File: NexusRepositoryIndexerImpl.java From netbeans with Apache License 2.0 | 4 votes |
/** * Uses {@link Scanner} to scan repository content. A {@link ArtifactScanningListener} is used to process found * artifacts and to add them to the index using * {@link NexusIndexer#artifactDiscovered(ArtifactContext, IndexingContext)}. * * @see DefaultScannerListener * @see #artifactDiscovered(ArtifactContext, IndexingContext) */ private void scan( final IndexingContext context, final String fromPath, final ArtifactScanningListener listener, final boolean update ) throws IOException { final File repositoryDirectory = context.getRepository(); if ( repositoryDirectory == null ) { // nothing to scan return; } if ( !repositoryDirectory.exists() ) { throw new IOException( "Repository directory " + repositoryDirectory + " does not exist" ); } // always use cache directory when reindexing final File tmpDir = new File(Places.getCacheDirectory(), "tmp-" + context.getRepositoryId()); if ( !tmpDir.mkdirs() ) { throw new IOException( "Cannot create temporary directory: " + tmpDir ); } final File tmpFile = new File(tmpDir, context.getId() + "-tmp"); IndexingContext tmpContext = null; try { final FSDirectory directory = FSDirectory.open( tmpDir.toPath() ); if ( update ) { IndexUtils.copyDirectory( context.getIndexDirectory(), directory ); } tmpContext = new DefaultIndexingContext( context.getId() + "-tmp", // context.getRepositoryId(), // context.getRepository(), // directory, // context.getRepositoryUrl(), // context.getIndexUpdateUrl(), // context.getIndexCreators(), // true ); scanner.scan( new ScanningRequest( tmpContext, // new DefaultScannerListener( tmpContext, embedder.lookup(IndexerEngine.class), update, listener ), fromPath ) ); tmpContext.updateTimestamp( true ); context.replace( tmpContext.getIndexDirectory() ); } catch ( Exception ex ) { throw new IOException("Error scanning context " + context.getId() + ": " + ex, ex); } finally { if ( tmpContext != null ) { tmpContext.close( true ); } if ( tmpFile.exists() ) { tmpFile.delete(); } FileUtils.deleteDirectory( tmpDir ); } }
Example 19
Source File: CLIEmbedServerTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
@Test public void testBaseDir() throws IOException, InterruptedException { String currBaseDir = null; final String newStandalone = "CLIEmbedServerTestCaseStandaloneTmp"; assertFalse(cli.isConnected()); try { // save the current value currBaseDir = WildFlySecurityManager.getPropertyPrivileged(JBOSS_SERVER_BASE_DIR, null); CLIEmbedUtil.copyServerBaseDir(ROOT, "standalone", newStandalone, true); //CLIEmbedUtil.copyConfig(ROOT, newStandalone, "logging.properties.backup", "logging.properties", false); String newBaseDir = ROOT + File.separator + newStandalone; setProperties(newBaseDir); String line = "embed-server --std-out=echo " + JBOSS_HOME; cli.sendLine(line); assertTrue(cli.isConnected()); assertPath(JBOSS_SERVER_BASE_DIR, ROOT + File.separator + newStandalone); assertPath(JBOSS_SERVER_CONFIG_DIR, ROOT + File.separator + newStandalone + File.separator + "configuration"); assertPath(JBOSS_SERVER_DATA_DIR, ROOT + File.separator + newStandalone + File.separator + "data"); assertPath(JBOSS_SERVER_LOG_DIR, ROOT + File.separator + newStandalone + File.separator + "log"); assertPath(JBOSS_SERVER_TEMP_DIR, ROOT + File.separator + newStandalone + File.separator + "tmp"); assertPath(JBOSS_CONTROLLER_TEMP_DIR, ROOT + File.separator + newStandalone + File.separator + "tmp"); cli.sendLine("/system-property=" + newStandalone + ":add(value=" + newStandalone +")"); assertProperty(newStandalone, newStandalone, false); // WFCORE-1187, when this overrides logging.properties correctly, we can check this // for now it will refer to the previously persisted log file in standalone/configuration/logging.properties //File f = new File(ROOT + File.separator + newStandalone + File.separator + "log" + File.separator + "server.log"); //assertTrue(f.exists()); //assertTrue(f.length() > 0); // stop the hc, and restart it with default properties cli.sendLine("stop-embedded-server"); setProperties(null); cli.sendLine(line); assertTrue(cli.isConnected()); // shouldn't be set assertProperty(newStandalone, null, true); cli.sendLine("stop-embedded-server"); setProperties(newBaseDir); cli.sendLine(line); assertTrue(cli.isConnected()); assertProperty(newStandalone, newStandalone, false); } finally { cli.sendLine("stop-embedded-server"); // restore the original setProperties(currBaseDir); FileUtils.deleteDirectory(new File(ROOT + File.separator + newStandalone)); } }
Example 20
Source File: AbstractDaemonGeneratorTest.java From appassembler with MIT License | 2 votes |
public void runTest( String generatorId, String pom, String descriptor, String outputPath ) throws Exception { File outputDir = getTestFile( outputPath ); DaemonGenerator generator = (DaemonGenerator) lookup( DaemonGenerator.ROLE, generatorId ); // ----------------------------------------------------------------------- // Build the MavenProject instance // ----------------------------------------------------------------------- MavenProjectBuilder projectBuilder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE ); MavenSettingsBuilder settingsBuilder = (MavenSettingsBuilder) lookup( MavenSettingsBuilder.ROLE ); Settings settings = settingsBuilder.buildSettings(); ArtifactRepositoryFactory artifactRepositoryFactory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE ); String localRepoUrl = new File( settings.getLocalRepository() ).toURL().toExternalForm(); ArtifactRepository localRepository = artifactRepositoryFactory.createDeploymentArtifactRepository( "local", localRepoUrl, new DefaultRepositoryLayout(), false ); ProfileManager profileManager = new DefaultProfileManager( getContainer() ); File tempPom = createFilteredFile( pom ); MavenProject project = projectBuilder.buildWithDependencies( tempPom, localRepository, profileManager ); // ----------------------------------------------------------------------- // Clean the output directory // ----------------------------------------------------------------------- FileUtils.deleteDirectory( outputDir ); FileUtils.forceMkdir( outputDir ); // ----------------------------------------------------------------------- // // ----------------------------------------------------------------------- DaemonGeneratorService daemonGeneratorService = (DaemonGeneratorService) lookup( DaemonGeneratorService.ROLE ); Daemon model = daemonGeneratorService.loadModel( getTestFile( descriptor ) ); generator.generate( new DaemonGenerationRequest( model, project, localRepository, outputDir, "bin" ) ); }