use of com.android.tools.build.bundletool.model.ModuleEntry in project bundletool by google.
the class ApkSigner method signEmbeddedApks.
/**
* Returns a new {@link ModuleSplit} with the same entries as the one given as parameter but with
* embedded APKs signed.
*/
@CheckReturnValue
public ModuleSplit signEmbeddedApks(ModuleSplit split) {
ImmutableSet<ZipPath> wear1ApkPaths = ImmutableSet.copyOf(WearApkLocator.findEmbeddedWearApkPaths(split));
ImmutableList.Builder<ModuleEntry> newEntries = ImmutableList.builder();
for (ModuleEntry entry : split.getEntries()) {
ZipPath pathInApk = ApkSerializerHelper.toApkEntryPath(entry.getPath());
if (entry.getShouldSign() || wear1ApkPaths.contains(pathInApk)) {
newEntries.add(signModuleEntry(split, entry));
} else {
newEntries.add(entry);
}
}
return split.toBuilder().setEntries(newEntries.build()).build();
}
use of com.android.tools.build.bundletool.model.ModuleEntry in project bundletool by google.
the class AppBundleSerializer method writeToDisk.
/**
* Writes the App Bundle on disk at the given location.
*/
public void writeToDisk(AppBundle bundle, Path pathOnDisk) throws IOException {
ZipBuilder zipBuilder = new ZipBuilder();
EntryOption[] compression = allEntriesUncompressed ? new EntryOption[] { EntryOption.UNCOMPRESSED } : new EntryOption[0];
zipBuilder.addFileWithProtoContent(ZipPath.create(BUNDLE_CONFIG_FILE_NAME), bundle.getBundleConfig(), compression);
// APEX bundles do not have metadata files.
if (bundle.getFeatureModules().isEmpty() || !bundle.isApex()) {
for (Entry<ZipPath, ByteSource> metadataEntry : bundle.getBundleMetadata().getFileContentMap().entrySet()) {
zipBuilder.addFile(METADATA_DIRECTORY.resolve(metadataEntry.getKey()), metadataEntry.getValue(), compression);
}
}
for (BundleModule module : bundle.getModules().values()) {
ZipPath moduleDir = ZipPath.create(module.getName().toString());
for (ModuleEntry entry : module.getEntries()) {
ZipPath entryPath = moduleDir.resolve(entry.getPath());
zipBuilder.addFile(entryPath, entry.getContent(), compression);
}
// Special module files are not represented as module entries (above).
zipBuilder.addFileWithProtoContent(moduleDir.resolve(SpecialModuleEntry.ANDROID_MANIFEST.getPath()), module.getAndroidManifest().getManifestRoot().getProto(), compression);
module.getAssetsConfig().ifPresent(assetsConfig -> zipBuilder.addFileWithProtoContent(moduleDir.resolve(SpecialModuleEntry.ASSETS_TABLE.getPath()), assetsConfig, compression));
module.getNativeConfig().ifPresent(nativeConfig -> zipBuilder.addFileWithProtoContent(moduleDir.resolve(SpecialModuleEntry.NATIVE_LIBS_TABLE.getPath()), nativeConfig, compression));
module.getResourceTable().ifPresent(resourceTable -> zipBuilder.addFileWithProtoContent(moduleDir.resolve(SpecialModuleEntry.RESOURCE_TABLE.getPath()), resourceTable, compression));
module.getApexConfig().ifPresent(apexConfig -> zipBuilder.addFileWithProtoContent(moduleDir.resolve(SpecialModuleEntry.APEX_TABLE.getPath()), apexConfig, compression));
module.getRuntimeEnabledSdkConfig().ifPresent(runtimeEnabledSdkConfig -> zipBuilder.addFileWithProtoContent(moduleDir.resolve(SpecialModuleEntry.RUNTIME_ENABLED_SDK_CONFIG.getPath()), runtimeEnabledSdkConfig, compression));
}
zipBuilder.writeTo(pathOnDisk);
}
use of com.android.tools.build.bundletool.model.ModuleEntry 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.tools.build.bundletool.model.ModuleEntry in project bundletool by google.
the class ModuleEntriesPack method mergeWith.
/**
* Merges two packs into a single one.
*
* <p>Prefers to merge smaller pack into bigger one. Removes zip file of unused pack.
*/
public ModuleEntriesPack mergeWith(ModuleEntriesPack anotherPack) {
checkArgument(Collections.disjoint(namePrefixes, anotherPack.namePrefixes), "Both packs contain the same name prefix.");
try {
long thisSize = Files.size(zipMap.getPath());
long anotherSize = Files.size(anotherPack.zipMap.getPath());
ModuleEntriesPack to = thisSize > anotherSize ? this : anotherPack;
ModuleEntriesPack from = thisSize > anotherSize ? anotherPack : this;
try (ZipArchive archive = new ZipArchive(to.zipMap.getPath())) {
archive.add(ZipSource.selectAll(from.zipMap.getPath()));
}
Files.delete(from.zipMap.getPath());
IdentityHashMap<ModuleEntry, String> mergedNames = Streams.concat(entryNameByModuleEntry.entrySet().stream(), anotherPack.entryNameByModuleEntry.entrySet().stream()).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (a, b) -> b, Maps::newIdentityHashMap));
return new ModuleEntriesPack(Sets.union(to.namePrefixes, from.namePrefixes).immutableCopy(), ZipMap.from(to.zipMap.getPath()), mergedNames);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
use of com.android.tools.build.bundletool.model.ModuleEntry in project bundletool by google.
the class ModuleEntriesPacker method pack.
/**
* Packs all entries which were previously added with provided {@link Zipper} and returns {@link
* ModuleEntriesPack} pointing to this pack.
*/
public ModuleEntriesPack pack(Zipper zipper) {
try {
zipper.zip(outputZip, ImmutableMap.copyOf(contentByEntryName));
IdentityHashMap<ModuleEntry, String> copyOfEntryNameByModuleEntry = Maps.newIdentityHashMap();
copyOfEntryNameByModuleEntry.putAll(entryNameByModuleEntry);
return new ModuleEntriesPack(ImmutableSet.of(namePrefix), ZipMap.from(outputZip), copyOfEntryNameByModuleEntry);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
Aggregations