@@ -107,6 +107,7 @@ public class CommandEnvironment {
107
107
private final ImmutableList .Builder <Any > responseExtensions = ImmutableList .builder ();
108
108
private final Consumer <String > shutdownReasonConsumer ;
109
109
private final BuildResultListener buildResultListener ;
110
+ private final CommandLinePathFactory commandLinePathFactory ;
110
111
111
112
private OutputService outputService ;
112
113
private String workspaceName ;
@@ -273,6 +274,23 @@ public void exit(AbruptExitException exception) {
273
274
}
274
275
this .buildResultListener = new BuildResultListener ();
275
276
this .eventBus .register (this .buildResultListener );
277
+
278
+ ImmutableMap .Builder <String , Path > wellKnownRoots = ImmutableMap .builder ();
279
+ // This is necessary because some tests don't have a workspace set.
280
+ putIfValueNotNull (wellKnownRoots , "workspace" , directories .getWorkspace ());
281
+
282
+ this .commandLinePathFactory =
283
+ new CommandLinePathFactory (runtime .getFileSystem (), wellKnownRoots .build ());
284
+ }
285
+
286
+ private static <K , V > void putIfValueNotNull (
287
+ ImmutableMap .Builder <K , V > map , K key , @ Nullable V value ) {
288
+ Preconditions .checkNotNull (map );
289
+ Preconditions .checkNotNull (key );
290
+
291
+ if (value != null ) {
292
+ map .put (key , value );
293
+ }
276
294
}
277
295
278
296
private Path computeWorkingDirectory (CommonCommandOptions commandOptions )
@@ -840,4 +858,8 @@ public void addResponseExtensions(Iterable<Any> extensions) {
840
858
public BuildResultListener getBuildResultListener () {
841
859
return buildResultListener ;
842
860
}
861
+
862
+ public CommandLinePathFactory getCommandLinePathFactory () {
863
+ return commandLinePathFactory ;
864
+ }
843
865
}
0 commit comments