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