Search in sources :

Example 21 with InvalidCommandException

use of com.android.tools.build.bundletool.model.exceptions.InvalidCommandException in project bundletool by google.

the class InstallMultiApksCommandTest method fromFlags_exclusiveApksOptions.

@Test
public void fromFlags_exclusiveApksOptions() {
    Path apkDir = tmpDir.resolve("apk_dir");
    Path apkFile1 = apkDir.resolve("file1.apks");
    Path apkFile2 = apkDir.resolve("file2.apks");
    Path zipFile = tmpDir.resolve("container.zip");
    InvalidCommandException e = assertThrows(InvalidCommandException.class, () -> InstallMultiApksCommand.fromFlags(new FlagParser().parse(String.format("--apks=%s,%s", apkFile1, apkFile2), "--apks-zip=" + zipFile), systemEnvironmentProvider, fakeServerOneDevice(qDeviceWithLocales("en-US"))));
    assertThat(e).hasMessageThat().contains("Exactly one of");
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) InvalidCommandException(com.android.tools.build.bundletool.model.exceptions.InvalidCommandException) FlagParser(com.android.tools.build.bundletool.flags.FlagParser) Test(org.junit.Test)

Example 22 with InvalidCommandException

use of com.android.tools.build.bundletool.model.exceptions.InvalidCommandException in project bundletool by google.

the class ApkMatcherTest method apkMatch_withModuleNameFiltering_instantApks_checksModuleName_exists.

@Test
public void apkMatch_withModuleNameFiltering_instantApks_checksModuleName_exists() {
    DeviceSpec device = deviceWithSdk(21);
    ZipPath apk = ZipPath.create("master-de-fr.apk");
    BuildApksResult buildApksResult = buildApksResult(createVariant(VariantTargeting.getDefaultInstance(), splitApkSet(/* moduleName= */
    "base", instantApkDescription(ApkTargeting.getDefaultInstance(), apk))));
    Optional<ImmutableSet<String>> allModules = Optional.empty();
    assertThat(createInstantMatcher(device, allModules).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(apk));
    Optional<ImmutableSet<String>> baseModuleOnly = Optional.of(ImmutableSet.of("base"));
    assertThat(createInstantMatcher(device, baseModuleOnly).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(apk));
    Optional<ImmutableSet<String>> unknownModuleOnly = Optional.of(ImmutableSet.of("unknown_module"));
    InvalidCommandException exception = assertThrows(InvalidCommandException.class, () -> createInstantMatcher(device, unknownModuleOnly).getMatchingApks(buildApksResult));
    assertThat(exception).hasMessageThat().contains("The APK Set archive does not contain the following modules: [unknown_module]");
}
Also used : DeviceSpec(com.android.bundle.Devices.DeviceSpec) ImmutableSet(com.google.common.collect.ImmutableSet) InvalidCommandException(com.android.tools.build.bundletool.model.exceptions.InvalidCommandException) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ZipPath(com.android.tools.build.bundletool.model.ZipPath) Test(org.junit.Test)

Example 23 with InvalidCommandException

use of com.android.tools.build.bundletool.model.exceptions.InvalidCommandException in project bundletool by google.

the class BuildApksCommandTest method oldestSignerFlag_noLineage_fails.

@Test
public void oldestSignerFlag_noLineage_fails() {
    InvalidCommandException e = assertThrows(InvalidCommandException.class, () -> BuildApksCommand.fromFlags(new FlagParser().parse("--bundle=" + bundlePath, "--output=" + outputFilePath, "--aapt2=" + AAPT2_PATH, "--ks=" + keystorePath, "--ks-key-alias=" + KEY_ALIAS, "--ks-pass=pass:" + KEYSTORE_PASSWORD, "--key-pass=pass:" + KEY_PASSWORD, "--oldest-signer=" + oldestSignerPropertiesPath), fakeAdbServer));
    assertThat(e).hasMessageThat().isEqualTo("Flag 'lineage' is required when 'oldest-signer' is set.");
}
Also used : InvalidCommandException(com.android.tools.build.bundletool.model.exceptions.InvalidCommandException) FlagParser(com.android.tools.build.bundletool.flags.FlagParser) Test(org.junit.Test)

Example 24 with InvalidCommandException

use of com.android.tools.build.bundletool.model.exceptions.InvalidCommandException in project bundletool by google.

the class BuildApksCommandTest method keystoreFlags_keystoreNotSet.

@Test
public void keystoreFlags_keystoreNotSet() {
    InvalidCommandException e = assertThrows(InvalidCommandException.class, () -> BuildApksCommand.fromFlags(new FlagParser().parse("--bundle=" + bundlePath, "--output=" + outputFilePath, "--aapt2=" + AAPT2_PATH, "--ks-key-alias=" + KEY_ALIAS), fakeAdbServer));
    assertThat(e).hasMessageThat().isEqualTo("Flag --ks is required when --ks-key-alias is set.");
}
Also used : InvalidCommandException(com.android.tools.build.bundletool.model.exceptions.InvalidCommandException) FlagParser(com.android.tools.build.bundletool.flags.FlagParser) Test(org.junit.Test)

Example 25 with InvalidCommandException

use of com.android.tools.build.bundletool.model.exceptions.InvalidCommandException in project bundletool by google.

the class BuildApksCommandTest method stampKeystoreFlags_noKeystore_fails.

@Test
public void stampKeystoreFlags_noKeystore_fails() throws Exception {
    SystemEnvironmentProvider provider = new FakeSystemEnvironmentProvider(/* variables= */
    ImmutableMap.of(ANDROID_HOME, "/android/home", ANDROID_SERIAL, DEVICE_ID), /* properties= */
    ImmutableMap.of(USER_HOME.key(), "/"));
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    InvalidCommandException e = assertThrows(InvalidCommandException.class, () -> BuildApksCommand.fromFlags(new FlagParser().parse("--bundle=" + bundlePath, "--output=" + outputFilePath, "--aapt2=" + AAPT2_PATH, "--create-stamp=" + true), new PrintStream(output), provider, fakeAdbServer));
    assertThat(e).hasMessageThat().isEqualTo("No key was found to sign the stamp.");
}
Also used : PrintStream(java.io.PrintStream) InvalidCommandException(com.android.tools.build.bundletool.model.exceptions.InvalidCommandException) FakeSystemEnvironmentProvider(com.android.tools.build.bundletool.testing.FakeSystemEnvironmentProvider) FakeSystemEnvironmentProvider(com.android.tools.build.bundletool.testing.FakeSystemEnvironmentProvider) SystemEnvironmentProvider(com.android.tools.build.bundletool.model.utils.SystemEnvironmentProvider) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FlagParser(com.android.tools.build.bundletool.flags.FlagParser) Test(org.junit.Test)

Aggregations

InvalidCommandException (com.android.tools.build.bundletool.model.exceptions.InvalidCommandException)26 Test (org.junit.Test)26 FlagParser (com.android.tools.build.bundletool.flags.FlagParser)12 ZipPath (com.android.tools.build.bundletool.model.ZipPath)6 BuildApksResult (com.android.bundle.Commands.BuildApksResult)4 DeviceSpec (com.android.bundle.Devices.DeviceSpec)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 Path (java.nio.file.Path)3 SystemEnvironmentProvider (com.android.tools.build.bundletool.model.utils.SystemEnvironmentProvider)1 FakeSystemEnvironmentProvider (com.android.tools.build.bundletool.testing.FakeSystemEnvironmentProvider)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintStream (java.io.PrintStream)1