(maven) 01/01: [MNG-5726] Support regular expression matching in profile activation for OS version

2024-02-28 Thread kwin
This is an automated email from the ASF dual-hosted git repository.

kwin pushed a commit to branch feature/MNG-5726-maven3.9
in repository https://gitbox.apache.org/repos/asf/maven.git

commit f61298cc63458f5c964ebc423eb579b0d8253db9
Author: Konrad Windszus 
AuthorDate: Wed Feb 28 19:04:58 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.
---
 maven-model-builder/pom.xml|   4 -
 .../OperatingSystemProfileActivator.java   |  55 +++--
 .../src/main/java/org/apache/maven/utils/Os.java   | 233 +
 .../OperatingSystemProfileActivatorTest.java   | 144 +
 4 files changed, 410 insertions(+), 26 deletions(-)

diff --git a/maven-model-builder/pom.xml b/maven-model-builder/pom.xml
index 8357f7ec38..97347635c9 100644
--- a/maven-model-builder/pom.xml
+++ b/maven-model-builder/pom.xml
@@ -32,10 +32,6 @@ under the License.
   The effective model builder, with inheritance, profile 
activation, interpolation, ...
 
   
-
-  org.codehaus.plexus
-  plexus-utils
-
 
   org.codehaus.plexus
   plexus-interpolation
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 f7445199ff..a9c2c76a88 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
@@ -21,12 +21,14 @@ package org.apache.maven.model.profile.activation;
 import javax.inject.Named;
 import javax.inject.Singleton;
 
+import java.util.Locale;
+
 import org.apache.maven.model.Activation;
 import org.apache.maven.model.ActivationOS;
 import org.apache.maven.model.Profile;
 import org.apache.maven.model.building.ModelProblemCollector;
 import org.apache.maven.model.profile.ProfileActivationContext;
-import org.codehaus.plexus.util.Os;
+import org.apache.maven.utils.Os;
 
 /**
  * Determines profile activation based on the operating system of the current 
runtime platform.
@@ -38,6 +40,8 @@ import org.codehaus.plexus.util.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();
@@ -54,17 +58,21 @@ public class OperatingSystemProfileActivator implements 
ProfileActivator {
 
 boolean active = ensureAtLeastOneNonNull(os);
 
+String actualOsName = 
context.getSystemProperties().get("os.name").toLowerCase(Locale.ENGLISH);
+String actualOsArch = 
context.getSystemProperties().get("os.arch").toLowerCase(Locale.ENGLISH);
+String actualOsVersion = 
context.getSystemProperties().get("os.version").toLowerCase(Locale.ENGLISH);
+
 if (active && os.getFamily() != null) {
-active = determineFamilyMatch(os.getFamily());
+active = determineFamilyMatch(os.getFamily(), actualOsName);
 }
 if (active && os.getName() != null) {
-active = determineNameMatch(os.getName());
+active = determineNameMatch(os.getName(), actualOsName);
 }
 if (active && os.getArch() != null) {
-active = determineArchMatch(os.getArch());
+active = determineArchMatch(os.getArch(), actualOsArch);
 }
 if (active && os.getVersion() != null) {
-active = determineVersionMatch(os.getVersion());
+active = determineVersionMatch(os.getVersion(), actualOsVersion);
 }
 
 return active;
@@ -90,22 +98,25 @@ public class OperatingSystemProfileActivator implements 
ProfileActivator {
 return os.getArch() != null || os.getFamily() != null || os.getName() 
!= null || os.getVersion() != null;
 }
 
-private boolean determineVersionMatch(String version) {
-String test = version;
+private boolean determineVersionMatch(String expectedVersion, String 
actualVersion) {
+String test = expectedVersion;
 boolean reverse = false;
-
-if (test.startsWith("!")) {
-reverse = true;
-test = test.substring(1);
+final boolean result;
+if (test.startsWith(REGEX_PREFIX)) {
+result = 
actualVersion.matches(test.substring(REGEX_PREFIX.length()));
+} else {
+if (test.startsWith("!")) {
+reverse = true;
+test = test.substring(1);
+}
+result = actualVersion.equals(test);
 }
 
-boolean 

(maven) 01/01: [MNG-5726] Support regular expression matching in profile activation for OS version

2024-02-23 Thread kwin
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 8e79ecc0e593a09b21381130e08b55c6fe680f0d
Author: Konrad Windszus 
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.
---
 .../OperatingSystemProfileActivator.java   | 51 +-
 .../src/main/java/org/apache/maven/utils/Os.java   | 45 ---
 2 files changed, 60 insertions(+), 36 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..8afc691565 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
@@ -21,6 +21,8 @@ package org.apache.maven.model.profile.activation;
 import javax.inject.Named;
 import javax.inject.Singleton;
 
+import java.util.Locale;
+
 import org.apache.maven.model.Activation;
 import org.apache.maven.model.ActivationOS;
 import org.apache.maven.model.Profile;
@@ -37,6 +39,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();
@@ -53,17 +57,21 @@ public class OperatingSystemProfileActivator implements 
ProfileActivator {
 
 boolean active = ensureAtLeastOneNonNull(os);
 
+String actualOsName = 
context.getSystemProperties().get("os.name").toLowerCase(Locale.ENGLISH);
+String actualOsArch = 
context.getSystemProperties().get("os.arch").toLowerCase(Locale.ENGLISH);
+String actualOsVersion = 
context.getSystemProperties().get("os.version").toLowerCase(Locale.ENGLISH);
+
 if (active && os.getFamily() != null) {
-active = determineFamilyMatch(os.getFamily());
+active = determineFamilyMatch(os.getFamily(), actualOsName);
 }
 if (active && os.getName() != null) {
-active = determineNameMatch(os.getName());
+active = determineNameMatch(os.getName(), actualOsName);
 }
 if (active && os.getArch() != null) {
-active = determineArchMatch(os.getArch());
+active = determineArchMatch(os.getArch(), actualOsArch);
 }
 if (active && os.getVersion() != null) {
-active = determineVersionMatch(os.getVersion());
+active = determineVersionMatch(os.getVersion(), actualOsVersion);
 }
 
 return active;
@@ -86,22 +94,25 @@ public class OperatingSystemProfileActivator implements 
ProfileActivator {
 return os.getArch() != null || os.getFamily() != null || os.getName() 
!= null || os.getVersion() != null;
 }
 
-private boolean determineVersionMatch(String version) {
-String test = version;
+private boolean determineVersionMatch(String expectedVersion, String 
actualVersion) {
+String test = expectedVersion;
 boolean reverse = false;
-
-if (test.startsWith("!")) {
-reverse = true;
-test = test.substring(1);
+final boolean result;
+if (test.startsWith(REGEX_PREFIX)) {
+result = 
actualVersion.matches(test.substring(REGEX_PREFIX.length()));
+} else {
+if (test.startsWith("!")) {
+reverse = true;
+test = test.substring(1);
+}
+result = actualVersion.equals(test);
 }
 
-boolean result = Os.OS_VERSION.equals(test);
-
 return reverse != result;
 }
 
-private boolean determineArchMatch(String arch) {
-String test = arch;
+private boolean determineArchMatch(String expectedArch, String actualArch) 
{
+String test = expectedArch;
 boolean reverse = false;
 
 if (test.startsWith("!")) {
@@ -109,13 +120,13 @@ public class OperatingSystemProfileActivator implements 
ProfileActivator {
 test = test.substring(1);
 }
 
-boolean result = Os.OS_ARCH.equals(test);
+boolean result = actualArch.equals(test);
 
 return reverse != result;
 }
 
-private boolean determineNameMatch(String name) {
-String test = name;
+private boolean determineNameMatch(String expectedName, String actualName) 
{
+String 

(maven) 01/01: [MNG-5726] Support regular expression matching in profile activation for OS version

2024-02-23 Thread kwin
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 
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;
 }