Search in sources :

Example 6 with CustomZipOutputStream

use of com.facebook.buck.zip.CustomZipOutputStream in project buck by facebook.

the class CachingBuildEngineTest method writeEntriesToZip.

private static void writeEntriesToZip(Path file, ImmutableMap<Path, String> entries) throws IOException {
    try (CustomZipOutputStream zip = ZipOutputStreams.newOutputStream(file)) {
        for (Map.Entry<Path, String> mapEntry : entries.entrySet()) {
            CustomZipEntry entry = new CustomZipEntry(mapEntry.getKey());
            // We want deterministic ZIPs, so avoid mtimes. -1 is timzeone independent, 0 is not.
            entry.setTime(ZipConstants.getFakeTime());
            // We set the external attributes to this magic value which seems to match the attributes
            // of entries created by {@link InMemoryArtifactCache}.
            entry.setExternalAttributes(33188L << 16);
            zip.putNextEntry(entry);
            zip.write(mapEntry.getValue().getBytes());
            zip.closeEntry();
        }
    }
}
Also used : Path(java.nio.file.Path) LazyPath(com.facebook.buck.io.LazyPath) BorrowablePath(com.facebook.buck.io.BorrowablePath) CustomZipOutputStream(com.facebook.buck.zip.CustomZipOutputStream) CustomZipEntry(com.facebook.buck.zip.CustomZipEntry) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap)

Example 7 with CustomZipOutputStream

use of com.facebook.buck.zip.CustomZipOutputStream in project buck by facebook.

the class PrebuiltJarSymbolsFinderTest method createFinderForFileWithEntries.

private PrebuiltJarSymbolsFinder createFinderForFileWithEntries(String jarFileName, Iterable<String> entries) throws IOException {
    Clock clock = new FakeClock(1);
    Path jarFile = tmp.newFile(jarFileName);
    try (OutputStream stream = new BufferedOutputStream(java.nio.file.Files.newOutputStream(jarFile));
        CustomZipOutputStream out = ZipOutputStreams.newOutputStream(stream, ZipOutputStreams.HandleDuplicates.THROW_EXCEPTION, clock)) {
        for (String entry : entries) {
            out.putNextEntry(new ZipEntry(entry));
        }
    }
    ProjectFilesystem filesystem = new ProjectFilesystem(tmp.getRoot());
    SourcePath sourcePath = new PathSourcePath(filesystem, Paths.get(jarFileName));
    return new PrebuiltJarSymbolsFinder(sourcePath);
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FakeClock(com.facebook.buck.timing.FakeClock) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) CustomZipOutputStream(com.facebook.buck.zip.CustomZipOutputStream) ZipEntry(java.util.zip.ZipEntry) PathSourcePath(com.facebook.buck.rules.PathSourcePath) CustomZipOutputStream(com.facebook.buck.zip.CustomZipOutputStream) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Clock(com.facebook.buck.timing.Clock) FakeClock(com.facebook.buck.timing.FakeClock) BufferedOutputStream(java.io.BufferedOutputStream)

Aggregations

CustomZipOutputStream (com.facebook.buck.zip.CustomZipOutputStream)7 Path (java.nio.file.Path)5 CustomZipEntry (com.facebook.buck.zip.CustomZipEntry)3 ZipEntry (java.util.zip.ZipEntry)3 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)2 BufferedOutputStream (java.io.BufferedOutputStream)2 OutputStream (java.io.OutputStream)2 BorrowablePath (com.facebook.buck.io.BorrowablePath)1 LazyPath (com.facebook.buck.io.LazyPath)1 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)1 PathSourcePath (com.facebook.buck.rules.PathSourcePath)1 SourcePath (com.facebook.buck.rules.SourcePath)1 ExecutionContext (com.facebook.buck.step.ExecutionContext)1 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)1 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)1 Zip (com.facebook.buck.testutil.Zip)1 Clock (com.facebook.buck.timing.Clock)1 FakeClock (com.facebook.buck.timing.FakeClock)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableMap (com.google.common.collect.ImmutableMap)1