Search in sources :

Example 1 with CustomZipEntry

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

the class ProjectFilesystem method createZip.

/**
   * Takes a sequence of paths relative to the project root and writes a zip file to {@code out}
   * with the contents and structure that matches that of the specified paths.
   */
public void createZip(Collection<Path> pathsToIncludeInZip, Path out) throws IOException {
    try (CustomZipOutputStream zip = ZipOutputStreams.newOutputStream(out)) {
        for (Path path : pathsToIncludeInZip) {
            boolean isDirectory = isDirectory(path);
            CustomZipEntry entry = new CustomZipEntry(path, isDirectory);
            // We want deterministic ZIPs, so avoid mtimes.
            entry.setFakeTime();
            entry.setExternalAttributes(getFileAttributesForZipEntry(path));
            zip.putNextEntry(entry);
            if (!isDirectory) {
                try (InputStream input = newFileInputStream(path)) {
                    ByteStreams.copy(input, zip);
                }
            }
            zip.closeEntry();
        }
    }
}
Also used : Path(java.nio.file.Path) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) CustomZipOutputStream(com.facebook.buck.zip.CustomZipOutputStream) CustomZipEntry(com.facebook.buck.zip.CustomZipEntry)

Example 2 with CustomZipEntry

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

the class DefaultDefectReporter method writeReport.

private void writeReport(DefectReport defectReport, OutputStream outputStream) throws IOException {
    try (BufferedOutputStream baseOut = new BufferedOutputStream(outputStream);
        CustomZipOutputStream out = ZipOutputStreams.newOutputStream(baseOut, APPEND_TO_ZIP)) {
        if (defectReport.getSourceControlInfo().isPresent() && defectReport.getSourceControlInfo().get().getDiff().isPresent()) {
            addStringsAsFilesToArchive(out, ImmutableMap.of(DIFF_FILE_NAME, defectReport.getSourceControlInfo().get().getDiff().get()));
        }
        addFilesToArchive(out, defectReport.getIncludedPaths());
        out.putNextEntry(new CustomZipEntry(REPORT_FILE_NAME));
        objectMapper.writeValue(out, defectReport);
    }
}
Also used : CustomZipOutputStream(com.facebook.buck.zip.CustomZipOutputStream) CustomZipEntry(com.facebook.buck.zip.CustomZipEntry) BufferedOutputStream(java.io.BufferedOutputStream)

Example 3 with CustomZipEntry

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

the class DefaultDefectReporter method addFilesToArchive.

private void addFilesToArchive(CustomZipOutputStream out, ImmutableSet<Path> paths) throws IOException {
    for (Path logFile : paths) {
        Preconditions.checkArgument(!logFile.isAbsolute(), "Should be a relative Path.", logFile);
        // If the file is hidden(UNIX terms) save it as normal file.
        if (logFile.getFileName().toString().startsWith(".")) {
            out.putNextEntry(new CustomZipEntry(Paths.get(logFile.getFileName().toString().substring(1))));
        } else {
            out.putNextEntry(new CustomZipEntry(logFile));
        }
        try (InputStream input = filesystem.newFileInputStream(logFile)) {
            ByteStreams.copy(input, out);
        }
        out.closeEntry();
    }
}
Also used : Path(java.nio.file.Path) InputStream(java.io.InputStream) CustomZipEntry(com.facebook.buck.zip.CustomZipEntry)

Example 4 with CustomZipEntry

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

the class DefaultDefectReporter method addStringsAsFilesToArchive.

private void addStringsAsFilesToArchive(CustomZipOutputStream out, ImmutableMap<String, String> files) throws IOException {
    for (Map.Entry<String, String> file : files.entrySet()) {
        out.putNextEntry(new CustomZipEntry(file.getKey()));
        out.write(file.getValue().getBytes(Charsets.UTF_8));
        out.closeEntry();
    }
}
Also used : CustomZipEntry(com.facebook.buck.zip.CustomZipEntry) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 5 with CustomZipEntry

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

the class JavaInMemoryFileManager method createEntry.

/**
   * Creates a ZipEntry for placing in the jar output stream. Sets the modification time to 0 for
   * a deterministic jar.
   * @param name the name of the entry
   * @return the zip entry for the file specified
   */
public static ZipEntry createEntry(String name) {
    CustomZipEntry entry = new CustomZipEntry(name);
    // We want deterministic JARs, so avoid mtimes.
    entry.setFakeTime();
    return entry;
}
Also used : CustomZipEntry(com.facebook.buck.zip.CustomZipEntry)

Aggregations

CustomZipEntry (com.facebook.buck.zip.CustomZipEntry)6 CustomZipOutputStream (com.facebook.buck.zip.CustomZipOutputStream)3 Path (java.nio.file.Path)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 InputStream (java.io.InputStream)2 Map (java.util.Map)2 BorrowablePath (com.facebook.buck.io.BorrowablePath)1 LazyPath (com.facebook.buck.io.LazyPath)1 BufferedInputStream (java.io.BufferedInputStream)1 BufferedOutputStream (java.io.BufferedOutputStream)1 HashMap (java.util.HashMap)1