Skip to content

[MNG-7131] Add regression tests for maven.config one-arg-per-line contract - #13150

Open
gnodet wants to merge 1 commit into
apache:masterfrom
gnodet:mng7131-regression-tests
Open

gnodet wants to merge 1 commit into
apache:masterfrom
gnodet:mng7131-regression-tests

Conversation

@gnodet

@gnodet gnodet commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Problem

maven.config uses a one-argument-per-line format (introduced by MNG-7131, commit 331c5c3435, July 2021), modelled after Java @argfiles. Each line is a single argv token — whitespace inside a line is never re-split. This allows property values containing spaces:

# .mvn/maven.config
--define
label=Apache Maven

The two lines are passed as two separate tokens to Commons CLI, which consumes the second as the argument to --define.

PR #13093 (2829a73de4) broke this contract by adding flatMap(line -> CleanArgument.splitLine(line).stream()) in MavenParser.parseMavenConfigOptions, re-tokenizing each line on unquoted whitespace. It was reverted in #13148. There were no regression tests protecting this contract, so this PR adds them.

Changes

compat/maven-embedder

  • New test fixture: compat/maven-embedder/src/test/projects/mavenConfigSpacedValues/.mvn/maven.config
    Uses the --define / value with spaces two-line form for two properties.
  • New test: MavenCliTest#testMavenConfigMultiLineDefineWithSpaces()
    Calls initializecliproperties and asserts both user properties are parsed correctly.

impl/maven-cli

  • New test class: MavenParserTest (same package as MavenParser for protected access)
    Five test cases covering:
    1. testMultiLineDefineWithSpacedValue — core regression: --define / label=Apache Maven must yield label=Apache Maven (the exact case Fix #13092: tokenize quoted --define in maven.config #13093 broke)
    2. testMultiLineDefineSimple — two-line form without spaces
    3. testSingleLineDefine — compact -Dkey=value form still works
    4. testCommentsAndEmptyLinesSkipped — comment/blank lines are filtered
    5. testGoalRejected — goals throw IllegalArgumentException

Testing

mvn verify -pl compat/maven-embedder -am -B   # MavenCliTest: 1/1 PASS
mvn verify -pl impl/maven-cli -am -B          # MavenParserTest: 5/5 PASS

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solid regression guard for MNG-7131. The two-layer approach (compat MavenCliTest + impl-level MavenParserTest) is exactly right: the compat test exercises the full initialize → cli → properties pipeline through a real on-disk fixture, while MavenParserTest directly unit-tests parseMavenConfigOptions with all the edge cases that matter.

Specific notes:

  • parseMavenConfigOptions is protected in MavenParser, accessible from the same package — the test placement in org.apache.maven.cling.invoker.mvn is correct.
  • new MavenParser() instantiates via the default no-arg constructor (no CDI injection required at this level) — valid.
  • Five test cases cover: spaced-value two-line form (the regressed case), simple two-line form, compact -D form, comment/blank-line filtering, and goal rejection. Coverage is complete for the documented contract.
  • testGoalRejected correctly exercises the IllegalArgumentException path (commandLine.getArgList() returns ["verify"], goals().isPresent() → throws).
  • The compat fixture mirrors exactly the format that triggered the MNG-7131 fix: a comment line, two-line --define/label=Apache Maven, two-line --define/revision=1.0.0.
  • No functional code is changed — pure test addition.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants