Search in sources :

Example 1 with WatchmanDiagnostic

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

the class ProjectBuildFileParser method handleWatchmanDiagnostic.

private static void handleWatchmanDiagnostic(Path buildFile, String level, String message, BuckEventBus buckEventBus) throws IOException {
    WatchmanDiagnostic.Level watchmanDiagnosticLevel;
    switch(level) {
        // then return.
        case "debug":
            LOG.debug("%s (watchman): %s", buildFile, message);
            return;
        case "info":
            LOG.info("%s (watchman): %s", buildFile, message);
            return;
        case "warning":
            watchmanDiagnosticLevel = WatchmanDiagnostic.Level.WARNING;
            break;
        case "error":
            watchmanDiagnosticLevel = WatchmanDiagnostic.Level.ERROR;
            break;
        case "fatal":
            throw new IOException(String.format("%s: %s", buildFile, message));
        default:
            throw new RuntimeException(String.format("Unrecognized watchman diagnostic level: %s (message=%s)", level, message));
    }
    WatchmanDiagnostic watchmanDiagnostic = WatchmanDiagnostic.of(watchmanDiagnosticLevel, message);
    buckEventBus.post(new WatchmanDiagnosticEvent(watchmanDiagnostic));
}
Also used : WatchmanDiagnosticEvent(com.facebook.buck.io.WatchmanDiagnosticEvent) WatchmanDiagnostic(com.facebook.buck.io.WatchmanDiagnostic) IOException(java.io.IOException)

Example 2 with WatchmanDiagnostic

use of com.facebook.buck.io.WatchmanDiagnostic 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

WatchmanDiagnostic (com.facebook.buck.io.WatchmanDiagnostic)2 BuckEventBus (com.facebook.buck.event.BuckEventBus)1 WatchmanDiagnosticEvent (com.facebook.buck.io.WatchmanDiagnosticEvent)1 WatchmanDiagnosticEventListener (com.facebook.buck.io.WatchmanDiagnosticEventListener)1 FakeClock (com.facebook.buck.timing.FakeClock)1 EventBus (com.google.common.eventbus.EventBus)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 EasyMock.anyObject (org.easymock.EasyMock.anyObject)1 Test (org.junit.Test)1