This is an automated email from the ASF dual-hosted git repository.
gnodet pushed a commit to branch maven-4.0.x
in repository https://gitbox.apache.org/repos/asf/maven.git
The following commit(s) were added to refs/heads/maven-4.0.x by this push:
new 780ac40ca9 [Backport maven-4.0.x] #14073: Keep the case of an OS
version regex in profiles (#14078)
780ac40ca9 is described below
commit 780ac40ca9c648a9ec4b56509f190522e03f1003
Author: Guillaume Nodet <[email protected]>
AuthorDate: Thu Nov 19 16:49:33 2026 +0100
[Backport maven-4.0.x] #14073: Keep the case of an OS version regex in
profiles (#14078)
Since the OS activation values are compared in lower case, a version
given as a regular expression was lower-cased too, which changes its
meaning: \S became \s and \p{Digit} was rejected. Maven 3 leaves the
pattern alone. It now keeps its case and matches case-insensitively.
Cherry-picked from 5223074e77771a93a3670af95f2155fbde6f38f3
Co-authored-by: Sharang Gupta <[email protected]>
---
.../model/profile/OperatingSystemProfileActivator.java | 7 ++++++-
.../profile/OperatingSystemProfileActivatorTest.java | 17 +++++++++++++++++
2 files changed, 23 insertions(+), 1 deletion(-)
diff --git
a/impl/maven-impl/src/main/java/org/apache/maven/impl/model/profile/OperatingSystemProfileActivator.java
b/impl/maven-impl/src/main/java/org/apache/maven/impl/model/profile/OperatingSystemProfileActivator.java
index 8e01dcdf8a..6c0676fd60 100644
---
a/impl/maven-impl/src/main/java/org/apache/maven/impl/model/profile/OperatingSystemProfileActivator.java
+++
b/impl/maven-impl/src/main/java/org/apache/maven/impl/model/profile/OperatingSystemProfileActivator.java
@@ -19,6 +19,7 @@
package org.apache.maven.impl.model.profile;
import java.util.Locale;
+import java.util.regex.Pattern;
import org.apache.maven.api.di.Named;
import org.apache.maven.api.di.Singleton;
@@ -105,7 +106,11 @@ private boolean determineVersionMatch(String
expectedVersion, String actualVersi
boolean reverse = false;
final boolean result;
if (test.startsWith(REGEX_PREFIX)) {
- result =
actualVersion.matches(test.substring(REGEX_PREFIX.length()));
+ // the pattern keeps its case: lower-casing it would turn \S into
\s;
+ // CASE_INSENSITIVE keeps the matching case-insensitive, as it was
before
+ result =
Pattern.compile(expectedVersion.substring(REGEX_PREFIX.length()),
Pattern.CASE_INSENSITIVE)
+ .matcher(actualVersion)
+ .matches();
} else {
if (test.startsWith("!")) {
reverse = true;
diff --git
a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/OperatingSystemProfileActivatorTest.java
b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/OperatingSystemProfileActivatorTest.java
index fbcfd79e28..1ad5478d1c 100644
---
a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/OperatingSystemProfileActivatorTest.java
+++
b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/OperatingSystemProfileActivatorTest.java
@@ -70,6 +70,23 @@ void testVersionRegexMatching() throws Exception {
assertActivation(false, profile, newContext(null,
newProperties("linux", "3.1.0", "amd64")));
}
+ @Test
+ void testVersionRegexKeepsCaseOfThePattern() throws Exception {
+ Profile profile =
newProfile(ActivationOS.newBuilder().version("regex:\\S+-generic"));
+
+ assertActivation(true, profile, newContext(null,
newProperties("linux", "6.5.0-41-generic", "amd64")));
+
+ assertActivation(false, profile, newContext(null,
newProperties("linux", "6.5.0 41-generic", "amd64")));
+ }
+
+ @Test
+ void testVersionRegexMatchingIsCaseInsensitive() throws Exception {
+ Profile profile =
newProfile(ActivationOS.newBuilder().version("regex:.*AWS"));
+
+ assertActivation(true, profile, newContext(null,
newProperties("linux", "6.5.0-1014-aws", "amd64")));
+ assertActivation(true, profile, newContext(null,
newProperties("linux", "6.5.0-1014-AWS", "amd64")));
+ }
+
@Test
void testName() {
Profile profile =
newProfile(ActivationOS.newBuilder().name("windows"));