fix(df): read Maven settings the way the launcher does
What does this MR do and why?
glab df maven sometimes merged its proxy into a different settings file from the one mvn reads, or dropped the caller's settings without saying so. It looked for .mvn/maven.config from its own working directory, read ${...} in -s literally, and couldn't parse a file declared Latin-1 or using . This MR finds the settings file the way the mvn launcher does. It replaces !4327 (closed).
- The project directory comes from
MAVEN_BASEDIR, else the first-for--file, else the working directory, as in the Unixbin/mvn. -sand-gsexpand${env.X},${maven.multiModuleProjectDirectory},${user.home},${user.dir}and-Dproperties, and accept--s,-settingsand the other forms commons-cli takes.- Every settings reader uses one decoder that accepts a declared encoding for ASCII content, and HTML entities.
- When the caller's settings can't be used, glab prints a
warning:naming the file. - When
-snames a plain path (no${...}, quote or glob) whose file doesn't exist, glab stops before mvn starts, as mvn does. Other values only warn, so glab doesn't stop a build because it resolved an expression differently from Maven.
Change to the Maven proxy reader from !4283 (merged): mavenUpstreamProxy now uses the same lookup, without .mvn/maven.config, so a project still can't choose the file that supplies proxy credentials. It no longer errors on a missing -s itself. It found the path differently and stopped builds that mvn completes, such as -s ${env.X}/settings.xml. Arpit, please check this part.
Change to the JVM truststore lookup from !4280 (merged): mavenJVMConfig now finds .mvn/jvm.config through this MR's mavenBaseDir. It resolves symlinks in the -f target, as the launcher's pwd -P does, and uses the parent directory when the -f target isn't a directory.
Not modelled: JVM options that move user.home or user.dir (MAVEN_OPTS, JAVA_TOOL_OPTIONS and the like, .mvn/jvm.config), the launcher's rc files, ${maven.home}, and non-ASCII bytes in a non-UTF-8 file.
How has this been tested?
Tests and checks
TestMavenProjectBaseDirectory,TestMavenSettingsPathExpressions,TestMavenGlobalSettingsFile: base directory, expressions and-Dprecedence.TestMavenSetupStopsOnAMissingSettingsFile,TestMavenSetupLeavesUncertainPathsToTheWarning,TestRunStopsWhenTheNamedSettingsFileIsMissing: which missing-sfiles stop and which only warn.TestMergeMavenProxiesReadsWhatMavenReads,TestMavenUserSettingsFallback: encodings, entities, and the warnings.TestMavenUpstreamProxyFromSettings,TestJVMConfigPathsThatResolveInsideTheProjectAreNotRead,TestMavenUpstreamProxyIgnoresMavenConfig: the proxy reader, including the no-project-files rule.- Compared with real mvn 3.9.12 on 142 inputs, through the proxy reader and
Setup. glab stops 13 builds that mvn completes, all from inputs listed as not modelled.mainstops 36, including those 13. The 16 inputs that pass onmainand now stop all fail in mvn as well.
go test -race ./internal/dependencyfirewall/... ./internal/commands/df/..., golangci-lint run.
Relates to https://gitlab.com/gitlab-org/gitlab/-/work_items/637331.