@@ -0,0 +1,3993 @@
+/*%0A * Copyright 2017-present Facebook, Inc.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22); you may%0A * not use this file except in compliance with the License. You may obtain%0A * a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS, WITHOUT%0A * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the%0A * License for the specific language governing permissions and limitations%0A * under the License.%0A */%0A%0Apackage com.facebook.buck.util.unarchive;%0A%0Aimport com.facebook.buck.io.filesystem.ProjectFilesystem;%0Aimport com.facebook.buck.io.filesystem.ProjectFilesystemFactory;%0Aimport com.google.common.collect.ImmutableList;%0Aimport java.io.IOException;%0Aimport java.nio.file.Files;%0Aimport java.nio.file.Path;%0Aimport java.util.Optional;%0A%0A/** Simple interface to extract archives of varying types */%0Apublic abstract class Unarchiver %7B%0A%0A  /**%0A   * Extract a given archive to a destination%0A   *%0A   * @param archiveFile The path to the archive%0A   * @param filesystem The filesystem that will be extracted into%0A   * @param relativePath The path relative to the filesystem to extract files into%0A   * @param stripPrefix If provided, only files under this prefix will be extracted. This prefix%0A   *     prefix will also be removed from the destination path. e.g. foo.tar.gz/foo/bar/baz with a%0A   *     prefix of foo will extract bar/baz into the destination directory. If not provided, no%0A   *     stripping is done.%0A   * @param existingFileMode How to handle existing files%0A   * @return A list of paths to files that were created%0A   * @throws IOException If the archive could not be extracted for any reason%0A   */%0A  public abstract ImmutableList%3CPath%3E extractArchive(%0A      Path archiveFile,%0A      ProjectFilesystem filesystem,%0A      Path relativePath,%0A      Optional%3CPath%3E stripPrefix,%0A      ExistingFileMode existingFileMode)%0A      throws IOException;%0A%0A  /**%0A   * Extract a given archive to a destination%0A   *%0A   * @param archiveFile The path to the archive%0A   * @param filesystem The filesystem that will be extracted into%0A   * @param existingFileMode How to handle existing files%0A   * @return A list of paths to files that were created%0A   * @throws IOException If the archive could not be extracted for any reason%0A   */%0A  public ImmutableList%3CPath%3E extractArchive(%0A      Path archiveFile, ProjectFilesystem filesystem, ExistingFileMode existingFileMode)%0A      throws IOException %7B%0A    return extractArchive(%0A        archiveFile, filesystem, filesystem.getPath(%22%22), Optional.empty(), existingFileMode);%0A  %7D%0A%0A  /**%0A   * Extract a given archive to a specific directory%0A   *%0A   * @param projectFilesystemFactory A factory that creates filesystems%0A   * @param archiveFile The path to the archive%0A   * @param destination The destination directory where the archive should be extracted to%0A   * @param existingFileMode How to handle existing files%0A   * @return A list of paths to files that were created%0A   * @throws InterruptedException If a filesystem could not be created in the destination directory%0A   * @throws IOException If the archive could not be extracted for any reason%0A   */%0A  public ImmutableList%3CPath%3E extractArchive(%0A      ProjectFilesystemFactory projectFilesystemFactory,%0A      Path archiveFile,%0A      final Path destination,%0A      ExistingFileMode existingFileMode)%0A      throws InterruptedException, IOException %7B%0A    // Create output directory if it does not exist%0A    Files.createDirectories(destination);%0A    return extractArchive(%0A            archiveFile,%0A            projectFilesystemFactory.createProjectFilesystem(destination),%0A            destination.getFileSystem().getPath(%22%22),%0A            Optional.empty(),%0A            existingFileMode)%0A        .stream()%0A        .map(input -%3E destination.resolve(input).toAbsolutePath())%0A        .collect(ImmutableList.toImmutableList());%0A  %7D%0A%7D%0A

Add Unarchiver interface