Search in sources :

Example 11 with ProjectFilesystemDelegate

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

the class EdenProjectFilesystemDelegateTest method computeSha1ForOrdinaryFileUnderMount.

@Test
public void computeSha1ForOrdinaryFileUnderMount() throws IOException, EdenError, TException {
    FileSystem fs = Jimfs.newFileSystem(Configuration.unix());
    Path root = fs.getPath(JIMFS_WORKING_DIRECTORY);
    ProjectFilesystemDelegate delegate = new DefaultProjectFilesystemDelegate(root);
    EdenMount mount = createMock(EdenMount.class);
    Path path = fs.getPath("foo/bar");
    expect(mount.getBindMounts()).andReturn(ImmutableList.of());
    expect(mount.getPathRelativeToProjectRoot(root.resolve(path))).andReturn(Optional.of(path));
    expect(mount.getSha1(path)).andReturn(DUMMY_SHA1);
    replay(mount);
    EdenProjectFilesystemDelegate edenDelegate = new EdenProjectFilesystemDelegate(mount, delegate);
    assertEquals(DUMMY_SHA1, edenDelegate.computeSha1(path));
    verify(mount);
}
Also used : Path(java.nio.file.Path) FileSystem(java.nio.file.FileSystem) DefaultProjectFilesystemDelegate(com.facebook.buck.io.DefaultProjectFilesystemDelegate) ProjectFilesystemDelegate(com.facebook.buck.io.ProjectFilesystemDelegate) DefaultProjectFilesystemDelegate(com.facebook.buck.io.DefaultProjectFilesystemDelegate) Test(org.junit.Test)

Example 12 with ProjectFilesystemDelegate

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

the class EdenProjectFilesystemDelegateTest method computeSha1ForOrdinaryFileUnderMountButBehindBindMount.

@Test
public void computeSha1ForOrdinaryFileUnderMountButBehindBindMount() throws IOException, EdenError, TException {
    FileSystem fs = Jimfs.newFileSystem(Configuration.unix());
    Path root = fs.getPath(JIMFS_WORKING_DIRECTORY);
    ProjectFilesystemDelegate delegate = new DefaultProjectFilesystemDelegate(root);
    EdenMount mount = createMock(EdenMount.class);
    Path path = fs.getPath("buck-out/gen/some-output");
    Files.createDirectories(path.getParent());
    Files.createFile(path);
    byte[] bytes = new byte[] { 66, 85, 67, 75 };
    Files.write(path, bytes);
    expect(mount.getBindMounts()).andReturn(ImmutableList.of(fs.getPath("buck-out")));
    expect(mount.getPathRelativeToProjectRoot(root.resolve(path))).andReturn(Optional.of(path));
    replay(mount);
    EdenProjectFilesystemDelegate edenDelegate = new EdenProjectFilesystemDelegate(mount, delegate);
    assertEquals("EdenProjectFilesystemDelegate.computeSha1() should compute the SHA-1 directly via " + "DefaultProjectFilesystemDelegate because the path is behind a bind mount.", Sha1HashCode.fromHashCode(Hashing.sha1().hashBytes(bytes)), edenDelegate.computeSha1(path));
    verify(mount);
}
Also used : Path(java.nio.file.Path) FileSystem(java.nio.file.FileSystem) DefaultProjectFilesystemDelegate(com.facebook.buck.io.DefaultProjectFilesystemDelegate) ProjectFilesystemDelegate(com.facebook.buck.io.ProjectFilesystemDelegate) DefaultProjectFilesystemDelegate(com.facebook.buck.io.DefaultProjectFilesystemDelegate) Test(org.junit.Test)

Example 13 with ProjectFilesystemDelegate

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

the class EdenProjectFilesystemDelegateTest method computeSha1ForOrdinaryFileOutsideMount.

@Test
public void computeSha1ForOrdinaryFileOutsideMount() throws IOException {
    FileSystem fs = Jimfs.newFileSystem(Configuration.unix());
    Path root = fs.getPath(JIMFS_WORKING_DIRECTORY);
    ProjectFilesystemDelegate delegate = new DefaultProjectFilesystemDelegate(root);
    Path target = fs.getPath("/example");
    Files.createFile(target);
    byte[] bytes = new byte[] { 66, 85, 67, 75 };
    Files.write(target, bytes);
    EdenMount mount = createMock(EdenMount.class);
    expect(mount.getBindMounts()).andReturn(ImmutableList.of());
    expect(mount.getPathRelativeToProjectRoot(target)).andReturn(Optional.empty());
    replay(mount);
    EdenProjectFilesystemDelegate edenDelegate = new EdenProjectFilesystemDelegate(mount, delegate);
    assertEquals("EdenProjectFilesystemDelegate.computeSha1() should return the SHA-1 of a file that is " + "outside of the EdenFS root.", Sha1HashCode.fromHashCode(Hashing.sha1().hashBytes(bytes)), edenDelegate.computeSha1(target));
    verify(mount);
}
Also used : Path(java.nio.file.Path) FileSystem(java.nio.file.FileSystem) DefaultProjectFilesystemDelegate(com.facebook.buck.io.DefaultProjectFilesystemDelegate) ProjectFilesystemDelegate(com.facebook.buck.io.ProjectFilesystemDelegate) DefaultProjectFilesystemDelegate(com.facebook.buck.io.DefaultProjectFilesystemDelegate) Test(org.junit.Test)

Example 14 with ProjectFilesystemDelegate

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

the class AutoSparseIntegrationTest method testExists.

@Test
public void testExists() {
    ProjectFilesystemDelegate delegate = createDelegate();
    Assume.assumeTrue(delegate.exists(repoPath.resolve("file1")));
}
Also used : ProjectFilesystemDelegate(com.facebook.buck.io.ProjectFilesystemDelegate) Test(org.junit.Test)

Example 15 with ProjectFilesystemDelegate

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

the class AutoSparseIntegrationTest method testMaterialize.

@Test
public void testMaterialize() throws IOException {
    ProjectFilesystemDelegate delegate = createDelegate(repoPath, true, ImmutableList.of("subdir"));
    // Touch various files, these should be part of the profile
    delegate.exists(repoPath.resolve("file1"));
    delegate.exists(repoPath.resolve("file2"));
    // Only directly include the file, not the parent dir
    delegate.exists(repoPath.resolve("subdir/file_in_subdir"));
    // Only include the parent directory, not the file
    delegate.exists(repoPath.resolve("not_hidden_subdir/file_in_subdir_not_hidden"));
    delegate.ensureConcreteFilesExist(BuckEventBusFactory.newInstance(new FakeClock(0)));
    List<String> lines = Files.readAllLines(repoPath.resolve(".hg/sparse"), Charset.forName(System.getProperty("file.encoding", "UTF-8")));
    List<String> expected = ImmutableList.of("%include sparse_profile", "[include]", "file1", "file2", "not_hidden_subdir", "subdir/file_in_subdir", "[exclude]", // sparse always writes a newline at the end
    "");
    Assert.assertEquals(expected, lines);
}
Also used : FakeClock(com.facebook.buck.timing.FakeClock) ProjectFilesystemDelegate(com.facebook.buck.io.ProjectFilesystemDelegate) Test(org.junit.Test)

Aggregations

ProjectFilesystemDelegate (com.facebook.buck.io.ProjectFilesystemDelegate)19 Test (org.junit.Test)19 Path (java.nio.file.Path)6 DefaultProjectFilesystemDelegate (com.facebook.buck.io.DefaultProjectFilesystemDelegate)5 FileSystem (java.nio.file.FileSystem)5 EdenError (com.facebook.eden.thrift.EdenError)2 FakeClock (com.facebook.buck.timing.FakeClock)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1