public final class ProjectManager extends Object
Modifier and Type | Class and Description |
---|---|
static class |
ProjectManager.Result
A result (immutable) object returned from
ProjectManager.isProject2(org.openide.filesystems.FileObject) method. |
Modifier and Type | Method and Description |
---|---|
void |
clearNonProjectCache()
Clear the cached list of folders thought not to be projects.
|
Project |
findProject(FileObject projectDirectory)
Find an open project corresponding to a given project directory.
|
static ProjectManager |
getDefault()
Returns the singleton project manager instance.
|
Set<Project> |
getModifiedProjects()
Get a list of all projects which are modified and need to be saved.
|
boolean |
isModified(Project p)
Check whether a given project is current modified.
|
boolean |
isProject(FileObject projectDirectory)
Check whether a given directory is likely to contain a project without
actually loading it.
|
ProjectManager.Result |
isProject2(FileObject projectDirectory)
Check whether a given directory is likely to contain a project without
actually loading it.
|
boolean |
isValid(Project p)
Checks whether a project is still valid.
|
static Mutex |
mutex()
Get a read/write lock to be used for all project metadata accesses.
|
static Mutex |
mutex(boolean autoSave,
Project project,
Project... otherProjects)
Get a read/write lock to be used for project metadata accesses.
|
void |
saveAllProjects()
Save all modified projects.
|
void |
saveProject(Project p)
Save one project (if it was in fact modified).
|
@NonNull public static ProjectManager getDefault()
@NonNull public static Mutex mutex()
@NonNull public static Mutex mutex(boolean autoSave, @NonNull Project project, @NonNull Project... otherProjects)
autoSave
- if true the other most write operation automatically saves
the passed project(s)project
- the project to lockotherProjects
- other projects to lock@CheckForNull public Project findProject(@NonNull FileObject projectDirectory) throws IOException, IllegalArgumentException
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 wrapper Project
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.
projectDirectory
- the project top directoryProjectFactory
(might be null even if ProjectManager.isProject(org.openide.filesystems.FileObject)
returns true)IOException
- if the project was recognized but could not be loadedIllegalArgumentException
- if the supplied file object is null or not a folderpublic boolean isProject(@NonNull FileObject projectDirectory) throws IllegalArgumentException
ProjectManager.findProject(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 but ProjectManager.findProject(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 ProjectManager.findProject(org.openide.filesystems.FileObject)
afterwards. It is intended for only those clients which would discard the
result of ProjectManager.findProject(org.openide.filesystems.FileObject)
other than to check for null, and which
can also tolerate false positives.
projectDirectory
- a directory which may be some project's top directoryProjectFactory
IllegalArgumentException
- if the supplied file object is null or not a folder@CheckForNull public ProjectManager.Result isProject2(@NonNull FileObject projectDirectory) throws IllegalArgumentException
ProjectManager.Result
object contains additional
information about the found project.
Should be faster and use less memory than ProjectManager.findProject(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 but ProjectManager.findProject(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 ProjectManager.findProject(org.openide.filesystems.FileObject)
afterwards. It is intended for only those clients which would discard the
result of ProjectManager.findProject(org.openide.filesystems.FileObject)
other than to check for null, and which
can also tolerate false positives.
projectDirectory
- a directory which may be some project's top directoryProjectFactory
, or null if not a project folder.IllegalArgumentException
- if the supplied file object is null or not a folderpublic void clearNonProjectCache()
@NonNull public Set<Project> getModifiedProjects()
Acquires read access.
public boolean isModified(@NonNull Project p)
Acquires read access.
p
- a project loaded by this managerpublic void saveProject(@NonNull Project p) throws IOException
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.
p
- the project to saveIOException
- if it cannot be savedProjectFactory.saveProject(org.netbeans.api.project.Project)
public void saveAllProjects() throws IOException
Acquires write access.
IOException
- if any of them cannot be savedProjectFactory.saveProject(org.netbeans.api.project.Project)