Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,15 @@ public DefaultClient(DaemonParameters parameters) {
true);
}

/**
* The environment forwarded to the daemon in the {@link Message.BuildRequest}. Defaults to the
* client's own environment; overridable so tests can run hermetically (e.g. without inheriting
* an ambient {@code MAVEN_ARGS}).
*/
protected Map<String, String> buildRequestEnvironment() {
return System.getenv();
}

@Override
public ExecutionResult execute(ClientOutput output, List<String> argv) {
LOGGER.debug("Starting client");
Expand Down Expand Up @@ -374,7 +383,7 @@ public ExecutionResult execute(ClientOutput output, List<String> argv) {
args,
parameters.userDir().toString(),
parameters.multiModuleProjectDirectory().toString(),
System.getenv()));
buildRequestEnvironment()));

output.accept(Message.buildStatus(
"Connected to daemon " + daemon.getDaemon().getId() + ", scanning for projects..."));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

Expand All @@ -42,6 +43,18 @@ public JvmTestClient(DaemonParameters parameters) {
this.parameters = parameters;
}

/**
* Strip any ambient {@code MAVEN_ARGS} (e.g. actions/setup-java sets it to {@code -ntp}) from the
* environment forwarded to the daemon, so it cannot override per-test flags such as
* ConcurrentDownloadsTest's transfer-progress expectation. Keeps the test daemon hermetic.
*/
@Override
protected Map<String, String> buildRequestEnvironment() {
final Map<String, String> env = new HashMap<>(super.buildRequestEnvironment());
env.remove("MAVEN_ARGS");
return env;
}

@Override
public ExecutionResult execute(ClientOutput output, List<String> argv) {
setMultiModuleProjectDirectory(argv);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.IOException;
import java.io.UncheckedIOException;
import java.lang.reflect.Field;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -235,7 +236,7 @@ public static MvndResource create(
multiModuleProjectDirectory,
Paths.get(System.getProperty("java.home")).toAbsolutePath().normalize(),
localMavenRepository,
null,
createIsolatedSettings(testDir.resolve("settings.xml")),
TimeUtils.toDuration(Environment.MVND_IDLE_TIMEOUT.getDefault()),
keepAlive != null && !keepAlive.isEmpty()
? TimeUtils.toDuration(keepAlive)
Expand All @@ -251,6 +252,24 @@ public static MvndResource create(
return new MvndResource(parameters, registry, isNative, timeoutMs);
}

/**
* Writes a minimal, isolated {@code settings.xml} and returns its path so that the daemon
* is always launched with an explicit {@code -s} and never falls back to the ambient
* {@code ${user.home}/.m2/settings.xml}. Without this, when running with {@code -Dmrm=false}
* (as CI does), the daemon reads the runner's user settings. actions/setup-java writes one
* containing {@code <interactiveMode>false</interactiveMode>}, which made {@code versions:set}
* run non-interactively and broke InteractiveTest. An empty settings keeps the defaults
* (interactive, no ambient mirrors) so the tests behave the same everywhere.
*/
static Path createIsolatedSettings(Path settingsPath) {
try {
Files.write(settingsPath, "<settings/>\n".getBytes(StandardCharsets.UTF_8));
} catch (IOException e) {
throw new RuntimeException("Could not write " + settingsPath, e);
}
return settingsPath;
}

private static void prefillLocalRepo(final Path localMavenRepository) {
/* Workaround for https://github.com/apache/maven-mvnd/issues/281 */
final String preinstallArtifacts =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ public ExecutionResult execute(ClientOutput output, List<String> args) throws In
.redirectErrorStream(true);

final Map<String, String> env = builder.environment();
// Strip any ambient MAVEN_ARGS (e.g. actions/setup-java sets it to -ntp) so it cannot leak
// through the native binary into the daemon and override per-test flags. Keeps tests hermetic.
env.remove("MAVEN_ARGS");
if (!Environment.MVND_HOME.hasCommandLineOption(args)) {
env.put(Environment.MVND_HOME.getEnvironmentVariable(), Environment.MVND_HOME.asString());
}
Expand Down
Loading