use of java.nio.file.FileSystem in project buck by facebook.
the class StackedDownloaderTest method createDownloadersForEachEntryInTheMavenRepositoriesSection.
@Test
public void createDownloadersForEachEntryInTheMavenRepositoriesSection() throws IOException {
boolean isWindows = Platform.detect() == Platform.WINDOWS;
Configuration configuration = isWindows ? Configuration.windows() : Configuration.unix();
FileSystem vfs = Jimfs.newFileSystem(configuration);
Path m2Root = vfs.getPath(jimfAbsolutePath("/home/user/.m2/repository"));
Files.createDirectories(m2Root);
// Set up a config so we expect to see both a local and a remote maven repo.
Path projectRoot = vfs.getPath(jimfAbsolutePath("/opt/local/src"));
Files.createDirectories(projectRoot);
BuckConfig config = FakeBuckConfig.builder().setFilesystem(new ProjectFilesystem(projectRoot)).setSections("[maven_repositories]", "local = " + m2Root.toString(), "central = https://repo1.maven.org/maven2").build();
Downloader downloader = StackedDownloader.createFromConfig(config, Optional.empty());
List<Downloader> downloaders = unpackDownloaders(downloader);
boolean seenRemote = false;
boolean seenLocal = false;
for (Downloader seen : downloaders) {
if (seen instanceof RemoteMavenDownloader) {
seenRemote = true;
} else if (seen instanceof OnDiskMavenDownloader) {
seenLocal = true;
}
}
assertTrue(seenLocal);
assertTrue(seenRemote);
}
use of java.nio.file.FileSystem in project buck by facebook.
the class AsynchronousDirectoryContentsCleanerTest method contentsOfTrashDirectoryCleanedAsynchronously.
@Test
public void contentsOfTrashDirectoryCleanedAsynchronously() throws Exception {
FileSystem vfs = Jimfs.newFileSystem(Configuration.unix());
Path dirToDelete = vfs.getPath("/tmp/fake-tmp-dir");
Path fooDir = dirToDelete.resolve("foo");
Path fooBarDir = fooDir.resolve("bar");
Files.createDirectories(fooBarDir.resolve("baz"));
Path fooBarBlechTxtFile = fooBarDir.resolve("blech.txt");
Files.write(fooBarBlechTxtFile, "hello world\n".getBytes(UTF_8));
AsynchronousDirectoryContentsCleaner cleaner = new AsynchronousDirectoryContentsCleaner(MoreExecutors.directExecutor());
assertThat(Files.exists(dirToDelete), is(true));
assertThat(Files.exists(fooBarDir), is(true));
assertThat(Files.exists(fooBarBlechTxtFile), is(true));
// This executes synchronously, since we passed in a direct executor above.
cleaner.startCleaningDirectory(dirToDelete);
assertThat(Files.exists(dirToDelete), is(true));
assertThat(Files.exists(fooBarDir), is(false));
assertThat(Files.exists(fooBarBlechTxtFile), is(false));
}
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"));
}
Aggregations