Repository navigation
[3.10.x] Accept the ? optional-profile prefix in -P - #13480
Conversation
Maven 4 reads -P ?id as an optional profile; Maven 3 read it as a profile named ?id and left id off. The prefix is now removed after the +, - and ! prefixes, in the same order as Maven 4.
gnodet-bot
left a comment
There was a problem hiding this comment.
The new performProfileActivation method is missing an isEmpty() guard after stripping all prefixes. Degenerate inputs like -P ?, -P -?, or -P ! strip down to an empty string that is silently inserted into the active/inactive profile list. Maven 4's equivalent method guards each substring call with !profileId.isEmpty() before adding — this backport should do the same.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
gnodet-bot
left a comment
There was a problem hiding this comment.
Following up on my earlier review — both issues have been addressed.
isEmpty() guard — ✅ addressed. The new commit adds if (profileId.isEmpty()) { continue; } after the ? stripping, which correctly skips empty-string tokens for all degenerate inputs (-P ?, -P -?, -P !?, bare -P -, etc.).
testDegenerateProfileTokens — ✅ addressed. The new test exercises ?,!,+,-,+?,-?,!?, and asserts both active and inactive lists remain empty, which directly validates the guard.
Pre-fix validation: static trace confirms testDegenerateProfileTokens was failing before the fix — token ? strips to "", without the guard activeProfiles.add("") is called, and assertTrue(active.isEmpty()) fails.
LGTM.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
|
@slachiewicz why is the difference with the trim kept on purpose ? |
The 3.x line has always trimmed each token before reading its +, - or ! prefix; the old code removed by the PR does nextToken().trim(). Maven 4 trims too, and its -/! check reads the trimmed id. Only its + check reads the raw token (token.charAt(0) == '+'), and that looks like a slip rather than a design choice. With -P "a, +b", Maven 4 tries to activate a profile literally named +b. Master has the same check twice in MavenInvoker.java (lines 405 and 432), presumably once for profiles and once for projects. Matching Maven 4 would mean copying that slip into 3.10.
That looks like a slip rather than intent; I can open a PR to make MavenInvoker check profileId on master and 4.0.x so both lines agree. |
Yes, that sounds like a good idea. |
Fixes #13479. Maven 4 reads
-P ?idas an optional profile (MNG-7051); Maven 3.10 read?idas a profile literally named?idand leftidoff, so a build passing-P ?run-itsto both Maven 3 and 4 silently skipped the profile on Maven 3. The?is now removed after the+,-and!prefixes, in the same order as Maven 4, so?id,+?id,-?idand!?idwork; a token that is empty after the prefixes (-P ?,-P -?) is ignored. A missing optional profile still logs the existing "could not be activated" warning, now with the plain id: Maven 3 does not fail on missing profiles, and dropping the warning would need the optional flag onMavenExecutionRequest. The parsing moves into a package-privateperformProfileActivation, as in Maven 4, so it can be unit tested.Each token is trimmed before its prefixes are read, as Maven 4 does once #13502 fixes its
+check, which read the untrimmed token; empty tokens such asa,,bstay ignored, as in both lines.All
-Psources (the command line,.mvn/maven.configandMAVEN_ARGS) go through this method.maven-3.9.xkeeps the old parsing, since that line takes serious bug fixes only.Verified: a 3.10.1-SNAPSHOT build activates the profile with
-P ?run-itswhere 3.10.0 does not, deactivates it with!?run-its, and succeeds with-P ?missing;mvn -pl maven-embedder test→ 43 tests pass, includingtestOptionalProfilesandtestDegenerateProfileTokens.