Search in sources :

Example 96 with ZipPath

use of com.android.tools.build.bundletool.model.ZipPath in project bundletool by google.

the class BundleFilesValidatorTest method validateOtherFile_inUnknownDirectory_throws.

@Test
public void validateOtherFile_inUnknownDirectory_throws() throws Exception {
    ZipPath otherFile = ZipPath.create("unrecognized/path.txt");
    InvalidBundleException e = assertThrows(InvalidBundleException.class, () -> new BundleFilesValidator().validateModuleFile(otherFile));
    assertThat(e).hasMessageThat().contains("Module files can be only in pre-defined directories");
}
Also used : InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) ZipPath(com.android.tools.build.bundletool.model.ZipPath) Test(org.junit.Test)

Example 97 with ZipPath

use of com.android.tools.build.bundletool.model.ZipPath in project bundletool by google.

the class BundleFilesValidatorTest method validateDexFile_nonDexExtension_throws.

@Test
public void validateDexFile_nonDexExtension_throws() throws Exception {
    ZipPath nonDexFile = ZipPath.create("dex/classes.dat");
    InvalidBundleException e = assertThrows(InvalidBundleException.class, () -> new BundleFilesValidator().validateModuleFile(nonDexFile));
    assertThat(e).hasMessageThat().contains("Files under dex/ must have .dex extension, found 'dex/classes.dat'.");
}
Also used : InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) ZipPath(com.android.tools.build.bundletool.model.ZipPath) Test(org.junit.Test)

Example 98 with ZipPath

use of com.android.tools.build.bundletool.model.ZipPath in project bundletool by google.

the class BundleFilesValidatorTest method assetsInRootDirectory_valid.

@Test
public void assetsInRootDirectory_valid() throws Exception {
    ZipPath assetsFileInRoot = ZipPath.create("root/assets/org/apache/commons/math3/exception/util/LocalizedFormats_fr.properties");
    new BundleFilesValidator().validateModuleFile(assetsFileInRoot);
}
Also used : ZipPath(com.android.tools.build.bundletool.model.ZipPath) Test(org.junit.Test)

Example 99 with ZipPath

use of com.android.tools.build.bundletool.model.ZipPath in project bundletool by google.

the class ResourceTableValidator method validateModule.

@Override
public void validateModule(BundleModule module) {
    // If module has no resource table, treat it as if the resource table were empty.
    ResourceTable resourceTable = module.getResourceTable().orElse(ResourceTable.getDefaultInstance());
    String moduleName = module.getName().getName();
    ImmutableSet<ZipPath> resFiles = module.findEntriesUnderPath(BundleModule.RESOURCES_DIRECTORY).map(ModuleEntry::getPath).collect(toImmutableSet());
    if (!resFiles.isEmpty() && !module.getResourceTable().isPresent()) {
        throw InvalidBundleException.builder().withUserMessage("Module '%s' contains resource files but is missing a resource table.", moduleName).build();
    }
    ImmutableSet<ZipPath> referencedFiles = ResourcesUtils.getAllFileReferences(resourceTable);
    for (ZipPath referencedFile : referencedFiles) {
        if (!referencedFile.startsWith(BundleModule.RESOURCES_DIRECTORY)) {
            throw InvalidBundleException.builder().withUserMessage("Resource table of module '%s' references file '%s' outside of the '%s/'" + " directory.", moduleName, referencedFile, BundleModule.RESOURCES_DIRECTORY).build();
        }
    }
    ImmutableSet<ZipPath> nonReferencedFiles = ImmutableSet.copyOf(difference(resFiles, referencedFiles));
    if (!nonReferencedFiles.isEmpty()) {
        throw InvalidBundleException.builder().withUserMessage("Module '%s' contains resource files that are not referenced from the resource" + " table: %s", moduleName, nonReferencedFiles).build();
    }
    ImmutableSet<ZipPath> nonExistingFiles = ImmutableSet.copyOf(difference(referencedFiles, resFiles));
    if (!nonExistingFiles.isEmpty()) {
        throw InvalidBundleException.builder().withUserMessage("Resource table of module '%s' contains references to non-existing files: %s", moduleName, nonExistingFiles).build();
    }
}
Also used : ZipPath(com.android.tools.build.bundletool.model.ZipPath) ResourceTable(com.android.aapt.Resources.ResourceTable)

Example 100 with ZipPath

use of com.android.tools.build.bundletool.model.ZipPath in project bundletool by google.

the class BundleFilesValidatorTest method validateApexFile_unknownAbi_throws.

@Test
public void validateApexFile_unknownAbi_throws() throws Exception {
    ZipPath nonImgFile = ZipPath.create("apex/sparc.img");
    InvalidBundleException e = assertThrows(InvalidBundleException.class, () -> new BundleFilesValidator().validateModuleFile(nonImgFile));
    assertThat(e).hasMessageThat().contains("Unrecognized native architecture for file");
}
Also used : InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) ZipPath(com.android.tools.build.bundletool.model.ZipPath) Test(org.junit.Test)

Aggregations

ZipPath (com.android.tools.build.bundletool.model.ZipPath)194 Test (org.junit.Test)154 BuildApksResult (com.android.bundle.Commands.BuildApksResult)106 Path (java.nio.file.Path)55 DeviceSpec (com.android.bundle.Devices.DeviceSpec)44 InvalidBundleException (com.android.tools.build.bundletool.model.exceptions.InvalidBundleException)23 ImmutableSet (com.google.common.collect.ImmutableSet)23 ModuleEntry (com.android.tools.build.bundletool.model.ModuleEntry)19 Variant (com.android.bundle.Commands.Variant)16 ApksArchiveHelpers.createVariant (com.android.tools.build.bundletool.testing.ApksArchiveHelpers.createVariant)15 BundleModule (com.android.tools.build.bundletool.model.BundleModule)13 ImmutableList (com.google.common.collect.ImmutableList)12 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)11 ApksArchiveHelpers.standaloneVariant (com.android.tools.build.bundletool.testing.ApksArchiveHelpers.standaloneVariant)10 Theory (org.junit.experimental.theories.Theory)10 AdbServer (com.android.tools.build.bundletool.device.AdbServer)9 IOException (java.io.IOException)9 ModuleSplit (com.android.tools.build.bundletool.model.ModuleSplit)8 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)8 UncheckedIOException (java.io.UncheckedIOException)8