Search in sources :

Example 6 with FileSystem

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);
}
Also used : Path(java.nio.file.Path) Configuration(com.google.common.jimfs.Configuration) BuckConfig(com.facebook.buck.cli.BuckConfig) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) FileSystem(java.nio.file.FileSystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 7 with FileSystem

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));
}
Also used : Path(java.nio.file.Path) FileSystem(java.nio.file.FileSystem) Test(org.junit.Test)

Example 8 with FileSystem

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));
}
Also used : Path(java.nio.file.Path) FileSystem(java.nio.file.FileSystem) Test(org.junit.Test)

Example 9 with FileSystem

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")));
}
Also used : Path(java.nio.file.Path) FileSystem(java.nio.file.FileSystem) Test(org.junit.Test)

Example 10 with FileSystem

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