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

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

Introduction

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

Prototype

public static void forceDeleteOnExit(File file) throws IOException 

Source Link

Document

Schedules a file to be deleted when JVM exits.

Usage

From source file:org.polymap.service.geoserver.GeoServerWms.java

protected void initGeoServer() throws Exception {

    context = new PluginServletContext(getServletContext());
    log.debug("initGeoServer(): contextPath=" + context.getContextPath());

    ClassLoader threadLoader = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(context.cl);

    try {/*from w w w.ja  v  a  2 s .  com*/
        File cacheDir = GeoServerPlugin.getDefault().getCacheDir();
        dataDir = new File(cacheDir, Stringer.on(map.getLabel()).toFilename("_").toString());
        log.debug("    dataDir=" + dataDir.getAbsolutePath());
        dataDir.mkdirs();
        FileUtils.forceDeleteOnExit(dataDir);

        // web.xml
        context.setAttribute("serviceStrategy", "SPEED");
        context.setAttribute("contextConfigLocation",
                "classpath*:/applicationContext.xml classpath*:/applicationSecurityContext.xml");
        context.setAttribute("enableVersioning", "false");
        context.setAttribute("GEOSERVER_DATA_DIR", dataDir.getAbsoluteFile());

        try {
            servers.set(this);

            loaders.add(new LoggingStartupContextListener());
            loaders.add(new ContextLoaderListener());

            ServletContextEvent ev = new ServletContextEvent(context);
            for (Object loader : loaders) {
                ((ServletContextListener) loader).contextInitialized(ev);
            }
        } finally {
            servers.set(null);
        }

        dispatcher = new DispatcherServlet();
        log.debug("Dispatcher: " + dispatcher.getClass().getClassLoader());
        dispatcher.init(new ServletConfig() {

            public String getInitParameter(String name) {
                return GeoServerWms.this.getInitParameter(name);
            }

            public Enumeration getInitParameterNames() {
                return GeoServerWms.this.getInitParameterNames();
            }

            public ServletContext getServletContext() {
                return context;
            }

            public String getServletName() {
                return "dispatcher";
            }
        });
    } finally {
        Thread.currentThread().setContextClassLoader(threadLoader);
    }
}

From source file:org.semanticscience.narf.graphs.lib.CycleSerializerTest.java

/**
 * @throws java.lang.Exception//from ww  w .ja v  a 2 s .  c  o m
 */
@AfterClass
public static void tearDownAfterClass() throws Exception {
    FileUtils.forceDeleteOnExit(pdbFilesDir);
    nucs = null;
    fcb = null;
    cycleBasisList = null;
}

From source file:org.silverpeas.file.FileUtil.java

public static void deleteFilesOnExit(final String _file) throws IOException {
    // Deleting the children recursively
    final File file = new File(_file);
    FileUtils.forceDeleteOnExit(file);
}

From source file:org.silverpeas.search.indexEngine.model.TestDidYouMeanIndexer.java

/**
 * @throws java.lang.Exception//from  w w w  .ja v a  2s .  c  o m
 */
@AfterClass
public static void tearDownAfterClass() throws Exception {
    File file = new File(PathTestUtil.TARGET_DIR + "test-classes" + File.separatorChar + "index"
            + File.separatorChar + "kmelia1");
    FileUtils.forceDeleteOnExit(file);

}

From source file:org.sonar.plugins.findbugs.FindbugsConfiguration.java

private File copyLib(String name) {
    try {// w  w  w  . j a  v a  2s  .  c  om
        InputStream is = getClass().getResourceAsStream(name);
        File temp = File.createTempFile("findbugs", ".jar");
        FileUtils.forceDeleteOnExit(temp);
        OutputStream os = FileUtils.openOutputStream(temp);
        IOUtils.copy(is, os);
        return temp;
    } catch (IOException e) {
        throw new SonarException(e);
    }
}

From source file:org.sonar.plugins.groovyjacoco.jacoco.JaCoCoAgentDownloader.java

private File extractAgent() {
    try {// w ww . j av  a 2s .c o m
        File agent = File.createTempFile("jacocoagent", ".jar");
        AgentJar.extractTo(agent);
        // TODO evil method
        FileUtils.forceDeleteOnExit(agent);
        JaCoCoUtils.LOG.info("JaCoCo agent (version " + JaCoCo.VERSION + ") extracted: {}", agent);
        return agent;
    } catch (IOException e) {
        throw new SonarException(e);
    }
}

From source file:org.sonar.plugins.jacoco.JaCoCoAgentDownloader.java

private File extractAgent() {
    try {/* w  w  w . j  av  a  2s .  co m*/
        File agent = File.createTempFile("jacocoagent", ".jar");
        AgentJar.extractTo(agent);
        FileUtils.forceDeleteOnExit(agent); // TODO evil method
        JaCoCoUtils.LOG.info("JaCoCo agent (version " + JaCoCo.VERSION + ") extracted: {}", agent);
        return agent;
    } catch (IOException e) {
        throw new SonarException(e);
    }
}

From source file:org.wso2.carbon.config.annotationprocessor.AnnotationProcessorTest.java

@AfterClass
public void cleanOutputs() throws IOException {
    File file = Paths.get(System.getProperty("user.dir"), "temp_config_classnames.txt").toFile();
    FileUtils.forceDeleteOnExit(file);
    File classFile = Paths.get(System.getProperty("user.dir"), packagePath, "Configurations.class").toFile();
    FileUtils.forceDeleteOnExit(classFile);
    classFile = Paths.get(System.getProperty("user.dir"), packagePath, "Transport.class").toFile();
    FileUtils.forceDeleteOnExit(classFile);
    classFile = Paths.get(System.getProperty("user.dir"), packagePath, "Transports.class").toFile();
    FileUtils.forceDeleteOnExit(classFile);
}

From source file:org.wso2.carbon.config.test.annotationprocessor.AnnotationProcessorTest.java

@AfterClass
public void cleanOutputs() throws IOException {
    File file = Paths.get(System.getProperty("user.dir"), ConfigConstants.TEMP_CONFIG_FILE_NAME).toFile();
    FileUtils.forceDeleteOnExit(file);
    File classFile = Paths.get(System.getProperty("user.dir"), packagePath, "TestConfiguration.class").toFile();
    FileUtils.forceDeleteOnExit(classFile);
    classFile = Paths.get(System.getProperty("user.dir"), packagePath, "Transport.class").toFile();
    FileUtils.forceDeleteOnExit(classFile);
    classFile = Paths.get(System.getProperty("user.dir"), packagePath, "Transports.class").toFile();
    FileUtils.forceDeleteOnExit(classFile);
}

From source file:org.wso2.carbon.container.CarbonTestContainer.java

/**
 * Force cleanup directories if required.
 *///from  w  ww  . j  a  v  a 2s  .  c  o m
private void forceCleanup() {
    try {
        FileUtils.forceDeleteOnExit(targetDirectory.toFile());
    } catch (IOException e) {
        logger.error("Error occured when deleting the Directory.", e);
    }
}