Extract interfaces for ModuleActionContextRegistry and SpawnStrategyRegistry to enable incremental migration.

Part of the rollforward of https://github.com/bazelbuild/bazel/commit/37aeabcd39fe326d1c4e55693d8d207f9f7ac6c4.

PiperOrigin-RevId: 303180445
diff --git a/src/main/java/com/google/devtools/build/lib/exec/ModuleActionContextRegistry.java b/src/main/java/com/google/devtools/build/lib/exec/ModuleActionContextRegistry.java
index c0ad57f..8e91d6d 100644
--- a/src/main/java/com/google/devtools/build/lib/exec/ModuleActionContextRegistry.java
+++ b/src/main/java/com/google/devtools/build/lib/exec/ModuleActionContextRegistry.java
@@ -87,10 +87,52 @@
   }
 
   /**
+   * Returns a new {@link Builder} suitable for creating instances of ModuleActionContextRegistry.
+   */
+  public static Builder builder() {
+    return new BuilderImpl();
+  }
+
+  /**
    * Builder collecting the contexts and restrictions thereon for a {@link
    * ModuleActionContextRegistry}.
    */
-  public static final class Builder {
+  // TODO(katre): This exists only to allow incremental migration from SpawnActionContextMaps.
+  // Delete ASAP.
+  public interface Builder {
+
+    /**
+     * Restricts the registry to only return implementations for the given type if they were
+     * {@linkplain #register registered} with the provided restriction as a command-line identifier.
+     *
+     * <p>Note that if no registered action context matches the requested command-line identifiers
+     * when it is {@linkplain #build() built} then the registry will return {@code null} when
+     * queried for this identifying type.
+     *
+     * <p>This behavior can be reset by passing an empty restriction to this method which will cause
+     * the default behavior (last implementation registered for the identifying type) to be used.
+     *
+     * @param restriction command-line identifier used during registration of the desired
+     *     implementation or {@code ""} to allow any implementation of the identifying type
+     */
+    ModuleActionContextRegistry.Builder restrictTo(Class<?> identifyingType, String restriction);
+
+    /**
+     * Registers an action context implementation identified by the given type and which can be
+     * {@linkplain #restrictTo restricted} by its provided command-line identifiers.
+     */
+    <T extends ActionContext> ModuleActionContextRegistry.Builder register(
+        Class<T> identifyingType, T context, String... commandLineIdentifiers);
+
+    /** Constructs the registry configured by this builder. */
+    ModuleActionContextRegistry build() throws ExecutorInitException;
+  }
+
+  /**
+   * Builder collecting the contexts and restrictions thereon for a {@link
+   * ModuleActionContextRegistry}.
+   */
+  private static final class BuilderImpl implements Builder {
 
     private final List<ActionContextInformation<?>> actionContexts = new ArrayList<>();
     private final Map<Class<?>, String> typeToRestriction = new HashMap<>();
@@ -109,6 +151,7 @@
      * @param restriction command-line identifier used during registration of the desired
      *     implementation or {@code ""} to allow any implementation of the identifying type
      */
+    @Override
     public Builder restrictTo(Class<?> identifyingType, String restriction) {
       typeToRestriction.put(identifyingType, restriction);
       return this;
@@ -118,6 +161,7 @@
      * Registers an action context implementation identified by the given type and which can be
      * {@linkplain #restrictTo restricted} by its provided command-line identifiers.
      */
+    @Override
     public <T extends ActionContext> Builder register(
         Class<T> identifyingType, T context, String... commandLineIdentifiers) {
       actionContexts.add(
@@ -127,6 +171,7 @@
     }
 
     /** Constructs the registry configured by this builder. */
+    @Override
     public ModuleActionContextRegistry build() throws ExecutorInitException {
       HashSet<Class<?>> usedTypes = new HashSet<>();
       MutableClassToInstanceMap<ActionContext> contextToInstance =
diff --git a/src/main/java/com/google/devtools/build/lib/exec/SpawnStrategyRegistry.java b/src/main/java/com/google/devtools/build/lib/exec/SpawnStrategyRegistry.java
index 4c2e75f..a87d2bd 100644
--- a/src/main/java/com/google/devtools/build/lib/exec/SpawnStrategyRegistry.java
+++ b/src/main/java/com/google/devtools/build/lib/exec/SpawnStrategyRegistry.java
@@ -18,6 +18,7 @@
 import com.google.auto.value.AutoValue;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Joiner;
+import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableListMultimap;
 import com.google.common.collect.ImmutableMultimap;
@@ -217,6 +218,11 @@
         .collect(joining(", "));
   }
 
+  /** Returns a new {@link Builder} suitable for creating instances of SpawnStrategyRegistry. */
+  public static Builder builder() {
+    return new BuilderImpl();
+  }
+
   /**
    * Builder collecting the strategies and restrictions thereon for a {@link SpawnStrategyRegistry}.
    *
@@ -231,7 +237,126 @@
    * all registered strategies, in registration order (i.e. the earliest strategy registered will be
    * first in the list of strategies returned by {@link SpawnStrategyRegistry#getStrategies}).
    */
-  public static final class Builder {
+  // TODO(katre): This exists only to allow incremental migration from SpawnActionContextMaps.
+  // Delete ASAP.
+  public interface Builder {
+
+    /**
+     * Adds a filter limiting any spawn whose {@linkplain
+     * ActionExecutionMetadata#getProgressMessage() owner's progress message} matches the regular
+     * expression to only use strategies with the given command-line identifiers, in order.
+     *
+     * <p>If multiple filters match the same spawn (including an identical filter) the order of
+     * precedence of calls to this method is determined by {@link
+     * #useLegacyDescriptionFilterPrecedence()}.
+     */
+    SpawnStrategyRegistry.Builder addDescriptionFilter(
+        RegexFilter filter, List<String> identifiers);
+
+    /**
+     * Adds a filter limiting any spawn whose {@linkplain Spawn#getMnemonic() mnemonic}
+     * (case-sensitively) matches the given mnemonic to only use strategies with the given
+     * command-line identifiers, in order.
+     *
+     * <p>If the same mnemonic is registered multiple times the last such call will take precedence.
+     *
+     * <p>Note that if a spawn matches a {@linkplain #addDescriptionFilter registered description
+     * filter} that filter will take precedence over any mnemonic-based filters.
+     */
+    // last one wins
+    SpawnStrategyRegistry.Builder addMnemonicFilter(String mnemonic, List<String> identifiers);
+
+    default SpawnStrategyRegistry.Builder registerStrategy(
+        SpawnStrategy strategy, String... commandlineIdentifiers) {
+      return registerStrategy(strategy, ImmutableList.copyOf(commandlineIdentifiers));
+    }
+
+    /**
+     * Registers a strategy implementation with this collector, distinguishing it from other
+     * strategies with the given command-line identifiers (of which at least one is required).
+     *
+     * <p>If multiple strategies are registered with the same command-line identifier the last one
+     * so registered will take precedence.
+     */
+    SpawnStrategyRegistry.Builder registerStrategy(
+        SpawnStrategy strategy, List<String> commandlineIdentifiers);
+
+    /**
+     * Instructs this collector to use the legacy description filter precedence, i.e. to prefer the
+     * first regular expression filter that matches a spawn over any later registered filters.
+     *
+     * <p>The default behavior of this collector is to prefer the last registered description filter
+     * over any previously registered matching filters.
+     */
+    SpawnStrategyRegistry.Builder useLegacyDescriptionFilterPrecedence();
+
+    /**
+     * Explicitly sets the identifiers of default strategies to use if a spawn matches no filters.
+     *
+     * <p>Note that if this method is not called on the builder, all registered strategies are
+     * considered default strategies, in registration order. See also the {@linkplain Builder class
+     * documentation}.
+     */
+    SpawnStrategyRegistry.Builder setDefaultStrategies(List<String> defaultStrategies);
+
+    /**
+     * Sets the strategy names to use in the remote branch of dynamic execution for a given action
+     * mnemonic.
+     *
+     * <p>During execution, each strategy is {@linkplain SpawnStrategy#canExec(Spawn,
+     * ActionContextRegistry) asked} whether it can execute a given Spawn. The first strategy in the
+     * list that says so will get the job.
+     */
+    SpawnStrategyRegistry.Builder addDynamicRemoteStrategiesByMnemonic(
+        String mnemonic, List<String> strategies);
+
+    /**
+     * Sets the strategy names to use in the local branch of dynamic execution for a given action
+     * mnemonic.
+     *
+     * <p>During execution, each strategy is {@linkplain SpawnStrategy#canExec(Spawn,
+     * ActionContextRegistry) asked} whether it can execute a given Spawn. The first strategy in the
+     * list that says so will get the job.
+     */
+    SpawnStrategyRegistry.Builder addDynamicLocalStrategiesByMnemonic(
+        String mnemonic, List<String> strategies);
+
+    /**
+     * Sets the commandline identifier of the strategy to be used when falling back from remote to
+     * local execution.
+     *
+     * <p>Note that this is an optional setting, if not provided {@link
+     * SpawnStrategyRegistry#getRemoteLocalFallbackStrategy()} will return {@code null}. If the
+     * value <b>is</b> provided it must match the commandline identifier of a registered strategy
+     * (at {@linkplain #build build} time).
+     */
+    SpawnStrategyRegistry.Builder setRemoteLocalFallbackStrategyIdentifier(
+        String commandlineIdentifier);
+
+    /**
+     * Finalizes the construction of the registry.
+     *
+     * @throws ExecutorInitException if a strategy command-line identifier was used in a filter or
+     *     the default strategies but no strategy for that identifier was registered
+     */
+    SpawnStrategyRegistry build() throws ExecutorInitException;
+  }
+
+  /**
+   * Builder collecting the strategies and restrictions thereon for a {@link SpawnStrategyRegistry}.
+   *
+   * <p>To {@linkplain SpawnStrategyRegistry#getStrategies match a strategy to a spawn} it needs to
+   * be both {@linkplain #registerStrategy registered} and its registered command-line identifier
+   * has to match {@linkplain #addDescriptionFilter a filter on the spawn's progress message},
+   * {@linkplain #addMnemonicFilter a filter on the spawn's mnemonic} or be part of the default
+   * strategies (see below).
+   *
+   * <p><strong>Default strategies</strong> are either {@linkplain #setDefaultStrategies set
+   * explicitly} or, if {@link #setDefaultStrategies} is not called on this builder, comprised of
+   * all registered strategies, in registration order (i.e. the earliest strategy registered will be
+   * first in the list of strategies returned by {@link SpawnStrategyRegistry#getStrategies}).
+   */
+  private static final class BuilderImpl implements Builder {
 
     private ImmutableList<String> explicitDefaultStrategies = ImmutableList.of();
     // TODO(schmitt): Using a list and autovalue so as to be able to reverse order while legacy sort
@@ -258,6 +383,7 @@
      * precedence of calls to this method is determined by {@link
      * #useLegacyDescriptionFilterPrecedence()}.
      */
+    @Override
     public Builder addDescriptionFilter(RegexFilter filter, List<String> identifiers) {
       filterAndIdentifiers.add(
           new AutoValue_SpawnStrategyRegistry_FilterAndIdentifiers(
@@ -276,6 +402,7 @@
      * filter} that filter will take precedence over any mnemonic-based filters.
      */
     // last one wins
+    @Override
     public Builder addMnemonicFilter(String mnemonic, List<String> identifiers) {
       mnemonicToIdentifiers.put(mnemonic, identifiers);
       return this;
@@ -288,11 +415,10 @@
      * <p>If multiple strategies are registered with the same command-line identifier the last one
      * so registered will take precedence.
      */
-    public Builder registerStrategy(
-        SpawnStrategy strategy,
-        String firstCommandlineIdentifier,
-        String... commandlineIdentifiers) {
-      identifierToStrategy.put(firstCommandlineIdentifier, strategy);
+    @Override
+    public Builder registerStrategy(SpawnStrategy strategy, List<String> commandlineIdentifiers) {
+      Preconditions.checkArgument(
+          commandlineIdentifiers.size() >= 1, "At least one commandLineIdentifier must be given");
       for (String identifier : commandlineIdentifiers) {
         identifierToStrategy.put(identifier, strategy);
       }
@@ -307,6 +433,7 @@
      * <p>The default behavior of this collector is to prefer the last registered description filter
      * over any previously registered matching filters.
      */
+    @Override
     public Builder useLegacyDescriptionFilterPrecedence() {
       legacyFilterIterationOrder = true;
       return this;
@@ -319,6 +446,7 @@
      * considered default strategies, in registration order. See also the {@linkplain Builder class
      * documentation}.
      */
+    @Override
     public Builder setDefaultStrategies(List<String> defaultStrategies) {
       this.explicitDefaultStrategies = ImmutableList.copyOf(defaultStrategies);
       useRegistrationOrderForDefault = false;
@@ -333,6 +461,7 @@
      * ActionContextRegistry) asked} whether it can execute a given Spawn. The first strategy in the
      * list that says so will get the job.
      */
+    @Override
     public Builder addDynamicRemoteStrategiesByMnemonic(String mnemonic, List<String> strategies) {
       mnemonicToRemoteIdentifiers.put(mnemonic, strategies);
       return this;
@@ -346,6 +475,7 @@
      * ActionContextRegistry) asked} whether it can execute a given Spawn. The first strategy in the
      * list that says so will get the job.
      */
+    @Override
     public Builder addDynamicLocalStrategiesByMnemonic(String mnemonic, List<String> strategies) {
       mnemonicToLocalIdentifiers.put(mnemonic, strategies);
       return this;
@@ -360,6 +490,7 @@
      * value <b>is</b> provided it must match the commandline identifier of a registered strategy
      * (at {@linkplain #build build} time).
      */
+    @Override
     public Builder setRemoteLocalFallbackStrategyIdentifier(String commandlineIdentifier) {
       this.remoteLocalFallbackStrategyIdentifier = commandlineIdentifier;
       return this;
@@ -371,6 +502,7 @@
      * @throws ExecutorInitException if a strategy command-line identifier was used in a filter or
      *     the default strategies but no strategy for that identifier was registered
      */
+    @Override
     public SpawnStrategyRegistry build() throws ExecutorInitException {
       List<FilterAndIdentifiers> orderedFilterAndIdentifiers = filterAndIdentifiers;
 
diff --git a/src/test/java/com/google/devtools/build/lib/exec/ModuleActionContextRegistryTest.java b/src/test/java/com/google/devtools/build/lib/exec/ModuleActionContextRegistryTest.java
index e26db24..2d6413c 100644
--- a/src/test/java/com/google/devtools/build/lib/exec/ModuleActionContextRegistryTest.java
+++ b/src/test/java/com/google/devtools/build/lib/exec/ModuleActionContextRegistryTest.java
@@ -30,7 +30,7 @@
   public void testRegistration() throws Exception {
     AC2 context = new AC2();
     ModuleActionContextRegistry contextRegistry =
-        new ModuleActionContextRegistry.Builder().register(IT1.class, context).build();
+        ModuleActionContextRegistry.builder().register(IT1.class, context).build();
     assertThat(contextRegistry.getContext(IT1.class)).isEqualTo(context);
   }
 
@@ -38,7 +38,7 @@
   public void testDoubleRegistration() throws Exception {
     AC2 context = new AC2();
     ModuleActionContextRegistry contextRegistry =
-        new ModuleActionContextRegistry.Builder()
+        ModuleActionContextRegistry.builder()
             .register(IT1.class, context)
             .register(IT1.class, context)
             .build();
@@ -50,7 +50,7 @@
     AC2 context1 = new AC2();
     AC2 context2 = new AC2();
     ModuleActionContextRegistry contextRegistry =
-        new ModuleActionContextRegistry.Builder()
+        ModuleActionContextRegistry.builder()
             .register(IT1.class, context1)
             .register(IT1.class, context2)
             .build();
@@ -61,7 +61,7 @@
   public void testSelfIdentifyingType() throws Exception {
     AC1 context = new AC1();
     ModuleActionContextRegistry contextRegistry =
-        new ModuleActionContextRegistry.Builder().register(AC1.class, context).build();
+        ModuleActionContextRegistry.builder().register(AC1.class, context).build();
     assertThat(contextRegistry.getContext(AC1.class)).isEqualTo(context);
   }
 
@@ -70,7 +70,7 @@
     AC2 general = new AC2();
     AC2 specific = new AC2();
     ModuleActionContextRegistry contextRegistry =
-        new ModuleActionContextRegistry.Builder()
+        ModuleActionContextRegistry.builder()
             .register(IT1.class, general)
             .register(IT1.class, specific, "specific", "foo")
             .register(IT1.class, general)
@@ -84,7 +84,7 @@
     AC2 context1 = new AC2();
     AC2 context2 = new AC2();
     ModuleActionContextRegistry contextRegistry =
-        new ModuleActionContextRegistry.Builder()
+        ModuleActionContextRegistry.builder()
             .register(IT1.class, context1, "foo")
             .register(IT1.class, context2, "foo")
             .restrictTo(IT1.class, "foo")
@@ -96,7 +96,7 @@
   public void testUsedNotification() throws Exception {
     RecordingContext context = new RecordingContext();
     ModuleActionContextRegistry contextRegistry =
-        new ModuleActionContextRegistry.Builder()
+        ModuleActionContextRegistry.builder()
             .register(RecordingContext.class, context)
             .register(RecordingContext.class, context)
             .build();
@@ -111,7 +111,7 @@
     AC2 general = new AC2();
     AC2 specific = new AC2();
     ModuleActionContextRegistry contextRegistry =
-        new ModuleActionContextRegistry.Builder()
+        ModuleActionContextRegistry.builder()
             .register(IT1.class, general)
             .register(IT1.class, specific, "specific", "foo")
             .register(IT1.class, general)
@@ -124,7 +124,7 @@
   @Test
   public void testNoMatch() throws Exception {
     ModuleActionContextRegistry contextRegistry =
-        new ModuleActionContextRegistry.Builder().register(AC1.class, new AC1()).build();
+        ModuleActionContextRegistry.builder().register(AC1.class, new AC1()).build();
 
     assertThat(contextRegistry.getContext(IT1.class)).isNull();
   }
@@ -134,7 +134,7 @@
     AC2 context1 = new AC2();
     AC2 context2 = new AC2();
     ModuleActionContextRegistry.Builder builder =
-        new ModuleActionContextRegistry.Builder()
+        ModuleActionContextRegistry.builder()
             .register(IT1.class, context1, "foo")
             .register(IT1.class, context2, "baz", "boz")
             .restrictTo(IT1.class, "bar");
diff --git a/src/test/java/com/google/devtools/build/lib/exec/SpawnStrategyRegistryTest.java b/src/test/java/com/google/devtools/build/lib/exec/SpawnStrategyRegistryTest.java
index 1511110..86672c9 100644
--- a/src/test/java/com/google/devtools/build/lib/exec/SpawnStrategyRegistryTest.java
+++ b/src/test/java/com/google/devtools/build/lib/exec/SpawnStrategyRegistryTest.java
@@ -53,7 +53,7 @@
   public void testRegistration() throws Exception {
     NoopStrategy strategy = new NoopStrategy("");
     SpawnStrategyRegistry strategyRegistry =
-        new SpawnStrategyRegistry.Builder()
+        SpawnStrategyRegistry.builder()
             .registerStrategy(strategy, "foo")
             .setDefaultStrategies(ImmutableList.of("foo"))
             .build();
@@ -70,7 +70,7 @@
     NoopStrategy strategy1 = new NoopStrategy("1");
     NoopStrategy strategy2 = new NoopStrategy("2");
     SpawnStrategyRegistry strategyRegistry =
-        new SpawnStrategyRegistry.Builder()
+        SpawnStrategyRegistry.builder()
             .registerStrategy(strategy1, "foo")
             .registerStrategy(strategy2, "bar")
             .addMnemonicFilter("mnem", ImmutableList.of("bar", "foo"))
@@ -88,7 +88,7 @@
     NoopStrategy strategy1 = new NoopStrategy("1");
     NoopStrategy strategy2 = new NoopStrategy("2");
     SpawnStrategyRegistry strategyRegistry =
-        new SpawnStrategyRegistry.Builder()
+        SpawnStrategyRegistry.builder()
             .registerStrategy(strategy1, "foo")
             .registerStrategy(strategy2, "foo")
             .addMnemonicFilter("mnem", ImmutableList.of("foo"))
@@ -106,7 +106,7 @@
     NoopStrategy strategy1 = new NoopStrategy("1");
     NoopStrategy strategy2 = new NoopStrategy("2");
     SpawnStrategyRegistry strategyRegistry =
-        new SpawnStrategyRegistry.Builder()
+        SpawnStrategyRegistry.builder()
             .registerStrategy(strategy1, "foo")
             .registerStrategy(strategy2, "bar")
             .addDescriptionFilter(ELLO_MATCHER, ImmutableList.of("bar", "foo"))
@@ -123,7 +123,7 @@
   public void testFilterNoMatch() throws Exception {
     NoopStrategy strategy = new NoopStrategy("");
     SpawnStrategyRegistry strategyRegistry =
-        new SpawnStrategyRegistry.Builder()
+        SpawnStrategyRegistry.builder()
             .registerStrategy(strategy, "foo")
             .addMnemonicFilter("mnem", ImmutableList.of("foo"))
             .setDefaultStrategies(ImmutableList.of())
@@ -141,7 +141,7 @@
     NoopStrategy strategy1 = new NoopStrategy("1");
     NoopStrategy strategy2 = new NoopStrategy("2");
     SpawnStrategyRegistry strategyRegistry =
-        new SpawnStrategyRegistry.Builder()
+        SpawnStrategyRegistry.builder()
             .registerStrategy(strategy1, "foo")
             .registerStrategy(strategy2, "bar")
             .addMnemonicFilter("mnem", ImmutableList.of("foo"))
@@ -160,7 +160,7 @@
     NoopStrategy strategy1 = new NoopStrategy("1");
     NoopStrategy strategy2 = new NoopStrategy("2");
     SpawnStrategyRegistry strategyRegistry =
-        new SpawnStrategyRegistry.Builder()
+        SpawnStrategyRegistry.builder()
             .registerStrategy(strategy1, "foo")
             .registerStrategy(strategy2, "bar")
             .addMnemonicFilter("mnem", ImmutableList.of("foo"))
@@ -179,7 +179,7 @@
     NoopStrategy strategy1 = new NoopStrategy("1");
     NoopStrategy strategy2 = new NoopStrategy("2");
     SpawnStrategyRegistry strategyRegistry =
-        new SpawnStrategyRegistry.Builder()
+        SpawnStrategyRegistry.builder()
             .registerStrategy(strategy1, "foo")
             .registerStrategy(strategy2, "bar")
             .addDescriptionFilter(ELLO_MATCHER, ImmutableList.of("foo"))
@@ -200,7 +200,7 @@
     NoopStrategy strategy1 = new NoopStrategy("1");
     NoopStrategy strategy2 = new NoopStrategy("2");
     SpawnStrategyRegistry strategyRegistry =
-        new SpawnStrategyRegistry.Builder()
+        SpawnStrategyRegistry.builder()
             .registerStrategy(strategy1, "foo")
             .registerStrategy(strategy2, "bar")
             .addDescriptionFilter(ELLO_MATCHER, ImmutableList.of("foo"))
@@ -223,7 +223,7 @@
     NoopStrategy strategy2 = new NoopStrategy("2");
     NoopStrategy strategy3 = new NoopStrategy("3");
     SpawnStrategyRegistry strategyRegistry =
-        new SpawnStrategyRegistry.Builder()
+        SpawnStrategyRegistry.builder()
             .registerStrategy(strategy1, "foo")
             .registerStrategy(strategy2, "bar")
             .registerStrategy(strategy3, "baz")
@@ -243,7 +243,7 @@
     NoopStrategy strategy2 = new NoopStrategy("2");
     NoopStrategy strategy3 = new NoopStrategy("3");
     SpawnStrategyRegistry strategyRegistry =
-        new SpawnStrategyRegistry.Builder()
+        SpawnStrategyRegistry.builder()
             .registerStrategy(strategy1, "foo")
             .registerStrategy(strategy2, "bar")
             .registerStrategy(strategy3, "baz")
@@ -269,7 +269,7 @@
     NoopStrategy strategy1 = new NoopStrategy("1");
     NoopStrategy strategy2 = new NoopStrategy("2");
     SpawnStrategyRegistry strategyRegistry =
-        new SpawnStrategyRegistry.Builder()
+        SpawnStrategyRegistry.builder()
             .registerStrategy(strategy1, "foo")
             .registerStrategy(strategy2, "bar")
             .build();
@@ -287,7 +287,7 @@
     NoopStrategy strategy2 = new NoopStrategy("2");
     NoopStrategy strategy3 = new NoopStrategy("3");
     SpawnStrategyRegistry strategyRegistry =
-        new SpawnStrategyRegistry.Builder()
+        SpawnStrategyRegistry.builder()
             .registerStrategy(strategy1, "foo")
             .registerStrategy(strategy2, "bar")
             .registerStrategy(strategy3, "foo")
@@ -307,7 +307,7 @@
         assertThrows(
             ExecutorInitException.class,
             () ->
-                new SpawnStrategyRegistry.Builder()
+                SpawnStrategyRegistry.builder()
                     .registerStrategy(strategy1, "foo")
                     .addMnemonicFilter("mnem", ImmutableList.of("bar", "foo"))
                     .build());
@@ -322,7 +322,7 @@
         assertThrows(
             ExecutorInitException.class,
             () ->
-                new SpawnStrategyRegistry.Builder()
+                SpawnStrategyRegistry.builder()
                     .registerStrategy(strategy1, "foo")
                     .addDescriptionFilter(ELLO_MATCHER, ImmutableList.of("bar", "foo"))
                     .build());
@@ -337,7 +337,7 @@
         assertThrows(
             ExecutorInitException.class,
             () ->
-                new SpawnStrategyRegistry.Builder()
+                SpawnStrategyRegistry.builder()
                     .registerStrategy(strategy1, "foo")
                     .setDefaultStrategies(ImmutableList.of("bar"))
                     .build());
@@ -350,7 +350,7 @@
     NoopStrategy strategy1 = new NoopSandboxedStrategy("1");
     NoopStrategy strategy2 = new NoopSandboxedStrategy("2");
     SpawnStrategyRegistry strategyRegistry =
-        new SpawnStrategyRegistry.Builder()
+        SpawnStrategyRegistry.builder()
             .registerStrategy(strategy1, "foo")
             .registerStrategy(strategy2, "bar")
             .addDynamicLocalStrategiesByMnemonic("mnem", ImmutableList.of("bar"))
@@ -374,7 +374,7 @@
         assertThrows(
             ExecutorInitException.class,
             () ->
-                new SpawnStrategyRegistry.Builder()
+                SpawnStrategyRegistry.builder()
                     .registerStrategy(strategy1, "foo")
                     .addDynamicLocalStrategiesByMnemonic("mnem", ImmutableList.of("bar"))
                     .build());
@@ -389,7 +389,7 @@
         assertThrows(
             ExecutorInitException.class,
             () ->
-                new SpawnStrategyRegistry.Builder()
+                SpawnStrategyRegistry.builder()
                     .registerStrategy(strategy1, "foo")
                     .addDynamicLocalStrategiesByMnemonic("mnem", ImmutableList.of("foo"))
                     .build());
@@ -402,7 +402,7 @@
     NoopAbstractStrategy strategy1 = new NoopAbstractStrategy("1");
     NoopAbstractStrategy strategy2 = new NoopAbstractStrategy("2");
     SpawnStrategyRegistry strategyRegistry =
-        new SpawnStrategyRegistry.Builder()
+        SpawnStrategyRegistry.builder()
             .registerStrategy(strategy1, "foo")
             .registerStrategy(strategy2, "bar")
             .setRemoteLocalFallbackStrategyIdentifier("bar")
@@ -418,7 +418,7 @@
         assertThrows(
             ExecutorInitException.class,
             () ->
-                new SpawnStrategyRegistry.Builder()
+                SpawnStrategyRegistry.builder()
                     .registerStrategy(strategy1, "foo")
                     .setRemoteLocalFallbackStrategyIdentifier("bar")
                     .build());
@@ -430,7 +430,7 @@
   public void testRemoteLocalFallbackNotRegistered() throws Exception {
     NoopStrategy strategy1 = new NoopStrategy("1");
     SpawnStrategyRegistry strategyRegistry =
-        new SpawnStrategyRegistry.Builder().registerStrategy(strategy1, "foo").build();
+        SpawnStrategyRegistry.builder().registerStrategy(strategy1, "foo").build();
 
     assertThat(strategyRegistry.getRemoteLocalFallbackStrategy()).isNull();
   }
@@ -447,7 +447,7 @@
     NoopStrategy strategy8 = new NoopStrategy("8");
     NoopStrategy strategy9 = new NoopStrategy("9");
     SpawnStrategyRegistry strategyRegistry =
-        new SpawnStrategyRegistry.Builder()
+        SpawnStrategyRegistry.builder()
             .registerStrategy(strategy1, "1")
             .registerStrategy(strategy2, "2")
             .registerStrategy(strategy3, "3")
@@ -490,7 +490,7 @@
     NoopStrategy strategy6 = new NoopSandboxedStrategy("6");
     NoopStrategy strategy7 = new NoopStrategy("7");
     SpawnStrategyRegistry strategyRegistry =
-        new SpawnStrategyRegistry.Builder()
+        SpawnStrategyRegistry.builder()
             .registerStrategy(strategy1, "1") // no notification: regular strategies are separate
             .registerStrategy(strategy2, "2") // no notification: regular strategies are separate
             .registerStrategy(strategy3, "3") // no notification: regular strategies are separate