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");
}
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'.");
}
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);
}
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();
}
}
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");
}
Aggregations