Java Code Examples for com.google.common.jimfs.Configuration#unix()

The following examples show how to use com.google.common.jimfs.Configuration#unix() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FakeProjectFilesystem.java    From buck with Apache License 2.0 5 votes vote down vote up
public static ProjectFilesystem createJavaOnlyFilesystem(String rootPath) {
  boolean isWindows = Platform.detect() == Platform.WINDOWS;

  Configuration configuration = isWindows ? Configuration.windows() : Configuration.unix();
  rootPath = isWindows && !rootPath.startsWith("C:") ? "C:" + rootPath : rootPath;

  FileSystem vfs =
      Jimfs.newFileSystem(configuration.toBuilder().setAttributeViews("basic", "posix").build());

  AbsPath root = AbsPath.of(vfs.getPath(rootPath));
  try {
    Files.createDirectories(root.getPath());
  } catch (IOException e) {
    throw new RuntimeException(e);
  }

  return new DefaultProjectFilesystem(
      CanonicalCellName.rootCell(),
      root,
      new DefaultProjectFilesystemDelegate(root.getPath()),
      DefaultProjectFilesystemFactory.getWindowsFSInstance(),
      TestProjectFilesystems.BUCK_OUT_INCLUDE_TARGET_CONFIG_HASH_FOR_TEST) {
    @Override
    public Path resolve(Path path) {
      // Avoid resolving paths from different Java FileSystems.
      return resolve(path.toString());
    }
  };
}
 
Example 2
Source File: UnixUploadOutputsTest.java    From bazel-buildfarm with Apache License 2.0 4 votes vote down vote up
public UnixUploadOutputsTest() {
  super(Configuration.unix());
}
 
Example 3
Source File: StackedDownloaderTest.java    From buck with Apache License 2.0 4 votes vote down vote up
@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(TestProjectFilesystems.createProjectFilesystem(projectRoot))
          .setSections(
              "[maven_repositories]",
              "local = " + m2Root,
              "central = https://repo1.maven.org/maven2")
          .build();

  Downloader downloader =
      StackedDownloader.createFromConfig(
          config,
          new ToolchainProviderBuilder().build(),
          UnconfiguredTargetConfiguration.INSTANCE);

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