use of com.android.tools.build.bundletool.flags.FlagParser in project bundletool by google.
the class BuildSdkApksCommandTest method buildingCommandViaFlags_sdkBundlePathNotSet.
@Test
public void buildingCommandViaFlags_sdkBundlePathNotSet() {
Throwable e = assertThrows(RequiredFlagNotSetException.class, () -> BuildSdkApksCommand.fromFlags(new FlagParser().parse("")));
assertThat(e).hasMessageThat().contains("Missing the required --sdk-bundle flag");
}
use of com.android.tools.build.bundletool.flags.FlagParser in project bundletool by google.
the class ExtractApksCommandTest method permanentlyMergedModule.
@Test
public void permanentlyMergedModule() throws Exception {
ZipPath apkLBase = ZipPath.create("apkL-base.apk");
BuildApksResult tableOfContentsProto = BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(createVariant(VariantTargeting.getDefaultInstance(), createSplitApkSet("base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), apkLBase)))).addPermanentlyFusedModules(PermanentlyFusedModule.newBuilder().setName("permanent").build()).build();
Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
Path deviceSpecFile = createDeviceSpecFile(deviceWithSdk(21), tmpDir.resolve("device.json"));
ExtractApksCommand command = ExtractApksCommand.fromFlags(new FlagParser().parse("--device-spec=" + deviceSpecFile, "--apks=" + apksArchiveFile, "--modules=permanent"));
ImmutableList<Path> matchedApks = command.execute();
assertThat(matchedApks.stream().map(apk -> apk.getFileName().toString())).containsExactly("apkL-base.apk");
}
use of com.android.tools.build.bundletool.flags.FlagParser in project bundletool by google.
the class ExtractApksCommandTest method builderAndFlagsConstruction_inJavaViaFiles_equivalent.
@Test
public void builderAndFlagsConstruction_inJavaViaFiles_equivalent() throws Exception {
Path deviceSpecFile = createDeviceSpecFile(deviceWithSdk(21), tmpDir.resolve("device.json"));
BuildApksResult tableOfContentsProto = minimalApkSet();
Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
ExtractApksCommand fromFlags = ExtractApksCommand.fromFlags(new FlagParser().parse("--device-spec=" + deviceSpecFile, "--apks=" + apksArchiveFile));
ExtractApksCommand fromBuilderApi = ExtractApksCommand.builder().setApksArchivePath(apksArchiveFile).setDeviceSpec(deviceSpecFile).build();
assertThat(fromFlags).isEqualTo(fromBuilderApi);
}
use of com.android.tools.build.bundletool.flags.FlagParser in project bundletool by google.
the class ExtractApksCommandTest method deviceSpecFromPbJson.
@Test
public void deviceSpecFromPbJson() throws Exception {
DeviceSpec.Builder expectedDeviceSpecBuilder = DeviceSpec.newBuilder();
try (Reader reader = TestData.openReader("testdata/device/pixel2_spec.json")) {
JsonFormat.parser().merge(reader, expectedDeviceSpecBuilder);
}
DeviceSpec expectedDeviceSpec = expectedDeviceSpecBuilder.build();
BuildApksResult tableOfContentsProto = minimalApkSet();
Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
Path deviceSpecFile = copyToTempDir("testdata/device/pixel2_spec.json");
ExtractApksCommand command = ExtractApksCommand.fromFlags(new FlagParser().parse("--device-spec=" + deviceSpecFile, "--apks=" + apksArchiveFile));
assertThat(command.getDeviceSpec()).isEqualTo(expectedDeviceSpec);
}
use of com.android.tools.build.bundletool.flags.FlagParser in project bundletool by google.
the class ExtractApksCommandTest method nonExistentDeviceSpecFile_throws.
@Test
public void nonExistentDeviceSpecFile_throws() throws Exception {
Path apksArchiveFile = createApksArchiveFile(minimalApkSet(), tmpDir.resolve("bundle.apks"));
Throwable exception = assertThrows(IllegalArgumentException.class, () -> ExtractApksCommand.fromFlags(new FlagParser().parse("--device-spec=not-found.pb", "--apks=" + apksArchiveFile)));
assertThat(exception).hasMessageThat().contains("File 'not-found.pb' was not found");
}
Aggregations