use of com.android.tools.build.bundletool.model.ModuleEntry.ModuleEntryBundleLocation 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