Move anonymous inner class to nested class
@@ -72,12 +72,48 @@ public abstract class AbstractSpawnStrategy implements SandboxedSpawnActionConte
actionExecutionContext.reportSubcommand(spawn);
}
final Duration timeout = Spawns.getTimeout(spawn);
- SpawnExecutionPolicy policy = new SpawnExecutionPolicy() {
+ SpawnExecutionPolicy policy =
+ new SpawnExecutionPolicyImpl(
+ spawn, actionExecutionContext, writeOutputFiles, timeout);
+ SpawnResult result;
+ try {
+ result = spawnRunner.exec(spawn, policy);
+ } catch (IOException e) {
+ throw new EnvironmentalExecException("Unexpected IO error.", e);
+ }
+
+ if ((result.status() != Status.SUCCESS) || (result.exitCode() != 0)) {
+ String cwd = actionExecutionContext.getExecRoot().getPathString();
+ String message =
+ CommandFailureUtils.describeCommandFailure(
+ verboseFailures, spawn.getArguments(), spawn.getEnvironment(), cwd);
+ throw new SpawnExecException(
+ message, result, /*forciblyRunRemotely=*/false, /*catastrophe=*/false);
+ }
+ }
+
+ private final class SpawnExecutionPolicyImpl implements SpawnExecutionPolicy {
+ private final Spawn spawn;
+ private final ActionExecutionContext actionExecutionContext;
+ private final AtomicReference<Class<? extends SpawnActionContext>> writeOutputFiles;
+ private final Duration timeout;
+
private final int id = execCount.incrementAndGet();
// Memoize the input mapping so that prefetchInputs can reuse it instead of recomputing it.
// TODO(ulfjack): Guard against client modification of this map.
private SortedMap<PathFragment, ActionInput> lazyInputMapping;
+ public SpawnExecutionPolicyImpl(
+ Spawn spawn,
+ ActionExecutionContext actionExecutionContext,
+ AtomicReference<Class<? extends SpawnActionContext>> writeOutputFiles,
+ Duration timeout) {
+ this.spawn = spawn;
+ this.actionExecutionContext = actionExecutionContext;
+ this.writeOutputFiles = writeOutputFiles;
+ this.timeout = timeout;
+ }
+
@Override
public int getId() {
return id;
@@ -151,21 +187,5 @@ public abstract class AbstractSpawnStrategy implements SandboxedSpawnActionConte
break;
}
}
- };
- SpawnResult result;
- try {
- result = spawnRunner.exec(spawn, policy);
- } catch (IOException e) {
- throw new EnvironmentalExecException("Unexpected IO error.", e);
- }
-
- if ((result.status() != Status.SUCCESS) || (result.exitCode() != 0)) {
- String cwd = actionExecutionContext.getExecRoot().getPathString();
- String message =
- CommandFailureUtils.describeCommandFailure(
- verboseFailures, spawn.getArguments(), spawn.getEnvironment(), cwd);
- throw new SpawnExecException(
- message, result, /*forciblyRunRemotely=*/false, /*catastrophe=*/false);
- }
}
}
