Search in sources :

Example 51 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 52 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 53 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)

Example 54 with FileSystem

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

the class FakeProjectFilesystem method createJavaOnlyFilesystem.

public static ProjectFilesystem createJavaOnlyFilesystem(String rootPath) {
    boolean isWindows = Platform.detect() == Platform.WINDOWS;
    Configuration configuration = isWindows ? Configuration.windows() : Configuration.unix();
    rootPath = isWindows ? "C:" + rootPath : rootPath;
    FileSystem vfs = Jimfs.newFileSystem(configuration);
    Path root = vfs.getPath(rootPath);
    try {
        Files.createDirectories(root);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return new ProjectFilesystem(root) {

        @Override
        public Path resolve(Path path) {
            // Avoid resolving paths from different Java FileSystems.
            return super.resolve(path.toString());
        }
    };
}
Also used : Path(java.nio.file.Path) Configuration(com.google.common.jimfs.Configuration) FileSystem(java.nio.file.FileSystem) IOException(java.io.IOException) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem)

Example 55 with FileSystem

use of java.nio.file.FileSystem in project neo4j by neo4j.

the class SpecSuiteResources method unpackResources.

private static void unpackResources(Class<?> klass) {
    String specSuiteName = getSpecSuiteName(klass);
    File featuresDirectory = createTargetDirectory(specSuiteName, "features");
    File graphsDirectory = createTargetDirectory(specSuiteName, "graphs");
    URI uri;
    try {
        uri = getResourceUri(klass);
    } catch (URISyntaxException e) {
        throw new IllegalStateException("Failed to find resources for TCK feature files in JAR!", e);
    }
    try {
        try (FileSystem fileSystem = FileSystems.newFileSystem(uri, Collections.emptyMap())) {
            Path path = fileSystem.getPath("/");
            findAndUnpackTo(fileSystem, path, featuresDirectory, graphsDirectory);
        } catch (IllegalArgumentException e) {
            // This is a workaround as the JDK doesn't give us a filesystem for subdirectories
            if ("file".equals(uri.getScheme())) {
                Path path = new File(uri.getPath()).toPath();
                findAndUnpackTo(FileSystems.getDefault(), path, featuresDirectory, graphsDirectory);
            } else {
                throw e;
            }
        }
    } catch (IOException e) {
        throw new IllegalStateException("Unexpected error while unpacking Cypher TCK feature files", e);
    }
}
Also used : Path(java.nio.file.Path) FileSystem(java.nio.file.FileSystem) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) File(java.io.File) URI(java.net.URI)

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