Example usage for org.apache.commons.io FileUtils deleteDirectory

List of usage examples for org.apache.commons.io FileUtils deleteDirectory

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils deleteDirectory.

Prototype

public static void deleteDirectory(File directory) throws IOException 

Source Link

Document

Deletes a directory recursively.

Usage

From source file:de.uzk.hki.da.cb.CleanWorkAreaAction.java

@Override
public boolean implementation() {
    setKILLATEXIT(true);//  w  w  w .j  av a2  s  .  c o  m

    // to prevent leftover files from irods collection removal we delete the dirs on the filesystem first.
    try {
        FileUtils.deleteDirectory(object.getPath().toFile());
    } catch (IOException e) {
        throw new RuntimeException("Exception while deleting \"" + object.getPath() + "\"", e);
    }

    object.getLatestPackage().getFiles().clear();
    object.getLatestPackage().getEvents().clear();

    createPublicationJob();
    return true;
}

From source file:com.adguard.compiler.FilterUtils.java

/**
 * Downloads filters from our backend server
 *
 * @param source Path to extension sources
 * @throws IOException/*w ww  .ja v a 2  s. co  m*/
 */
public static void updateLocalFilters(File source) throws IOException {

    File dest = new File(source, "tmp-filters");
    File filtersDir = new File(source, "filters");

    List<File> filesToCopy = new ArrayList<File>();
    try {
        for (int filterId = 1; filterId <= 10; filterId++) {

            log.debug("Start download filter " + filterId);

            String downloadUrl = String.format(FILTER_DOWNLOAD_URL, filterId);
            String response = UrlUtils.downloadString(new URL(downloadUrl), "UTF-8");

            File filterFile = new File(dest, "filter_" + filterId + ".txt");
            FileUtils.write(filterFile, response);
            filesToCopy.add(filterFile);

            log.debug("Filter " + filterId + " download successfully");
        }

        for (File file : filesToCopy) {
            FileUtils.copyFileToDirectory(file, filtersDir);
        }
    } finally {
        FileUtils.deleteDirectory(dest);
    }
}

From source file:com.bancvue.mongomigrate.CreateCommandTests.java

@After
public void tearDown() throws IOException {
    // Delete all js files in that the test may have created.
    File directory = new File(".");
    Collection<File> files = FileUtils.listFiles(directory, new WildcardFileFilter("*.js"), null);
    for (File file : files) {
        FileUtils.deleteQuietly(file);//from  ww  w  .java2 s.c  om
    }

    // Delete migrations folder
    File migrationsFolder = new File("migrations");
    FileUtils.deleteDirectory(migrationsFolder);
}

From source file:com.splout.db.common.TestSploutConfiguration.java

public void innerTest() throws UnsupportedEncodingException, IOException {
    File testConfig = new File("testConfig");
    testConfig.mkdir();// w  ww .java2 s  .  co m
    // foo.property=value1 in defaults file
    Files.write("foo.property\tvalue1".getBytes("UTF-8"),
            new File(testConfig, SploutConfiguration.SPLOUT_PROPERTIES + ".default"));
    assertEquals(SploutConfiguration.get("testConfig").getString("foo.property"), "value1");
    // foo.property=value2 in main file - assert that it overrides default
    Files.write("foo.property\tvalue2".getBytes("UTF-8"),
            new File(testConfig, SploutConfiguration.SPLOUT_PROPERTIES));
    assertEquals(SploutConfiguration.get("testConfig").getString("foo.property"), "value2");
    FileUtils.deleteDirectory(testConfig);
}

From source file:com.abiquo.testng.AMRepositoryListener.java

@Override
public void onFinish(ISuite suite) {
    try {//from w w  w  .j av a 2 s. c  om
        FileUtils.deleteDirectory(new File(REPO_PATH));
    } catch (IOException e) {
        throw new RuntimeException("Can't clean test repository filesystem", e);
    }
}

From source file:com.talis.platform.sequencing.zookeeper.ZkTestHelper.java

public void cleanUp() throws Exception {
    for (String hostPort : serverFactories.keySet()) {
        stopServer(hostPort);/*from www  . j  av  a2 s  . com*/
    }
    for (File tmpDir : tmpDirs.values()) {
        FileUtils.deleteDirectory(tmpDir);
    }
}

From source file:com.galenframework.tests.runner.JsTestCollectorTest.java

@AfterClass
public void removeAllTempFiles() throws IOException {
    FileUtils.deleteDirectory(new File(TEST_DIR_PATH));
}

From source file:com.splout.db.integration.TestReplicaBalanceIntegration.java

@Test
public void test() throws Throwable {
    FileUtils.deleteDirectory(new File(TMP_FOLDER));
    new File(TMP_FOLDER).mkdirs();

    createSploutEnsemble(N_QNODES, N_DNODES);
    Random random = new Random(SEED);

    Tablespace testTablespace = createTestTablespace(N_DNODES);

    File deployData = new File(TMP_FOLDER + "/" + "deploy-folder-" + random.nextInt());
    deployData.mkdir();//from   w  ww. jav  a 2  s .  c o  m

    for (int i = 0; i < N_DNODES; i++) {
        File dbData = new File(deployData, i + ".db");
        Files.write(new String("foo").getBytes(), dbData);
    }

    final SploutClient[] clients = new SploutClient[N_QNODES];

    for (int i = 0; i < N_QNODES; i++) {
        clients[i] = new SploutClient(getqNodes().get(i).getAddress());
    }
    final SploutClient client1 = clients[0];

    // Check that all QNodes have the full list of DNodes
    new TestUtils.NotWaitingForeverCondition() {
        @Override
        public boolean endCondition() {
            try {
                for (int i = 0; i < N_QNODES; i++) {
                    List<String> dNodeList = clients[i].dNodeList();
                    if (dNodeList.size() != 3) {
                        return false;
                    }
                    QNodeHandler handler = (QNodeHandler) getqNodes().get(i).getHandler();
                    for (String dnode : dNodeList) {
                        if (handler.getContext().getThriftClientCache().get(dnode) == null) {
                            return false;
                        }
                    }
                }
                return true;
            } catch (IOException e) {
                // test failed
                e.printStackTrace();
                return true;
            }
        }
    }.waitAtMost(20000);

    // Deploy
    client1.deploy("p1", testTablespace.getPartitionMap(), testTablespace.getReplicationMap(),
            deployData.getAbsoluteFile().toURI());

    // Check that all QNodes have the deployment data
    new TestUtils.NotWaitingForeverCondition() {

        @Override
        public boolean endCondition() {
            try {
                for (int i = 0; i < N_QNODES; i++) {
                    Map<String, Tablespace> t = clients[i].overview().getTablespaceMap();
                    if (t.size() != 1) {
                        return false;
                    }
                    for (int k = 0; k < 3; k++) {
                        if (t.get("p1").getReplicationMap().getReplicationEntries().get(k).getNodes()
                                .size() != 2) {
                            return false;
                        }
                    }
                }
                return true;
            } catch (IOException e) {
                // test failed
                e.printStackTrace();
                return true;
            }
        }
    }.waitAtMost(20000);

    final DNode dnode1 = getdNodes().get(1);

    final Set<Integer> partitionsByNode1 = new HashSet<Integer>();
    partitionsByNode1.add(0);
    partitionsByNode1.add(1);

    // shutdown DNode1 and see what happens with auto-rebalancing
    // the "partitionsByNode1" will become under-replicated and after a short period of time should be balanced
    dnode1.testCommand(TestCommands.SHUTDOWN.toString());

    // waiting until the system becomes under-replicated
    new TestUtils.NotWaitingForeverCondition() {

        @Override
        public boolean endCondition() {
            try {
                boolean dnode1NotPresent = true;
                for (int i = 0; i < N_QNODES; i++) {
                    Map.Entry<String, Tablespace> tEntry = clients[i].overview().getTablespaceMap().entrySet()
                            .iterator().next();
                    ReplicationMap currentReplicationMap = tEntry.getValue().getReplicationMap();
                    for (ReplicationEntry entry : currentReplicationMap.getReplicationEntries()) {
                        if (entry.getNodes().contains(dnode1.getAddress())) {
                            dnode1NotPresent = false;
                        }
                    }
                }
                return dnode1NotPresent;
            } catch (IOException e) {
                // test failed
                e.printStackTrace();
                return true;
            }
        }
    }.waitAtMost(60000);

    // waiting now until the system recovers itself without dnode1
    new TestUtils.NotWaitingForeverCondition() {

        @Override
        public boolean endCondition() {
            try {
                boolean balanced = true;
                for (int i = 0; i < N_QNODES; i++) {
                    Map.Entry<String, Tablespace> tEntry = clients[i].overview().getTablespaceMap().entrySet()
                            .iterator().next();
                    ReplicationMap currentReplicationMap = tEntry.getValue().getReplicationMap();
                    for (ReplicationEntry entry : currentReplicationMap.getReplicationEntries()) {
                        if (entry.getNodes().size() < entry.getExpectedReplicationFactor()) {
                            balanced = false;
                        }
                    }
                }
                return balanced;
            } catch (IOException e) {
                // test failed
                e.printStackTrace();
                return true;
            }
        }
    }.waitAtMost(20000);

    // now we bring back dnode1 to life
    // what will happen now is that the partitions it seves will be over-replicated
    dnode1.testCommand(TestCommands.RESTART.toString());

    // waiting now until the system is over-replicated
    new TestUtils.NotWaitingForeverCondition() {

        @Override
        public boolean endCondition() {
            try {
                boolean overreplicated = true;
                for (int i = 0; i < N_QNODES; i++) {
                    Map.Entry<String, Tablespace> tEntry = clients[i].overview().getTablespaceMap().entrySet()
                            .iterator().next();
                    ReplicationMap currentReplicationMap = tEntry.getValue().getReplicationMap();
                    for (ReplicationEntry entry : currentReplicationMap.getReplicationEntries()) {
                        if (partitionsByNode1.contains(entry.getShard())
                                && entry.getNodes().size() <= entry.getExpectedReplicationFactor()) {
                            overreplicated = false;
                        }
                    }
                }
                return overreplicated;
            } catch (IOException e) {
                // test failed
                e.printStackTrace();
                return true;
            }
        }
    }.waitAtMost(20000);

    assertEquals(2, partitionsByNode1.size());
    assertTrue(partitionsByNode1.contains(0));
    assertTrue(partitionsByNode1.contains(1));
}

From source file:com.googlecode.osde.internal.db.PersonTest.java

@After
public void tearDown() throws Exception {
    HibernateUtils.closeSession();
    dbServer.stop();
    FileUtils.deleteDirectory(dbDir);
}

From source file:com.splout.db.integration.TestMultiQNodeDeploy.java

@Test
public void test() throws Throwable {
    FileUtils.deleteDirectory(new File(TMP_FOLDER));
    new File(TMP_FOLDER).mkdirs();

    createSploutEnsemble(N_QNODES, N_DNODES);
    Random random = new Random(SEED);

    try {/*from  w  w w.j a v a  2s  .  c om*/
        for (int i = 0; i < 3; i++) {
            deployAndQueryRandomTablespace(random);
        }
    } finally {
        closeSploutEnsemble();
        FileUtils.deleteDirectory(new File(TMP_FOLDER));
    }
}