List of usage examples for org.apache.commons.io FileUtils touch
public static void touch(File file) throws IOException
From source file:com.mindquarry.desktop.workspace.SVNTestBase.java
/** * Creates a file inside the working copy (wcPath). *//*from w w w . j a va2s . c om*/ protected void touch(String relativePath) throws IOException { FileUtils.touch(new File(wcPath + "/" + relativePath)); }
From source file:edu.kit.dama.staging.ap.AbstractStagingAccessPoint.java
/** * Prepare the cleanup the provided transfer. During cleanup preparation the * AccessPoint first takes care, that no file is write protected and * everything can be removed automatically. For this purpose, {@link #prepareCleanupInternal(edu.kit.dama.staging.interfaces.ITransferInformation, edu.kit.dama.authorization.entities.IAuthorizationContext) * } is called. Afterwards, to mark the transfer folder as "deleteable", a * file named StagingService.DELETED_FILENAME (.deleted) is created inside * the folder of the transfer./*from w ww . j a va 2s . c o m*/ * * @param pTransferInformation The transfer to cleanup. * @param pSecurityContext Security context used to authorize access and to * obtain user/group information. * * @return TRUE if the cleanup was succeeded (.deleted was created) or no * files were left, FALSE if .deleted could not be created and there are * files left. */ public final boolean prepareCleanup(ITransferInformation pTransferInformation, IAuthorizationContext pSecurityContext) { boolean result; URL accessUrl = getAccessUrl(pTransferInformation, pSecurityContext); File localPath = getLocalPathForUrl(accessUrl, pSecurityContext); if (!localPath.exists()) { //nothing exists...looks already "clean" to me. result = true; } else { LOGGER.debug("Performing method-specific cleanup preparation."); result = prepareCleanupInternal(pTransferInformation, pSecurityContext); if (result) { File deleteFile = new File(localPath, Constants.STAGING_DELETED_FILENAME); LOGGER.debug("Try creating cleanup indicator file at {}", deleteFile); try { FileUtils.touch(deleteFile); LOGGER.debug("Cleanup indicator successfully created."); } catch (IOException ex) { LOGGER.error("Failed to touch cleanup indicator file " + deleteFile + ". Cleanup preparation failed.", ex); result = false; } } } return result; }
From source file:com.mindquarry.desktop.workspace.SVNTestBase.java
/** * Creates a file inside the 'remote' working copy (wcPathRemote). *//*from w w w .j av a 2s. c om*/ private void touchRemote(String relativePath) throws IOException { FileUtils.touch(new File(wcPathRemote + "/" + relativePath)); }
From source file:de.tor.tribes.ui.windows.DSWorkbenchSplashScreen.java
protected HIDE_RESULT hideSplash() { try {//w ww . j a v a2 s. com if (!new File(".").canWrite()) { try { throw new IOException( "Failed to access installation directory " + new File(".").getAbsolutePath()); } catch (Exception e) { showFatalError(e); return HIDE_RESULT.ERROR; } } File f = new File("./servers"); if (!f.exists() && !f.mkdir()) { try { throw new IOException( "Failed to create server directory at location " + new File(".").getAbsolutePath()); } catch (Exception e) { showFatalError(e); return HIDE_RESULT.ERROR; } } ProfileManager.getSingleton().loadProfiles(); if (ProfileManager.getSingleton().getProfiles().length == 0) { logger.debug("Starting first start wizard"); //first start wizard if (!new File("./hfsw").exists()) { logger.debug(" - Initializing first start wizard"); Map result = new HashMap<>(); try { WizardPanelProvider provider = new FirstStartWizard(); Wizard wizard = provider.createWizard(); logger.debug(" - Showing wizard"); result = (Map) WizardDisplayer.showWizard(wizard); logger.debug("Wizard finished with result " + result); } catch (Throwable t) { logger.error("Wizard exception", t); result = null; } logger.debug(" - Wizard has finished"); if (result == null) { logger.warn(" - Wizard returned no result. Startup will fail."); JOptionPaneHelper.showWarningBox(self, "Du musst die grundlegenden Einstellungen zumindest einmalig durchfhren,\n" + "um DS Workbench verwenden zu knnen. Bitte starte DS Workbench neu.", "Abbruch"); return HIDE_RESULT.ERROR; } else { logger.debug("Wizard result: " + result); } logger.debug("- First start wizard finished"); GlobalOptions.addProperty("proxySet", result.get("proxySet").toString()); GlobalOptions.addProperty("proxyHost", result.get("proxyHost").toString()); GlobalOptions.addProperty("proxyPort", result.get("proxyPort").toString()); GlobalOptions.addProperty("proxyType", result.get("proxyType").toString()); GlobalOptions.addProperty("proxyUser", result.get("proxyUser").toString()); GlobalOptions.addProperty("proxyPassword", result.get("proxyPassword").toString()); GlobalOptions.addProperty("default.server", result.get("server").toString()); GlobalOptions.addProperty("default.player", result.get("tribe.id").toString()); logger.debug("Creating initial profile"); UserProfile p = UserProfile.create(GlobalOptions.getProperty("default.server"), result.get("tribe.name").toString()); GlobalOptions.setSelectedProfile(p); GlobalOptions.addProperty("selected.profile", Long.toString(p.getProfileId())); logger.debug(" - Disabling first start wizard"); FileUtils.touch(new File("./hfsw")); GlobalOptions.saveProperties(); } } //load properties, cursors, skins, world decoration logger.debug("Adding startup listeners"); DataHolder.getSingleton().addDataHolderListener(this); DataHolder.getSingleton().addDataHolderListener(DSWorkbenchSettingsDialog.getSingleton()); GlobalOptions.addDataHolderListener(this); } catch (Exception e) { logger.error("Failed to initialize global options", e); showFatalError(e); return HIDE_RESULT.ERROR; } logger.debug("Starting profile selection"); boolean settingsRestored = false; ServerManager.loadServerList(DSWorkbenchSettingsDialog.getSingleton().getWebProxy()); try { //open profile selection if (ProfileManager.getSingleton().getProfiles().length == 0) { logger.debug("No profile exists, SettingsDialog will handle this"); //no profile found...this is handles by the settings validation } else if (ProfileManager.getSingleton().getProfiles().length == 1) { logger.debug("One profile exists. Using it..."); //only one single profile was found, use it UserProfile profile = ProfileManager.getSingleton().getProfiles()[0]; String server = profile.getServerId(); GlobalOptions.setSelectedServer(server); GlobalOptions.setSelectedProfile(profile); GlobalOptions.addProperty("default.server", server); GlobalOptions.addProperty("selected.profile", Long.toString(profile.getProfileId())); } else { logger.debug("More than one profiles exist. Showing selection dialog"); File f = new File("./servers"); List<String> servers = new LinkedList<>(); for (File server : f.listFiles()) { servers.add(server.getName()); } //sort server names Collections.sort(servers, new Comparator<String>() { @Override public int compare(String o1, String o2) { if (o1.length() < o2.length()) { return -1; } else if (o1.length() > o2.length()) { return 1; } return o1.compareTo(o2); } }); List<Object> path = new LinkedList<>(); DefaultMutableTreeNode root = new DefaultMutableTreeNode("Profile"); long selectedProfile = GlobalOptions.getProperties().getLong("selected.profile"); path.add(root); for (String server : servers) { DefaultMutableTreeNode serverNode = new DefaultMutableTreeNode(server); boolean profileAdded = false; for (UserProfile profile : ProfileManager.getSingleton().getProfiles(server)) { DefaultMutableTreeNode profileNode = new DefaultMutableTreeNode(profile); if (profile.getProfileId() == selectedProfile) { path.add(serverNode); path.add(profileNode); } serverNode.add(profileNode); profileAdded = true; } if (profileAdded) { root.add(serverNode); } } jTree1.setModel(new DefaultTreeModel(root)); jTree1.setSelectionPath(new TreePath(path.toArray())); jTree1.scrollPathToVisible(new TreePath(path.toArray())); jTree1.setCellRenderer(new ProfileTreeNodeRenderer()); jProfileDialog.setVisible(true); } logger.debug("Profile selection finished"); //check settings DSWorkbenchSettingsDialog.getSingleton().restoreProperties(); settingsRestored = true; if (!DSWorkbenchSettingsDialog.getSingleton().checkSettings()) { logger.debug("Settings check in settings dialog failed"); logger.info("Reading user settings returned error(s)"); DSWorkbenchSettingsDialog.getSingleton().setBlocking(true); DSWorkbenchSettingsDialog.getSingleton().setVisible(true); } } catch (Exception e) { logger.warn("Failed to open profile manager", e); } if (!settingsRestored) { DSWorkbenchSettingsDialog.getSingleton().restoreProperties(); } // <editor-fold defaultstate="collapsed" desc=" Check for data updates "> logger.debug("Checking for application updates"); boolean checkForUpdates = GlobalOptions.getProperties().getBoolean("check.updates.on.startup"); try { if (!DataHolder.getSingleton().loadData(checkForUpdates)) { throw new Exception("loadData() returned 'false'. See log for more details."); } } catch (Exception e) { logger.error("Failed to load server data", e); showFatalError(e); return HIDE_RESULT.ERROR; } // </editor-fold> try { logger.debug("Initializing application window"); DSWorkbenchMainFrame.getSingleton().init(); logger.info("Showing application window"); DSWorkbenchMainFrame.getSingleton().setVisible(true); //check for version updates logger.info("Checking for DS Workbench update."); UpdateInfo info = GithubVersionCheck.getUpdateInformation(); switch (info.getStatus()) { case UPDATE_AVAILABLE: NotifierFrame.doNotification( "Eine neue DS Workbench Version ist verfgbar. Klick den grnen Punkt oben links, um auf die Download Seite zu gelangen. ", NotifierFrame.NOTIFY_UPDATE); default: logger.info("No update available or update check failed."); } try { ReportServer.getSingleton().start(GlobalOptions.getProperties().getInt("report.server.port")); } catch (Exception e) { logger.error("Failed to start report server", e); } // <editor-fold defaultstate="collapsed" desc=" Init HelpSystem "> if (!Constants.DEBUG) { GlobalOptions.getHelpBroker().enableHelpKey(DSWorkbenchSimulatorFrame.getSingleton().getRootPane(), "pages.astar", GlobalOptions.getHelpBroker().getHelpSet()); GlobalOptions.getHelpBroker().enableHelpKey(DSWorkbenchMainFrame.getSingleton().getRootPane(), "index", GlobalOptions.getHelpBroker().getHelpSet()); } // </editor-fold> // <editor-fold defaultstate="collapsed" desc=" Init A*Star Servers "> ServerManager.giveSimulatorServerList(); // </editor-fold> t.stopRunning(); setVisible(false); GlobalOptions.removeDataHolderListener(this); return HIDE_RESULT.SUCCESS; } catch (Throwable th) { logger.fatal("Fatal error while running DS Workbench", th); showFatalError(th); return HIDE_RESULT.ERROR; } }
From source file:com.izforge.izpack.panels.target.TargetPanelTest.java
/** * Verifies that when {@link TargetPanel#setExistFiles(String[])} is used, the specified files must exist * in order for the panel to be valid.//from w w w. java 2s . com * * @throws Exception for any error */ @Test public void testFilesExist() throws Exception { String[] requiredFiles = { "a", "b" }; GUIInstallData installData = getInstallData(); Messages messages = installData.getMessages(); File root = temporaryFolder.getRoot(); File dir = new File(root, "install"); assertTrue(dir.mkdirs()); installData.setDefaultInstallPath(dir.getAbsolutePath()); // show the panel FrameFixture fixture = show(TargetPanel.class, SimpleFinishPanel.class); Thread.sleep(1000); assertTrue(getPanels().getView() instanceof TargetPanel); TargetPanel panel = (TargetPanel) getPanels().getView(); panel.setMustExist(true); // to avoid popping up a Directory already exists dialog panel.setExistFiles(requiredFiles); fixture.button(GuiId.BUTTON_NEXT.id).click(); Thread.sleep(1000); checkErrorMessage(fixture, messages.get("PathInputPanel.notValid")); // create the required files for (String required : requiredFiles) { File file = new File(dir, required); FileUtils.touch(file); } fixture.button(GuiId.BUTTON_NEXT.id).click(); Thread.sleep(1000); assertTrue(getPanels().getView() instanceof SimpleFinishPanel); assertEquals(dir.getAbsolutePath(), installData.getInstallPath()); }
From source file:hudson.FilePathTest.java
private FilePath createFilePath(final File base, final String... path) throws IOException { File building = base;/*w w w .jav a2s . c o m*/ for (final String component : path) { building = new File(building, component); } FileUtils.touch(building); return new FilePath(building); }
From source file:hudson.plugins.jobConfigHistory.FileHistoryDaoTest.java
/** * Test of getRevisions method, of class FileHistoryDao. *//*from w w w . ja v a2s . co m*/ @Test public void testGetRevisionsForItemWithoutHistory() throws IOException { final String jobWithoutHistory = "NewJobWithoutHistory"; final File configFile = new File(unpackResourceZip.getResource("jobs/" + jobWithoutHistory), "config.xml"); FileUtils.touch(configFile); assertEquals(0, sutWithUserAndNoDuplicateHistory.getRevisions(configFile).size()); }
From source file:de.tudarmstadt.ukp.dkpro.core.io.web1t.util.Web1TConverter.java
private Map<Integer, BufferedWriter> initializeWriters(int min, int max) throws IOException { Map<Integer, BufferedWriter> writers = new HashMap<Integer, BufferedWriter>(); for (int level = min; level <= max; level++) { File outputFile = new File(outputPath, level + ".txt"); if (outputFile.exists()) { outputFile.delete();//from w w w. j av a2 s .c om } FileUtils.touch(outputFile); writers.put(level, new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputFile), outputEncoding))); } return writers; }
From source file:com.moscona.dataSpace.persistence.DirectoryDataStore.java
private void createLockFile() throws DataSpaceException { try {// w ww .ja v a 2 s .c o m FileUtils.touch(new File(lockFilePath())); } catch (IOException e) { throw new DataSpaceException("Exception while trying to create a lock file " + lockFilePath()); } }
From source file:net.pms.configuration.DownloadPlugins.java
private boolean command(String cmd, String args) throws ConfigurationException { if (cmd.equalsIgnoreCase("move")) { // arg1 is src and arg2 is dst String[] tmp = args.split(","); try {//w w w.j av a2 s. c o m FileUtils.moveFile(new File(tmp[1]), new File(tmp[2])); } catch (IOException e) { // Ignore errors, just log it LOGGER.debug("couldn't move file " + tmp[1] + " to " + tmp[2]); } return true; } if (cmd.equalsIgnoreCase("touch")) { // arg1 is file to touch String[] tmp = args.split(","); try { FileUtils.touch(new File(tmp[1])); } catch (IOException e) { // Ignore errors, just log it LOGGER.debug("couldn't touch file " + tmp[1]); } return true; } if (cmd.equalsIgnoreCase("conf")) { String[] tmp = args.split(",", 2); tmp = tmp[1].split("="); configuration.setCustomProperty(tmp[1], tmp[2]); configuration.save(); return true; } if (cmd.equalsIgnoreCase("exec")) { try { doExec(args); } catch (ConfigurationException | IOException | InterruptedException e) { } return true; } return false; }