This is an automated email from the ASF dual-hosted git repository. gnodet pushed a commit to branch fix/model-validator-activation-condition-basedir in repository https://gitbox.apache.org/repos/asf/maven.git
commit dc4a22948ec4f5e51a31a20af3a8ec82fda84e96 Author: Guillaume Nodet <[email protected]> AuthorDate: Mon Dec 8 13:09:36 2025 +0100 Allow ${project.basedir} in profile activation.condition 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. --- .../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 5198ec5513..159ac111d1 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 @@ -686,7 +686,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 879cc70aed..dc118703bb 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 @@ -968,4 +968,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>
