Search in sources :

Example 1 with FileUtils

use of org.apache.commons.io.FileUtils in project gocd by gocd.

the class AgentBootstrapper method cleanupTempFiles.

private void cleanupTempFiles() {
    FileUtils.deleteQuietly(new File(FileUtil.TMP_PARENT_DIR));
    // launchers extracted from old versions
    FileUtils.deleteQuietly(new File("exploded_agent_launcher_dependencies"));
    FileUtils.listFiles(new File("."), AGENT_LAUNCHER_TMP_FILE_FILTER, FalseFileFilter.INSTANCE).forEach(FileUtils::deleteQuietly);
    FileUtils.deleteQuietly(new File(new SystemEnvironment().getConfigDir(), "trust.jks"));
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) FileUtils(org.apache.commons.io.FileUtils) File(java.io.File)

Example 2 with FileUtils

use of org.apache.commons.io.FileUtils in project cas by apereo.

the class SamlSPUtilsTests method shutdown.

@AfterAll
public static void shutdown() {
    val file = new File(FileUtils.getTempDirectoryPath(), "idp-metadata-test");
    val cols = FileUtils.listFiles(file, new String[] { "crt", "key", "xml" }, false);
    cols.forEach(FileUtils::deleteQuietly);
}
Also used : lombok.val(lombok.val) FileUtils(org.apache.commons.io.FileUtils) File(java.io.File) AfterAll(org.junit.jupiter.api.AfterAll)

Example 3 with FileUtils

use of org.apache.commons.io.FileUtils in project jmeter by apache.

the class Save method backupAndSave.

/**
 * Backup existing file according to jmeter/user.properties settings
 * and save
 * @param e {@link ActionEvent}
 * @param subTree HashTree Test plan to save
 * @param fullSave Partial or full save
 * @param newFile File to save
 * @throws IllegalUserActionException
 */
void backupAndSave(ActionEvent e, HashTree subTree, boolean fullSave, String newFile) throws IllegalUserActionException {
    // 
    List<File> expiredBackupFiles = EMPTY_FILE_LIST;
    if (GuiPackage.getInstance().isDirty()) {
        File fileToBackup = new File(newFile);
        log.debug("Test plan has changed, make backup of {}", fileToBackup);
        try {
            expiredBackupFiles = createBackupFile(fileToBackup);
        } catch (Exception ex) {
            // $NON-NLS-1$
            log.error("Failed to create a backup for {}", fileToBackup, ex);
        }
    }
    try {
        convertSubTree(subTree);
    } catch (Exception err) {
        if (log.isWarnEnabled()) {
            log.warn("Error converting subtree. {}", err.toString());
        }
    }
    try (FileOutputStream ostream = new FileOutputStream(newFile)) {
        SaveService.saveTree(subTree, ostream);
        if (fullSave) {
            // Only update the stored copy of the tree for a full save
            FileServer.getFileServer().setScriptName(new File(newFile).getName());
            // refetch, because convertSubTree affects it
            subTree = GuiPackage.getInstance().getTreeModel().getTestPlan();
            ActionRouter.getInstance().doActionNow(new ActionEvent(subTree, e.getID(), ActionNames.SUB_TREE_SAVED));
        }
        // delete expired backups : here everything went right so we can
        // proceed to deletion
        expiredBackupFiles.forEach(FileUtils::deleteQuietly);
    } catch (RuntimeException ex) {
        throw ex;
    } catch (Exception ex) {
        log.error("Error saving tree.", ex);
        throw new IllegalUserActionException("Couldn't save test plan to file: " + newFile, ex);
    }
}
Also used : FileUtils(org.apache.commons.io.FileUtils) ActionEvent(java.awt.event.ActionEvent) FileOutputStream(java.io.FileOutputStream) IllegalUserActionException(org.apache.jmeter.exceptions.IllegalUserActionException) File(java.io.File) IOException(java.io.IOException) IllegalUserActionException(org.apache.jmeter.exceptions.IllegalUserActionException)

Aggregations

File (java.io.File)3 FileUtils (org.apache.commons.io.FileUtils)3 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)1 ActionEvent (java.awt.event.ActionEvent)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 lombok.val (lombok.val)1 IllegalUserActionException (org.apache.jmeter.exceptions.IllegalUserActionException)1 AfterAll (org.junit.jupiter.api.AfterAll)1