use of com.google.common.eventbus.EventBus in project bazel by bazelbuild.
the class LexerTest method createLexer.
/**
* Create a lexer which takes input from the specified string. Resets the
* error handler beforehand.
*/
private Lexer createLexer(String input) {
PathFragment somePath = new PathFragment("/some/path.txt");
ParserInputSource inputSource = ParserInputSource.create(input, somePath);
Reporter reporter = new Reporter(new EventBus());
reporter.addHandler(new EventHandler() {
@Override
public void handle(Event event) {
if (EventKind.ERRORS.contains(event.getKind())) {
lastErrorLocation = event.getLocation();
lastError = lastErrorLocation.getPath() + ":" + event.getLocation().getStartLineAndColumn().getLine() + ": " + event.getMessage();
}
}
});
return new Lexer(inputSource, reporter);
}
use of com.google.common.eventbus.EventBus in project bazel by bazelbuild.
the class DarwinSandboxedStrategy method exec.
@Override
public void exec(Spawn spawn, ActionExecutionContext actionExecutionContext, AtomicReference<Class<? extends SpawnActionContext>> writeOutputFiles) throws ExecException, InterruptedException {
Executor executor = actionExecutionContext.getExecutor();
// Certain actions can't run remotely or in a sandbox - pass them on to the standalone strategy.
if (!spawn.isRemotable() || spawn.hasNoSandbox()) {
SandboxHelpers.fallbackToNonSandboxedExecution(spawn, actionExecutionContext, executor);
return;
}
EventBus eventBus = actionExecutionContext.getExecutor().getEventBus();
ActionExecutionMetadata owner = spawn.getResourceOwner();
eventBus.post(ActionStatusMessage.schedulingStrategy(owner));
try (ResourceHandle handle = ResourceManager.instance().acquireResources(owner, spawn.getLocalResources())) {
SandboxHelpers.postActionStatusMessage(eventBus, spawn);
actuallyExec(spawn, actionExecutionContext, writeOutputFiles);
}
}
use of com.google.common.eventbus.EventBus in project bazel by bazelbuild.
the class LinuxSandboxedStrategy method exec.
@Override
public void exec(Spawn spawn, ActionExecutionContext actionExecutionContext, AtomicReference<Class<? extends SpawnActionContext>> writeOutputFiles) throws ExecException, InterruptedException {
Executor executor = actionExecutionContext.getExecutor();
// Certain actions can't run remotely or in a sandbox - pass them on to the standalone strategy.
if (!spawn.isRemotable() || spawn.hasNoSandbox()) {
SandboxHelpers.fallbackToNonSandboxedExecution(spawn, actionExecutionContext, executor);
return;
}
EventBus eventBus = actionExecutionContext.getExecutor().getEventBus();
ActionExecutionMetadata owner = spawn.getResourceOwner();
eventBus.post(ActionStatusMessage.schedulingStrategy(owner));
try (ResourceHandle handle = ResourceManager.instance().acquireResources(owner, spawn.getLocalResources())) {
SandboxHelpers.postActionStatusMessage(eventBus, spawn);
actuallyExec(spawn, actionExecutionContext, writeOutputFiles);
}
}
use of com.google.common.eventbus.EventBus in project buck by facebook.
the class WatchmanWatcherIntegrationTest method setUp.
@Before
public void setUp() throws InterruptedException, IOException {
// Create an empty watchman config file.
Files.write(tmp.getRoot().resolve(".watchmanconfig"), new byte[0]);
watchman = Watchman.build(ImmutableSet.of(tmp.getRoot()), ImmutableMap.copyOf(System.getenv()), new Console(Verbosity.ALL, System.out, System.err, Ansi.withoutTty()), new DefaultClock(), Optional.empty());
assumeTrue(watchman.getWatchmanClient().isPresent());
eventBus = new EventBus();
watchmanEventCollector = new WatchmanEventCollector();
eventBus.register(watchmanEventCollector);
}
use of com.google.common.eventbus.EventBus in project buck by facebook.
the class WatchmanWatcherTest method whenWatchmanProducesAWarningThenWarningAddedToCache.
@Test
public void whenWatchmanProducesAWarningThenWarningAddedToCache() throws IOException, InterruptedException {
String message = "I'm a warning!";
ImmutableMap<String, Object> watchmanOutput = ImmutableMap.of("files", ImmutableList.of(), "warning", message);
EventBus eventBus = new EventBus("watchman test");
WatchmanWatcher watcher = createWatcher(eventBus, watchmanOutput);
Set<WatchmanDiagnostic> diagnostics = new HashSet<>();
BuckEventBus buckEventBus = BuckEventBusFactory.newInstance(new FakeClock(0));
buckEventBus.register(new WatchmanDiagnosticEventListener(buckEventBus, diagnostics));
watcher.postEvents(buckEventBus, WatchmanWatcher.FreshInstanceAction.NONE);
assertThat(diagnostics, hasItem(WatchmanDiagnostic.of(WatchmanDiagnostic.Level.WARNING, message)));
}
Aggregations