Class NbMavenProject

java.lang.Object
org.netbeans.modules.maven.api.NbMavenProject

public final class NbMavenProject extends Object
an instance resides in project lookup, allows to get notified on project and relative path changes.

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";
    }
}
Shows a service, that will become available from project Lookup whenever the project uses org.netbeans.modules.maven:test.plugin plugin in its model.
  • Field Details

  • Method Details

    • isUnloadable

      public boolean isUnloadable()
      Checks if the project is completely broken. Also see getPartialProject(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

      public void addPropertyChangeListener(PropertyChangeListener propertyChangeListener)
    • removePropertyChangeListener

      public void removePropertyChangeListener(PropertyChangeListener propertyChangeListener)
    • 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 check isErrorPlaceholder(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 while getMavenProject() 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

      @NonNull public CompletableFuture<org.apache.maven.project.MavenProject> 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

      public URI[] getResources(boolean test)
      Parameters:
      test - are test resources requested, if false, resources for base sources are returned
      Returns:
    • getOutputDirectory

      public File getOutputDirectory(boolean test)
      Standardized way of finding output directory even for broken projects.
      Parameters:
      test - true for target/test-classes, false for target/classes
      Returns:
      the configured output directory (normalized)
    • getWebAppDirectory

      public URI getWebAppDirectory()
      Returns:
    • getEarAppDirectory

      public URI getEarAppDirectory()
    • getPackagingType

      public String getPackagingType()
      Gets an "effective" packaging for the project. Normally this is just the Maven model's declared packaging. But PackagingProviders 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.ModelBuildingException
      Returns the raw pom model for the project.
      Returns:
      Throws:
      org.apache.maven.model.building.ModelBuildingException
    • addWatchedPath

      public void addWatchedPath(String relPath)
      Parameters:
      relPath -
    • addWatchedPath

      public void addWatchedPath(URI uri)
      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 public void downloadDependencyAndJavadocSource()
    • 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

      public void removeWatchedPath(String relPath)
    • removeWatchedPath

      public void removeWatchedPath(URI uri)
    • 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 is null

      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 see isIncomplete(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. Each isErrorPlaceholder(org.apache.maven.project.MavenProject) is an incomplete project. If the project is just missing proper referenced artifacts, it will not be reported as a isErrorPlaceholder(org.apache.maven.project.MavenProject), but as isIncomplete(org.apache.maven.project.MavenProject).
      Parameters:
      project -
      Returns:
      true, if the project is not completely resolved
      Since:
      2.161
    • toString

      public String toString()
      Overrides:
      toString in class Object