Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CommandLinePathFactory to CommandEnvironment #15905

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
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 @@ -107,6 +107,7 @@ public class CommandEnvironment {
private final ImmutableList.Builder<Any> responseExtensions = ImmutableList.builder();
private final Consumer<String> shutdownReasonConsumer;
private final BuildResultListener buildResultListener;
private final CommandLinePathFactory commandLinePathFactory;

private OutputService outputService;
private String workspaceName;
Expand Down Expand Up @@ -273,6 +274,23 @@ public void exit(AbruptExitException exception) {
}
this.buildResultListener = new BuildResultListener();
this.eventBus.register(this.buildResultListener);

ImmutableMap.Builder<String, Path> wellKnownRoots = ImmutableMap.builder();
// This is necessary because some tests don't have a workspace set.
putIfValueNotNull(wellKnownRoots, "workspace", directories.getWorkspace());
Yannic marked this conversation as resolved.
Show resolved Hide resolved

this.commandLinePathFactory =
new CommandLinePathFactory(runtime.getFileSystem(), wellKnownRoots.build());
}

private static <K, V> void putIfValueNotNull(
ImmutableMap.Builder<K, V> map, K key, @Nullable V value) {
Preconditions.checkNotNull(map);
Preconditions.checkNotNull(key);

if (value != null) {
map.put(key, value);
}
}

private Path computeWorkingDirectory(CommonCommandOptions commandOptions)
Expand Down Expand Up @@ -840,4 +858,8 @@ public void addResponseExtensions(Iterable<Any> extensions) {
public BuildResultListener getBuildResultListener() {
return buildResultListener;
}

public CommandLinePathFactory getCommandLinePathFactory() {
return commandLinePathFactory;
}
}