Class ProjectUtils
-
Method Summary
Modifier and TypeMethodDescriptionReturns the active configuration for the given project.static AuxiliaryConfiguration
getAuxiliaryConfiguration
(Project project) Find a way of storing extra configuration in a project.static org.openide.filesystems.FileObject
getCacheDirectory
(Project project, Class<?> owner) Gets a directory in which modules may store arbitrary extra unversioned files associated with a project.getContainedProjects
(Project root, boolean recursive) Utility method for access toProjectContainerProvider
, a less vague variant of theSubprojectProvider
for code that wants to access projects that the current project serves as container for.getDependencyProjects
(Project root, boolean recursive) Utility method for access toDependencyProjectProvider
, a less vague variant of theSubprojectProvider
for code that wants to access project's dependencies that are also projects.static ProjectInformation
Get basic information about a project.static Preferences
getPreferences
(Project project, Class clazz, boolean shared) ReturnPreferences
for the given project and given module.static Sources
Get a list of sources for a project.static boolean
hasSubprojectCycles
(Project master, Project candidate) Check whether a project has, or might have, cycles in its subproject graph.static Project
Utility method forParentProjectProvider
.static Project
Utility method forRootProjectProvider
.<C extends ProjectConfiguration>
booleansetActiveConfiguration
(Project p, C cfg) Sets the active configuration to a project.
-
Method Details
-
getActiveConfiguration
Returns the active configuration for the given project. Returnsnull
, if the project does not support configurations at all.- Parameters:
p
- the project- Returns:
- the active configuration, or
null
if configurations are not supported. - Since:
- 1.89
-
setActiveConfiguration
public <C extends ProjectConfiguration> boolean setActiveConfiguration(@NonNull Project p, @NonNull C cfg) throws IOException Sets the active configuration to a project. The configuration should have been previously obtained bygetActiveConfiguration(org.netbeans.api.project.Project)
from the same project. The method returnsfalse
, if the configuration could not be set: if the project does not support configurations at all, or the project failed to switch the configurations. Since the active configuration setting is persisted, the method throwsIOException
if the setting save fails.- Type Parameters:
C
- configuration type- Parameters:
p
- the projectcfg
- configuration ornull
for default configuration.- Returns:
- true, if the configuration was successfully set.
- Throws:
IOException
- when the selected configuration cannot be persisted.- Since:
- 1.89
-
getInformation
Get basic information about a project. If the project has aProjectInformation
instance in its lookup, that is used. Otherwise, a basic dummy implementation is returned.- Parameters:
p
- a project- Returns:
- some information about it
- See Also:
-
getSources
Get a list of sources for a project. If the project has aSources
instance in its lookup, that is used. Otherwise, a basic implementation is returned usingGenericSources.genericOnly(org.netbeans.api.project.Project)
.- Parameters:
p
- a project- Returns:
- a list of sources for it
- See Also:
-
hasSubprojectCycles
Check whether a project has, or might have, cycles in its subproject graph.If the candidate parameter is null, this simply checks whether the master project's current directed graph of (transitive) subprojects contains any cycles. If the candidate is also passed, this checks whether the master project's subproject graph would contain cycles if the candidate were added as a (direct) subproject of the master project.
All cycles are reported even if they do not contain the master project.
If the master project already contains the candidate as a (direct) subproject, the effect is as if the candidate were null.
Projects with no
SubprojectProvider
are considered to have no subprojects, just as if the provider returned an empty set.Acquires read access.
Project types which let the user somehow configure subprojects in the GUI (perhaps indirectly, e.g. via a classpath) should use this call to check for possible cycles before adding new subprojects.
- Parameters:
master
- a project to root the subproject graph fromcandidate
- a potential direct subproject of the master project, or null- Returns:
- true if the master project currently has a cycle somewhere in its subproject graph, regardless of the candidate parameter, or if the candidate is not null and the master project does not currently have a cycle but would have one if the candidate were added as a subproject
- See Also:
-
getDependencyProjects
Utility method for access toDependencyProjectProvider
, a less vague variant of theSubprojectProvider
for code that wants to access project's dependencies that are also projects. Even when recursive, will only use DependencyProjectProvider on other projects. Unlike some java level API this doesn't distinguish between compile, runtime, test level dependencies.- Parameters:
root
- project where to start calculating dependenciesrecursive
- true if entire dependency tree should be calculated, some project implementation can return just direct dependency projects that themselves have dependency projects. Please note that false value does NOT guarantee that only direct dependency projects will be returned.- Returns:
- null if project doesn't have
DependencyProjectProvider
in it's lookup, or a set with projects, ordering not mandated - Since:
- 1.56
-
getContainedProjects
Utility method for access toProjectContainerProvider
, a less vague variant of theSubprojectProvider
for code that wants to access projects that the current project serves as container for. Eg. in case of Maven based projects it means projects referenced by <modules> pom.xml section. Even when recursive, will only use ProjectContainerProvider on other projects.- Parameters:
root
- project where to start calculating contained projectsrecursive
- true if entire container tree should be calculated, some project implementation can return just direct subprojects that themselves contain projects. Please note that false value does NOT guarantee that only direct projects will be returned.- Returns:
- null if project doesn't have
ProjectContainerProvider
in it's lookup, or a set with projects, ordering not mandated - Since:
- 1.56
-
parentOf
Utility method forParentProjectProvider
. If the given project supportParentProjectProvider
this method will return the immediate parent of that project ornull
if that can not be determined or the project has no parent. This method also returnsnull
if the given project has noParentProjectProvider
support.- Parameters:
project
- a suspected child project- Returns:
- the immediate parent of the given project if known or
null
. - Since:
- 1.79
-
rootOf
Utility method forRootProjectProvider
. If the given project supportRootProjectProvider
this method will return its farthest parent.If the given project itself is root the it returns that. If the the farthest parent cannot be determined the given project is considered to be a root project and will be returned.- Parameters:
project
- a suspected child project- Returns:
- the farthest parent of the given project if known or
this
. - Since:
- 1.79
-
getPreferences
public static Preferences getPreferences(@NonNull Project project, @NonNull Class clazz, boolean shared) ReturnPreferences
for the given project and given module.The preferences are stored in the project using either
AuxiliaryConfiguration
orAuxiliaryProperties
.- Parameters:
project
- project for which preferences should be returnedclazz
- module specification as inNbPreferences.forModule(java.lang.Class)
shared
- whether the returned settings should be shared- Returns:
Preferences
for the given project- Since:
- 1.16
-
getAuxiliaryConfiguration
Find a way of storing extra configuration in a project. If the project's lookup does not provide an instance, a fallback implementation is used.The current fallback implementation uses file attributes for "nonsharable" configuration, and a specially named file in the project directory for "sharable" configuration. For compatibility purposes (in case a project adds an
AuxiliaryConfiguration
instance to its lookup where before it had none), the fallback storage is read (but not written) even if there is an instance in project lookup.- Parameters:
project
- a project- Returns:
- an auxiliary configuration handle
- Since:
- org.netbeans.modules.projectapi/1 1.17
-
getCacheDirectory
public static org.openide.filesystems.FileObject getCacheDirectory(@NonNull Project project, @NonNull Class<?> owner) throws IOException Gets a directory in which modules may store arbitrary extra unversioned files associated with a project. These could be caches of information found in sources, logs or snapshots from activities associated with developing the project, etc.If the project supplies a
CacheDirectoryProvider
, that will be used for the parent directory. Otherwise an unspecified storage area will be used.- Parameters:
project
- a projectowner
- a class from the calling module (each module or package will get its own space)- Returns:
- a directory available for storing miscellaneous files
- Throws:
IOException
- if no such directory could be created- Since:
- org.netbeans.modules.projectapi/1 1.26
-