Search in sources :

Example 1 with ModuleEntryBundleLocation

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);
    }
}
Also used : ZipPath(com.android.tools.build.bundletool.model.ZipPath) Path(java.nio.file.Path) ZipSource(com.android.zipflinger.ZipSource) HashMap(java.util.HashMap) SpecialModuleEntry(com.android.tools.build.bundletool.model.BundleModule.SpecialModuleEntry) ModuleEntry(com.android.tools.build.bundletool.model.ModuleEntry) ZipPath(com.android.tools.build.bundletool.model.ZipPath) ModuleEntryBundleLocation(com.android.tools.build.bundletool.model.ModuleEntry.ModuleEntryBundleLocation) HashMap(java.util.HashMap) Map(java.util.Map) BundleModule(com.android.tools.build.bundletool.model.BundleModule)

Aggregations

BundleModule (com.android.tools.build.bundletool.model.BundleModule)1 SpecialModuleEntry (com.android.tools.build.bundletool.model.BundleModule.SpecialModuleEntry)1 ModuleEntry (com.android.tools.build.bundletool.model.ModuleEntry)1 ModuleEntryBundleLocation (com.android.tools.build.bundletool.model.ModuleEntry.ModuleEntryBundleLocation)1 ZipPath (com.android.tools.build.bundletool.model.ZipPath)1 ZipSource (com.android.zipflinger.ZipSource)1 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1