Java Code Examples for org.apache.commons.io.FileUtils#deleteDirectory()

The following examples show how to use org.apache.commons.io.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: SpringDataSourceExtractionTest.java    From windup with Eclipse Public License 1.0 7 votes vote down vote up
private void startWindup(String xmlFilePath, GraphContext context) throws IOException
{
    ProjectModel pm = context.getFramed().addFramedVertex(ProjectModel.class);
    pm.setName("Main Project");
    FileModel inputPath = context.getFramed().addFramedVertex(FileModel.class);
    inputPath.setFilePath(xmlFilePath);

    Path outputPath = Paths.get(FileUtils.getTempDirectory().toString(), "windup_"
                + UUID.randomUUID().toString());
    FileUtils.deleteDirectory(outputPath.toFile());
    Files.createDirectories(outputPath);

    pm.addFileModel(inputPath);
    pm.setRootFileModel(inputPath);
    WindupConfiguration windupConfiguration = new WindupConfiguration()
                .setGraphContext(context);
    windupConfiguration.addInputPath(Paths.get(inputPath.getFilePath()));
    windupConfiguration.setOutputDirectory(outputPath);
    processor.execute(windupConfiguration);
}
 
Example 2
Source File: TomcatTestCase.java    From sqoop-on-spark with Apache License 2.0 7 votes vote down vote up
@BeforeMethod(alwaysRun = true)
public void startServer() throws Exception {
	// Get and set temporary path in hadoop cluster.
	tmpPath = HdfsUtils.joinPathFragments(TMP_PATH_BASE, getClass()
			.getName(), name);
	FileUtils.deleteDirectory(new File(tmpPath));

	LOG.debug("Temporary Directory: " + tmpPath);

	// Start server
	cluster = createSqoopMiniCluster();
	cluster.start();

	// Initialize Sqoop Client API
	client = new SqoopClient(getServerUrl());
}
 
Example 3
Source File: XMLConfigurationProviderTest.java    From walkmod-core with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void testAddConfigurationParameterWithoutChain() throws Exception {
   AddTransformationCommand command = new AddTransformationCommand("imports-cleaner", null, false, null, null, null,
         null, false);

   File aux = new File("src/test/resources/xmlparams");
   aux.mkdirs();
   File xml = new File(aux, "walkmod.xml");
   XMLConfigurationProvider prov = new XMLConfigurationProvider(xml.getPath(), false);
   try {
      prov.createConfig();

      TransformationConfig transfCfg = command.buildTransformationCfg();
      prov.addTransformationConfig(null, null, transfCfg, false, null, null);

      prov.addConfigurationParameter("testParam", "hello", "imports-cleaner", null, null, null, false);

      String output = FileUtils.readFileToString(xml);
      System.out.println(output);

      Assert.assertTrue(output.contains("testParam") && output.contains("hello"));
   } finally {
      FileUtils.deleteDirectory(aux);
   }
}
 
Example 4
Source File: MiniKafkaCluster.java    From AthenaX with Apache License 2.0 5 votes vote down vote up
@Override
public void close() throws IOException {
  for (KafkaServer s : kafkaServer) {
    s.shutdown();
  }
  this.zkServer.close();
  FileUtils.deleteDirectory(tempDir.toFile());
}
 
Example 5
Source File: CoreUtils.java    From TranskribusCore with GNU General Public License v3.0 5 votes vote down vote up
public static void deleteDir(File dir) {
	if (dir != null) {
		logger.debug("deleting dir: " + dir.getAbsolutePath());
		try {
			FileUtils.deleteDirectory(dir);
		} catch (IOException e) {
			logger.error("Error deleting directory: " + e.getMessage(), e);
		}
	}
}
 
Example 6
Source File: ContractsSwaggerUIGeneratorTest.java    From servicecomb-toolkit with Apache License 2.0 5 votes vote down vote up
@Test
public void testContractTransferToSwaggerUI() throws IOException {

  InputStream in = ContractsSwaggerUIGeneratorTest.class.getClassLoader().getResourceAsStream("HelloEndPoint.yaml");

  StringBuilder sb = new StringBuilder();
  byte[] bytes = new byte[1024];
  int len = -1;
  while ((len = in.read(bytes)) != -1) {
    sb.append(new String(bytes, 0, len));
  }

  OpenAPIParser openAPIParser = new OpenAPIParser();
  SwaggerParseResult swaggerParseResult = openAPIParser.readContents(sb.toString(), null, null);

  Path tempDir = Files.createTempDirectory(null);
  Path outputPath = Paths.get(tempDir.toFile().getAbsolutePath()
      + File.separator + "swagger-ui.html");
  DocGenerator docGenerator = GeneratorFactory.getGenerator(DocGenerator.class, "default");
  Map<String, Object> docGeneratorConfig = new HashMap<>();
  docGeneratorConfig.put("contractContent", swaggerParseResult.getOpenAPI());
  docGeneratorConfig.put("outputPath", outputPath.toFile().getCanonicalPath());
  Objects.requireNonNull(docGenerator).configure(docGeneratorConfig);
  docGenerator.generate();

  Assert.assertTrue(Files.exists(outputPath));
  FileUtils.deleteDirectory(tempDir.toFile());
}
 
Example 7
Source File: ImportWorker.java    From magarena with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Delete "players" folder and replace with imported copy.
 */
private void importPlayerProfiles() throws IOException {
    setProgressNote(MText.get(_S8));
    final String directoryName = "players";
    final Path targetPath = MagicFileSystem.getDataPath().resolve(directoryName);
    FileUtils.deleteDirectory(targetPath.toFile());
    final Path sourcePath = importDataPath.resolve(directoryName);
    if (sourcePath.toFile().exists()) {
        FileUtils.copyDirectory(sourcePath.toFile(), targetPath.toFile());
        PlayerProfiles.refreshMap();
    }
    setProgressNote(OK_STRING);
}
 
Example 8
Source File: RedshiftJdbcTransactionalOperatorTest.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
@Override
protected void finished(Description description)
{
  try {
    FileUtils.deleteDirectory(new File(baseDirectory));
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}
 
Example 9
Source File: ParallelCallbackTest.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
/**
 * Tests sync where a directory exists with a matching name to an existing file in depot
 *
 * @throws Exception
 */
@Test
public void syncWithDirectoryMatchingDepotFile() throws Exception {
	String clientName = "test-client-duplicate-dir";
	String clientRoot = p4d.getPathToRoot() + "/" + clientName;

	String[] paths = {"//depot/basic/... //" + clientName + "/..."};

	FileUtils.deleteDirectory(new File(clientRoot));

	IClient testClient = Client.newClient(server, clientName, "testing parallel sync", clientRoot, paths);
	server.createClient(testClient);

	IClient testClientFromServer = server.getClient(clientName);
	Assert.assertNotNull(testClientFromServer);

	server.setCurrentClient(testClientFromServer);

	boolean pathExists = Files.exists(Paths.get(clientRoot));
	Assert.assertEquals(false, pathExists);

	// creates client workspace
	Files.createDirectories(Paths.get(clientRoot));

	//Create directory with a matching name to a depot file and the it should fail.
	createDirectory(clientRoot, "/readonly/sync/p4cmd/src/gnu/getopt/Getopt.java/foo");

	ParallelSyncOptions poptions = new ParallelSyncOptions(0, 0, 1, 1, 4, null);
	SyncOptions syncOptions = new SyncOptions();
	List<IFileSpec> fileSpec = FileSpecBuilder.makeFileSpecList("//depot/basic/...");
	List<IFileSpec> resultSpec = testClientFromServer.syncParallel(fileSpec, syncOptions, poptions);
	Assert.assertNotNull(resultSpec);
	Assert.assertTrue(resultSpec.size() > 10);
	assertFileSpecError(resultSpec);
}
 
Example 10
Source File: HBaseTestCase.java    From aliyun-maxcompute-data-collectors with Apache License 2.0 5 votes vote down vote up
public void shutdown() throws Exception {
  LOG.info("In shutdown() method");
  if (null != hbaseTestUtil) {
    LOG.info("Shutting down HBase cluster");
    hbaseCluster.shutdown();
    zookeeperCluster.shutdown();
    hbaseTestUtil = null;
  }
  FileUtils.deleteDirectory(new File(workDir));
  LOG.info("shutdown() method returning.");
}
 
Example 11
Source File: RealtimeClusterIntegrationTest.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
@AfterClass
public void tearDown()
    throws Exception {
  dropRealtimeTable(getTableName());
  stopServer();
  stopBroker();
  stopController();
  stopKafka();
  stopZk();
  FileUtils.deleteDirectory(_tempDir);
}
 
Example 12
Source File: BOMResolver.java    From camel-spring-boot with Apache License 2.0 4 votes vote down vote up
private void cleanupLocalRepo() throws IOException {
    File f = new File(LOCAL_REPO);
    if (f.exists()) {
        FileUtils.deleteDirectory(f);
    }
}
 
Example 13
Source File: FileStore.java    From molgenis with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void deleteDirectory(String dirName) throws IOException {
  FileUtils.deleteDirectory(getFileUnchecked(dirName));
}
 
Example 14
Source File: CubeHFileMapper2Test.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
@After
public void after() throws Exception {
    cleanupTestMetadata();
    FileUtils.deleteDirectory(new File("../job/meta"));
}
 
Example 15
Source File: InboundEndpointContentTypePlainTest.java    From product-ei with Apache License 2.0 4 votes vote down vote up
@BeforeClass(alwaysRun = true)
public void setEnvironment() throws Exception {

 pathToFtpDir = getESBResourceLocation() + File.separator + "synapseconfig" + File.separator + "vfsTransport";

    InboundFileFolder = new File(pathToFtpDir + File.separator + "InboundFileFolder");

    // create InboundFileFolder if not exists
    if (InboundFileFolder.exists()) {
        FileUtils.deleteDirectory(InboundFileFolder);
    }
    Assert.assertTrue(InboundFileFolder.mkdir(), "InboundFileFolder not created");


    super.init();

    logViewerClient = new LogViewerClient(contextUrls.getBackEndUrl(),
            getSessionCookie());

}
 
Example 16
Source File: Job092308.java    From p4ic4idea with Apache License 2.0 4 votes vote down vote up
/**
 * Unicode enabled server:
 *
 * File added with BOM and type 'unicode', expect no-BOM when sync with CHARSET set to 'utf8'
 *
 * @throws Exception
 */
@Test
public void testUnicodeCharsetUTF8nobom() throws Exception {

	server.setCharsetName("utf8");

	// Add Source file to depot
	client = server.getCurrentClient();
	IChangelist change = new Changelist();
	change.setDescription("Add foo.txt");
	change = client.createChangelist(change);

	// ... copy from resource to workspace
	File from = loadFileFromClassPath(CLASS_PATH_PREFIX + "/utf8_with_bom_unix_lineending.txt");
	File testFile = new File(client.getRoot() + File.separator + "unicode.txt");
	Files.copy(from.toPath(), testFile.toPath());

	// ... add to pending change
	List<IFileSpec> fileSpecs = FileSpecBuilder.makeFileSpecList(testFile.getAbsolutePath());
	AddFilesOptions addOpts = new AddFilesOptions();
	addOpts.setFileType("unicode");
	addOpts.setChangelistId(change.getId());
	List<IFileSpec> msg = client.addFiles(fileSpecs, addOpts);
	assertNotNull(msg);
	assertEquals(FileSpecOpStatus.VALID, msg.get(0).getOpStatus());
	assertEquals("unicode", msg.get(0).getFileType());

	// ... submit file and validate
	msg = change.submit(false);
	assertNotNull(msg);
	assertEquals(FileSpecOpStatus.VALID, msg.get(0).getOpStatus());
	assertEquals(FileAction.ADD, msg.get(0).getAction());

	// Clean up directory
	String clientRoot = client.getRoot();
	FileUtils.deleteDirectory(new File(clientRoot));
	FileUtils.forceMkdir(new File(clientRoot));

	// Force sync client
	SyncOptions opts = new SyncOptions();
	opts.setForceUpdate(true);
	msg = client.sync(null, opts);
	assertNotNull(msg);
	assertEquals(FileSpecOpStatus.VALID, msg.get(0).getOpStatus());
	assertEquals("//depot/r161/unicode.txt", msg.get(0).getDepotPathString());

	// Verify content
	byte[] encoded = Files.readAllBytes(testFile.toPath());
	String content = new String(encoded, StandardCharsets.UTF_8);

	assertEquals("a\nb", content);
}
 
Example 17
Source File: GemFireXDDataExtractorDUnit.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void testMissingDataDictionary() throws Exception {
  String tableName = "REPLICATE_TABLE";
  String server1Name = "server1";
  String server2Name = "server2";
  int numDDL = 2;
  startVMs(1, 2);
  clientCreateDiskStore(1, testDiskStoreName);
 
  clientCreatePersistentReplicateTable(1, tableName, testDiskStoreName);
  //create table
  //insert/update/delete data
  insertData(tableName, 0, 100);
  updateData(tableName, 30, 60);
  deleteData(tableName, 60, 90);
  String server1Directory = getVM(-1).getSystem().getSystemDirectory() + "_" + getVM(-1).getPid();
  String server2Directory = getVM(-2).getSystem().getSystemDirectory() + "_" + getVM(-2).getPid();
  
  //Don't copy the data dictionary for this test
  //this.serverExecute(1, this.getCopyDataDictionary(server1Directory));
  this.serverExecute(2,  this.getCopyDataDictionary(server2Directory));
  
  this.serverExecute(1,  this.getCopyOplogsRunnable(server1Directory, testDiskStoreName));
  this.serverExecute(2,  this.getCopyOplogsRunnable(server2Directory, testDiskStoreName));

  String propertiesFileName = "test_salvage.properties";
  Properties properties = new Properties();
  String server1CopyDir = server1Directory + File.separator + copyDirectory;
  String server2CopyDir = server2Directory + File.separator + copyDirectory;
  
  properties.setProperty(server1Name, server1CopyDir + "," + server1CopyDir + File.separator + testDiskStoreName);
  properties.setProperty(server2Name, server2CopyDir + "," + server2CopyDir + File.separator + testDiskStoreName);
  properties.store(new FileOutputStream(new File(propertiesFileName)), "test properties");

  String userName =  TestUtil.currentUserName == null? "APP":TestUtil.currentUserName;
  //pass in properties file to salvager
  String args[] = new String[] {"property-file=" + propertiesFileName, "--user-name=" + userName};
  
  disconnectTestInstanceAndCleanUp();
  GemFireXDDataExtractorImpl salvager = GemFireXDDataExtractorImpl.doMain(args);

  String outputDirectoryString = salvager.getOutputDirectory();
  File outputDirectory = new File(outputDirectoryString);
  assertTrue(outputDirectory.exists());
  
  File server1OutputDirectory = new File(outputDirectory, server1Name);
  this.serverExecute(1, getCheckDDLSizeRunnable(server1Directory, 0));
  
  File server2OutputDirectory = new File(outputDirectory, server2Name);
  assertTrue(serverExportedCorrectly(server2OutputDirectory, new String[] {tableName}, numDDL));

  File summaryFile = new File(outputDirectory, "Summary.txt");
  assertTrue(summaryFile.exists());
  
  File recommended = new File(outputDirectory, "Recommended.txt");
  assertTrue(recommended.exists());
  FileUtils.deleteDirectory(outputDirectory);
}
 
Example 18
Source File: TestOMDbCheckpointServlet.java    From hadoop-ozone with Apache License 2.0 4 votes vote down vote up
@Override
public void cleanupCheckpoint() throws IOException {
  FileUtils.deleteDirectory(checkpointFile.toFile());
}
 
Example 19
Source File: JMSTestBase.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
@After
public void afterTest() throws Exception
{
  broker.stop();
  FileUtils.deleteDirectory(new File("target/activemq-data").getAbsoluteFile());
}
 
Example 20
Source File: CassandraIOTest.java    From beam with Apache License 2.0 4 votes vote down vote up
@AfterClass
public static void afterClass() throws InterruptedException, IOException {
  shutdownHook.shutDownNow();
  FileUtils.deleteDirectory(new File(TEMPORARY_FOLDER));
}