Class DefaultProfileActivationContext

java.lang.Object
org.apache.maven.impl.model.DefaultProfileActivationContext
All Implemented Interfaces:
ProfileActivationContext

public class DefaultProfileActivationContext extends Object implements ProfileActivationContext
Describes the environmental context used to determine the activation status of profiles.
  • Constructor Details

  • Method Details

    • isProfileActive

      public boolean isProfileActive(String profileId)
      Description copied from interface: ProfileActivationContext
      Checks if the specified profile has been explicitly activated.
      Specified by:
      isProfileActive in interface ProfileActivationContext
      Parameters:
      profileId - the profile id
      Returns:
      whether the profile has been activated
    • isProfileInactive

      public boolean isProfileInactive(String profileId)
      Description copied from interface: ProfileActivationContext
      Checks if the specified profile has been explicitly deactivated.
      Specified by:
      isProfileInactive in interface ProfileActivationContext
      Parameters:
      profileId - the profile id
      Returns:
      whether the profile has been deactivated
    • getSystemProperty

      public String getSystemProperty(String key)
      Description copied from interface: ProfileActivationContext
      Gets the system property to use for interpolation and profile activation. The system properties are collected from the runtime environment like System.getProperties() and environment variables.
      Specified by:
      getSystemProperty in interface ProfileActivationContext
      Parameters:
      key - the name of the system property
      Returns:
      the system property for the specified key, or null
    • setSystemProperties

      public DefaultProfileActivationContext setSystemProperties(Map<String,String> systemProperties)
      Sets the system properties to use for interpolation and profile activation. The system properties are collected from the runtime environment like System.getProperties() and environment variables.
      Parameters:
      systemProperties - The system properties, may be null.
      Returns:
      This context, never null.
    • getUserProperty

      public String getUserProperty(String key)
      Description copied from interface: ProfileActivationContext
      Gets the user property to use for interpolation and profile activation. The user properties have been configured directly by the user on his discretion, e.g. via the -Dkey=value parameter on the command line.

      In repository-resolved (external) model builds (dependency POMs, parent POMs, imported BOMs), this always returns null. Consumer -D flags are not propagated to dependency profile activation: the consumer did not set those flags for the dependency, and doing so would make dependency resolution non-deterministic and open to accidental (or malicious) profile injection.

      Specified by:
      getUserProperty in interface ProfileActivationContext
      Parameters:
      key - the name of the user property
      Returns:
      The user property for the specified key, or null.
    • setUserProperties

      public DefaultProfileActivationContext setUserProperties(Map<String,String> userProperties)
      Sets the user properties to use for interpolation and profile activation. The user properties have been configured directly by the user on his discretion, e.g. via the -Dkey=value parameter on the command line.
      Parameters:
      userProperties - The user properties, may be null.
      Returns:
      This context, never null.
    • getModelArtifactId

      public String getModelArtifactId()
      Description copied from interface: ProfileActivationContext
      Gets the artifactId from the current model.
      Specified by:
      getModelArtifactId in interface ProfileActivationContext
      Returns:
      The artifactId of the current model, or null if not set.
    • getModelPackaging

      public String getModelPackaging()
      Description copied from interface: ProfileActivationContext
      Gets the packaging type from the current model.
      Specified by:
      getModelPackaging in interface ProfileActivationContext
      Returns:
      The packaging type of the current model, or null if not set.
    • getModelProperty

      public String getModelProperty(String key)
      Description copied from interface: ProfileActivationContext
      Gets the model property to use for interpolation and profile activation.

      These are the properties declared in the model's own <properties> section. They are part of the artifact's published identity and are always consulted for profile activation, including in repository-resolved (external) model builds. Unlike ProfileActivationContext.getUserProperty(String), these are never suppressed when evaluating dependency profiles.

      Specified by:
      getModelProperty in interface ProfileActivationContext
      Parameters:
      key - the name of the model property
      Returns:
      The model property for the specified key, or null;
    • getModelBaseDirectory

      public String getModelBaseDirectory()
      Description copied from interface: ProfileActivationContext
      Gets the base directory of the current model.
      Specified by:
      getModelBaseDirectory in interface ProfileActivationContext
      Returns:
      The base directory path of the current model, or null if not set.
    • doGetModelBaseDirectory

      public String doGetModelBaseDirectory()
    • getModelRootDirectory

      public String getModelRootDirectory()
      Description copied from interface: ProfileActivationContext
      Gets the root directory of the current model.
      Specified by:
      getModelRootDirectory in interface ProfileActivationContext
      Returns:
      The root directory path of the current model, or null if not set.
    • setModel

      public DefaultProfileActivationContext setModel(Model model)
    • withoutUserPropertiesAndFilesystem

      public ProfileActivationContext withoutUserPropertiesAndFilesystem()
      Returns a sandboxed copy of this context suitable for evaluating profiles in repository-resolved (external) models — dependency POMs, parent POMs, and imported BOMs.

      The sandboxed context:

      • Merges model properties into system property lookups: system properties (java.version, os.name, …) are checked first (preserving JDK/OS activation), then model properties (the POM's own <properties>) are used as a fallback. This makes POM-declared properties visible to the PropertyProfileActivator without modifying the activator's lookup chain for non-external models.
      • Suppresses user properties (consumer -D flags): they were not set for the dependency and must not accidentally activate its profiles.
      • Disables file existence checks: the publisher's file system paths do not exist in the consumer's environment. File-activated profiles should be pre-filtered by the caller before reaching this context (the sandbox's exists() returns false as a safety net, but that alone would incorrectly activate <missing> profiles).
      Returns:
      a sandboxed ProfileActivationContext for external model evaluation
    • interpolatePath

      public String interpolatePath(String path) throws InterpolatorException
      Description copied from interface: ProfileActivationContext
      Interpolates the given path string using the current context's properties.
      Specified by:
      interpolatePath in interface ProfileActivationContext
      Parameters:
      path - The path string to interpolate
      Returns:
      The interpolated path string
      Throws:
      InterpolatorException - if an error occurs during interpolation
    • exists

      public boolean exists(String path, boolean enableGlob) throws ModelBuilderException
      Description copied from interface: ProfileActivationContext
      Checks if a file or directory matching the given glob pattern exists at the specified path.
      Specified by:
      exists in interface ProfileActivationContext
      Parameters:
      path - the base path to check
      enableGlob - whether the path can be a glob expression
      Returns:
      true if a matching file exists, false otherwise
      Throws:
      ModelBuilderException - if an error occurs while checking the path