Search in sources :

Example 1 with PathOrGlobMatcher

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

the class ProjectTest method testDoNotIgnoreAllOfBuckOut.

@Test
public void testDoNotIgnoreAllOfBuckOut() {
    SourcePathResolver resolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
    ProjectFilesystem projectFilesystem = FakeProjectFilesystem.createJavaOnlyFilesystem("/opt/src/buck");
    BuildTarget buildTarget = BuildTarget.builder(projectFilesystem.getRootPath(), "//", "base").build();
    BuildRule buildRule = new FakeBuildRule(buildTarget, resolver);
    SerializableModule module = new SerializableModule(buildRule, buildTarget);
    Project.addRootExcludes(module, buildRule, projectFilesystem);
    ImmutableSortedSet.Builder<SourceFolder> expectedExcludeFolders = ImmutableSortedSet.orderedBy(SerializableModule.ALPHABETIZER);
    expectedExcludeFolders.add(new SourceFolder("file://$MODULE_DIR$/buck-out/bin", /* isTestSource */
    false));
    expectedExcludeFolders.add(new SourceFolder("file://$MODULE_DIR$/buck-out/log", /* isTestSource */
    false));
    expectedExcludeFolders.add(new SourceFolder("file://$MODULE_DIR$/buck-out/tmp", /* isTestSource */
    false));
    for (Path ignorePath : FluentIterable.from(projectFilesystem.getIgnorePaths()).filter(input -> input.getType() == PathOrGlobMatcher.Type.PATH).transform(PathOrGlobMatcher::getPath)) {
        if (!ignorePath.equals(projectFilesystem.getBuckPaths().getBuckOut()) && !ignorePath.equals(projectFilesystem.getBuckPaths().getGenDir())) {
            expectedExcludeFolders.add(new SourceFolder("file://$MODULE_DIR$/" + MorePaths.pathWithUnixSeparators(ignorePath), /* isTestSource */
            false));
        }
    }
    assertEquals("Specific subfolders of buck-out should be excluded rather than all of buck-out.", expectedExcludeFolders.build(), module.excludeFolders);
}
Also used : Path(java.nio.file.Path) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) ProjectConfig(com.facebook.buck.rules.ProjectConfig) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) ObjectMappers(com.facebook.buck.util.ObjectMappers) Assert.assertThat(org.junit.Assert.assertThat) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) KeystoreBuilder(com.facebook.buck.jvm.java.KeystoreBuilder) FluentIterable(com.google.common.collect.FluentIterable) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) InMemoryBuildFileTree(com.facebook.buck.model.InMemoryBuildFileTree) Pair(com.facebook.buck.model.Pair) Path(java.nio.file.Path) JavaPackageFinder(com.facebook.buck.jvm.core.JavaPackageFinder) JavaLibraryBuilder(com.facebook.buck.jvm.java.JavaLibraryBuilder) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) AndroidLibraryBuilder(com.facebook.buck.android.AndroidLibraryBuilder) TargetGraph(com.facebook.buck.rules.TargetGraph) PathOrGlobMatcher(com.facebook.buck.io.PathOrGlobMatcher) BuildTarget(com.facebook.buck.model.BuildTarget) List(java.util.List) NdkLibraryBuilder(com.facebook.buck.android.NdkLibraryBuilder) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(java.util.Optional) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Iterables(com.google.common.collect.Iterables) FakeJavaPackageFinder(com.facebook.buck.jvm.java.FakeJavaPackageFinder) AndroidResourceBuilder(com.facebook.buck.android.AndroidResourceBuilder) JavaTestBuilder(com.facebook.buck.jvm.java.JavaTestBuilder) ArrayList(java.util.ArrayList) Assert.assertSame(org.junit.Assert.assertSame) BuildRule(com.facebook.buck.rules.BuildRule) ExecutionContext(com.facebook.buck.step.ExecutionContext) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) ImmutableList(com.google.common.collect.ImmutableList) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) ProjectConfigBuilder(com.facebook.buck.rules.ProjectConfigBuilder) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) BuildTargetFactory(com.facebook.buck.model.BuildTargetFactory) AndroidBinaryBuilder(com.facebook.buck.android.AndroidBinaryBuilder) Nullable(javax.annotation.Nullable) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) OutputStream(java.io.OutputStream) Properties(java.util.Properties) TargetNode(com.facebook.buck.rules.TargetNode) Assert.assertTrue(org.junit.Assert.assertTrue) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) IOException(java.io.IOException) EasyMock(org.easymock.EasyMock) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) MorePaths(com.facebook.buck.io.MorePaths) Paths(java.nio.file.Paths) TargetGraphFactory(com.facebook.buck.testutil.TargetGraphFactory) MoreAsserts.assertListEquals(com.facebook.buck.testutil.MoreAsserts.assertListEquals) Preconditions(com.google.common.base.Preconditions) NdkLibrary(com.facebook.buck.android.NdkLibrary) PrebuiltJarBuilder(com.facebook.buck.jvm.java.PrebuiltJarBuilder) Assert.assertEquals(org.junit.Assert.assertEquals) SourceFolder(com.facebook.buck.jvm.java.intellij.SerializableModule.SourceFolder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) SourceFolder(com.facebook.buck.jvm.java.intellij.SerializableModule.SourceFolder) BuildTarget(com.facebook.buck.model.BuildTarget) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) PathOrGlobMatcher(com.facebook.buck.io.PathOrGlobMatcher) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 2 with PathOrGlobMatcher

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

the class WatchmanWatcherIntegrationTest method globMatchesWholeName.

@Test
public void globMatchesWholeName() throws IOException, InterruptedException {
    WatchmanWatcher watcher = createWatchmanWatcher(new PathOrGlobMatcher("*.txt"));
    // Create a dot-file which should be ignored by the above glob.
    Path path = tmp.getRoot().getFileSystem().getPath("foo/bar/hello.txt");
    Files.createDirectories(tmp.getRoot().resolve(path).getParent());
    Files.write(tmp.getRoot().resolve(path), new byte[0]);
    // Verify we still get an event for the created path.
    watcher.postEvents(new BuckEventBus(new FakeClock(0), new BuildId()), WatchmanWatcher.FreshInstanceAction.NONE);
    ImmutableList<WatchEvent<?>> events = watchmanEventCollector.getEvents();
    assertThat(events.size(), Matchers.equalTo(1));
    WatchEvent<?> event = events.get(0);
    Path eventPath = (Path) event.context();
    assertThat(eventPath, Matchers.equalTo(path));
    assertSame(event.kind(), StandardWatchEventKinds.ENTRY_CREATE);
}
Also used : Path(java.nio.file.Path) BuckEventBus(com.facebook.buck.event.BuckEventBus) BuildId(com.facebook.buck.model.BuildId) FakeClock(com.facebook.buck.timing.FakeClock) PathOrGlobMatcher(com.facebook.buck.io.PathOrGlobMatcher) WatchEvent(java.nio.file.WatchEvent) Test(org.junit.Test)

Example 3 with PathOrGlobMatcher

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

the class WatchmanWatcherIntegrationTest method ignoreDotFileInGlob.

@Test
public void ignoreDotFileInGlob() throws IOException, InterruptedException {
    WatchmanWatcher watcher = createWatchmanWatcher(new PathOrGlobMatcher("**/*.swp"));
    // Create a dot-file which should be ignored by the above glob.
    Path path = tmp.getRoot().getFileSystem().getPath("foo/bar/.hello.swp");
    Files.createDirectories(tmp.getRoot().resolve(path).getParent());
    Files.write(tmp.getRoot().resolve(path), new byte[0]);
    // Verify we don't get an event for the path.
    watcher.postEvents(new BuckEventBus(new FakeClock(0), new BuildId()), WatchmanWatcher.FreshInstanceAction.NONE);
    assertThat(watchmanEventCollector.getEvents(), Matchers.empty());
}
Also used : Path(java.nio.file.Path) BuckEventBus(com.facebook.buck.event.BuckEventBus) BuildId(com.facebook.buck.model.BuildId) FakeClock(com.facebook.buck.timing.FakeClock) PathOrGlobMatcher(com.facebook.buck.io.PathOrGlobMatcher) Test(org.junit.Test)

Example 4 with PathOrGlobMatcher

use of com.facebook.buck.io.PathOrGlobMatcher 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 5 with PathOrGlobMatcher

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

Aggregations

PathOrGlobMatcher (com.facebook.buck.io.PathOrGlobMatcher)11 Path (java.nio.file.Path)7 Test (org.junit.Test)6 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)3 WatchmanQuery (com.facebook.buck.io.WatchmanQuery)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 IOException (java.io.IOException)3 NdkLibrary (com.facebook.buck.android.NdkLibrary)2 BuckEventBus (com.facebook.buck.event.BuckEventBus)2 Logger (com.facebook.buck.log.Logger)2 BuildId (com.facebook.buck.model.BuildId)2 FakeClock (com.facebook.buck.timing.FakeClock)2 Ansi (com.facebook.buck.util.Ansi)2 Console (com.facebook.buck.util.Console)2 ProcessExecutor (com.facebook.buck.util.ProcessExecutor)2 Verbosity (com.facebook.buck.util.Verbosity)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Joiner (com.google.common.base.Joiner)2 Preconditions (com.google.common.base.Preconditions)2