Search in sources :

Example 6 with InvalidCommandException

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");
}
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 7 with InvalidCommandException

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]");
}
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 8 with InvalidCommandException

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");
}
Also used : InvalidCommandException(com.android.tools.build.bundletool.model.exceptions.InvalidCommandException) Test(org.junit.Test)

Example 9 with InvalidCommandException

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.");
}
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 10 with InvalidCommandException

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.");
}
Also used : InvalidCommandException(com.android.tools.build.bundletool.model.exceptions.InvalidCommandException) 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