Search in sources :

Example 91 with FlagParser

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

the class ExtractApksCommandTest method builderAndFlagsConstruction_optionalOutputDirectory_equivalent.

@Test
public void builderAndFlagsConstruction_optionalOutputDirectory_equivalent() throws Exception {
    DeviceSpec deviceSpec = deviceWithSdk(21);
    Path deviceSpecFile = createDeviceSpecFile(deviceSpec, tmpDir.resolve("device.json"));
    BuildApksResult tableOfContentsProto = minimalApkSet();
    Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
    ExtractApksCommand fromFlags = ExtractApksCommand.fromFlags(new FlagParser().parse("--device-spec=" + deviceSpecFile, "--apks=" + apksArchiveFile, // Optional values.
    "--output-dir=" + tmp.getRoot()));
    ExtractApksCommand fromBuilderApi = ExtractApksCommand.builder().setApksArchivePath(apksArchiveFile).setDeviceSpec(deviceSpec).setOutputDirectory(tmpDir).build();
    assertThat(fromFlags).isEqualTo(fromBuilderApi);
}
Also used : DeviceSpec(com.android.bundle.Devices.DeviceSpec) 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)

Example 92 with FlagParser

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

the class GetDeviceSpecCommandTest method fromFlagsEquivalentToBuilder_noDeviceId.

@Test
public void fromFlagsEquivalentToBuilder_noDeviceId() {
    SystemEnvironmentProvider androidHomeProvider = new FakeSystemEnvironmentProvider(ImmutableMap.of(ANDROID_HOME, sdkDirPath.toString()));
    Path outputPath = tmpDir.resolve("device.json");
    GetDeviceSpecCommand commandViaFlags = GetDeviceSpecCommand.fromFlags(new FlagParser().parse("--adb=" + adbPath, "--output=" + outputPath), androidHomeProvider, fakeServerOneDevice(lDeviceWithLocales("en-US")));
    GetDeviceSpecCommand commandViaBuilder = GetDeviceSpecCommand.builder().setAdbPath(adbPath).setOutputPath(outputPath).setAdbServer(commandViaFlags.getAdbServer()).build();
    assertThat(commandViaFlags).isEqualTo(commandViaBuilder);
}
Also used : Path(java.nio.file.Path) 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) FlagParser(com.android.tools.build.bundletool.flags.FlagParser) Test(org.junit.Test)

Example 93 with FlagParser

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

the class GetDeviceSpecCommandTest method fromFlagsEquivalentToBuilder_onlyOutputPath.

@Test
public void fromFlagsEquivalentToBuilder_onlyOutputPath() {
    Path outputPath = tmpDir.resolve("device.json");
    GetDeviceSpecCommand commandViaFlags = GetDeviceSpecCommand.fromFlags(new FlagParser().parse("--output=" + outputPath), systemEnvironmentProvider, fakeServerOneDevice(lDeviceWithLocales("en-US")));
    // The command via flags uses $ANDROID_HOME as a base for ADB location if the --adb flag is
    // missing. The builder doesn't support that so we pass what should be the resolved ADB location
    // for verification.
    GetDeviceSpecCommand commandViaBuilder = GetDeviceSpecCommand.builder().setOutputPath(outputPath).setAdbPath(sdkDirPath.resolve("platform-tools").resolve("adb")).setAdbServer(commandViaFlags.getAdbServer()).setDeviceId(DEVICE_ID).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 94 with FlagParser

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

the class GetDeviceSpecCommandTest method fromFlagsEquivalentToBuilder_allFlagsUsed_overwrite.

@Test
public void fromFlagsEquivalentToBuilder_allFlagsUsed_overwrite() {
    Path outputPath = tmpDir.resolve("device.json");
    GetDeviceSpecCommand commandViaFlags = GetDeviceSpecCommand.fromFlags(new FlagParser().parse("--adb=" + adbPath, "--device-id=" + DEVICE_ID, "--output=" + outputPath, "--overwrite"), systemEnvironmentProvider, fakeServerOneDevice(lDeviceWithLocales("en-US")));
    GetDeviceSpecCommand commandViaBuilder = GetDeviceSpecCommand.builder().setAdbPath(adbPath).setDeviceId(DEVICE_ID).setOutputPath(outputPath).setAdbServer(commandViaFlags.getAdbServer()).setOverwriteOutput(true).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 95 with FlagParser

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

the class GetDeviceSpecCommandTest method missingOuputFlag_fails.

@Test
public void missingOuputFlag_fails() {
    expectMissingRequiredBuilderPropertyException("output", () -> GetDeviceSpecCommand.builder().setAdbPath(adbPath).build());
    expectMissingRequiredFlagException("output", () -> GetDeviceSpecCommand.fromFlags(new FlagParser().parse("--adb=" + adbPath), systemEnvironmentProvider, fakeServerOneDevice(lDeviceWithLocales("en-US"))));
}
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