Dev-next-gen opened a new pull request, #13160:
URL: https://github.com/apache/maven/pull/13160

   The `activation/condition` docs in maven.mdo give 
`exists('${project.basedir}/src/**/*.xsd')` as the file-existence example. On 
Windows that condition never matches, and a relative pattern like 
`exists('**/*.xsd')` fails the profile with an exception.
   
   `DefaultProfileActivationContext.doExists` ran the whole pattern through 
`interpolatePath()`, which aligns it to the project directory, and only then 
split it into a fixed directory and a glob. On Windows that goes wrong in two 
ways:
   
   - For an absolute pattern, alignment turns every `/` into `\`, so the glob 
becomes `**\*.xsd`. The JDK glob syntax treats `\` as an escape character on 
Windows too (there, `/` is what matches the separator), so the pattern looks 
for a literal `*` and nothing matches. `exists()` is always false and 
`missing()` always true.
   - For a relative pattern, alignment calls `basedir.resolve("**\*.xsd")`, 
which throws `InvalidPathException: Illegal char <*> at index 0: **\*.xsd` 
because `*` is not a valid Windows path character. The condition activator 
reports it as `Error invoking function 'exists'`.
   
   The fix splits the interpolated pattern first, on either `/` or `\`. It then 
aligns only the fixed part to the base directory and uses `/` as the separator 
in the glob. `interpolatePath()` keeps its behavior; its interpolation step 
moves into a private `interpolate()` so `doExists` can use it before alignment. 
On Linux and macOS the result is the same as before, since alignment already 
turned `\` into `/` there.
   
   `testFileWilcards` in `ConditionProfileActivatorTest` covers exactly these 
patterns but has been `@Disabled` since the condition activator was added. It 
passes on Linux as is, so I re-enabled it and added two negative assertions 
(`missing(...)` on an existing match, `exists(...)` on a missing one). To check 
on Windows 11 (JDK 17), I ran the test class against `maven-impl` classes built 
from master and from this branch:
   
   ```
   before: 35 tests successful, 1 failed
     testFileWilcards => AssertionFailedError: expected: <true> but was: <false>
   after:  36 tests successful, 0 failed
   ```
   
   `FileProfileActivatorTest` passes on both. On Linux (JDK 21), all 
`maven-impl` tests pass (709 run, 0 failures) and `spotless:check` is clean.
   
   - [x] Your pull request should address just one issue, without pulling in 
other changes.
   - [x] Write a pull request description that is detailed enough to understand 
what the pull request does, how, and why.
   - [x] Each commit in the pull request should have a meaningful subject line 
and body.
   - [x] Write unit tests that match behavioral changes, where the tests fail 
if the changes to the runtime are not applied.
   - [ ] Run `mvn verify` to make sure basic checks pass.
   - [ ] You have run the [Core IT][core-its] successfully.
   
   - [ ] I hereby declare this contribution to be licenced under the [Apache 
License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)
   - [ ] In any other case, please file an [Apache Individual Contributor 
License Agreement](https://www.apache.org/licenses/icla.pdf).
   
   [core-its]: https://maven.apache.org/core-its/core-it-suite/
   
   Found by a defect-hunting pipeline I build and run 
([Dev-next-gen](https://github.com/Dev-next-gen)), using Claude Code with 
Anthropic's Claude Opus 5.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to