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