List of usage examples for org.apache.commons.io FileUtils forceDeleteOnExit
public static void forceDeleteOnExit(File file) throws IOException
From source file:org.deventropy.junithelper.derby.directory.simple01.DatabaseDbCustomDirAllTest.java
/** * Cleans up the resource and database.//from www .j a v a 2 s . co m * @throws IOException Exception with file operations */ @After public void afterTest() { try { embeddedDerbyResource.close(); } catch (IOException e) { log.catching(Level.TRACE, e); } try { FileUtils.deleteDirectory(dbHomeDir); } catch (IOException e) { try { FileUtils.forceDeleteOnExit(dbHomeDir); } catch (IOException e1) { log.catching(Level.TRACE, e1); } } try { FileUtils.deleteDirectory(derbySystemHomeDir); } catch (IOException e) { try { FileUtils.forceDeleteOnExit(derbySystemHomeDir); } catch (IOException e1) { log.catching(Level.TRACE, e1); } } }
From source file:org.jenkinsci.plugins.aptly.AptlyPublisher.java
/** * {@inheritDoc}/*from w w w.j a va 2s .c o m*/ * * @param build * @param launcher * @param listener * @return * @throws InterruptedException * @throws IOException * {@inheritDoc} * @see hudson.tasks.BuildStep#perform(hudson.model.Build, hudson.Launcher, hudson.model.BuildListener) */ @Override public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { listener.getLogger().println("Perform AptlyPublisher "); if (skip != null && skip) { listener.getLogger().println("Publish built packages via Aptly - Skipping... "); return true; } if (build.getResult() == Result.FAILURE || build.getResult() == Result.ABORTED) { // build failed return true; } Map<String, String> envVars = build.getEnvironment(listener); AptlySite aptlysite = null; aptlysite = getSite(); listener.getLogger().println("Using aptly site: " + aptlysite.getHostname()); listener.getLogger().println("Port " + aptlysite.getPort()); listener.getLogger().println("Username " + aptlysite.getUsername()); listener.getLogger().println("Timeout " + aptlysite.getTimeOut()); AptlyRestClient client = new AptlyRestClient(listener.getLogger(), aptlysite.getHostname(), Integer.parseInt(aptlysite.getPort()), aptlysite.getTimeOut(), aptlysite.getUsername(), aptlysite.getPassword()); try { String result = client.getAptlyServerVersion(); listener.getLogger().println("Aptly API version response: " + result); } catch (Throwable th) { th.printStackTrace(listener.error("Failed to connect to the server")); build.setResult(Result.UNSTABLE); return false; } List<PackageItem> itemlist = getPackageItems(); for (PackageItem i : itemlist) { String uploaddirid = envVars.get("JOB_NAME") + "-" + envVars.get("BUILD_NUMBER") + "-" + UUID.randomUUID().toString().substring(0, 6); // Creating a temp dir for copying the remote files File tempDir = File.createTempFile("aptlyplugin", null); tempDir.delete(); tempDir.mkdirs(); FilePath workspace = new FilePath(launcher.getChannel(), build.getWorkspace().getRemote()); //expand the macros like ${BUILD_NUM} String expanded = Util.replaceMacro(i.getSourceFiles(), envVars); //expand the file globs FilePath[] remoteFiles = workspace.list(expanded); if (remoteFiles.length == 0) { listener.getLogger().println("No matching file found to upload in: " + expanded); build.setResult(Result.UNSTABLE); return false; } //copy the remote file into the local dir, collect all of the // filepaths into 'filelist', and pass the list for uploading ArrayIterator filesiterator = new ArrayIterator(remoteFiles); List<File> filelist = new ArrayList<File>(); while (filesiterator.hasNext()) { FilePath filepath = (FilePath) filesiterator.next(); if (filepath.isRemote()) { FilePath localfilepath = new FilePath(new FilePath(tempDir), filepath.getName()); filepath.copyTo(localfilepath); filepath = localfilepath; } File file = new File(filepath.toURI()); listener.getLogger().println("Found file to upload: " + file.toString()); //this is already ensured to be a local and absoulute path filelist.add(file); } try { client.uploadFiles(filelist, uploaddirid); } catch (Throwable th) { th.printStackTrace(listener.error("Failed to upload files")); build.setResult(Result.UNSTABLE); } finally { try { FileUtils.deleteDirectory(tempDir); } catch (IOException e) { try { FileUtils.forceDeleteOnExit(tempDir); } catch (IOException e1) { e1.printStackTrace(listener.getLogger()); } } } // ################### ADD THE PACKAGES TO THE REPO ############### try { client.addUploadedFilesToRepo(i.getRepositoryName(), uploaddirid); } catch (Throwable th) { th.printStackTrace(listener.error("Failed to upload files")); build.setResult(Result.UNSTABLE); return false; } // ################### UPDATE THE PUBLISHED REPO ################### try { client.updatePublishRepo(i.getPrefixName(), i.getDistributionName()); } catch (Throwable th) { th.printStackTrace(listener.error("Failed to upload files")); build.setResult(Result.UNSTABLE); return false; } } return true; }
From source file:org.kalypso.simulation.core.util.SimulationUtilitites.java
public static File createSimulationTmpDir(final String id) throws IOException { final String javaTmpDir = FrameworkProperties.getProperty(FileUtilities.JAVA_IO_TMPDIR); final String simDir = FrameworkProperties.getProperty(ISimulationConstants.SYSPROP_SIM_DIR, javaTmpDir); final File simTmpDir = new File(simDir); final File tmpDir = new File(simTmpDir, "Simulation-" + id + "-" + System.currentTimeMillis()); //$NON-NLS-1$ //$NON-NLS-2$ FileUtils.forceMkdir(tmpDir);//from w w w . j a va 2 s . c om FileUtils.forceDeleteOnExit(tmpDir); return tmpDir; }
From source file:org.kuali.kra.infrastructure.TestUtilities.java
License:asdf
public static void initializePluginDirectories() throws Exception { File enPluginDir = getEnPluginsDirectory(); if (enPluginDir.exists()) { FileUtils.forceDelete(enPluginDir); }/*w w w .j a v a 2s . c om*/ File pluginDir = getPluginsDirectory(); if (pluginDir.exists()) { FileUtils.forceDelete(pluginDir); } FileUtils.forceMkdir(enPluginDir); FileUtils.forceMkdir(pluginDir); FileUtils.forceDeleteOnExit(enPluginDir); FileUtils.forceDeleteOnExit(pluginDir); }
From source file:org.kuali.rice.kew.plugin.ExtraClassPathTest.java
@Override public void setUp() throws Exception { // we want to copy the ziptest plugin into the plugin directories before the // test harness starts up. That way the plugin will be loaded at startup time. super.setUp(); TestUtilities.initializePluginDirectories(); String pluginZipFileLocation = new ClasspathOrFileResourceLoader() .getResource("classpath:org/kuali/rice/kew/plugin/extraclasspathtest.zip").getURL().getPath(); File pluginZipFile = new File(pluginZipFileLocation); assertTrue("File " + pluginZipFileLocation + " should exist", pluginZipFile.exists()); assertTrue("File " + pluginZipFileLocation + " should be a file", pluginZipFile.isFile()); FileUtils.copyFileToDirectory(pluginZipFile, TestUtilities.getPluginsDirectory()); pluginZipFile = new File(TestUtilities.getPluginsDirectory(), pluginZipFile.getName()); FileUtils.forceDeleteOnExit(pluginZipFile); registry = new PluginRegistryFactory().createPluginRegistry(); registry.start();//from w w w. ja v a 2 s . c o m }
From source file:org.kuali.rice.kew.test.TestUtilities.java
public static void initializePluginDirectories() throws Exception { File pluginDir = getPluginsDirectory(); if (pluginDir.exists()) { FileUtils.forceDelete(pluginDir); }//w w w . j a v a 2 s . c om FileUtils.forceMkdir(pluginDir); FileUtils.forceDeleteOnExit(pluginDir); }
From source file:org.lexgrid.valuesets.helper.compiler.FileSystemCachingValueSetDefinitionCompilerDecorator.java
/** * Retrieve coded node set./*from w w w . java 2s . c om*/ * * @param md5 the md5 * * @return the coded node set * * @throws Exception the exception */ protected CodedNodeSet retrieveCodedNodeSet(String md5) { try { File cachedCnsFile = new File(this.getDiskStorePath() + File.separator + this.getFileName(md5)); if (!cachedCnsFile.exists()) { LoggerFactory.getLogger().info("Compiled Value Set Definition cache miss."); return null; } else { LoggerFactory.getLogger().info("Compiled Value Set Definition cache hit."); FileUtils.touch(cachedCnsFile); } ObjectInput in = new ObjectInputStream(new FileInputStream(cachedCnsFile)); CodedNodeSetImpl cns; try { cns = (CodedNodeSetImpl) in.readObject(); } catch (Exception e) { LoggerFactory.getLogger().warn( "Compiled Value Set Definition was found, but it is invalid or corrupted. Removing...", e); if (!FileUtils.deleteQuietly(cachedCnsFile)) { FileUtils.forceDeleteOnExit(cachedCnsFile); } throw e; } in.close(); if (cns == null) { return null; } else { return cns; } } catch (Exception e) { LoggerFactory.getLogger() .warn("There was an error retrieving the Compiled Value Set Definition from the Cache." + " Caching will not be used for this Value Set Definition.", e); return null; } }
From source file:org.omegat.util.TestPreferencesInitializer.java
/** * Init the preferences system using a temp dir for the config dir where * prefs files are read and written. Convenience method for * {@link #init(String)}.//from ww w .jav a 2 s. c o m * * @throws IOException */ public static void init() throws IOException { Path tmp = Files.createTempDirectory("omegat"); init(tmp.toString()); FileUtils.forceDeleteOnExit(tmp.toFile()); }
From source file:org.onehippo.cms7.essentials.dashboard.utils.MavenModelReaderWriterTest.java
@AfterClass public static void tearDownClass() throws Exception { assertTrue(target.exists());/*from w w w . jav a2 s . c o m*/ final boolean access = target.delete(); if (access) { FileUtils.forceDeleteOnExit(target); assertFalse(target.exists()); } }
From source file:org.opencredo.cloud.storage.azure.AzureTemplateTest.java
@Test public void testReceiveAndSaveToFile() throws IOException { String containerName = TEST_CONATINER_PREFIX + UUID.randomUUID().toString(); template.createContainer(containerName); String objectName = "string-1"; template.send(containerName, objectName, TEST_FILE); File f = File.createTempFile(getClass().getSimpleName(), ".txt"); FileUtils.forceDeleteOnExit(f); template.receiveAndSaveToFile(containerName, objectName, f); String receivedFileContent = FileUtils.readFileToString(f); System.out.println("Received file content: " + receivedFileContent); String orgFileContent = FileUtils.readFileToString(TEST_FILE); assertEquals("File conetent does not match", orgFileContent, receivedFileContent); }