Search in sources :

Example 51 with FlagParser

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

the class ExtractApksCommandTest method builderAndFlagsConstruction_optionalInstant_equivalent.

@Test
public void builderAndFlagsConstruction_optionalInstant_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.
    "--instant"));
    ExtractApksCommand fromBuilderApi = ExtractApksCommand.builder().setApksArchivePath(apksArchiveFile).setDeviceSpec(deviceSpec).setInstant(true).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 52 with FlagParser

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

the class ExtractApksCommandTest method deviceSpecUnknownExtension_throws.

@Test
public void deviceSpecUnknownExtension_throws() throws Exception {
    DeviceSpec deviceSpec = deviceWithSdk(21);
    Path deviceSpecFile = createDeviceSpecFile(deviceSpec, tmpDir.resolve("bad_filename.dat"));
    BuildApksResult tableOfContentsProto = minimalApkSet();
    Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
    Throwable exception = assertThrows(InvalidDeviceSpecException.class, () -> ExtractApksCommand.fromFlags(new FlagParser().parse("--device-spec=" + deviceSpecFile, "--apks=" + apksArchiveFile)));
    assertThat(exception).hasMessageThat().contains("Expected .json extension for the device spec");
}
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 53 with FlagParser

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

the class ExtractApksCommandTest method builderAndFlagsConstruction_optionalModules_equivalent.

@Test
public void builderAndFlagsConstruction_optionalModules_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.
    "--modules=base"));
    ExtractApksCommand fromBuilderApi = ExtractApksCommand.builder().setApksArchivePath(apksArchiveFile).setDeviceSpec(deviceSpec).setModules(ImmutableSet.of("base")).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 54 with FlagParser

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

the class ExtractApksCommandTest method missingDeviceSpecFlag_throws.

@Test
public void missingDeviceSpecFlag_throws() throws Exception {
    Path apksArchiveFile = createApksArchiveFile(minimalApkSet(), tmpDir.resolve("bundle.apks"));
    expectMissingRequiredFlagException("device-spec", () -> ExtractApksCommand.fromFlags(new FlagParser().parse("--apks=" + apksArchiveFile)));
}
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 55 with FlagParser

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

the class ExtractApksCommandTest method nonExistentApksArchiveFile_throws.

@Test
public void nonExistentApksArchiveFile_throws() throws Exception {
    Path deviceSpecFile = createDeviceSpecFile(deviceWithSdk(21), tmpDir.resolve("device.json"));
    Throwable exception = assertThrows(IllegalArgumentException.class, () -> ExtractApksCommand.fromFlags(new FlagParser().parse("--device-spec=" + deviceSpecFile, "--apks=nonexistent")).execute());
    assertThat(exception).hasMessageThat().contains("File 'nonexistent' was not found");
}
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)

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