use of com.android.tools.build.bundletool.model.exceptions.InvalidCommandException in project bundletool by google.
the class ApkMatcherTest method apkMatch_withModuleNameFiltering_standaloneApkMatches_throws.
@Test
public void apkMatch_withModuleNameFiltering_standaloneApkMatches_throws() {
DeviceSpec x86Device = lDeviceWithAbis("x86");
ZipPath apk = ZipPath.create("master-x86.apk");
BuildApksResult buildApksResult = buildApksResult(standaloneVariant(variantAbiTargeting(X86), apkAbiTargeting(X86), apk));
// Sanity-check that the device matches the standalone APK.
assertThat(new ApkMatcher(x86Device).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(apk));
Optional<ImmutableSet<String>> baseModuleOnly = Optional.of(ImmutableSet.of("base"));
InvalidCommandException exception = assertThrows(InvalidCommandException.class, () -> createMatcher(x86Device, baseModuleOnly).getMatchingApks(buildApksResult));
assertThat(exception).hasMessageThat().contains("Cannot restrict modules");
}
use of com.android.tools.build.bundletool.model.exceptions.InvalidCommandException in project bundletool by google.
the class ApkMatcherTest method apkMatch_withModuleNameFiltering_splitApks_checksModuleName.
// Module name filtering.
@Test
public void apkMatch_withModuleNameFiltering_splitApks_checksModuleName() {
DeviceSpec device = deviceWithSdk(21);
ZipPath apk = ZipPath.create("master-de-fr.apk");
BuildApksResult buildApksResult = buildApksResult(createVariant(VariantTargeting.getDefaultInstance(), splitApkSet(/* moduleName= */
"base", splitApkDescription(ApkTargeting.getDefaultInstance(), apk))));
Optional<ImmutableSet<String>> allModules = Optional.empty();
assertThat(createMatcher(device, allModules).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(apk));
Optional<ImmutableSet<String>> baseModuleOnly = Optional.of(ImmutableSet.of("base"));
assertThat(createMatcher(device, baseModuleOnly).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(apk));
Optional<ImmutableSet<String>> unknownModuleOnly = Optional.of(ImmutableSet.of("unknown_module"));
InvalidCommandException exception = assertThrows(InvalidCommandException.class, () -> createMatcher(device, unknownModuleOnly).getMatchingApks(buildApksResult));
assertThat(exception).hasMessageThat().contains("The APK Set archive does not contain the following modules: [unknown_module]");
}
use of com.android.tools.build.bundletool.model.exceptions.InvalidCommandException in project bundletool by google.
the class BundleToolErrorTest method testInvalidCommand.
@Test
public void testInvalidCommand() {
InvalidCommandException exception = InvalidCommandException.builder().withInternalMessage("internal msg").withCause(new IllegalArgumentException("illegal arg")).build();
assertError(exception.toProto(), ErrorType.INVALID_COMMAND_ERROR, "", "internal msg");
}
use of com.android.tools.build.bundletool.model.exceptions.InvalidCommandException in project bundletool by google.
the class BuildBundleCommandTest method metadataFileDoesNotExist_throws.
@Test
public void metadataFileDoesNotExist_throws() throws Exception {
Path baseModulePath = buildSimpleModule("base");
Path nonExistentFilePath = tmpDir.resolve("metadata.txt");
InvalidCommandException exceptionViaApi = assertThrows(InvalidCommandException.class, () -> BuildBundleCommand.builder().setOutputPath(bundlePath).setModulesPaths(ImmutableList.of(baseModulePath)).addMetadataFile("com.some.namespace", "file-name", nonExistentFilePath).build().execute());
assertThat(exceptionViaApi).hasMessageThat().matches("Metadata file .* does not exist.");
InvalidCommandException exceptionViaFlags = assertThrows(InvalidCommandException.class, () -> BuildBundleCommand.fromFlags(new FlagParser().parse("--output=" + bundlePath, "--modules=" + baseModulePath, "--metadata-file=com.some.namespace/file-name:" + nonExistentFilePath)));
assertThat(exceptionViaFlags).hasMessageThat().matches("Metadata file .* does not exist.");
}
use of com.android.tools.build.bundletool.model.exceptions.InvalidCommandException in project bundletool by google.
the class BuildSdkApksCommandTest method keystoreSet_keyAliasNotSet_throws.
@Test
public void keystoreSet_keyAliasNotSet_throws() {
InvalidCommandException e = assertThrows(InvalidCommandException.class, () -> BuildSdkApksCommand.fromFlags(getDefaultFlagsWithAdditionalFlags("--ks=" + keystorePath)));
assertThat(e).hasMessageThat().isEqualTo("Flag --ks-key-alias is required when --ks is set.");
}
Aggregations