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

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

Introduction

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

Prototype

public static void cleanDirectory(File directory) throws IOException 

Source Link

Document

Cleans a directory without deleting it.

Usage

From source file:com.sonar.it.jenkins.orchestrator.container.JenkinsDownloader.java

public synchronized File download(JenkinsDistribution distrib) {
    LOG.info("Downloading Jenkins-" + distrib.getVersion());

    // Add a "j" prefix to not conflict with SonarQube
    File toDir = new File(fileSystem.workspace(), "j" + String.valueOf(sharedDirId.addAndGet(1)));
    if (toDir.exists()) {
        try {//from   www  .java2 s .c om
            FileUtils.cleanDirectory(toDir);
        } catch (IOException e) {
            throw new IllegalStateException("Fail to clean directory: " + toDir, e);
        }
    }

    LOG.info("Download Jenkins-" + distrib.getVersion() + " in " + toDir.getAbsolutePath());
    File war = downloadWar(distrib);

    LOG.info("Copy " + war);
    try {
        FileUtils.copyFileToDirectory(war, toDir);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    return toDir;
}

From source file:com.proofpoint.zookeeper.io.TempLocalDirectory.java

public void cleanupPrevious() {
    try {/*ww w . jav a  2  s . c o m*/
        FileUtils.cleanDirectory(path);
        log.debug("Cleaned up local temp dir: " + path.getAbsolutePath());
    } catch (IOException e) {
        log.warn(e, "Error cleaning up temp local directory: %s", path.getAbsolutePath());
        throw new Error(e);
    }
}

From source file:dk.itst.oiosaml.sp.ConfigurationTest.java

@Before
public void setUp() throws Exception {
    tmpdir = new File(System.getProperty("java.io.tmpdir") + "/oiosaml-" + Math.random());
    if (tmpdir.exists()) {
        FileUtils.cleanDirectory(tmpdir);
    }//w  w w .ja  va 2 s . c  o  m
    tmpdir.mkdir();

    SAMLConfiguration.setSystemConfiguration(null);
    IdpMetadata.setMetadata(null);
    SPMetadata.setMetadata(null);
    System.setProperty(SAMLUtil.OIOSAML_HOME, tmpdir.getAbsolutePath());

    server = new Server(8808);
    WebAppContext wac = new WebAppContext();
    wac.setClassLoader(Thread.currentThread().getContextClassLoader());
    wac.setContextPath("/saml");
    wac.setWar("webapp/");

    server.setHandler(wac);
    server.start();

    client = new WebClient();
    page = (HtmlPage) client.getPage(BASE + "/saml/configure");
}

From source file:com.legstar.coxb.gen.AbstractCoxbGenTest.java

/** @{inheritDoc */
public void setUp() throws Exception {
    super.setUp();
    CodeGenUtil.initVelocity();/*from ww w .j ava  2 s  .c  o m*/
    mParameters = new HashMap<String, Object>();
    CodeGenHelper helper = new CodeGenHelper();
    mParameters.put("helper", helper);
    mParameters.put("coxbHelper", new CoxbHelper());
    FileUtils.forceMkdir(GEN_SRC_DIR);
    FileUtils.cleanDirectory(GEN_SRC_DIR);
    FileUtils.forceMkdir(GEN_ANT_DIR);
    FileUtils.cleanDirectory(GEN_ANT_DIR);
    FileUtils.forceMkdir(GEN_BIN_DIR);
    FileUtils.cleanDirectory(GEN_BIN_DIR);
}

From source file:com.seleniumtests.ut.util.squashta.TestTaFolderStructureGenerator.java

/**
 * folder structure generation without any file present in dest
 * @throws IOException/*  w w w  .  j  a  va  2s .  c o m*/
 */
@Test(groups = { "squash" })
public void testGenerateDefaultStructure() throws IOException {
    File tmpFolder = Paths.get(SeleniumTestsContextManager.getDataPath(), "tmp").toFile();
    TaFolderStructureGenerator structGen = new TaFolderStructureGenerator("core", null,
            tmpFolder.getAbsolutePath());
    try {
        structGen.generateDefaultStructure();
        Assert.assertTrue(Paths.get(tmpFolder.getPath(), "pom.xml").toFile().exists());
        Assert.assertTrue(Paths.get(tmpFolder.getPath(), "src", "squashTA", "resources", "junit", "java",
                "SeleniumRobotTest.java").toFile().exists());
        Assert.assertTrue(Paths.get(tmpFolder.getPath(), "src", "squashTA", "tests", "core_generic.ta").toFile()
                .exists());
    } finally {
        FileUtils.cleanDirectory(tmpFolder);
        tmpFolder.delete();
    }
}

From source file:hudson.maven.Maven3BuildTest.java

public void testSimpleMaven3BuildRedeployPublisher() throws Exception {

    MavenModuleSet m = createMavenProject();
    MavenInstallation mavenInstallation = configureMaven3();
    m.setMaven(mavenInstallation.getName());
    File repo = createTmpDir();/*from w  w  w  .j a  v a  2s  . c o m*/
    FileUtils.cleanDirectory(repo);
    m.getReporters().add(new TestReporter());
    m.getPublishersList().add(new RedeployPublisher("", repo.toURI().toString(), true, false));
    m.setScm(new ExtractResourceSCM(getClass().getResource("maven3-project.zip")));
    m.setGoals("clean install");
    MavenModuleSetBuild b = buildAndAssertSuccess(m);
    assertTrue(MavenUtil.maven3orLater(b.getMavenVersionUsed()));
    File artifactDir = new File(repo, "com/mycompany/app/my-app/1.7-SNAPSHOT/");
    String[] files = artifactDir.list(new FilenameFilter() {

        public boolean accept(File dir, String name) {
            System.out.println("file name : " + name);
            return name.endsWith(".jar");
        }
    });
    assertTrue("SNAPSHOT exist", !files[0].contains("SNAPSHOT"));
    assertTrue("file not ended with -1.jar", files[0].endsWith("-1.jar"));
}

From source file:com.bbc.remarc.util.ResourceManager.java

public static void processUploadDir(String uploadDir, String resourcesDir) {

    File uploadFolder = new File(uploadDir);

    log.debug("processing resources within upload directory: " + uploadFolder.getPath()
            + " with resources directory: " + resourcesDir);

    processUploadDir(uploadFolder, resourcesDir);

    //delete everything in the upload directory now that it's been processed
    try {/*from w w w  . j  a v a  2 s  . c o m*/
        FileUtils.cleanDirectory(uploadFolder);
    } catch (IOException e) {
        log.error("ERROR! Could not clean uploadFolder: " + e);
    }
}

From source file:com.tc.test.TempDirectoryHelper.java

@Override
protected File fetchDirectory() throws IOException {
    File root = getRoot();// w  ww . j ava  2 s .  c o  m
    if (!root.exists()) {
        root.mkdirs();
    }
    String shortClassName = getTargetClass().getName();
    String[] tokens = shortClassName.split("\\.");
    if (tokens.length > 1) {
        shortClassName = tokens[tokens.length - 1];
    }
    File directory = new File(root, shortClassName);
    if ((!directory.exists()) && (!directory.mkdirs())) {
        FileNotFoundException fnfe = new FileNotFoundException(
                "Directory '" + directory.getAbsolutePath() + "' can't be created.");
        throw fnfe;
    }

    if (cleanDir) {
        int count = 0;
        while (true) {
            count++;
            try {
                FileUtils.cleanDirectory(directory);
                break;
            } catch (Exception e) {
                System.err.println("Unable to clean up the directory - " + directory + "; Exception: " + e);
            }

            if (count > 10) {
                System.err.println("Skipping clean up for directory - " + directory);
                break;
            }

            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        }
    }
    return directory;
}

From source file:jp.co.tis.gsp.tools.dba.mojo.ExportSchemaMojo.java

@Override
protected void executeMojoSpec() throws MojoExecutionException, MojoFailureException {
    Dialect dialect = DialectFactory.getDialect(url, driver);
    DialectUtil.setDialect(dialect);//from  w  w w.  j a  v  a2  s  .  co m

    outputDirectoryTemp = new File(outputDirectory.getParentFile(), "_exptmp");

    if (outputDirectoryTemp.exists()) {
        try {
            FileUtils.cleanDirectory(outputDirectoryTemp);
        } catch (IOException e) {
            throw new MojoExecutionException("Can't clean outputDirectory:" + outputDirectoryTemp);
        }
    } else {
        try {
            FileUtils.forceMkdir(outputDirectoryTemp);
        } catch (IOException e) {
            throw new MojoExecutionException("Can't create dump output directory." + outputDirectoryTemp, e);
        }
    }

    getLog().info(schema + "?Export???");

    try {
        ExportParams expParams = createExportParams();
        dialect.exportSchema(expParams);

    } catch (Exception e) {
        throw new MojoExecutionException("?Export????? ", e);
    }

    jarArchiver.addDirectory(outputDirectoryTemp);
    jarArchiver.setDestFile(new File(outputDirectory, jarName()));

    try {
        jarArchiver.createArchive();
    } catch (IOException e) {
        throw new MojoExecutionException("?????", e);
    }
    getLog().info(schema + "?Export ");
}

From source file:com.github.ipaas.ideploy.agent.handler.BackupCodeHandlerTest.java

/**
 * @throws java.lang.Exception/*from w w  w  .j a va2  s  .c  om*/
 */
@After
public void tearDown() throws Exception {
    File srcFile = new File(SRC_PATH);
    if (srcFile.exists()) {
        FileUtils.cleanDirectory(srcFile);
    }
    File targetFile = new File(TARGET_PATH);
    if (targetFile.exists()) {
        FileUtils.cleanDirectory(targetFile);
    }
}