diff options
author | 2016-10-31 16:52:48 +0000 | |
---|---|---|
committer | 2016-11-02 08:25:42 +0000 | |
commit | a0e3af46ca41f55163188d4beef10534c006aaca (patch) | |
tree | d9cc68a79c856f7d536244d17267e7c7ea0e2c87 /src/main/java/com/google/devtools/build/lib/actions | |
parent | 03afc7d463149860df6e7c7aa04a6325bb9391e3 (diff) |
Refactor the module API to use the builder pattern for executor creation.
This significantly simplifies several of our modules.
--
MOS_MIGRATED_REVID=137713119
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/actions')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/actions/ExecutorBuilder.java | 64 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/actions/SimpleActionContextProvider.java | 14 |
2 files changed, 66 insertions, 12 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/actions/ExecutorBuilder.java b/src/main/java/com/google/devtools/build/lib/actions/ExecutorBuilder.java new file mode 100644 index 0000000000..c25fc07245 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/actions/ExecutorBuilder.java @@ -0,0 +1,64 @@ +// Copyright 2016 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package com.google.devtools.build.lib.actions; + +import com.google.common.collect.ImmutableList; +import com.google.devtools.build.lib.actions.Executor.ActionContext; +import java.util.ArrayList; +import java.util.List; + +/** + * Builder class to create an {@link Executor} instance. This class is part of the module API, + * which allows modules to affect how the executor is initialized. + */ +public class ExecutorBuilder { + private final List<ActionContextProvider> actionContextProviders = new ArrayList<>(); + private final List<ActionContextConsumer> actionContextConsumers = new ArrayList<>(); + + // These methods shouldn't be public, but they have to be right now as ExecutionTool is in another + // package. + public ImmutableList<ActionContextProvider> getActionContextProviders() { + return ImmutableList.copyOf(actionContextProviders); + } + + public ImmutableList<ActionContextConsumer> getActionContextConsumers() { + return ImmutableList.copyOf(actionContextConsumers); + } + + /** + * Adds the specified action context providers to the executor. + */ + public ExecutorBuilder addActionContextProvider(ActionContextProvider provider) { + this.actionContextProviders.add(provider); + return this; + } + + /** + * Adds the specified action context to the executor, by wrapping it in a simple action context + * provider implementation. + */ + public ExecutorBuilder addActionContext(ActionContext context) { + return addActionContextProvider(new SimpleActionContextProvider(context)); + } + + /** + * Adds the specified action context consumer to the executor. + */ + public ExecutorBuilder addActionContextConsumer(ActionContextConsumer consumer) { + this.actionContextConsumers.add(consumer); + return this; + } + +} + diff --git a/src/main/java/com/google/devtools/build/lib/actions/SimpleActionContextProvider.java b/src/main/java/com/google/devtools/build/lib/actions/SimpleActionContextProvider.java index 1239ccb0f9..642bc09ada 100644 --- a/src/main/java/com/google/devtools/build/lib/actions/SimpleActionContextProvider.java +++ b/src/main/java/com/google/devtools/build/lib/actions/SimpleActionContextProvider.java @@ -15,25 +15,15 @@ package com.google.devtools.build.lib.actions; import com.google.common.collect.ImmutableList; import com.google.devtools.build.lib.actions.Executor.ActionContext; - import java.util.List; /** * An {@link ActionContextProvider} that just provides the {@link ActionContext}s it's given. */ -public class SimpleActionContextProvider extends ActionContextProvider { - - /** - * Creates an immutable list containing a single SimpleActionContextProvider with the given - * contexts as a convenience for BlazeModule.getActionContextProviders(). - */ - public static List<ActionContextProvider> of(ActionContext ... contexts) { - return ImmutableList.<ActionContextProvider>of(new SimpleActionContextProvider(contexts)); - } - +final class SimpleActionContextProvider extends ActionContextProvider { private final List<ActionContext> actionContexts; - public SimpleActionContextProvider(ActionContext ... contexts) { + public SimpleActionContextProvider(ActionContext... contexts) { actionContexts = ImmutableList.<ActionContext>copyOf(contexts); } |