+ Rather than having to call
+ Respository.getDefault().getDefaultFileSystem().getRoot().getFileObject("foo/bar")
,
+ you can simply call
+ FileUtil.getConfigFileObject("foo/bar").
+
- * FileSystem sfs = Repository.getDefault().getDefaultFileSystem(); - * // now use somehow, e.g. - * FileObject menus = sfs.findResource("Menu"); + * FileObject menus = FileUtil.getConfigFileObject("Menu"); * // ... ** Formerly (NB 3.x) contained a list of mounted filesystems. This functionality @@ -168,6 +169,11 @@ /** * Gets the NetBeans default (system, configuration) filesystem. + * The default implementation is a merge of + * all of the XML layer files provided by enabled modules, and the + * {@code config} subfolder of the userdir on the user's disk. + * If you want to simply get a file or folder from this filesystem, + * it is simpler to call {@link FileUtil#getConfigFileObject(java.lang.String)}. * @return the default filesystem */ public final FileSystem getDefaultFileSystem() { diff --git a/openide.filesystems/test/unit/src/org/openide/filesystems/FileUtilTest.java b/openide.filesystems/test/unit/src/org/openide/filesystems/FileUtilTest.java --- a/openide.filesystems/test/unit/src/org/openide/filesystems/FileUtilTest.java +++ b/openide.filesystems/test/unit/src/org/openide/filesystems/FileUtilTest.java @@ -319,4 +319,19 @@ logger.removeHandler(handler); } } + + /** Tests getConfigFileObject method (see #91534). */ + public void testGetConfigFileObject() throws IOException { + FileObject rootDFS = Repository.getDefault().getDefaultFileSystem().getRoot(); + assertNotNull("Sample FileObject not created.", rootDFS.createFolder("folder1").createFolder("folder2").createData("file.ext")); + assertNotNull("Existing FileObject not found.", FileUtil.getConfigFileObject("folder1/folder2/file.ext")); + assertNull("Path with backslashes is not valid.", FileUtil.getConfigFileObject("folder1\\folder2\\file.ext")); + assertEquals("Root should be returned for empty path.", rootDFS, FileUtil.getConfigFileObject("")); + try { + FileUtil.getConfigFileObject(null); + fail("NullPointerException should be thrown for null path."); + } catch (NullPointerException npe) { + // OK + } + } }