Search in sources :

Example 1 with ResourcesUtils

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

the class DumpManager method printResources.

void printResources(Predicate<ResourceTableEntry> resourcePredicate, boolean printValues) {
    ImmutableList<ResourceTable> resourceTables;
    try (ZipFile zipFile = new ZipFile(bundlePath.toFile())) {
        resourceTables = ZipUtils.allFileEntriesPaths(zipFile).filter(path -> path.endsWith(SpecialModuleEntry.RESOURCE_TABLE.getPath())).map(path -> extractAndParse(zipFile, path, ResourceTable::parseFrom)).collect(toImmutableList());
    } catch (IOException e) {
        throw new UncheckedIOException("Error occurred when reading the bundle.", e);
    }
    ImmutableListMultimap<String, ResourceTableEntry> entriesByPackageName = resourceTables.stream().flatMap(ResourcesUtils::entries).filter(resourcePredicate).collect(groupingBySortedKeys(entry -> entry.getPackage().getPackageName()));
    for (String packageName : entriesByPackageName.keySet()) {
        printStream.printf("Package '%s':%n", packageName);
        entriesByPackageName.get(packageName).forEach(entry -> printEntry(entry, printValues));
        printStream.println();
    }
}
Also used : XPathExpressionException(javax.xml.xpath.XPathExpressionException) XPath(javax.xml.xpath.XPath) BundleModuleName(com.android.tools.build.bundletool.model.BundleModuleName) ZipPath(com.android.tools.build.bundletool.model.ZipPath) XmlProtoNode(com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoNode) XPathResolver(com.android.tools.build.bundletool.xml.XPathResolver) CollectorUtils.groupingBySortedKeys(com.android.tools.build.bundletool.model.utils.CollectorUtils.groupingBySortedKeys) XPathResult(com.android.tools.build.bundletool.xml.XPathResolver.XPathResult) XPathExpression(javax.xml.xpath.XPathExpression) ResourceTableEntry(com.android.tools.build.bundletool.model.ResourceTableEntry) XmlUtils(com.android.tools.build.bundletool.xml.XmlUtils) ImmutableList(com.google.common.collect.ImmutableList) XmlProtoToXmlConverter(com.android.tools.build.bundletool.xml.XmlProtoToXmlConverter) Document(org.w3c.dom.Document) ZipFile(java.util.zip.ZipFile) Path(java.nio.file.Path) ZipEntry(java.util.zip.ZipEntry) ResourceTable(com.android.aapt.Resources.ResourceTable) OutputStream(java.io.OutputStream) PrintStream(java.io.PrintStream) XmlNamespaceContext(com.android.tools.build.bundletool.xml.XmlNamespaceContext) ZipException(java.util.zip.ZipException) ConfigValue(com.android.aapt.Resources.ConfigValue) InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) Predicate(java.util.function.Predicate) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) IOException(java.io.IOException) SpecialModuleEntry(com.android.tools.build.bundletool.model.BundleModule.SpecialModuleEntry) UncheckedIOException(java.io.UncheckedIOException) XPathFactory(javax.xml.xpath.XPathFactory) XmlProtoPrintUtils(com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoPrintUtils) XmlNode(com.android.aapt.Resources.XmlNode) JsonFormat(com.google.protobuf.util.JsonFormat) BundleConfig(com.android.bundle.Config.BundleConfig) ResourcesUtils(com.android.tools.build.bundletool.model.utils.ResourcesUtils) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) InvalidCommandException(com.android.tools.build.bundletool.model.exceptions.InvalidCommandException) Optional(java.util.Optional) ZipUtils(com.android.tools.build.bundletool.model.utils.ZipUtils) Configuration(com.android.aapt.ConfigurationOuterClass.Configuration) InputStream(java.io.InputStream) ResourceTableEntry(com.android.tools.build.bundletool.model.ResourceTableEntry) ZipFile(java.util.zip.ZipFile) ResourcesUtils(com.android.tools.build.bundletool.model.utils.ResourcesUtils) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) ResourceTable(com.android.aapt.Resources.ResourceTable)

Aggregations

Configuration (com.android.aapt.ConfigurationOuterClass.Configuration)1 ConfigValue (com.android.aapt.Resources.ConfigValue)1 ResourceTable (com.android.aapt.Resources.ResourceTable)1 XmlNode (com.android.aapt.Resources.XmlNode)1 BundleConfig (com.android.bundle.Config.BundleConfig)1 SpecialModuleEntry (com.android.tools.build.bundletool.model.BundleModule.SpecialModuleEntry)1 BundleModuleName (com.android.tools.build.bundletool.model.BundleModuleName)1 ResourceTableEntry (com.android.tools.build.bundletool.model.ResourceTableEntry)1 ZipPath (com.android.tools.build.bundletool.model.ZipPath)1 InvalidBundleException (com.android.tools.build.bundletool.model.exceptions.InvalidBundleException)1 InvalidCommandException (com.android.tools.build.bundletool.model.exceptions.InvalidCommandException)1 CollectorUtils.groupingBySortedKeys (com.android.tools.build.bundletool.model.utils.CollectorUtils.groupingBySortedKeys)1 ResourcesUtils (com.android.tools.build.bundletool.model.utils.ResourcesUtils)1 ZipUtils (com.android.tools.build.bundletool.model.utils.ZipUtils)1 XmlProtoNode (com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoNode)1 XmlProtoPrintUtils (com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoPrintUtils)1 XPathResolver (com.android.tools.build.bundletool.xml.XPathResolver)1 XPathResult (com.android.tools.build.bundletool.xml.XPathResolver.XPathResult)1 XmlNamespaceContext (com.android.tools.build.bundletool.xml.XmlNamespaceContext)1 XmlProtoToXmlConverter (com.android.tools.build.bundletool.xml.XmlProtoToXmlConverter)1