Search in sources :

Example 1 with WatchmanDiagnosticEventListener

use of com.facebook.buck.io.WatchmanDiagnosticEventListener in project buck by facebook.

the class Main method addEventListeners.

@SuppressWarnings("PMD.PrematureDeclaration")
private ImmutableList<BuckEventListener> addEventListeners(BuckEventBus buckEventBus, ProjectFilesystem projectFilesystem, InvocationInfo invocationInfo, BuckConfig buckConfig, Optional<WebServer> webServer, Clock clock, AbstractConsoleEventBusListener consoleEventBusListener, Supplier<BuckEventListener> missingSymbolsListenerSupplier, CounterRegistry counterRegistry, Iterable<BuckEventListener> commandSpecificEventListeners) {
    ImmutableList.Builder<BuckEventListener> eventListenersBuilder = ImmutableList.<BuckEventListener>builder().add(new JavaUtilsLoggingBuildListener()).add(consoleEventBusListener).add(new LoggingBuildListener());
    if (buckConfig.isChromeTraceCreationEnabled()) {
        try {
            eventListenersBuilder.add(new ChromeTraceBuildListener(projectFilesystem, invocationInfo, clock, objectMapper, buckConfig.getMaxTraces(), buckConfig.getCompressTraces()));
        } catch (IOException e) {
            LOG.error("Unable to create ChromeTrace listener!");
        }
    } else {
        LOG.warn("::: ChromeTrace listener disabled");
    }
    if (webServer.isPresent()) {
        eventListenersBuilder.add(webServer.get().createListener());
    }
    loadListenersFromBuckConfig(eventListenersBuilder, projectFilesystem, buckConfig);
    if (buckConfig.isRuleKeyLoggerEnabled()) {
        eventListenersBuilder.add(new RuleKeyLoggerListener(projectFilesystem, invocationInfo, MostExecutors.newSingleThreadExecutor(new CommandThreadFactory(getClass().getName()))));
    }
    if (buckConfig.isMachineReadableLoggerEnabled()) {
        try {
            eventListenersBuilder.add(new MachineReadableLoggerListener(invocationInfo, projectFilesystem, MostExecutors.newSingleThreadExecutor(new CommandThreadFactory(getClass().getName()))));
        } catch (FileNotFoundException e) {
            LOG.warn("Unable to open stream for machine readable log file.");
        }
    }
    JavaBuckConfig javaBuckConfig = buckConfig.getView(JavaBuckConfig.class);
    if (!javaBuckConfig.getSkipCheckingMissingDeps()) {
        eventListenersBuilder.add(missingSymbolsListenerSupplier.get());
    }
    eventListenersBuilder.add(new LoadBalancerEventsListener(counterRegistry));
    eventListenersBuilder.add(new CacheRateStatsListener(buckEventBus));
    eventListenersBuilder.add(new WatchmanDiagnosticEventListener(buckEventBus));
    eventListenersBuilder.addAll(commandSpecificEventListeners);
    ImmutableList<BuckEventListener> eventListeners = eventListenersBuilder.build();
    eventListeners.forEach(buckEventBus::register);
    return eventListeners;
}
Also used : LoggingBuildListener(com.facebook.buck.event.listener.LoggingBuildListener) JavaUtilsLoggingBuildListener(com.facebook.buck.event.listener.JavaUtilsLoggingBuildListener) ImmutableList(com.google.common.collect.ImmutableList) CommandThreadFactory(com.facebook.buck.log.CommandThreadFactory) FileNotFoundException(java.io.FileNotFoundException) JavaUtilsLoggingBuildListener(com.facebook.buck.event.listener.JavaUtilsLoggingBuildListener) MachineReadableLoggerListener(com.facebook.buck.event.listener.MachineReadableLoggerListener) JavaBuckConfig(com.facebook.buck.jvm.java.JavaBuckConfig) BuckEventListener(com.facebook.buck.event.BuckEventListener) IOException(java.io.IOException) WatchmanDiagnosticEventListener(com.facebook.buck.io.WatchmanDiagnosticEventListener) ChromeTraceBuildListener(com.facebook.buck.event.listener.ChromeTraceBuildListener) CacheRateStatsListener(com.facebook.buck.event.listener.CacheRateStatsListener) RuleKeyLoggerListener(com.facebook.buck.event.listener.RuleKeyLoggerListener) LoadBalancerEventsListener(com.facebook.buck.event.listener.LoadBalancerEventsListener)

Example 2 with WatchmanDiagnosticEventListener

use of com.facebook.buck.io.WatchmanDiagnosticEventListener 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)));
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) FakeClock(com.facebook.buck.timing.FakeClock) WatchmanDiagnostic(com.facebook.buck.io.WatchmanDiagnostic) EasyMock.anyObject(org.easymock.EasyMock.anyObject) BuckEventBus(com.facebook.buck.event.BuckEventBus) EventBus(com.google.common.eventbus.EventBus) WatchmanDiagnosticEventListener(com.facebook.buck.io.WatchmanDiagnosticEventListener) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

WatchmanDiagnosticEventListener (com.facebook.buck.io.WatchmanDiagnosticEventListener)2 BuckEventBus (com.facebook.buck.event.BuckEventBus)1 BuckEventListener (com.facebook.buck.event.BuckEventListener)1 CacheRateStatsListener (com.facebook.buck.event.listener.CacheRateStatsListener)1 ChromeTraceBuildListener (com.facebook.buck.event.listener.ChromeTraceBuildListener)1 JavaUtilsLoggingBuildListener (com.facebook.buck.event.listener.JavaUtilsLoggingBuildListener)1 LoadBalancerEventsListener (com.facebook.buck.event.listener.LoadBalancerEventsListener)1 LoggingBuildListener (com.facebook.buck.event.listener.LoggingBuildListener)1 MachineReadableLoggerListener (com.facebook.buck.event.listener.MachineReadableLoggerListener)1 RuleKeyLoggerListener (com.facebook.buck.event.listener.RuleKeyLoggerListener)1 WatchmanDiagnostic (com.facebook.buck.io.WatchmanDiagnostic)1 JavaBuckConfig (com.facebook.buck.jvm.java.JavaBuckConfig)1 CommandThreadFactory (com.facebook.buck.log.CommandThreadFactory)1 FakeClock (com.facebook.buck.timing.FakeClock)1 ImmutableList (com.google.common.collect.ImmutableList)1 EventBus (com.google.common.eventbus.EventBus)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 EasyMock.anyObject (org.easymock.EasyMock.anyObject)1