Search in sources :

Example 46 with FileSystem

use of java.nio.file.FileSystem in project buck by facebook.

the class MoreFilesTest method deleteRecursivelyContentsOnlyLeavesParentDirectory.

@Test
public void deleteRecursivelyContentsOnlyLeavesParentDirectory() throws IOException {
    FileSystem vfs = Jimfs.newFileSystem(Configuration.unix());
    Path fakeTmpDir = vfs.getPath("/tmp/fake-tmp-dir");
    Path dirToDelete = fakeTmpDir.resolve("delete-me");
    Path childDir = dirToDelete.resolve("child-dir");
    Files.createDirectories(childDir);
    MoreFiles.deleteRecursivelyWithOptions(dirToDelete, EnumSet.of(MoreFiles.DeleteRecursivelyOptions.DELETE_CONTENTS_ONLY));
    assertThat(Files.exists(dirToDelete), is(true));
    assertThat(Files.exists(childDir), is(false));
}
Also used : Path(java.nio.file.Path) FileSystem(java.nio.file.FileSystem) Test(org.junit.Test)

Example 47 with FileSystem

use of java.nio.file.FileSystem in project buck by facebook.

the class MoreFilesTest method concatenatingTwoNonEmptyFilesReturnsTrueAndWritesConcatenatedFile.

@Test
public void concatenatingTwoNonEmptyFilesReturnsTrueAndWritesConcatenatedFile() throws Exception {
    FileSystem vfs = Jimfs.newFileSystem(Configuration.unix());
    Path fooPath = vfs.getPath("foo.txt");
    Files.write(fooPath, "hello world\n".getBytes(UTF_8));
    Path barPath = vfs.getPath("bar.txt");
    Files.write(barPath, "goodbye world\n".getBytes(UTF_8));
    Path outputPath = vfs.getPath("logs.txt");
    boolean concatenated = MoreFiles.concatenateFiles(outputPath, ImmutableList.of(fooPath, barPath));
    assertThat(concatenated, is(true));
    assertThat(Files.readAllLines(outputPath, UTF_8), Matchers.equalTo(ImmutableList.of("hello world", "goodbye world")));
}
Also used : Path(java.nio.file.Path) FileSystem(java.nio.file.FileSystem) Test(org.junit.Test)

Example 48 with FileSystem

use of java.nio.file.FileSystem in project buck by facebook.

the class ProjectFilesystemTest method getPathReturnsPathWithCorrectFilesystem.

@Test
public void getPathReturnsPathWithCorrectFilesystem() throws IOException {
    FileSystem vfs = Jimfs.newFileSystem(Configuration.unix());
    Path root = vfs.getPath("/root");
    Files.createDirectories(root);
    assertEquals(vfs, new ProjectFilesystem(root).getPath("bar").getFileSystem());
    assertEquals(vfs.getPath("bar"), new ProjectFilesystem(root).getPath("bar"));
}
Also used : Path(java.nio.file.Path) FileSystem(java.nio.file.FileSystem) Test(org.junit.Test)

Example 49 with FileSystem

use of java.nio.file.FileSystem in project buck by facebook.

the class CellTest method shouldResolveNamesOfCellsAgainstThoseGivenInTheBuckConfig.

@Test
public void shouldResolveNamesOfCellsAgainstThoseGivenInTheBuckConfig() throws IOException, InterruptedException {
    FileSystem vfs = Jimfs.newFileSystem(Configuration.unix());
    Path root = vfs.getPath("/opt/local/");
    Path cell1Root = root.resolve("repo1");
    Files.createDirectories(cell1Root);
    Path cell2Root = root.resolve("repo2");
    Files.createDirectories(cell2Root);
    ProjectFilesystem filesystem1 = new ProjectFilesystem(cell1Root.toAbsolutePath());
    ProjectFilesystem filesystem2 = new ProjectFilesystem(cell2Root.toAbsolutePath());
    BuckConfig config = FakeBuckConfig.builder().setFilesystem(filesystem1).setSections("[repositories]", "example = " + filesystem2.getRootPath().toString()).build();
    Cell cell1 = new TestCellBuilder().setBuckConfig(config).setFilesystem(filesystem1).build();
    BuildTarget target = BuildTargetFactory.newInstance(filesystem2, "//does/not:matter");
    Cell other = cell1.getCell(target);
    assertEquals(cell2Root, other.getFilesystem().getRootPath());
}
Also used : Path(java.nio.file.Path) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) BuckConfig(com.facebook.buck.cli.BuckConfig) BuildTarget(com.facebook.buck.model.BuildTarget) FileSystem(java.nio.file.FileSystem) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 50 with FileSystem

use of java.nio.file.FileSystem in project buck by facebook.

the class DefaultCellPathResolverTest method transitiveMappingForDiamond.

@Test
public void transitiveMappingForDiamond() throws Exception {
    FileSystem vfs = Jimfs.newFileSystem(Configuration.unix());
    Path root = vfs.getPath("/opt/local/");
    Path cell1Root = root.resolve("repo1");
    Files.createDirectories(cell1Root);
    Path cellLeftRoot = root.resolve("left");
    Files.createDirectories(cellLeftRoot);
    Path cellRightRoot = root.resolve("right");
    Files.createDirectories(cellRightRoot);
    Path cellCenterRoot = root.resolve("center");
    Files.createDirectories(cellCenterRoot);
    DefaultCellPathResolver cellPathResolver = new DefaultCellPathResolver(cell1Root, ConfigBuilder.createFromText(REPOSITORIES_SECTION, " left = " + cellLeftRoot.toString(), " right = " + cellRightRoot.toString()));
    Files.write(cellLeftRoot.resolve(".buckconfig"), ImmutableList.of(REPOSITORIES_SECTION, " center = " + cellCenterRoot.toString()), StandardCharsets.UTF_8);
    Files.write(cellRightRoot.resolve(".buckconfig"), ImmutableList.of(REPOSITORIES_SECTION, " center = " + cellCenterRoot.toString()), StandardCharsets.UTF_8);
    assertThat(cellPathResolver.getTransitivePathMapping(), Matchers.equalTo(ImmutableMap.<RelativeCellName, Path>builder().put(RelativeCellName.ROOT_CELL_NAME, cell1Root).put(RelativeCellName.of(ImmutableList.of("left")), cellLeftRoot).put(RelativeCellName.of(ImmutableList.of("left", "center")), cellCenterRoot).put(RelativeCellName.of(ImmutableList.of("right", "center")), cellCenterRoot).put(RelativeCellName.of(ImmutableList.of("right")), cellRightRoot).build()));
}
Also used : Path(java.nio.file.Path) FileSystem(java.nio.file.FileSystem) Test(org.junit.Test)

Aggregations

FileSystem (java.nio.file.FileSystem)159 Path (java.nio.file.Path)112 Test (org.junit.Test)66 IOException (java.io.IOException)25 File (java.io.File)17 ArrayList (java.util.ArrayList)14 FilterFileSystem (org.apache.lucene.mockfile.FilterFileSystem)13 URI (java.net.URI)11 FilterPath (org.apache.lucene.mockfile.FilterPath)11 InputStream (java.io.InputStream)10 OutputStream (java.io.OutputStream)10 FileStore (java.nio.file.FileStore)8 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)6 HashMap (java.util.HashMap)6 DefaultProjectFilesystemDelegate (com.facebook.buck.io.DefaultProjectFilesystemDelegate)5 ProjectFilesystemDelegate (com.facebook.buck.io.ProjectFilesystemDelegate)5 WindowsFS (org.apache.lucene.mockfile.WindowsFS)5 FSDirectory (org.apache.lucene.store.FSDirectory)5 BuckConfig (com.facebook.buck.cli.BuckConfig)4 FakeBuckConfig (com.facebook.buck.cli.FakeBuckConfig)4