use of com.android.tools.build.bundletool.model.AppBundle in project bundletool by google.
the class BuildBundleCommandTest method bundleConfig_saved.
@Test
public void bundleConfig_saved() throws Exception {
Path module = createSimpleBaseModule();
// Any version supplied by the user is ignored and overwritten.
BundleConfig bundleConfigFromUser = BundleConfigBuilder.create().setVersion("0.0.0").build();
BundleConfig bundleConfigInBundle = new BundleConfigBuilder(bundleConfigFromUser).setVersion(BundleToolVersion.getCurrentVersion().toString()).build();
assertThat(bundleConfigFromUser.getBundletool().getVersion()).isNotEqualTo(bundleConfigInBundle.getBundletool().getVersion());
BuildBundleCommand.builder().setModulesPaths(ImmutableList.of(module)).setOutputPath(bundlePath).setBundleConfig(bundleConfigFromUser).build().execute();
try (ZipFile appBundleZip = new ZipFile(bundlePath.toFile())) {
AppBundle appBundle = AppBundle.buildFromZip(appBundleZip);
assertThat(appBundle.getBundleConfig()).isEqualTo(bundleConfigInBundle);
}
}
use of com.android.tools.build.bundletool.model.AppBundle in project bundletool by google.
the class DumpManagerTest method dumpManifest_withXPath_noNamespaceDeclaration.
@Test
public void dumpManifest_withXPath_noNamespaceDeclaration() throws Exception {
XmlNode manifestWithoutNamespaceDeclaration = androidManifest("com.app", withDebuggableAttribute(true), manifestElement -> manifestElement.getProto().clearNamespaceDeclaration());
AppBundle appBundle = new AppBundleBuilder().addModule("base", module -> module.setManifest(manifestWithoutNamespaceDeclaration)).build();
new AppBundleSerializer().writeToDisk(appBundle, bundlePath);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
DumpCommand.builder().setBundlePath(bundlePath).setDumpTarget(DumpTarget.MANIFEST).setXPathExpression("/manifest/application/@android:debuggable").setOutputStream(new PrintStream(outputStream)).build().execute();
assertThat(new String(outputStream.toByteArray(), UTF_8).trim()).isEqualTo("true");
}
use of com.android.tools.build.bundletool.model.AppBundle in project bundletool by google.
the class DumpManagerTest method dumpManifest_withXPath_nodeResult.
@Test
public void dumpManifest_withXPath_nodeResult() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", module -> module.setManifest(androidManifest("com.app", withMetadataValue("key1", "value1"), withMetadataValue("key2", "value2")))).build();
new AppBundleSerializer().writeToDisk(appBundle, bundlePath);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
DumpCommand dumpCommand = DumpCommand.builder().setBundlePath(bundlePath).setDumpTarget(DumpTarget.MANIFEST).setXPathExpression("/manifest/application/meta-data").setOutputStream(new PrintStream(outputStream)).build();
assertThrows(UnsupportedOperationException.class, () -> dumpCommand.execute());
}
use of com.android.tools.build.bundletool.model.AppBundle in project bundletool by google.
the class DumpManagerTest method createBundle.
private static void createBundle(Path bundlePath, ResourceTable resourceTable, BundleConfig bundleConfig) throws IOException {
AppBundle appBundle = new AppBundleBuilder().addModule("base", module -> module.setManifest(androidManifest("com.app")).setResourceTable(resourceTable)).setBundleConfig(bundleConfig).build();
new AppBundleSerializer().writeToDisk(appBundle, bundlePath);
}
use of com.android.tools.build.bundletool.model.AppBundle in project bundletool by google.
the class DumpManagerTest method dumpManifest_withXPath_multipleValues.
@Test
public void dumpManifest_withXPath_multipleValues() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", module -> module.setManifest(androidManifest("com.app", withMetadataValue("key1", "value1"), withMetadataValue("key2", "value2")))).build();
new AppBundleSerializer().writeToDisk(appBundle, bundlePath);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
DumpCommand.builder().setBundlePath(bundlePath).setDumpTarget(DumpTarget.MANIFEST).setXPathExpression("/manifest/application/meta-data/@android:value").setOutputStream(new PrintStream(outputStream)).build().execute();
assertThat(new String(outputStream.toByteArray(), UTF_8)).isEqualTo(String.format("value1%n" + "value2%n"));
}
Aggregations