Draft: fix(df): read Maven settings the way the launcher does, and warn when they're dropped
Superseded by !4449 (merged) (proxy policy checks and shutdown) and !4450 (reading Maven settings the way the launcher does). This MR is closed without merging; review continues there.
Description
glab df maven sometimes merges its proxy into the wrong settings file and says nothing. It looked for .mvn/maven.config from its own working directory, so mvn -f services/api/pom.xml missed services/api/.mvn/. It also read ${...} in a -s path literally, and couldn't parse a file declared Latin-1 or using .
This finds the settings file the way the mvn launcher does, and warns when the caller's settings can't be used.
flowchart LR
A["MAVEN_BASEDIR, or -f's directory,<br/>or the working directory"] --> B[".mvn/maven.config"]
B --> C["-s and -gs, ${...} expanded"]
C --> D{"merge the proxy in"}
D -->|ok| E["mvn -s merged copy"]
D -->|fails| F["warning, glab's own settings"]- The project directory comes from
MAVEN_BASEDIR, else the first-for--file, else the working directory, as in the Unixbin/mvn. Windowsmvn.cmdisn't modelled. ${env.X},${maven.multiModuleProjectDirectory},${maven.home},${user.home},${user.dir}and-Dproperties expand in-sand-gs;${user.home}/${user.dir}stay literal when a JVM option or rc file moves them.- The global settings that !4310 (merged) pins as
-gsare found the same way, so-fandMAVEN_BASEDIRno longer turn exact matching off. - Latin-1 and windows-1252 files with ASCII content, and HTML entities, now merge. glab can't list the mirrors in those files, so it checks every reading of a mirrored path there.
- A missing
-sfile stops glab before mvn starts, as mvn does, but only when glab models the whole lookup (no${...}, quote or glob left, no launcher rc file). Otherwise it warns, so it never stops a build mvn completes (142 cases checked against mvn 3.9.12). - When the caller's settings can't be used, glab prints a
warning:naming the file, never the parser's error, which can quote a password. That includes quoted-s "mine.xml"values, which Maven strips and glab doesn't. - The readings of a mirrored path are checked primary first, then four at a time, read in order. A panicking check blocks the request instead of ending glab.
Review follow-ups
Stopnow waits for plain-HTTP handlers too, so a Block recorded afterShutdowngives up on a stalled upload reaches the CI log (Rane on !4326).- The help text says the proxy isn't an egress filter (Rane on !4326).
- From !4310 (merged): Arpit (charsets, settings paths), Mike (check order, test names).
Related Issues
Relates to gitlab-org/gitlab#637331.
How has this been tested?
Real mvn 3.9.12, comparing the settings file each one reads:
| Setup | plain mvn |
before | this MR |
|---|---|---|---|
-f proj/pom.xml, maven.config sets -s ${maven.multiModuleProjectDirectory}/… |
project's file | ~/.m2 file |
project's file |
-f through a symlink into the project |
project's file | wrong file | project's file |
-D on the command line and in maven.config |
command line wins | maven.config wins |
command line wins |
-s names a missing file |
stops with an error | silent | stops with an error |
New tests
TestMavenProjectBaseDirectory:-f,--file,MAVEN_BASEDIR, symlinks, and the forms the launcher ignores.TestMavenSettingsPathExpressions: each expression, unset and empty variables, and-Dprecedence.TestMavenGlobalSettingsFile:-gswith a property, and-gsfrom a-forMAVEN_BASEDIRproject'smaven.config.TestMergeMavenProxiesReadsWhatMavenReads: Latin-1, windows-1252 and files merge byte for byte.TestMavenSetupStopsOnAMissingSettingsFile,TestMavenSetupLeavesUncertainPathsToTheWarning,TestMavenUserHomeSetOutsideMaven: which missing-sfiles stop and which only warn.TestMavenUserSettingsFallback,TestRunWarnsWhenTheCallersSettingsAreDropped: each fallback warns, without quoting the file.TestMavenMirrorPolicyMatching: readings run a few at a time, in candidate order, and a panicking check fails closed.TestProxyStopDrainsPlainHandlerBeforeVerdicts: a plain-HTTP handler that records afterShutdowntimes out still lands inVerdicts(). It fails without the fix.
Commands: go test -race ./internal/dependencyfirewall/... ./internal/commands/df/..., golangci-lint run ./internal/dependencyfirewall/..., lefthook run pre-push.