Class DefaultProfileActivationContext

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

public class DefaultProfileActivationContext extends Object implements org.apache.maven.api.services.model.ProfileActivationContext
Describes the environmental context used to determine the activation status of profiles.
  • Constructor Details

    • DefaultProfileActivationContext

      public DefaultProfileActivationContext(org.apache.maven.api.services.model.PathTranslator pathTranslator, org.apache.maven.api.services.model.RootLocator rootLocator, org.apache.maven.api.services.Interpolator interpolator)
    • DefaultProfileActivationContext

      public DefaultProfileActivationContext(org.apache.maven.api.services.model.PathTranslator pathTranslator, org.apache.maven.api.services.model.RootLocator rootLocator, org.apache.maven.api.services.Interpolator interpolator, List<String> activeProfileIds, List<String> inactiveProfileIds, Map<String,String> systemProperties, Map<String,String> userProperties, org.apache.maven.api.model.Model model)
  • Method Details

    • isProfileActive

      public boolean isProfileActive(String profileId)
      Specified by:
      isProfileActive in interface org.apache.maven.api.services.model.ProfileActivationContext
    • isProfileInactive

      public boolean isProfileInactive(String profileId)
      Specified by:
      isProfileInactive in interface org.apache.maven.api.services.model.ProfileActivationContext
    • getSystemProperty

      public String getSystemProperty(String key)
      Specified by:
      getSystemProperty in interface org.apache.maven.api.services.model.ProfileActivationContext
    • 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)
      Specified by:
      getUserProperty in interface org.apache.maven.api.services.model.ProfileActivationContext
    • 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()
      Specified by:
      getModelArtifactId in interface org.apache.maven.api.services.model.ProfileActivationContext
    • getModelPackaging

      public String getModelPackaging()
      Specified by:
      getModelPackaging in interface org.apache.maven.api.services.model.ProfileActivationContext
    • getModelProperty

      public String getModelProperty(String key)
      Specified by:
      getModelProperty in interface org.apache.maven.api.services.model.ProfileActivationContext
    • getModelBaseDirectory

      public String getModelBaseDirectory()
      Specified by:
      getModelBaseDirectory in interface org.apache.maven.api.services.model.ProfileActivationContext
    • doGetModelBaseDirectory

      public String doGetModelBaseDirectory()
    • getModelRootDirectory

      public String getModelRootDirectory()
      Specified by:
      getModelRootDirectory in interface org.apache.maven.api.services.model.ProfileActivationContext
    • setModel

      public DefaultProfileActivationContext setModel(org.apache.maven.api.model.Model model)
    • withoutUserPropertiesAndFilesystem

      public org.apache.maven.api.services.model.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 org.apache.maven.api.services.InterpolatorException
      Specified by:
      interpolatePath in interface org.apache.maven.api.services.model.ProfileActivationContext
      Throws:
      org.apache.maven.api.services.InterpolatorException
    • exists

      public boolean exists(String path, boolean enableGlob) throws org.apache.maven.api.services.ModelBuilderException
      Specified by:
      exists in interface org.apache.maven.api.services.model.ProfileActivationContext
      Throws:
      org.apache.maven.api.services.ModelBuilderException