Search in sources :

Example 26 with ModuleEntry

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();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ModuleEntry(com.android.tools.build.bundletool.model.ModuleEntry) ZipPath(com.android.tools.build.bundletool.model.ZipPath)

Example 27 with ModuleEntry

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();
}
Also used : Path(java.nio.file.Path) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableList(com.google.common.collect.ImmutableList) ModuleEntry(com.android.tools.build.bundletool.model.ModuleEntry) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) Test(org.junit.Test)

Example 28 with ModuleEntry

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();
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableList(com.google.common.collect.ImmutableList) ModuleEntry(com.android.tools.build.bundletool.model.ModuleEntry) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) Test(org.junit.Test)

Example 29 with ModuleEntry

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();
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableList(com.google.common.collect.ImmutableList) ModuleEntry(com.android.tools.build.bundletool.model.ModuleEntry) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) Test(org.junit.Test)

Example 30 with ModuleEntry

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();
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableList(com.google.common.collect.ImmutableList) ModuleEntry(com.android.tools.build.bundletool.model.ModuleEntry) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) Test(org.junit.Test)

Aggregations

ModuleEntry (com.android.tools.build.bundletool.model.ModuleEntry)41 ModuleSplit (com.android.tools.build.bundletool.model.ModuleSplit)22 ZipPath (com.android.tools.build.bundletool.model.ZipPath)18 ImmutableList (com.google.common.collect.ImmutableList)18 Test (org.junit.Test)13 BundleModule (com.android.tools.build.bundletool.model.BundleModule)12 ImmutableSet (com.google.common.collect.ImmutableSet)12 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)10 SpecialModuleEntry (com.android.tools.build.bundletool.model.BundleModule.SpecialModuleEntry)8 BundleModuleBuilder (com.android.tools.build.bundletool.testing.BundleModuleBuilder)6 HashMap (java.util.HashMap)6 Optional (java.util.Optional)6 TargetedAssetsDirectory (com.android.bundle.Files.TargetedAssetsDirectory)5 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)5 IOException (java.io.IOException)5 Map (java.util.Map)5 ResourceTable (com.android.aapt.Resources.ResourceTable)4 ApkTargeting (com.android.bundle.Targeting.ApkTargeting)4 BundleModuleName (com.android.tools.build.bundletool.model.BundleModuleName)4 ApkOptimizations (com.android.tools.build.bundletool.optimizations.ApkOptimizations)4