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));
}
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")));
}
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"));
}
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());
}
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()));
}
Aggregations