Search in sources :

Example 36 with FlagParser

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

the class CheckTransparencyCommandTest method buildingCommandViaFlags_bundleMode_withApkSigningKeyCertificateFlag.

@Test
public void buildingCommandViaFlags_bundleMode_withApkSigningKeyCertificateFlag() {
    Throwable e = assertThrows(UnknownFlagsException.class, () -> CheckTransparencyCommand.fromFlags(new FlagParser().parse("--mode=BUNDLE", "--bundle=" + bundlePath, "--apk-signing-key-certificate=" + apkSigningKeyCertificatePath), systemEnvironmentProvider, fakeAdbServer));
    assertThat(e).hasMessageThat().contains("Unrecognized flags: --apk-signing-key-certificate");
}
Also used : FlagParser(com.android.tools.build.bundletool.flags.FlagParser) Test(org.junit.Test)

Example 37 with FlagParser

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

the class BuildBundleCommandTest method buildingViaFlagsAndBuilderHasSameResult_optionalOverwrite.

@Test
public void buildingViaFlagsAndBuilderHasSameResult_optionalOverwrite() throws Exception {
    Path baseModulePath = buildSimpleModule("base");
    BuildBundleCommand commandViaBuilder = BuildBundleCommand.builder().setOutputPath(bundlePath).setModulesPaths(ImmutableList.of(baseModulePath)).setOverwriteOutput(true).build();
    BuildBundleCommand commandViaFlags = BuildBundleCommand.fromFlags(new FlagParser().parse("--output=" + bundlePath, "--modules=" + baseModulePath, "--overwrite"));
    assertThat(commandViaBuilder).isEqualTo(commandViaFlags);
}
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 38 with FlagParser

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

the class GetDeviceSpecCommandTest method fromFlagsEquivalentToBuilder_allFlagsUsed.

@Test
public void fromFlagsEquivalentToBuilder_allFlagsUsed() {
    Path outputPath = tmpDir.resolve("device.json");
    GetDeviceSpecCommand commandViaFlags = GetDeviceSpecCommand.fromFlags(new FlagParser().parse("--adb=" + adbPath, "--device-id=" + DEVICE_ID, "--output=" + outputPath, "--device-tier=" + DEVICE_TIER, "--device-groups=" + Joiner.on(",").join(DEVICE_GROUPS)), systemEnvironmentProvider, fakeServerOneDevice(lDeviceWithLocales("en-US")));
    GetDeviceSpecCommand commandViaBuilder = GetDeviceSpecCommand.builder().setAdbPath(adbPath).setDeviceId(DEVICE_ID).setOutputPath(outputPath).setAdbServer(commandViaFlags.getAdbServer()).setDeviceTier(DEVICE_TIER).setDeviceGroups(DEVICE_GROUPS).build();
    assertThat(commandViaFlags).isEqualTo(commandViaBuilder);
}
Also used : Path(java.nio.file.Path) FlagParser(com.android.tools.build.bundletool.flags.FlagParser) Test(org.junit.Test)

Example 39 with FlagParser

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

the class GetSizeCommandTest method wrongSubCommand_throws.

@Test
public void wrongSubCommand_throws() throws Exception {
    BuildApksResult tableOfContentsProto = BuildApksResult.getDefaultInstance();
    Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
    ParsedFlags flags = new FlagParser().parse("get-size", "full", "--apks=" + apksArchiveFile);
    Throwable exception = assertThrows(InvalidCommandException.class, () -> GetSizeCommand.fromFlags(flags));
    assertThat(exception).hasMessageThat().contains("Unrecognized get-size command target:");
    assertThat(exception).hasMessageThat().contains("full");
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ParsedFlags(com.android.tools.build.bundletool.flags.ParsedFlags) FlagParser(com.android.tools.build.bundletool.flags.FlagParser) Test(org.junit.Test)

Example 40 with FlagParser

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

the class GetSizeCommandTest method builderAndFlagsConstruction_optionalHumanReadableSizes.

@Test
public void builderAndFlagsConstruction_optionalHumanReadableSizes() throws Exception {
    BuildApksResult tableOfContentsProto = BuildApksResult.getDefaultInstance();
    Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
    GetSizeCommand fromFlags = GetSizeCommand.fromFlags(new FlagParser().parse("get-size", "total", "--apks=" + apksArchiveFile, // Optional values.
    "--human-readable-sizes"));
    GetSizeCommand fromBuilderApi = GetSizeCommand.builder().setApksArchivePath(apksArchiveFile).setHumanReadableSizes(true).setGetSizeSubCommand(GetSizeSubcommand.TOTAL).build();
    assertThat(fromFlags).isEqualTo(fromBuilderApi);
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) BuildApksResult(com.android.bundle.Commands.BuildApksResult) 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