use of com.android.tools.build.bundletool.model.ModuleEntry in project bundletool by google.
the class AppBundleObfuscationPreprocessor method obfuscateModuleEntries.
private static ImmutableList<ModuleEntry> obfuscateModuleEntries(ImmutableSet<ModuleEntry> toBeObfuscatedEntries, HashMap<String, String> resourceNameMapping) {
ImmutableList<ModuleEntry> sortedEntries = ImmutableList.sortedCopyOf(Comparator.comparing(ModuleEntry::getPath), toBeObfuscatedEntries);
ImmutableList.Builder<ModuleEntry> obfuscatedEntries = ImmutableList.builder();
for (ModuleEntry moduleEntry : sortedEntries) {
ZipPath newPath = obfuscateZipPath(moduleEntry.getPath(), ImmutableMap.copyOf(resourceNameMapping));
resourceNameMapping.put(moduleEntry.getPath().toString(), newPath.toString());
ModuleEntry newModuleEntry = moduleEntry.toBuilder().setPath(newPath).build();
obfuscatedEntries.add(newModuleEntry);
}
return obfuscatedEntries.build();
}
use of com.android.tools.build.bundletool.model.ModuleEntry in project bundletool by google.
the class ModuleSplitsToShardMergerTest method dexFiles_inMultipleModules_areMerged.
@Test
public void dexFiles_inMultipleModules_areMerged() throws Exception {
Map<ImmutableSet<ModuleEntry>, ImmutableList<Path>> dexMergingCache = createCache();
ModuleEntry dexEntry1 = createModuleEntryForFile("dex/classes.dex", CLASSES_DEX_CONTENT);
ModuleSplit baseSplit = createModuleSplitBuilder().setModuleName(BundleModuleName.create("base")).setEntries(ImmutableList.of(dexEntry1)).build();
ModuleEntry dexEntry2 = createModuleEntryForFile("dex/classes.dex", CLASSES_OTHER_DEX_CONTENT);
ModuleSplit featureSplit = createModuleSplitBuilder().setModuleName(BundleModuleName.create("feature")).setEntries(ImmutableList.of(dexEntry2)).build();
ModuleSplit merged = splitsToShardMerger.mergeSingleShard(ImmutableList.of(baseSplit, featureSplit), dexMergingCache);
assertThat(extractPaths(merged.getEntries())).containsExactly("dex/classes.dex");
byte[] mergedDexData = dexData(merged, "dex/classes.dex");
assertThat(mergedDexData.length).isGreaterThan(0);
assertThat(mergedDexData).isNotEqualTo(CLASSES_DEX_CONTENT);
assertThat(mergedDexData).isNotEqualTo(CLASSES_OTHER_DEX_CONTENT);
// The merged result should be cached.
assertThat(dexMergingCache).hasSize(1);
ImmutableSet<ModuleEntry> cacheKey = getOnlyElement(dexMergingCache.keySet());
assertThat(cacheKey).containsExactly(dexEntry1, dexEntry2);
ImmutableList<Path> cacheValue = getOnlyElement(dexMergingCache.values());
assertThat(cacheValue.stream().allMatch(cachedFile -> cachedFile.startsWith(tmpDir.getPath()))).isTrue();
}
use of com.android.tools.build.bundletool.model.ModuleEntry in project bundletool by google.
the class ModuleSplitsToShardMergerTest method dexFiles_inMultipleModules_areRenamedWhenMergeIsDisabled.
@Test
public void dexFiles_inMultipleModules_areRenamedWhenMergeIsDisabled() throws Exception {
TestComponent.useTestModule(this, TestModule.builder().withAppBundle(BUNDLE_WITH_ONE_FEATURE_DISABLED_MERGING).build());
Map<ImmutableSet<ModuleEntry>, ImmutableList<Path>> dexMergingCache = createCache();
ModuleEntry dexEntry1 = createModuleEntryForFile("dex/classes.dex", CLASSES_DEX_CONTENT);
ModuleSplit baseSplit = createModuleSplitBuilder().setModuleName(BundleModuleName.create("base")).setEntries(ImmutableList.of(dexEntry1)).build();
ModuleEntry dexEntry2 = createModuleEntryForFile("dex/classes.dex", CLASSES_OTHER_DEX_CONTENT);
ModuleSplit featureSplit = createModuleSplitBuilder().setModuleName(BundleModuleName.create("feature")).setEntries(ImmutableList.of(dexEntry2)).build();
ModuleSplit merged = splitsToShardMerger.mergeSingleShard(ImmutableList.of(baseSplit, featureSplit), dexMergingCache);
assertThat(extractPaths(merged.getEntries())).containsExactly("dex/classes.dex", "dex/classes2.dex");
assertThat(dexData(merged, "dex/classes.dex")).isEqualTo(CLASSES_DEX_CONTENT);
assertThat(dexData(merged, "dex/classes2.dex")).isEqualTo(CLASSES_OTHER_DEX_CONTENT);
// The merged result with rename should not be cached.
assertThat(dexMergingCache).isEmpty();
}
use of com.android.tools.build.bundletool.model.ModuleEntry in project bundletool by google.
the class ModuleSplitsToShardMergerTest method dexFiles_inMultipleModules_areRenamedForLPlus.
@Test
public void dexFiles_inMultipleModules_areRenamedForLPlus() throws Exception {
Map<ImmutableSet<ModuleEntry>, ImmutableList<Path>> dexMergingCache = createCache();
ModuleEntry dexEntry1 = createModuleEntryForFile("dex/classes.dex", CLASSES_DEX_CONTENT);
ModuleSplit baseSplit = createModuleSplitBuilder().setModuleName(BundleModuleName.create("base")).setEntries(ImmutableList.of(dexEntry1)).setAndroidManifest(L_PLUS_MANIFEST).build();
ModuleEntry dexEntry2 = createModuleEntryForFile("dex/classes.dex", CLASSES_OTHER_DEX_CONTENT);
ModuleEntry dexEntry3 = createModuleEntryForFile("dex/classes2.dex", CLASSES_DEX_CONTENT);
ModuleSplit featureSplit = createModuleSplitBuilder().setModuleName(BundleModuleName.create("feature")).setEntries(ImmutableList.of(dexEntry3, dexEntry2)).build();
ModuleSplit merged = splitsToShardMerger.mergeSingleShard(ImmutableList.of(baseSplit, featureSplit), dexMergingCache);
assertThat(extractPaths(merged.getEntries())).containsExactly("dex/classes.dex", "dex/classes2.dex", "dex/classes3.dex").inOrder();
assertThat(dexData(merged, "dex/classes.dex")).isEqualTo(CLASSES_DEX_CONTENT);
assertThat(dexData(merged, "dex/classes2.dex")).isEqualTo(CLASSES_OTHER_DEX_CONTENT);
assertThat(dexData(merged, "dex/classes3.dex")).isEqualTo(CLASSES_DEX_CONTENT);
// The merged result with rename should not be cached.
assertThat(dexMergingCache).isEmpty();
}
use of com.android.tools.build.bundletool.model.ModuleEntry in project bundletool by google.
the class ModuleSplitsToShardMergerTest method dexFiles_inMultipleModules_areRenamedForLPlusNoBaseModuleDex.
@Test
public void dexFiles_inMultipleModules_areRenamedForLPlusNoBaseModuleDex() throws Exception {
Map<ImmutableSet<ModuleEntry>, ImmutableList<Path>> dexMergingCache = createCache();
ModuleSplit baseSplit = createModuleSplitBuilder().setModuleName(BundleModuleName.create("base")).setEntries(ImmutableList.of()).setAndroidManifest(L_PLUS_MANIFEST).build();
ModuleEntry dexEntry1 = createModuleEntryForFile("dex/classes.dex", CLASSES_OTHER_DEX_CONTENT);
ModuleEntry dexEntry2 = createModuleEntryForFile("dex/classes2.dex", CLASSES_DEX_CONTENT);
ModuleSplit featureSplit = createModuleSplitBuilder().setModuleName(BundleModuleName.create("feature")).setEntries(ImmutableList.of(dexEntry1, dexEntry2)).build();
ModuleSplit merged = splitsToShardMerger.mergeSingleShard(ImmutableList.of(baseSplit, featureSplit), dexMergingCache);
assertThat(extractPaths(merged.getEntries())).containsExactly("dex/classes.dex", "dex/classes2.dex");
assertThat(dexData(merged, "dex/classes.dex")).isEqualTo(CLASSES_OTHER_DEX_CONTENT);
assertThat(dexData(merged, "dex/classes2.dex")).isEqualTo(CLASSES_DEX_CONTENT);
// The merged result with rename should not be cached.
assertThat(dexMergingCache).isEmpty();
}
Aggregations