use of com.facebook.buck.event.BuckEventBus 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)));
}
use of com.facebook.buck.event.BuckEventBus in project buck by facebook.
the class ProjectBuildFileParser method init.
/**
* Initialize the parser, starting buck.py.
*/
private void init() throws IOException {
projectBuildFileParseEventStarted = new ProjectBuildFileParseEvents.Started();
buckEventBus.post(projectBuildFileParseEventStarted);
try (SimplePerfEvent.Scope scope = SimplePerfEvent.scope(buckEventBus, PerfEventId.of("ParserInit"))) {
ImmutableMap.Builder<String, String> pythonEnvironmentBuilder = ImmutableMap.builder();
// Strip out PYTHONPATH. buck.py manually sets this to include only nailgun. We don't want
// to inject nailgun into the parser's PYTHONPATH, so strip that value out.
// If we wanted to pass on some environmental PYTHONPATH, we would have to do some actual
// merging of this and the BuckConfig's python module search path.
pythonEnvironmentBuilder.putAll(Maps.filterKeys(environment, k -> !PYTHONPATH_ENV_VAR_NAME.equals(k)));
if (options.getPythonModuleSearchPath().isPresent()) {
pythonEnvironmentBuilder.put(PYTHONPATH_ENV_VAR_NAME, options.getPythonModuleSearchPath().get());
}
ImmutableMap<String, String> pythonEnvironment = pythonEnvironmentBuilder.build();
ProcessExecutorParams params = ProcessExecutorParams.builder().setCommand(buildArgs()).setEnvironment(pythonEnvironment).build();
LOG.debug("Starting buck.py command: %s environment: %s", params.getCommand(), params.getEnvironment());
buckPyProcess = processExecutor.launchProcess(params);
LOG.debug("Started process %s successfully", buckPyProcess);
OutputStream stdin = buckPyProcess.getOutputStream();
InputStream stderr = buckPyProcess.getErrorStream();
InputStreamConsumer stderrConsumer = new InputStreamConsumer(stderr, (InputStreamConsumer.Handler) line -> buckEventBus.post(ConsoleEvent.warning("Warning raised by BUCK file parser: %s", line)));
stderrConsumerTerminationFuture = new FutureTask<>(stderrConsumer);
stderrConsumerThread = Threads.namedThread(ProjectBuildFileParser.class.getSimpleName(), stderrConsumerTerminationFuture);
stderrConsumerThread.start();
buckPyStdinWriter = new BufferedOutputStream(stdin);
}
}
use of com.facebook.buck.event.BuckEventBus in project buck by facebook.
the class AdbHelperTest method createAdbHelper.
private AdbHelper createAdbHelper(ExecutionContext executionContext, AdbOptions adbOptions, TargetDeviceOptions targetDeviceOptions) throws CmdLineException {
Console console = new TestConsole();
BuckEventBus eventBus = BuckEventBusFactory.newInstance();
return new AdbHelper(adbOptions, targetDeviceOptions, executionContext, console, eventBus, true) {
@Override
protected boolean isDeviceTempWritable(IDevice device, String name) {
return true;
}
};
}
use of com.facebook.buck.event.BuckEventBus in project buck by facebook.
the class AdbHelperTest method testQuietDeviceInstall.
@Test
public void testQuietDeviceInstall() throws InterruptedException {
final File apk = new File("/some/file.apk");
final AtomicReference<String> apkPath = new AtomicReference<>();
TestDevice device = new TestDevice() {
@Override
public void installPackage(String s, boolean b, String... strings) throws InstallException {
apkPath.set(s);
}
};
device.setSerialNumber("serial#1");
device.setName("testDevice");
final List<IDevice> deviceList = Lists.newArrayList((IDevice) device);
TestConsole console = new TestConsole();
BuckEventBus eventBus = BuckEventBusFactory.newInstance();
AdbHelper adbHelper = new AdbHelper(new AdbOptions(), new TargetDeviceOptions(), TestExecutionContext.newInstance(), console, eventBus, true) {
@Override
protected boolean isDeviceTempWritable(IDevice device, String name) {
return true;
}
@Override
public List<IDevice> getDevices(boolean quiet) {
return deviceList;
}
};
boolean success = adbHelper.adbCall(new AdbHelper.AdbCallable() {
@Override
public boolean call(IDevice device) throws Exception {
return basicAdbHelper.installApkOnDevice(device, apk, false, true);
}
@Override
public String toString() {
return "install apk";
}
}, true);
assertTrue(success);
assertEquals(apk.getAbsolutePath(), apkPath.get());
assertEquals("", console.getTextWrittenToStdOut());
assertEquals("", console.getTextWrittenToStdErr());
}
use of com.facebook.buck.event.BuckEventBus in project buck by facebook.
the class AdbHelperTest method testNonQuietShowsOutput.
@Test
public void testNonQuietShowsOutput() throws InterruptedException {
final File apk = new File("/some/file.apk");
final AtomicReference<String> apkPath = new AtomicReference<>();
TestDevice device = new TestDevice() {
@Override
public void installPackage(String s, boolean b, String... strings) throws InstallException {
apkPath.set(s);
}
};
device.setSerialNumber("serial#1");
device.setName("testDevice");
final List<IDevice> deviceList = Lists.newArrayList((IDevice) device);
TestConsole console = new TestConsole();
BuckEventBus eventBus = BuckEventBusFactory.newInstance();
AdbHelper adbHelper = new AdbHelper(new AdbOptions(), new TargetDeviceOptions(), TestExecutionContext.newInstance(), console, eventBus, true) {
@Override
protected boolean isDeviceTempWritable(IDevice device, String name) {
return true;
}
@Override
public List<IDevice> getDevices(boolean quiet) {
return deviceList;
}
};
boolean success = adbHelper.adbCall(new AdbHelper.AdbCallable() {
@Override
public boolean call(IDevice device) throws Exception {
return basicAdbHelper.installApkOnDevice(device, apk, false, false);
}
@Override
public String toString() {
return "install apk";
}
}, false);
assertTrue(success);
assertEquals(apk.getAbsolutePath(), apkPath.get());
assertEquals("", console.getTextWrittenToStdOut());
assertEquals("Successfully ran install apk on 1 device(s)\n", console.getTextWrittenToStdErr());
}
Aggregations