use of com.android.tools.build.bundletool.model.ZipPath in project bundletool by google.
the class ZipFlingerAppBundleSerializer method addNewEntries.
/**
* Adds new and modified entries to an archive, compressing them.
*/
private static void addNewEntries(ZipArchive archive, ImmutableListMultimap<BundleModule, ModuleEntry> entries) throws IOException {
for (Map.Entry<BundleModule, ModuleEntry> moduleAndEntry : entries.entries()) {
BundleModule module = moduleAndEntry.getKey();
ModuleEntry moduleEntry = moduleAndEntry.getValue();
checkState(!moduleEntry.getBundleLocation().isPresent());
ZipPath moduleDir = ZipPath.create(module.getName().toString());
ZipPath destPath = moduleDir.resolve(moduleEntry.getPath());
archive.add(new BytesSource(moduleEntry.getContent().read(), destPath.toString(), DEFAULT_COMPRESSION_LEVEL));
}
}
use of com.android.tools.build.bundletool.model.ZipPath in project bundletool by google.
the class BundleModuleMerger method getAllEntriesExceptDexAndSpecial.
private static ImmutableSet<ModuleEntry> getAllEntriesExceptDexAndSpecial(Set<BundleModule> bundleModulesToFuse) {
Map<ZipPath, ModuleEntry> mergedEntriesByPath = new HashMap<>();
bundleModulesToFuse.stream().flatMap(module -> module.getEntries().stream()).filter(moduleEntry -> !moduleEntry.getPath().startsWith(DEX_DIRECTORY) && !moduleEntry.isSpecialEntry()).forEach(moduleEntry -> {
ModuleEntry existingModuleEntry = mergedEntriesByPath.putIfAbsent(moduleEntry.getPath(), moduleEntry);
if (existingModuleEntry != null && !existingModuleEntry.equals(moduleEntry)) {
throw InvalidBundleException.builder().withUserMessage("Existing module entry '%s' with different contents.", moduleEntry.getPath()).build();
}
});
return ImmutableSet.copyOf(mergedEntriesByPath.values());
}
use of com.android.tools.build.bundletool.model.ZipPath in project bundletool by google.
the class ApkPathManager method getApkPath.
/**
* Returns a unique file path for the given ModuleSplit.
*
* <p>Note that calling this method twice for the same object will return a different result since
* each returned value is unique.
*/
public ZipPath getApkPath(ModuleSplit moduleSplit) {
if (apkBuildMode.equals(ApkBuildMode.UNIVERSAL)) {
return ZipPath.create("universal.apk");
}
String moduleName = moduleSplit.getModuleName().getName();
String targetingSuffix = getTargetingSuffix(moduleSplit);
ZipPath directory;
String apkFileName;
switch(moduleSplit.getSplitType()) {
case SPLIT:
directory = ZipPath.create("splits");
apkFileName = buildName(moduleName, targetingSuffix);
break;
case INSTANT:
directory = ZipPath.create("instant");
apkFileName = buildName("instant", moduleName, targetingSuffix);
break;
case STANDALONE:
directory = ZipPath.create("standalones");
apkFileName = buildName("standalone", targetingSuffix);
break;
case SYSTEM:
if (moduleSplit.isBaseModuleSplit() && moduleSplit.isMasterSplit()) {
directory = ZipPath.create("system");
apkFileName = buildName("system");
} else {
directory = ZipPath.create("splits");
apkFileName = buildName(moduleName, targetingSuffix);
}
break;
case ASSET_SLICE:
directory = ZipPath.create("asset-slices");
apkFileName = buildName(moduleName, targetingSuffix);
break;
case ARCHIVE:
directory = ZipPath.create("archive");
apkFileName = buildName("archive");
break;
default:
throw new IllegalStateException("Unrecognized split type: " + moduleSplit.getSplitType());
}
return findAndClaimUnusedPath(directory, apkFileName, fileExtension(moduleSplit));
}
use of com.android.tools.build.bundletool.model.ZipPath in project bundletool by google.
the class BundleFilesValidatorTest method validateLibFile_directoryStructureTooShallow_throws.
@Test
public void validateLibFile_directoryStructureTooShallow_throws() throws Exception {
ZipPath libFileDirectlyInLib = ZipPath.create("lib/libX.so");
InvalidBundleException e = assertThrows(InvalidBundleException.class, () -> new BundleFilesValidator().validateModuleFile(libFileDirectlyInLib));
assertThat(e).hasMessageThat().contains("paths in form 'lib/<single-directory>/<file>.so'");
}
use of com.android.tools.build.bundletool.model.ZipPath in project bundletool by google.
the class BundleFilesValidatorTest method validateManifestDirectory_otherFile_throws.
@Test
public void validateManifestDirectory_otherFile_throws() throws Exception {
ZipPath nonPbFile = ZipPath.create("manifest/AndroidManifest.dat");
InvalidBundleException e = assertThrows(InvalidBundleException.class, () -> new BundleFilesValidator().validateModuleFile(nonPbFile));
assertThat(e).hasMessageThat().contains("Only 'AndroidManifest.xml' is accepted under directory 'manifest/' but found file " + "'manifest/AndroidManifest.dat'");
}
Aggregations