Search in sources :

Example 81 with FlagParser

use of com.android.tools.build.bundletool.flags.FlagParser in project bundletool by google.

the class ExtractApksCommandTest method emptyModules_throws.

@Test
public void emptyModules_throws() throws Exception {
    Path apksArchiveFile = createApksArchiveFile(minimalApkSet(), 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="));
    Throwable exception = assertThrows(InvalidCommandException.class, command::execute);
    assertThat(exception).hasMessageThat().contains("The set of modules cannot be empty.");
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) FlagParser(com.android.tools.build.bundletool.flags.FlagParser) Test(org.junit.Test)

Example 82 with FlagParser

use of com.android.tools.build.bundletool.flags.FlagParser in project bundletool by google.

the class ExtractApksCommandTest method nonExistentModule_throws.

@Test
public void nonExistentModule_throws() 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)))).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=unknown_module"));
    Throwable exception = assertThrows(InvalidCommandException.class, command::execute);
    assertThat(exception).hasMessageThat().contains("The APK Set archive does not contain the following modules: [unknown_module]");
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ZipPath(com.android.tools.build.bundletool.model.ZipPath) FlagParser(com.android.tools.build.bundletool.flags.FlagParser) Test(org.junit.Test)

Example 83 with FlagParser

use of com.android.tools.build.bundletool.flags.FlagParser in project bundletool by google.

the class VersionCommandTest method executePrintsVersion.

@Test
public void executePrintsVersion() {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    VersionCommand.fromFlags(new FlagParser().parse(), new PrintStream(out)).execute();
    assertThat(asLines(out.toString())).containsExactly(BundleToolVersion.getCurrentVersion().toString(), "").inOrder();
}
Also used : PrintStream(java.io.PrintStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FlagParser(com.android.tools.build.bundletool.flags.FlagParser) Test(org.junit.Test)

Example 84 with FlagParser

use of com.android.tools.build.bundletool.flags.FlagParser in project bundletool by google.

the class CheckTransparencyCommandTest method buildingCommandViaFlags_apkMode_apkZipPathNotSet.

@Test
public void buildingCommandViaFlags_apkMode_apkZipPathNotSet() {
    Throwable e = assertThrows(RequiredFlagNotSetException.class, () -> CheckTransparencyCommand.fromFlags(new FlagParser().parse("--mode=APK"), systemEnvironmentProvider, fakeAdbServer));
    assertThat(e).hasMessageThat().contains("Missing the required --apk-zip flag");
}
Also used : FlagParser(com.android.tools.build.bundletool.flags.FlagParser) Test(org.junit.Test)

Example 85 with FlagParser

use of com.android.tools.build.bundletool.flags.FlagParser in project bundletool by google.

the class CheckTransparencyCommandTest method buildingCommandViaFlags_bundleMode_withTransparencyCertificateFlag_invalidFormat.

@Test
public void buildingCommandViaFlags_bundleMode_withTransparencyCertificateFlag_invalidFormat() {
    Throwable e = assertThrows(InvalidCommandException.class, () -> CheckTransparencyCommand.fromFlags(new FlagParser().parse("--mode=BUNDLE", "--bundle=" + bundlePath, "--transparency-key-certificate=" + apkZipPath), systemEnvironmentProvider, fakeAdbServer));
    assertThat(e).hasMessageThat().contains("Unable to read public key certificate from the provided path.");
}
Also used : FlagParser(com.android.tools.build.bundletool.flags.FlagParser) Test(org.junit.Test)

Aggregations

FlagParser (com.android.tools.build.bundletool.flags.FlagParser)138 Test (org.junit.Test)137 Path (java.nio.file.Path)63 ZipPath (com.android.tools.build.bundletool.model.ZipPath)55 ByteArrayOutputStream (java.io.ByteArrayOutputStream)29 PrintStream (java.io.PrintStream)29 BuildApksResult (com.android.bundle.Commands.BuildApksResult)22 InvalidCommandException (com.android.tools.build.bundletool.model.exceptions.InvalidCommandException)20 DeviceSpec (com.android.bundle.Devices.DeviceSpec)13 ParsedFlags (com.android.tools.build.bundletool.flags.ParsedFlags)12 ApksigSigningConfiguration (com.android.tools.build.bundletool.model.ApksigSigningConfiguration)10 SigningConfiguration (com.android.tools.build.bundletool.model.SigningConfiguration)10 FlagParseException (com.android.tools.build.bundletool.flags.FlagParser.FlagParseException)8 CommandExecutionException (com.android.tools.build.bundletool.model.exceptions.CommandExecutionException)8 InvalidBundleException (com.android.tools.build.bundletool.model.exceptions.InvalidBundleException)8 TestUtils.expectMissingRequiredBuilderPropertyException (com.android.tools.build.bundletool.testing.TestUtils.expectMissingRequiredBuilderPropertyException)8 TestUtils.expectMissingRequiredFlagException (com.android.tools.build.bundletool.testing.TestUtils.expectMissingRequiredFlagException)8 IOException (java.io.IOException)8 JoseException (org.jose4j.lang.JoseException)7 FakeSystemEnvironmentProvider (com.android.tools.build.bundletool.testing.FakeSystemEnvironmentProvider)6