Class NbMavenProject
From version 2.148 plugin-specific services can be registered using ProjectServiceProvider
annotation in subfolders of the project Lookup registration area whose names follow a Plugin group and
artifact ID.
@ProjectServiceProvider(service=PS.class,
projectType=NbMavenProject.TYPE + "/org.netbeans.modules.maven:test.plugin")
public static class PluginService implements PS {
public @Override String m() {
return "special";
}
}
org.netbeans.modules.maven:test.plugin
plugin in its model.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
the only property change fired by the class, means that the pom file has changed.static final String
TODO commentstatic final String
ID of the Maven project type.static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addPropertyChangeListener
(PropertyChangeListener propertyChangeListener) static void
addPropertyChangeListener
(org.netbeans.api.project.Project prj, PropertyChangeListener listener) void
addWatchedPath
(String relPath) void
addWatchedPath
(URI uri) void
Deprecated.void
downloadDependencyAndJavadocSource
(boolean synch) Download binaries and then trigger dependency javadoc/source download (in async mode) if download strategy is not DownloadStrategy.NEVER in options Not to be called from AWT thread in synch mode; the current thread will continue after downloading binaries and firing project change event.static void
fireMavenProjectReload
(org.netbeans.api.project.Project prj) utility method for triggering a maven project reload.org.apache.maven.project.MavenProject
getEvaluatedProject
(org.netbeans.api.project.ProjectActionContext context) Returns a project evaluated for a certain purpose.CompletableFuture
<org.apache.maven.project.MavenProject> Returns the original project, or waits for reload task if already pending.long
Returns timestamp of project (metadata) load.org.apache.maven.project.MavenProject
Returns the current maven project model from the embedder.getOutputDirectory
(boolean test) Standardized way of finding output directory even for broken projects.Gets an "effective" packaging for the project.static org.apache.maven.project.MavenProject
getPartialProject
(org.apache.maven.project.MavenProject project) Retrieves at least partial project information.org.apache.maven.model.Model
Returns the raw pom model for the project.URI[]
getResources
(boolean test) static boolean
isErrorPlaceholder
(org.apache.maven.project.MavenProject project) Checks whether a given project is just an error placeholder.static boolean
isIncomplete
(org.apache.maven.project.MavenProject project) Checks if the project resolved using incomplete or missing information.boolean
a marginally unreliable, non blocking method for figuring if the model is loaded or not.boolean
Checks if the project is completely broken.org.apache.maven.project.MavenProject
loadAlternateMavenProject
(org.netbeans.modules.maven.embedder.MavenEmbedder embedder, List<String> activeProfiles, Properties properties) void
removePropertyChangeListener
(PropertyChangeListener propertyChangeListener) static void
removePropertyChangeListener
(org.netbeans.api.project.Project prj, PropertyChangeListener listener) void
removeWatchedPath
(String relPath) void
removeWatchedPath
(URI uri) void
Not to be called from AWT, will wait til the project binary dependency resolution finishes.toString()
void
asynchronous dependency download, scheduled to some time in the future.void
triggerSourceJavadocDownload
(boolean javadoc)
-
Field Details
-
PROP_PROJECT
the only property change fired by the class, means that the pom file has changed.- See Also:
-
TYPE
-
PROP_RESOURCE
-
TYPE_JAR
- See Also:
-
TYPE_WAR
- See Also:
-
TYPE_EAR
- See Also:
-
TYPE_EJB
- See Also:
-
TYPE_APPCLIENT
- See Also:
-
TYPE_NBM
- See Also:
-
TYPE_NBM_APPLICATION
- See Also:
-
TYPE_OSGI
- See Also:
-
TYPE_POM
- See Also:
-
-
Method Details
-
isUnloadable
public boolean isUnloadable()Checks if the project is completely broken. Also seegetPartialProject(org.apache.maven.project.MavenProject)
.- Returns:
- true, if the project is broken and could not be loaded
- See Also:
-
getLoadTimestamp
public long getLoadTimestamp()Returns timestamp of project (metadata) load. Returns negative number, if the timestamp is not known or project is not loaded.- Returns:
- timestamp.
-
addPropertyChangeListener
-
removePropertyChangeListener
-
getMavenProject
@NonNull public org.apache.maven.project.MavenProject getMavenProject()Returns the current maven project model from the embedder. Should never be kept around for long but always reloaded from here, on a project change the correct instance changes as the embedder reloads it. Never returns null but checkisErrorPlaceholder(org.apache.maven.project.MavenProject)
if necessary.- Returns:
-
getEvaluatedProject
@NonNull public org.apache.maven.project.MavenProject getEvaluatedProject(org.netbeans.api.project.ProjectActionContext context) Returns a project evaluated for a certain purpose. The whilegetMavenProject()
works with the active configuration and does not apply any action-specific properties, this method tries to apply mappings, configurations, etc when loading the project model.Note that loading an evaluated project may take significant time (comparable to loading the base project itself). The implementation might optimize if the passed context does not prescribe different profiles, properties etc than have been used for the default model.
- Parameters:
context
- the loading context- Returns:
- evaluated project
-
getFreshProject
Returns the original project, or waits for reload task if already pending. Use with care, as the method blocks until the project reload eventually finishes in the reload thread / RP.- Returns:
- possibly reloaded Maven project.
-
isMavenProjectLoaded
public boolean isMavenProjectLoaded()a marginally unreliable, non blocking method for figuring if the model is loaded or not.- Returns:
-
loadAlternateMavenProject
@NonNull public org.apache.maven.project.MavenProject loadAlternateMavenProject(org.netbeans.modules.maven.embedder.MavenEmbedder embedder, List<String> activeProfiles, Properties properties) -
getResources
- Parameters:
test
- are test resources requested, if false, resources for base sources are returned- Returns:
-
getOutputDirectory
Standardized way of finding output directory even for broken projects.- Parameters:
test
- true fortarget/test-classes
, false fortarget/classes
- Returns:
- the configured output directory (normalized)
-
getWebAppDirectory
- Returns:
-
getEarAppDirectory
-
getPackagingType
Gets an "effective" packaging for the project. Normally this is just the Maven model's declared packaging. ButPackagingProvider
s can affect the decision. The resulting type will be used to control most IDE functions, including packaging-specific lookup.- Returns:
-
getRawModel
public org.apache.maven.model.Model getRawModel() throws org.apache.maven.model.building.ModelBuildingExceptionReturns the raw pom model for the project.- Returns:
- Throws:
org.apache.maven.model.building.ModelBuildingException
-
addWatchedPath
- Parameters:
relPath
-
-
addWatchedPath
- Parameters:
uri
-
-
triggerDependencyDownload
public void triggerDependencyDownload()asynchronous dependency download, scheduled to some time in the future. Useful for cases when a 3rd party codebase calls maven classes and can do so repeatedly in one sequence. -
synchronousDependencyDownload
public void synchronousDependencyDownload()Not to be called from AWT, will wait til the project binary dependency resolution finishes. -
downloadDependencyAndJavadocSource
Deprecated.UsedownloadDependencyAndJavadocSource(boolean)
withtrue
. -
downloadDependencyAndJavadocSource
public void downloadDependencyAndJavadocSource(boolean synch) Download binaries and then trigger dependency javadoc/source download (in async mode) if download strategy is not DownloadStrategy.NEVER in options Not to be called from AWT thread in synch mode; the current thread will continue after downloading binaries and firing project change event.- Parameters:
synch
- true to download dependencies binaries (not source/Javadoc) synchronously; false to download everything asynch
-
triggerSourceJavadocDownload
public void triggerSourceJavadocDownload(boolean javadoc) -
removeWatchedPath
-
removeWatchedPath
-
fireMavenProjectReload
public static void fireMavenProjectReload(org.netbeans.api.project.Project prj) utility method for triggering a maven project reload. if the project passed in is a Maven based project, will fire reload of the project, otherwise will do nothing.- Parameters:
prj
-
-
addPropertyChangeListener
public static void addPropertyChangeListener(org.netbeans.api.project.Project prj, PropertyChangeListener listener) -
removePropertyChangeListener
public static void removePropertyChangeListener(org.netbeans.api.project.Project prj, PropertyChangeListener listener) -
getPartialProject
public static org.apache.maven.project.MavenProject getPartialProject(org.apache.maven.project.MavenProject project) Retrieves at least partial project information. A MavenProject instance may be a fallback in case the reading fails because of locally missing artifacts and/or referenced parents. However partial model may be available. The function returns the passed project, if it read correctly. Otherwise, it attempts to locate a partially load project and returns that one. If a partial project is not available, it will return the passed (fallback) project.The result can be checked to be
isErrorPlaceholder(org.apache.maven.project.MavenProject)
to determine if the result was a returned partial project or not. Note that partial projects may not resolve all references properly, be prepared for unresolved artifacts and/or plugins. Do not pass partial projects blindly around.Returns
null
if the passed project isnull
- Parameters:
project
- the project to check- Returns:
- partial project if the passed project did not load properly and the partial project is available.
- Since:
- 2.161
-
isErrorPlaceholder
public static boolean isErrorPlaceholder(@NonNull org.apache.maven.project.MavenProject project) Checks whether a given project is just an error placeholder. Such project may be fundamentally broken, i.e. missing declarations from the parent, unresolved dependencies or versions. Also seeisIncomplete(org.apache.maven.project.MavenProject)
- Parameters:
project
- a project loaded by e.g.getMavenProject()
- Returns:
- true if it was loaded as an error fallback, false for a normal project
- Since:
- 2.24
- See Also:
-
isIncomplete
public static boolean isIncomplete(@NonNull org.apache.maven.project.MavenProject project) Checks if the project resolved using incomplete or missing information. EachisErrorPlaceholder(org.apache.maven.project.MavenProject)
is an incomplete project. If the project is just missing proper referenced artifacts, it will not be reported as aisErrorPlaceholder(org.apache.maven.project.MavenProject)
, but asisIncomplete(org.apache.maven.project.MavenProject)
.- Parameters:
project
-- Returns:
- true, if the project is not completely resolved
- Since:
- 2.161
-
toString
-
downloadDependencyAndJavadocSource(boolean)
withtrue
.