This is an automated email from the ASF dual-hosted git repository.
gnodet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven.git
The following commit(s) were added to refs/heads/master by this push:
new 766fa4d3ea Allow ${project.basedir} in profile activation.condition
(#11528) (#11531)
766fa4d3ea is described below
commit 766fa4d3ea944603eca1d05270f01cbc498567fc
Author: Guillaume Nodet <[email protected]>
AuthorDate: Tue Dec 9 21:39:15 2025 +0100
Allow ${project.basedir} in profile activation.condition (#11528) (#11531)
Previously, ${project.basedir} was only allowed in activation.file.exists
and activation.file.missing. This change extends the same allowance to
activation.condition, which is a new Maven 4.0.0 feature that also needs
to reference the project base directory for its expressions.
This fixes a false positive warning when using expressions like
exists("${project.basedir}/src/main/java") in activation conditions.
(cherry picked from commit fde721301c6797432cc5105d70e5e4908d350183)
---
.../maven/impl/model/DefaultModelValidator.java | 3 +-
.../impl/model/DefaultModelValidatorTest.java | 8 ++++
.../profile-activation-condition-with-basedir.xml | 44 ++++++++++++++++++++++
3 files changed, 54 insertions(+), 1 deletion(-)
diff --git
a/impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelValidator.java
b/impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelValidator.java
index 5994f207ce..72917cd7c6 100644
---
a/impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelValidator.java
+++
b/impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelValidator.java
@@ -738,7 +738,8 @@ private void
validate30RawProfileActivation(ModelProblemCollector problems, Acti
while (matcher.find()) {
String propertyName = matcher.group(0);
- if (path.startsWith("activation.file.") &&
"${project.basedir}".equals(propertyName)) {
+ if ((path.startsWith("activation.file.") ||
path.equals("activation.condition"))
+ && "${project.basedir}".equals(propertyName)) {
continue;
}
addViolation(
diff --git
a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultModelValidatorTest.java
b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultModelValidatorTest.java
index 6ed6483340..df38b262f7 100644
---
a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultModelValidatorTest.java
+++
b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultModelValidatorTest.java
@@ -1001,4 +1001,12 @@ void selfCombineBad() throws Exception {
SimpleProblemCollector result =
validateFile("raw-model/self-combine-bad.xml");
assertViolations(result, 0, 1, 0);
}
+
+ @Test
+ void profileActivationConditionWithBasedirExpression() throws Exception {
+ // Test that ${project.basedir} in activation.condition is allowed (no
warnings)
+ SimpleProblemCollector result = validateRaw(
+ "raw-model/profile-activation-condition-with-basedir.xml",
ModelValidator.VALIDATION_LEVEL_STRICT);
+ assertViolations(result, 0, 0, 0);
+ }
}
diff --git
a/impl/maven-impl/src/test/resources/poms/validation/raw-model/profile-activation-condition-with-basedir.xml
b/impl/maven-impl/src/test/resources/poms/validation/raw-model/profile-activation-condition-with-basedir.xml
new file mode 100644
index 0000000000..62ed35d22a
--- /dev/null
+++
b/impl/maven-impl/src/test/resources/poms/validation/raw-model/profile-activation-condition-with-basedir.xml
@@ -0,0 +1,44 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
https://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <modelVersion>4.1.0</modelVersion>
+ <artifactId>aid</artifactId>
+ <groupId>gid</groupId>
+ <version>0.1</version>
+ <packaging>pom</packaging>
+
+ <profiles>
+ <!-- This profile uses ${project.basedir} in activation.condition, which
should be allowed -->
+ <profile>
+ <id>condition-with-basedir</id>
+ <activation>
+ <condition>exists("${project.basedir}/src/main/java")</condition>
+ </activation>
+ </profile>
+ <!-- This profile uses ${basedir} in activation.condition, which should
also be allowed -->
+ <profile>
+ <id>condition-with-basedir-short</id>
+ <activation>
+ <condition>exists("${basedir}/src/test/java")</condition>
+ </activation>
+ </profile>
+ </profiles>
+</project>