Search in sources :

Example 1 with WatchmanQuery

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

the class WatchmanWatcherTest method watchmanQueryWithExcludePathsAddsMatchExpressionToQueryIfDirnameNotAvailable.

@Test
public void watchmanQueryWithExcludePathsAddsMatchExpressionToQueryIfDirnameNotAvailable() {
    WatchmanQuery query = WatchmanWatcher.createQuery(ProjectWatch.of("/path/to/repo", Optional.empty()), ImmutableSet.of(new PathOrGlobMatcher(Paths.get("foo")), new PathOrGlobMatcher(Paths.get("bar/baz"))), ImmutableSet.of());
    assertEquals(WatchmanQuery.of("/path/to/repo", ImmutableMap.of("expression", ImmutableList.of("not", ImmutableList.of("anyof", ImmutableList.of("type", "d"), ImmutableList.of("match", "foo" + File.separator + "*", "wholename"), ImmutableList.of("match", "bar" + File.separator + "baz" + File.separator + "*", "wholename"))), "empty_on_fresh_instance", true, "fields", ImmutableList.of("name", "exists", "new"))), query);
}
Also used : WatchmanQuery(com.facebook.buck.io.WatchmanQuery) PathOrGlobMatcher(com.facebook.buck.io.PathOrGlobMatcher) Test(org.junit.Test)

Example 2 with WatchmanQuery

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

the class WatchmanWatcherTest method watchmanQueryRelativizesExcludePaths.

@Test
public void watchmanQueryRelativizesExcludePaths() {
    String watchRoot = Paths.get("/path/to/repo").toAbsolutePath().toString();
    WatchmanQuery query = WatchmanWatcher.createQuery(ProjectWatch.of(watchRoot, Optional.empty()), ImmutableSet.of(new PathOrGlobMatcher(Paths.get("/path/to/repo/foo").toAbsolutePath()), new PathOrGlobMatcher(Paths.get("/path/to/repo/bar/baz").toAbsolutePath())), ImmutableSet.of(Watchman.Capability.DIRNAME));
    assertEquals(WatchmanQuery.of(watchRoot, ImmutableMap.of("expression", ImmutableList.of("not", ImmutableList.of("anyof", ImmutableList.of("type", "d"), ImmutableList.of("dirname", "foo"), ImmutableList.of("dirname", MorePaths.pathWithPlatformSeparators("bar/baz")))), "empty_on_fresh_instance", true, "fields", ImmutableList.of("name", "exists", "new"))), query);
}
Also used : WatchmanQuery(com.facebook.buck.io.WatchmanQuery) PathOrGlobMatcher(com.facebook.buck.io.PathOrGlobMatcher) Test(org.junit.Test)

Example 3 with WatchmanQuery

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

the class WatchmanWatcherTest method watchmanQueryWithExcludeGlobsAddsExpressionToQuery.

@Test
public void watchmanQueryWithExcludeGlobsAddsExpressionToQuery() {
    WatchmanQuery query = WatchmanWatcher.createQuery(ProjectWatch.of("/path/to/repo", Optional.empty()), ImmutableSet.of(new PathOrGlobMatcher("*.pbxproj")), ImmutableSet.of(Watchman.Capability.DIRNAME));
    assertEquals(WatchmanQuery.of("/path/to/repo", ImmutableMap.of("expression", ImmutableList.of("not", ImmutableList.of("anyof", ImmutableList.of("type", "d"), ImmutableList.of("match", "*.pbxproj", "wholename", ImmutableMap.<String, Object>of("includedotfiles", true)))), "empty_on_fresh_instance", true, "fields", ImmutableList.of("name", "exists", "new"))), query);
}
Also used : WatchmanQuery(com.facebook.buck.io.WatchmanQuery) PathOrGlobMatcher(com.facebook.buck.io.PathOrGlobMatcher) EasyMock.anyObject(org.easymock.EasyMock.anyObject) Test(org.junit.Test)

Example 4 with WatchmanQuery

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

the class WatchmanWatcher method postEvents.

/**
   * Query Watchman for file change events. If too many events are pending or an error occurs
   * an overflow event is posted to the EventBus signalling that events may have been lost
   * (and so typically caches must be cleared to avoid inconsistency). Interruptions and
   * IOExceptions are propagated to callers, but typically if overflow events are handled
   * conservatively by subscribers then no other remedial action is required.
   *
   * Any diagnostics posted by Watchman are added to watchmanDiagnosticCache.
   */
public void postEvents(BuckEventBus buckEventBus, FreshInstanceAction freshInstanceAction) throws IOException, InterruptedException {
    // Speculatively set to false
    AtomicBoolean filesHaveChanged = new AtomicBoolean(false);
    for (Path cellPath : queries.keySet()) {
        WatchmanQuery query = queries.get(cellPath);
        WatchmanCursor cursor = cursors.get(cellPath);
        if (query != null && cursor != null) {
            postEvents(buckEventBus, freshInstanceAction, query, cursor, filesHaveChanged);
        }
    }
    if (!filesHaveChanged.get()) {
        buckEventBus.post(WatchmanStatusEvent.zeroFileChanges());
    }
}
Also used : Path(java.nio.file.Path) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) WatchmanQuery(com.facebook.buck.io.WatchmanQuery) WatchmanCursor(com.facebook.buck.io.WatchmanCursor)

Example 5 with WatchmanQuery

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

the class WatchmanWatcherTest method watchmanQueryWithExcludePathsAddsExpressionToQuery.

@Test
public void watchmanQueryWithExcludePathsAddsExpressionToQuery() {
    WatchmanQuery query = WatchmanWatcher.createQuery(ProjectWatch.of("/path/to/repo", Optional.empty()), ImmutableSet.of(new PathOrGlobMatcher(Paths.get("foo")), new PathOrGlobMatcher(Paths.get("bar/baz"))), ImmutableSet.of(Watchman.Capability.DIRNAME));
    assertEquals(WatchmanQuery.of("/path/to/repo", ImmutableMap.of("expression", ImmutableList.of("not", ImmutableList.of("anyof", ImmutableList.of("type", "d"), ImmutableList.of("dirname", "foo"), ImmutableList.of("dirname", MorePaths.pathWithPlatformSeparators("bar/baz")))), "empty_on_fresh_instance", true, "fields", ImmutableList.of("name", "exists", "new"))), query);
}
Also used : WatchmanQuery(com.facebook.buck.io.WatchmanQuery) PathOrGlobMatcher(com.facebook.buck.io.PathOrGlobMatcher) Test(org.junit.Test)

Aggregations

WatchmanQuery (com.facebook.buck.io.WatchmanQuery)6 Test (org.junit.Test)5 PathOrGlobMatcher (com.facebook.buck.io.PathOrGlobMatcher)4 WatchmanCursor (com.facebook.buck.io.WatchmanCursor)1 Path (java.nio.file.Path)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 EasyMock.anyObject (org.easymock.EasyMock.anyObject)1