Package org.apache.maven.api.model
Class Activation
java.lang.Object
org.apache.maven.api.model.Activation
- All Implemented Interfaces:
- Serializable,- InputLocationTracker
@Experimental
@Generated
@ThreadSafe
@Immutable
public class Activation
extends Object
implements Serializable, InputLocationTracker
The conditions within the build runtime environment which will trigger the
 automatic inclusion of the build profile. Multiple conditions can be defined, which must
 be all satisfied to activate the profile.
 
 
In addition to the traditional activation mechanisms (JDK version, OS properties,
 file existence, etc.), Maven now supports a powerful condition-based activation
 through the condition field. This new mechanism allows for more flexible
 and expressive profile activation rules.
Condition Syntax
The condition is specified as a string expression that can include various functions, comparisons, and logical operators. Some key features include:
- Property access: ${property.name}
- Comparison operators: ==,!=,<,>,<=,>=
- Logical operators: &&(AND),||(OR),not(...)
- Functions: exists(...),missing(...),matches(...),inrange(...), and more
Supported Functions
The following functions are supported in condition expressions:
- length(string): Returns the length of the given string.
- upper(string): Converts the string to uppercase.
- lower(string): Converts the string to lowercase.
- substring(string, start, [end]): Returns a substring of the given string.
- indexOf(string, substring): Returns the index of the first occurrence of substring in string, or -1 if not found.
- contains(string, substring): Checks if the string contains the substring.
- matches(string, regex): Checks if the string matches the given regular expression.
- not(condition): Negates the given condition.
- if(condition, trueValue, falseValue): Returns trueValue if the condition is true, falseValue otherwise.
- exists(path): Checks if a file matching the given glob pattern exists.
- missing(path): Checks if a file matching the given glob pattern does not exist.
- inrange(version, range): Checks if the given version is within the specified version range.
Supported properties
The following properties are supported in expressions:
- `project.basedir`: The project directory
- `project.rootDirectory`: The root directory of the project
- `project.artifactId`: The artifactId of the project
- `project.packaging`: The packaging of the project
- user properties
- system properties (including environment variables prefixed with `env.`)
Examples
- JDK version range: inrange(${java.version}, '[11,)')(JDK 11 or higher)
- OS check: ${os.name} == 'windows'
- File existence: exists('${project.basedir}/src/**/*.xsd')
- Property check: ${my.property} != 'some-value'
- Regex matching: matches(${os.version}, '.*aws')
- Complex condition: ${os.name} == 'windows' && ${os.arch} != 'amd64' && inrange(${os.version}, '[10,)')
- String length check: length(${user.name}) > 5
- Substring with version: substring(${java.version}, 0, 3) == '1.8'
- Using indexOf: indexOf(${java.version}, '-') > 0
- Conditional logic: if(contains(${java.version}, '-'), substring(${java.version}, 0, indexOf(${java.version}, '-')), ${java.version})
This flexible condition mechanism allows for more precise control over profile activation, enabling developers to create profiles that respond to a wide range of environmental factors and project states.
- See Also:
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic classBuilder class used to create Activation instances.
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedActivation(Activation.Builder builder) Constructor for this class, to be called from its subclasses andActivation.Builder.
- 
Method SummaryModifier and TypeMethodDescriptionThe condition which must be satisfied to activate the profile.getFile()Specifies that this profile will be activated based on existence of a file.Gets the input location that caused this model to be read.getJdk()Specifies that this profile will be activated when a matching JDK is detected.getLocation(Object key) Gets the location of the specified field in the input source.Gets the keys of the locations of the input source.getOs()Specifies that this profile will be activated when matching operating system attributes are detected.Specifies that this profile will be activated based on the project's packaging.Specifies that this profile will be activated when this property is specified.booleanIf set to true, this profile will be active unless another profile in this pom is activated using the command line -P option or by one of that profile's activators.static Activation.BuilderCreates a newActivationbuilder instance.static Activation.BuildernewBuilder(boolean withDefaults) Creates a newActivationbuilder instance using default values or not.static Activation.BuildernewBuilder(Activation from) Creates a newActivationbuilder instance using the specified object as a basis.static Activation.BuildernewBuilder(Activation from, boolean forceCopy) Creates a newActivationbuilder instance using the specified object as a basis.static ActivationCreates a newActivationinstance.static ActivationnewInstance(boolean withDefaults) Creates a newActivationinstance using default values or not.with()Creates a new builder with this object as the basis.withActiveByDefault(boolean activeByDefault) Creates a newActivationinstance using the specified activeByDefault.withCondition(String condition) Creates a newActivationinstance using the specified condition.withFile(ActivationFile file) Creates a newActivationinstance using the specified file.Creates a newActivationinstance using the specified jdk.withOs(ActivationOS os) Creates a newActivationinstance using the specified os.withPackaging(String packaging) Creates a newActivationinstance using the specified packaging.withProperty(ActivationProperty property) Creates a newActivationinstance using the specified property.
- 
Constructor Details- 
ActivationConstructor for this class, to be called from its subclasses andActivation.Builder.- See Also:
 
 
- 
- 
Method Details- 
isActiveByDefaultpublic boolean isActiveByDefault()If set to true, this profile will be active unless another profile in this pom is activated using the command line -P option or by one of that profile's activators.- Returns:
- a boolean
 
- 
getJdkSpecifies that this profile will be activated when a matching JDK is detected. For example,1.4only activates on JDKs versioned 1.4, while!1.4matches any JDK that is not version 1.4. Ranges are supported too:[1.5,)activates when the JDK is 1.5 minimum.- Returns:
- a String
 
- 
getOsSpecifies that this profile will be activated when matching operating system attributes are detected.- Returns:
- a ActivationOS
 
- 
getPropertySpecifies that this profile will be activated when this property is specified.- Returns:
- a ActivationProperty
 
- 
getFileSpecifies that this profile will be activated based on existence of a file.- Returns:
- a ActivationFile
 
- 
getPackagingSpecifies that this profile will be activated based on the project's packaging.- Returns:
- a String
 
- 
getConditionThe condition which must be satisfied to activate the profile.- Returns:
- a String
 
- 
getLocationGets the location of the specified field in the input source.- Specified by:
- getLocationin interface- InputLocationTracker
 
- 
getLocationKeysGets the keys of the locations of the input source.
- 
getLocationKeyStream
- 
getImportedFromGets the input location that caused this model to be read.- Specified by:
- getImportedFromin interface- InputLocationTracker
- Returns:
- InputLocation
 
- 
withCreates a new builder with this object as the basis.- Returns:
- a Builder
 
- 
withActiveByDefaultCreates a newActivationinstance using the specified activeByDefault.- Parameters:
- activeByDefault- the new- booleanto use
- Returns:
- a Activationwith the specified activeByDefault
 
- 
withJdkCreates a newActivationinstance using the specified jdk.- Parameters:
- jdk- the new- Stringto use
- Returns:
- a Activationwith the specified jdk
 
- 
withOsCreates a newActivationinstance using the specified os.- Parameters:
- os- the new- ActivationOSto use
- Returns:
- a Activationwith the specified os
 
- 
withPropertyCreates a newActivationinstance using the specified property.- Parameters:
- property- the new- ActivationPropertyto use
- Returns:
- a Activationwith the specified property
 
- 
withFileCreates a newActivationinstance using the specified file.- Parameters:
- file- the new- ActivationFileto use
- Returns:
- a Activationwith the specified file
 
- 
withPackagingCreates a newActivationinstance using the specified packaging.- Parameters:
- packaging- the new- Stringto use
- Returns:
- a Activationwith the specified packaging
 
- 
withConditionCreates a newActivationinstance using the specified condition.- Parameters:
- condition- the new- Stringto use
- Returns:
- a Activationwith the specified condition
 
- 
newInstanceCreates a newActivationinstance. Equivalent tonewInstance(true).- Returns:
- a new Activation
- See Also:
 
- 
newInstanceCreates a newActivationinstance using default values or not. Equivalent tonewBuilder(withDefaults).build().- Parameters:
- withDefaults- the boolean indicating whether default values should be used
- Returns:
- a new Activation
 
- 
newBuilderCreates a newActivationbuilder instance. Equivalent tonewBuilder(true).- Returns:
- a new Builder
- See Also:
 
- 
newBuilderCreates a newActivationbuilder instance using default values or not.- Parameters:
- withDefaults- the boolean indicating whether default values should be used
- Returns:
- a new Builder
 
- 
newBuilderCreates a newActivationbuilder instance using the specified object as a basis. Equivalent tonewBuilder(from, false).- Parameters:
- from- the- Activationinstance to use as a basis
- Returns:
- a new Builder
 
- 
newBuilderCreates a newActivationbuilder instance using the specified object as a basis.- Parameters:
- from- the- Activationinstance to use as a basis
- forceCopy- the boolean indicating if a copy should be forced
- Returns:
- a new Builder
 
 
-