Class ProjectActionContext

java.lang.Object
org.netbeans.api.project.ProjectActionContext

public final class ProjectActionContext extends Object
This represents context for a project model query. The context describe a project action for which the query should be evaluated, project configuration (if not the active one), and possible custom overrides. ProjectConfiguration or the IDE-supported project action and the associated properties, profiles, or Lookup may affect behaviour of queries across the IDE.

Properties map to user-settable properties of the build system, such as system properties in Maven or project properties in Gradle.

Profiles map to profiles in Maven, but do not have any effect in Gradle at the moment; this might change.

Instances of ProjectActionContext may be passed to some queries as (part of the) parameters explicitly. In case the API does not support such flexibility directly, the implementation(s) may - the context may be published for the query computation using apply(java.lang.Runnable, org.netbeans.api.project.ProjectActionContext...); the implementation may then use find(org.netbeans.api.project.Project) to obtain a ProjectActionContext effective for that project.

Important note: Not all project queries support ProjectActionContext. Queries which do should mention that fact in their documentation, or expose it in their APIs.

Since:
1.89
  • Method Details

    • getProject

      @NonNull public Project getProject()
      Returns the project this context applies to. Having Project as a property allows multiple contexts, individually for each project, to be active.
      Returns:
      the target project.
    • getLookup

      public org.openide.util.Lookup getLookup()
      Additional information for the underlying project implementation, similar to context lookup in ActionProvider.invokeAction(java.lang.String, org.openide.util.Lookup). Project service implementors may optimize, if the returned value is Lookup.EMPTY reference.
      Returns:
      Lookup with additional information.
    • getProjectAction

      @CheckForNull public String getProjectAction()
      The project action in whose context the project queries are performed. May be left unspecified, so the implementation can choose an appropriate default behaviour.
      Returns:
      project aciton or null for unspecified.
    • getConfiguration

      @CheckForNull public ProjectConfiguration getConfiguration()
      The project configuration to use for the project query. Can be null to indicate the project's default Configuration should be used.
      Returns:
      the project's configuration or null.
    • getProperties

      @NonNull public Map<String,String> getProperties()
      User-customized properties that should be effective during the computation. The same customization should be made during project action execution to obtain the same results as evaluated by the query. If none specific properties are present, an empty map is returned.
      Returns:
      user properties
    • getProfiles

      @NonNull public Set<String> getProfiles()
      Profiles or some project system features/tags that should be applied for the evaluation. If no specific profiles are set an empty set is returned.
      Returns:
      applied additional profiles.
    • newDerivedBuilder

      @NonNull public ProjectActionContext.Builder newDerivedBuilder()
      Creates a Builder to create a similar ProjectActionContext to this one. All settings are copied to the Builder, so just calling ProjectActionContext.Builder.context() on the result will produce a copy of this ProjectActionContext.
      Returns:
      preconfigured ProjectActionContext.Builder instance.
    • newBuilder

      @NonNull public static ProjectActionContext.Builder newBuilder(Project p)
      Creates a new ProjectActionContext builder for the given project.
      Parameters:
      p - the project
      Returns:
      the builder instance
    • find

      @NonNull public static ProjectActionContext find(Project p)
      Find the ProjectActionContext for the project. If no context was specified explicitly,
      Parameters:
      p - the project in question
      Returns:
      the context
    • apply

      public void apply(Runnable r, ProjectActionContext... otherProjectContexts)
      Executes a query using this project context. Other contexts may be specified as well (optional). During the passed Runnable, or tasks initiated from the Runnable, the find(org.netbeans.api.project.Project) method will find the appropriate ProjectActionContext specified as parameter.
      Parameters:
      r - the code to execute.
      otherProjectContexts - optional instances for other projects
    • apply

      public <V, E extends Exception> V apply(ProjectActionContext.ProjectCallback<V,E> r, ProjectActionContext... otherProjectContexts) throws E
      Executes a query using this project context. Other contexts may be specified as well (optional). During the passed Runnable, or tasks initiated from the Runnable, the find(org.netbeans.api.project.Project) method will find the appropriate ProjectActionContext specified as parameter.
      Type Parameters:
      V - the return type
      E - exception thrown from the executed code.
      Parameters:
      r - the code to execute.
      otherProjectContexts - optional instances for other projects
      Throws:
      E
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object