[ https://issues.apache.org/jira/browse/MNG-8286?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Guillaume Nodet updated MNG-8286: --------------------------------- Description: GitHub Pull Request: [https://github.com/apache/maven/pull/1771] h1. Condition-Based Profile Activation in Maven 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. h2. 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 h2. 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. h2. 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.) h2. 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. This will be triggered using a new profile activation in the 4.1.0 model: {code:xml} <profile> <activation> <condition>inrange(${maven.version}, '[4,)')</condition> </activation> </profile> {code} was: GitHub Pull Request: [https://github.com/apache/maven/pull/1771] h1. Condition-Based Profile Activation in Maven 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. h2. 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 h2. 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. h2. 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.) h2. 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. This will be triggered using a new profile activation in the 4.1.0 model: {code:xml} <profile> <activation> <condition>inrange(${maven.version}, '[4,)')</condition> </activation> </profile> {code} > Add a condition profile based on a simple expressions > ----------------------------------------------------- > > Key: MNG-8286 > URL: https://issues.apache.org/jira/browse/MNG-8286 > Project: Maven > Issue Type: New Feature > Components: Profiles > Reporter: Guillaume Nodet > Assignee: Guillaume Nodet > Priority: Major > Fix For: 4.0.0-beta-5 > > > GitHub Pull Request: [https://github.com/apache/maven/pull/1771] > h1. Condition-Based Profile Activation in Maven > 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. > h2. 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 > h2. 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. > h2. 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.) > h2. 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. > This will be triggered using a new profile activation in the 4.1.0 model: > {code:xml} > <profile> > <activation> > <condition>inrange(${maven.version}, '[4,)')</condition> > </activation> > </profile> > {code} -- This message was sent by Atlassian Jira (v8.20.10#820010)