in initializer-generator/src/main/java/com/alibaba/initializer/protocol/archive/ProjectArchiveHandler.java [161:185]
private <T extends ArchiveEntry> Path createArchive(ProjectGenerationResult result, String fileExtension,
Function<OutputStream, ? extends ArchiveOutputStream> archiveOutputStream,
BiFunction<File, String, T> archiveEntry, BiConsumer<T, Integer> setMode) throws IOException {
Path root = result.getProjectRoot();
Path archive = root.resolveSibling(root.getFileName() + "." + fileExtension);
try (ArchiveOutputStream output = archiveOutputStream.apply(Files.newOutputStream(archive))) {
Files.walk(result.getProjectRoot())
.filter((path) -> !result.getProjectRoot().equals(path))
.forEach((path) -> {
try {
String entryName = getEntryName(result.getProjectRoot(), path);
T entry = archiveEntry.apply(path.toFile(), entryName);
setMode.accept(entry, getUnixMode(path));
output.putArchiveEntry(entry);
if (!Files.isDirectory(path)) {
Files.copy(path, output);
}
output.closeArchiveEntry();
} catch (IOException ex) {
throw new IllegalStateException(ex);
}
});
}
return archive;
}