Java Code Examples for org.openide.filesystems.FileObject#revert()
The following examples show how to use
org.openide.filesystems.FileObject#revert() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RemoveWritablesTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testRemovedFile() throws Exception { FileObject existingFile = FileUtil.getConfigFile( "foo/test1" ); assertNotNull( existingFile ); existingFile.delete(); File maskFile = new File( new File( configDir, "foo"), "test1_hidden" ); assertTrue( maskFile.exists() ); FileObject newFile = FileUtil.getConfigFile("foo"); assertTrue(newFile.canRevert()); newFile.revert(); assertFalse( "local file removed", maskFile.exists() ); assertNotNull( "FileObject exists again", FileUtil.getConfigFile( "foo/test1" ) ); }
Example 2
Source File: RemoveWritablesTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testRenamedFile() throws Exception { FileObject existingFile = FileUtil.getConfigFile( "foo/test1" ); assertNotNull( existingFile ); FileLock lock = existingFile.lock(); existingFile.rename( lock, "newName", "newExt" ); lock.releaseLock(); assertNotNull( FileUtil.getConfigFile( "foo/newName.newExt" ) ); File maskFile = new File( new File( configDir, "foo"), "test1_hidden" ); assertTrue( maskFile.exists() ); FileObject newFile = FileUtil.getConfigFile("foo"); assertTrue(newFile.canRevert()); newFile.revert(); assertFalse( "local file removed", maskFile.exists() ); assertNotNull( "FileObject exists again", FileUtil.getConfigFile( "foo/test1" ) ); assertNull( "renamed file is gone", FileUtil.getConfigFile( "foo/newName.newExt" ) ); }
Example 3
Source File: FeatureManager.java From netbeans with Apache License 2.0 | 6 votes |
public static void disableUnused(int howMuch) throws Exception { FileObject fo = FileUtil.getConfigFile("Modules"); // NOI18N final FileObject[] arr = fo.getChildren(); boolean first = true; for (int i = 0; i < arr.length; i++) { FileObject module = arr[i]; final Object when = module.getAttribute("ergonomicsEnabled"); // NOI18N LOG.log(Level.FINEST, "Checking {0}: {1}", new Object[] { module, when }); if (!(when instanceof Long) || ((Long) when) < module.lastModified().getTime()) { continue; } final Object unused = module.getAttribute("ergonomicsUnused"); // NOI18N LOG.log(Level.FINEST, "Unused {0}", unused); if (!(unused instanceof Number) || ((Number)unused).intValue() < howMuch) { continue; } String cnb = module.getName().replace('-', '.'); if (first) { LOG.info("Long time unused modules found, disabling:"); // NOI18N first = false; } LOG.info(cnb); module.revert(); } }
Example 4
Source File: ShortcutWizard.java From netbeans with Apache License 2.0 | 5 votes |
private static void delete(FileObject file) throws IOException { // cf. #162526 if (file.canRevert()) { file.revert(); } else { throw new IOException("Could not delete " + file); } }
Example 5
Source File: RemoveWritablesTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testAddedFile() throws Exception { FileObject folder = FileUtil.getConfigFile( "foo" ); FileObject newFile = folder.createData( "newFile", "ext" ); File writableFile = new File( new File( configDir, "foo"), "newFile.ext" ); assertTrue( writableFile.exists() ); assertTrue(newFile.canRevert()); newFile.revert(); assertFalse( "local file removed", writableFile.exists() ); assertNull( "FileObject does not exist", FileUtil.getConfigFile( "foo/newFile.ext" ) ); }
Example 6
Source File: RemoveWritablesTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testFolder() throws Exception { FileObject folder = FileUtil.getConfigFile("foo"); folder.createData("newFile", "ext"); File writableFolder = new File(configDir, "foo"); assertTrue(writableFolder.isDirectory()); assertTrue(folder.canRevert()); folder.revert(); assertFalse("local file removed", new File(writableFolder, "newFile.ext").exists()); assertNull("FileObject does not exist", FileUtil.getConfigFile("foo/newFile.ext")); folder = FileUtil.getConfigFile("foo"); assertNotNull("folder still there in layer", folder); assertFalse("no longer considered modified", folder.canRevert()); }
Example 7
Source File: ResetToolbarsAction.java From netbeans with Apache License 2.0 | 5 votes |
public void actionPerformed(ActionEvent e) { String name = ToolbarPool.getDefault().getConfiguration(); FileObject fo = FileUtil.getConfigFile( "Toolbars" ); //NOI18N try { fo.revert(); } catch (IOException ex) { Logger.getLogger(ResetToolbarsAction.class.getName()).log( Level.FINE, null, ex ); } ToolbarPool.getDefault().waitFinished(); ToolbarPool.getDefault().setConfiguration(name); }
Example 8
Source File: DataShadowUpdatesTest.java From netbeans with Apache License 2.0 | 4 votes |
/** * The test simulates a situation in which a .shadow file in the user * configuration is reverted, and an original contents/atributes, * with a different target, are revealed. * <p/> * The DataShadow should at least produce the appropriate cookies. * * @throws Exception T */ public void testShadowFileReverted() throws Exception { clearWorkDir(); File wd = getWorkDir(); File homeDir = new File(wd, "home"); File localDir = new File(wd, "data"); localDir.mkdirs(); homeDir.mkdirs(); LocalFileSystem lfs1 = new LocalFileSystem(); lfs1.setRootDirectory(homeDir); FileObject r = lfs1.getRoot(); Class c = SystemFileSystem.class; Method m = c.getDeclaredMethod("create", File.class, File.class, File[].class); m.setAccessible(true); FileSystem mfs = (FileSystem)m.invoke(null, localDir, homeDir, new File[] {} ); FileObject file1 = r.createData("org-openide-actions-NewTemplateAction.instance"); FileObject file2 = r.createData("org-openide-actions-SaveAsTemplateAction.instance"); FileObject shadow = r.createData("file.shadow"); shadow.setAttribute("originalFile", "org-openide-actions-NewTemplateAction.instance"); FileObject mfsRoot = mfs.getRoot(); FileObject mfsShadow = mfsRoot.getFileObject("file.shadow"); // must create the file contents, otherwise canRevert does not work either mfsShadow.getOutputStream().close(); mfsShadow.setAttribute("originalFile", "org-openide-actions-SaveAsTemplateAction.instance"); DataShadow s = (DataShadow)DataObject.find(mfsShadow); assertEquals( file2.getPath(), s.getOriginal().getPrimaryFile().getPath()); assertTrue(mfsShadow.canRevert()); InstanceCookie ic = s.getCookie(InstanceCookie.class); assertSame(SaveAsTemplateAction.class, ic.instanceClass()); mfsShadow.revert(); s = (DataShadow)DataObject.find(mfsShadow); ic = s.getCookie(InstanceCookie.class); assertSame(NewTemplateAction.class, ic.instanceClass()); assertEquals( file1.getPath(), s.getOriginal().getPrimaryFile().getPath()); }