Search in sources :

Example 11 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 12 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)

Example 13 with FileSystem

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

the class DefaultCellPathResolverTest method transtiveMappingForNonexistantCell.

@Test
public void transtiveMappingForNonexistantCell() throws Exception {
    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");
    DefaultCellPathResolver cellPathResolver = new DefaultCellPathResolver(cell1Root, ConfigBuilder.createFromText(REPOSITORIES_SECTION, " simple = " + cell2Root.toString()));
    // Allow non-existant paths; Buck should allow paths whose .buckconfigs
    // cannot be loaded.
    assertThat(cellPathResolver.getTransitivePathMapping(), Matchers.equalTo(ImmutableMap.of(RelativeCellName.ROOT_CELL_NAME, cell1Root, RelativeCellName.of(ImmutableList.of("simple")), cell2Root)));
}
Also used : Path(java.nio.file.Path) FileSystem(java.nio.file.FileSystem) Test(org.junit.Test)

Example 14 with FileSystem

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

the class DefaultCellPathResolverTest method transtiveMappingForSymlinkCycle.

@Test
public void transtiveMappingForSymlinkCycle() throws Exception {
    Assume.assumeTrue(Platform.detect() != Platform.WINDOWS);
    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);
    Path symlinkPath = cell2Root.resolve("symlink");
    Files.createSymbolicLink(symlinkPath, cell2Root);
    DefaultCellPathResolver cellPathResolver = new DefaultCellPathResolver(cell1Root, ConfigBuilder.createFromText(REPOSITORIES_SECTION, " two = ../repo2"));
    Files.write(cell2Root.resolve(".buckconfig"), ImmutableList.of(REPOSITORIES_SECTION, " three = symlink"), StandardCharsets.UTF_8);
    assertThat(cellPathResolver.getTransitivePathMapping(), Matchers.equalTo(ImmutableMap.of(RelativeCellName.ROOT_CELL_NAME, cell1Root, RelativeCellName.of(ImmutableList.of("two")), cell2Root)));
}
Also used : Path(java.nio.file.Path) FileSystem(java.nio.file.FileSystem) Test(org.junit.Test)

Example 15 with FileSystem

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

the class DefaultCellPathResolverTest method knownRulesForSimpleSetup.

@Test
public void knownRulesForSimpleSetup() throws Exception {
    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);
    DefaultCellPathResolver cellPathResolver = new DefaultCellPathResolver(cell1Root, ConfigBuilder.createFromText(REPOSITORIES_SECTION, " simple = " + cell2Root.toString()));
    assertThat(cellPathResolver.getKnownRoots(), Matchers.containsInAnyOrder(cell1Root, cell2Root));
}
Also used : Path(java.nio.file.Path) FileSystem(java.nio.file.FileSystem) Test(org.junit.Test)

Aggregations

FileSystem (java.nio.file.FileSystem)156 Path (java.nio.file.Path)109 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 FilterPath (org.apache.lucene.mockfile.FilterPath)11 InputStream (java.io.InputStream)10 OutputStream (java.io.OutputStream)10 URI (java.net.URI)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