This is an automated email from the ASF dual-hosted git repository.

kwin pushed a commit to branch feature/MNG-5726-regex-os-version-matching
in repository https://gitbox.apache.org/repos/asf/maven.git

commit ef0c4b07fdca2d085f5e794a6079ae8f9a514972
Author: Konrad Windszus <k...@apache.org>
AuthorDate: Fri Feb 23 12:16:11 2024 +0100

    [MNG-5726] Support regular expression matching in profile activation for
    OS version
    
    This requires using the reserved prefix "regex:" in the version element.
---
 .../activation/OperatingSystemProfileActivator.java     | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git 
a/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/OperatingSystemProfileActivator.java
 
b/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/OperatingSystemProfileActivator.java
index 8f0af6aa12..0e9fbf92a1 100644
--- 
a/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/OperatingSystemProfileActivator.java
+++ 
b/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/OperatingSystemProfileActivator.java
@@ -37,6 +37,8 @@ import org.apache.maven.utils.Os;
 @Singleton
 public class OperatingSystemProfileActivator implements ProfileActivator {
 
+    private static final String REGEX_PREFIX = "regex:";
+
     @Override
     public boolean isActive(Profile profile, ProfileActivationContext context, 
ModelProblemCollector problems) {
         Activation activation = profile.getActivation();
@@ -89,14 +91,17 @@ public class OperatingSystemProfileActivator implements 
ProfileActivator {
     private boolean determineVersionMatch(String version) {
         String test = version;
         boolean reverse = false;
-
-        if (test.startsWith("!")) {
-            reverse = true;
-            test = test.substring(1);
+        final boolean result;
+        if (test.startsWith(REGEX_PREFIX)) {
+            result = 
Os.OS_VERSION.matches(test.substring(REGEX_PREFIX.length()));
+        } else {
+            if (test.startsWith("!")) {
+                reverse = true;
+                test = test.substring(1);
+            }
+            result = Os.OS_VERSION.equals(test);
         }
 
-        boolean result = Os.OS_VERSION.equals(test);
-
         return reverse != result;
     }
 

Reply via email to