use of com.android.tools.build.bundletool.model.BundleModuleName in project bundletool by google.
the class FusingAndroidManifestMergerTest method onlyBaseManifest.
@Test
@Theory
public void onlyBaseManifest(FusingAndroidManifestMerger.Mode mode) {
SetMultimap<BundleModuleName, AndroidManifest> manifests = createManifests(androidManifest("com.testapp", withDebuggableAttribute(true), withCustomThemeActivity("activity", BASE_THEME_REF_ID)));
AndroidManifest merged = createMerger(mode).merge(manifests);
assertThat(merged).isEqualTo(getOnlyElement(manifests.get(BASE_MODULE_NAME)));
}
use of com.android.tools.build.bundletool.model.BundleModuleName in project bundletool by google.
the class FusingAndroidManifestMergerTest method noBaseManifest_throws.
@Test
public void noBaseManifest_throws() {
SetMultimap<BundleModuleName, AndroidManifest> manifests = ImmutableSetMultimap.of(BundleModuleName.create("feature"), AndroidManifest.create(androidManifest("com.testapp")));
CommandExecutionException exception = assertThrows(CommandExecutionException.class, () -> createMerger(Mode.REPLACE).merge(manifests));
assertThat(exception).hasMessageThat().isEqualTo("Expected to have base module.");
}
use of com.android.tools.build.bundletool.model.BundleModuleName in project bundletool by google.
the class BundleParser method extractModules.
/**
* Extracts all modules from bundle zip file and returns them in a list
*/
public static ImmutableList<BundleModule> extractModules(ZipFile bundleFile, BundleConfig bundleConfig, ImmutableSet<ZipPath> nonModuleDirectories) {
Map<BundleModuleName, BundleModule.Builder> moduleBuilders = new HashMap<>();
Enumeration<? extends ZipEntry> entries = bundleFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
if (entry.isDirectory()) {
continue;
}
Optional<BundleModuleName> moduleName = extractModuleName(entry, nonModuleDirectories);
if (!moduleName.isPresent()) {
continue;
}
BundleModule.Builder moduleBuilder = moduleBuilders.computeIfAbsent(moduleName.get(), name -> BundleModule.builder().setName(name).setBundleConfig(bundleConfig));
moduleBuilder.addEntry(ModuleEntry.builder().setBundleLocation(ModuleEntryBundleLocation.create(Paths.get(bundleFile.getName()), ZipPath.create(entry.getName()))).setPath(ZipUtils.convertBundleToModulePath(ZipPath.create(entry.getName()))).setContent(ZipUtils.asByteSource(bundleFile, entry)).build());
}
// We verify the presence of the manifest before building the BundleModule objects because the
// manifest is a required field of the BundleModule class.
checkModulesHaveManifest(moduleBuilders.values());
return moduleBuilders.values().stream().map(BundleModule.Builder::build).collect(toImmutableList());
}
use of com.android.tools.build.bundletool.model.BundleModuleName in project bundletool by google.
the class FusingAndroidManifestMerger method ensureOneManifestPerModule.
private static ImmutableMap<BundleModuleName, AndroidManifest> ensureOneManifestPerModule(SetMultimap<BundleModuleName, AndroidManifest> manifests) {
ImmutableMap.Builder<BundleModuleName, AndroidManifest> builder = ImmutableMap.builder();
for (BundleModuleName moduleName : manifests.keys()) {
Set<AndroidManifest> moduleManifests = manifests.get(moduleName);
if (moduleManifests.size() != 1) {
throw CommandExecutionException.builder().withInternalMessage("Expected exactly one %s module manifest, but found %d.", moduleName.getName(), moduleManifests.size()).build();
}
builder.put(moduleName, Iterables.getOnlyElement(moduleManifests));
}
return builder.build();
}
use of com.android.tools.build.bundletool.model.BundleModuleName in project bundletool by google.
the class FusingAndroidManifestMerger method merge.
private AndroidManifest merge(Map<BundleModuleName, AndroidManifest> manifests) {
AndroidManifest baseManifest = manifests.get(BASE_MODULE_NAME);
List<AndroidManifest> featureManifests = manifests.entrySet().stream().filter(entry -> !BASE_MODULE_NAME.equals(entry.getKey())).sorted(Comparator.comparing(entry -> entry.getKey().getName())).map(Map.Entry::getValue).collect(toImmutableList());
if (featureManifests.isEmpty()) {
return baseManifest;
}
return mergeManifests(baseManifest, featureManifests);
}
Aggregations