gnodet opened a new pull request, #14064:
URL: https://github.com/apache/maven/pull/14064
## Summary
Add two new condition functions to `ConditionFunctions`:
- **`exec(command)`** — executes an external command and returns its trimmed
stdout
- **`extract(str, regex)`** — extracts the first match (or first capturing
group) of a regex from a string
Together they enable version-gated profile activation based on tool output:
```xml
<condition>
executable('docker') &&
inrange(extract(exec('docker --version'), '\d+\.\d+[\.\d]*'), '[19.0,)')
</condition>
```
## Design
**`exec(command)`**
- Splits the command line on whitespace to build the argument array (quoted
arguments with spaces are not supported)
- Captures up to 4096 bytes of stdout; stderr is discarded via
`Redirect.DISCARD`
- 5-second wall-clock timeout; the process is forcibly killed on timeout via
`destroyForcibly()` in a `finally` block
- Returns an empty string on timeout, non-zero exit code, or any exception —
never throws
- Carries the same non-reproducibility warning as `executable()`
**`extract(str, regex)`**
- Returns the first capturing group if one is present, or the whole match
otherwise
- Returns an empty string when the pattern does not match or when an
optional group didn't participate in the match (guards against `null` from
`Matcher.group(1)`)
## Tests
- `testExtractNoGroup` — no capturing group returns whole match
- `testExtractWithCapturingGroup` — group(1) extraction
- `testExtractNoMatch` — returns empty string
- `testExtractEmptyInput` — empty input returns empty string
- `testExtractInrangeComposition` — full `extract + inrange` pipeline
- `testExecSimpleCommand` _(Unix only)_ — basic `echo` output
- `testExecEmptyArgument` — blank command returns empty string
- `testExecNonExistentCommand` — missing executable returns empty string
- `testExecWithExtract` _(Unix only)_ — full `exec + extract` pipeline
---
_Hermes Agent (Claude Sonnet) on behalf of Guillaume Nodet_
--
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]