diff --git a/openide.filesystems/apichanges.xml b/openide.filesystems/apichanges.xml --- a/openide.filesystems/apichanges.xml +++ b/openide.filesystems/apichanges.xml @@ -46,6 +46,24 @@ Filesystems API + + + Added FileUtil.getConfigFileObject for simpler access of default filesystem + + + + + +

+ Rather than having to call + Respository.getDefault().getDefaultFileSystem().getRoot().getFileObject("foo/bar"), + you can simply call + FileUtil.getConfigFileObject("foo/bar"). +

+
+ + +
FileChooserBuilder added diff --git a/openide.filesystems/nbproject/project.properties b/openide.filesystems/nbproject/project.properties --- a/openide.filesystems/nbproject/project.properties +++ b/openide.filesystems/nbproject/project.properties @@ -44,4 +44,4 @@ javadoc.main.page=org/openide/filesystems/doc-files/api.html javadoc.arch=${basedir}/arch.xml javadoc.apichanges=${basedir}/apichanges.xml -spec.version.base=7.17.0 +spec.version.base=7.18.0 diff --git a/openide.filesystems/src/org/openide/filesystems/FileUtil.java b/openide.filesystems/src/org/openide/filesystems/FileUtil.java --- a/openide.filesystems/src/org/openide/filesystems/FileUtil.java +++ b/openide.filesystems/src/org/openide/filesystems/FileUtil.java @@ -1771,6 +1771,21 @@ return Ordering.affectsOrder(event); } + /** + * Returns {@code FileObject} from the NetBeans default (system, configuration) + * filesystems or {@code null} if does not exist. Throws {@code NullPointerException} + * if the path is {@code null}. + * @param path the path from the root of the NetBeans default (system, configuration) + * filesystem delimited by '/' or empty string to get root folder. + * @return a {@code FileObject} for given path in the NetBeans default (system, configuration) + * filesystem or {@code null} if does not exist + * @since 7.18 + */ + public static FileObject getConfigFileObject(String path) { + Parameters.notNull("path", path); //NOI18N + return Repository.getDefault().getDefaultFileSystem().getRoot().getFileObject(path); + } + private static File wrapFileNoCanonicalize(File f) { if (f instanceof NonCanonicalizingFile) { return f; diff --git a/openide.filesystems/src/org/openide/filesystems/Repository.java b/openide.filesystems/src/org/openide/filesystems/Repository.java --- a/openide.filesystems/src/org/openide/filesystems/Repository.java +++ b/openide.filesystems/src/org/openide/filesystems/Repository.java @@ -60,12 +60,13 @@ import org.openide.util.io.NbMarshalledObject; /** - * Holder for system filesystem, used for most of NetBeans' runtime configuration. - * There is only one useful thing to do with this class: + * Holder for NetBeans default (system, configuration) filesystem, used for most + * of NetBeans' runtime configuration. 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 just want to modify configuration data use e.g. *
- * 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 + } + } }