Class ProjectManager
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
A result (immutable) object returned fromisProject2(org.openide.filesystems.FileObject)
method. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Clear the cached list of folders thought not to be projects.findProject
(org.openide.filesystems.FileObject projectDirectory) Find an open project corresponding to a given project directory.static ProjectManager
Returns the singleton project manager instance.Get a list of all projects which are modified and need to be saved.boolean
Check whether a given project is current modified.boolean
isProject
(org.openide.filesystems.FileObject projectDirectory) Check whether a given directory is likely to contain a project without actually loading it.isProject2
(org.openide.filesystems.FileObject projectDirectory) Check whether a given directory is likely to contain a project without actually loading it.boolean
Checks whether a project is still valid.static org.openide.util.Mutex
mutex()
Get a read/write lock to be used for all project metadata accesses.static org.openide.util.Mutex
Get a read/write lock to be used for project metadata accesses.void
Save all modified projects.void
Save one project (if it was in fact modified).
-
Method Details
-
getDefault
Returns the singleton project manager instance.- Returns:
- the default instance
-
mutex
@NonNull public static org.openide.util.Mutex mutex()Get a read/write lock to be used for all project metadata accesses. All methods relating to recognizing and loading projects, saving them, getting or setting their metadata, etc. should be controlled by this mutex and be marked as read operations or write operations. Unless otherwise stated, project-related methods automatically acquire the mutex for you, so you do not necessarily need to pay attention to it; but you may directly acquire the mutex in order to ensure that a block of reads does not have any interspersed writes, or in order to ensure that a write is not clobbering an unrelated write, etc.- Returns:
- a general read/write lock for project metadata operations of all sorts
-
mutex
@NonNull public static org.openide.util.Mutex mutex(boolean autoSave, @NonNull Project project, @NonNull Project... otherProjects) Get a read/write lock to be used for project metadata accesses. The returned lock may be optimized to limit contention only on given project(s).- Parameters:
autoSave
- if true the other most write operation automatically saves the passed project(s)project
- the project to lockotherProjects
- other projects to lock- Returns:
- a general read/write lock for project metadata operations
- Since:
- 1.59
-
findProject
@CheckForNull public Project findProject(@NonNull org.openide.filesystems.FileObject projectDirectory) throws IOException, IllegalArgumentException Find an open project corresponding to a given project directory. Will be created in memory if necessary.Acquires read access.
It is not guaranteed that the returned instance will be identical to that which is created by the appropriate
ProjectFactory
. In particular, the project manager is free to return only wrapperProject
instances which delegate to the factory's implementation. If you know your factory created a particular project, you cannot safely cast the return value of this method to your project type implementation class; you should instead place an implementation of some suitable private interface into your project's lookup, which would be safely proxied.- Parameters:
projectDirectory
- the project top directory- Returns:
- the project (object identity may or may not vary between calls)
or null if the directory is not recognized as a project by any
registered
ProjectFactory
(might be null even ifisProject(org.openide.filesystems.FileObject)
returns true) - Throws:
IOException
- if the project was recognized but could not be loadedIllegalArgumentException
- if the supplied file object is null or not a folder
-
isProject
public boolean isProject(@NonNull org.openide.filesystems.FileObject projectDirectory) throws IllegalArgumentException Check whether a given directory is likely to contain a project without actually loading it. Should be faster and use less memory thanfindProject(org.openide.filesystems.FileObject)
when called on a large number of directories.The result is not guaranteed to be accurate; there may be false positives (directories for which
isProject
is true butfindProject(org.openide.filesystems.FileObject)
will return null), for example if there is trouble loading the project. False negatives are possible only if there are bugs in the project factory.Acquires read access.
You do not need to call this method if you just plan to call
findProject(org.openide.filesystems.FileObject)
afterwards. It is intended for only those clients which would discard the result offindProject(org.openide.filesystems.FileObject)
other than to check for null, and which can also tolerate false positives.- Parameters:
projectDirectory
- a directory which may be some project's top directory- Returns:
- true if the directory is likely to contain a project according to
some registered
ProjectFactory
- Throws:
IllegalArgumentException
- if the supplied file object is null or not a folder
-
isProject2
@CheckForNull public ProjectManager.Result isProject2(@NonNull org.openide.filesystems.FileObject projectDirectory) throws IllegalArgumentException Check whether a given directory is likely to contain a project without actually loading it. The returnedProjectManager.Result
object contains additional information about the found project. Should be faster and use less memory thanfindProject(org.openide.filesystems.FileObject)
when called on a large number of directories.The result is not guaranteed to be accurate; there may be false positives (directories for which
isProject2
is non-null butfindProject(org.openide.filesystems.FileObject)
will return null), for example if there is trouble loading the project. False negatives are possible only if there are bugs in the project factory.Acquires read access.
You do not need to call this method if you just plan to call
findProject(org.openide.filesystems.FileObject)
afterwards. It is intended for only those clients which would discard the result offindProject(org.openide.filesystems.FileObject)
other than to check for null, and which can also tolerate false positives.- Parameters:
projectDirectory
- a directory which may be some project's top directory- Returns:
- Result object if the directory is likely to contain a project according to
some registered
ProjectFactory
, or null if not a project folder. - Throws:
IllegalArgumentException
- if the supplied file object is null or not a folder- Since:
- org.netbeans.modules.projectapi 1.22
-
clearNonProjectCache
public void clearNonProjectCache()Clear the cached list of folders thought not to be projects. This may be useful after creating project metadata in a folder, etc. Cached project objects, i.e. folders that are known to be projects, are not affected. -
getModifiedProjects
-
isModified
Check whether a given project is current modified.Acquires read access.
- Parameters:
p
- a project loaded by this manager- Returns:
- true if it is modified, false if has been saved since the last modification
-
saveProject
Save one project (if it was in fact modified).Acquires write access.
Although the project infrastructure permits a modified project to be saved at any time, current UI principles dictate that the "save project" concept should be internal only - i.e. a project customizer should automatically save the project when it is closed e.g. with an "OK" button. Currently there is no UI display of modified projects; this module does not ensure that modified projects are saved at system exit time the way modified files are, though the Project UI implementation module currently does this check.
- Parameters:
p
- the project to save- Throws:
IOException
- if it cannot be saved- See Also:
-
saveAllProjects
Save all modified projects.Acquires write access.
- Throws:
IOException
- if any of them cannot be saved- See Also:
-
isValid
Checks whether a project is still valid.Acquires read access.
- Parameters:
p
- a project- Returns:
- true if the project is still valid, false if it has been deleted
- Since:
- 1.6
-