use of com.android.zipflinger.ZipSource in project bundletool by google.
the class ModuleSplitSerializer method serializeSplit.
private void serializeSplit(Path outputPath, ModuleSplit split, ModuleEntriesPack allEntriesPack, ModuleEntriesPack uncompressedEntriesPack) {
FileUtils.createDirectories(outputPath.getParent());
try (ZipArchive archive = new ZipArchive(outputPath)) {
ImmutableMap<ZipPath, ModuleEntry> moduleEntriesByName = split.getEntries().stream().collect(toImmutableMap(entry -> toApkEntryPath(entry.getPath()), entry -> entry, // e.g. base/assets/foo and base/root/assets/foo.
(a, b) -> b));
// Sorting entries by name for determinism.
ImmutableList<ModuleEntry> sortedEntries = ImmutableList.sortedCopyOf(Comparator.comparing(e -> toApkEntryPath(e.getPath())), moduleEntriesByName.values());
ZipSource zipSource = allEntriesPack.select(sortedEntries, entry -> toApkEntryPath(entry.getPath(), /* binaryApk= */
true).toString(), entry -> alignmentForEntry(entry, uncompressedEntriesPack));
archive.add(zipSource);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
use of com.android.zipflinger.ZipSource in project bundletool by google.
the class ModuleEntriesPack method select.
/**
* Selects module entries as a {@link ZipSource} which next can be added into a new {@link
* ZipArchive}.
*
* <p>Requires to provide {@code nameFunction} which assigns final names for each {@link
* ModuleEntry} and {@code alignmentFunction} which assigns alignment in the final {@link
* ZipSource}.
*/
ZipSource select(ImmutableList<ModuleEntry> moduleEntries, Function<ModuleEntry, String> nameFunction, ToLongFunction<ModuleEntry> alignmentFunction) {
ZipSource source = new ZipSource(zipMap);
for (ModuleEntry entry : moduleEntries) {
checkArgument(entryNameByModuleEntry.containsKey(entry), "Module entry %s is not available in the pack.", entry);
source.select(entryNameByModuleEntry.get(entry), nameFunction.apply(entry), ZipSource.COMPRESSION_NO_CHANGE, alignmentFunction.applyAsLong(entry));
}
return source;
}
use of com.android.zipflinger.ZipSource in project bundletool by google.
the class ZipFlingerAppBundleSerializer method addEntriesFromSourceBundles.
/**
* Adds umodified entries to an archive, sourcing them from their original on-disk location.
*/
private static void addEntriesFromSourceBundles(ZipArchive archive, ImmutableListMultimap<BundleModule, ModuleEntry> entries) throws IOException {
Map<Path, ZipSource> bundleSources = new HashMap<>();
for (Map.Entry<BundleModule, ModuleEntry> moduleAndEntry : entries.entries()) {
BundleModule module = moduleAndEntry.getKey();
ModuleEntry moduleEntry = moduleAndEntry.getValue();
ModuleEntryBundleLocation location = moduleEntry.getBundleLocation().orElseThrow(IllegalStateException::new);
ZipPath entryFullPathInSourceBundle = location.entryPathInBundle();
ZipPath moduleDir = ZipPath.create(module.getName().toString());
ZipPath entryFullPathInDestBundle = moduleDir.resolve(moduleEntry.getPath());
Path pathToBundle = location.pathToBundle();
// We cannot use computeIfAbstent because new ZipSource may throw.
ZipSource entrySource = bundleSources.containsKey(pathToBundle) ? bundleSources.get(pathToBundle) : new ZipSource(pathToBundle);
bundleSources.putIfAbsent(pathToBundle, entrySource);
entrySource.select(entryFullPathInSourceBundle.toString(), /* newName= */
entryFullPathInDestBundle.toString());
}
for (ZipSource source : bundleSources.values()) {
archive.add(source);
}
}
Aggregations