Search in sources :

Example 86 with DeviceSpec

use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.

the class GetDeviceSpecCommandTest method overwriteSet_overwritesFile.

@Test
public void overwriteSet_overwritesFile() throws Exception {
    DeviceSpec deviceSpec = mergeSpecs(sdkVersion(21), density(480), abis("x86"), locales("en-US"));
    Path outputPath = tmp.getRoot().toPath().resolve("device.json");
    Files.createFile(outputPath);
    GetDeviceSpecCommand.builder().setAdbPath(adbPath).setAdbServer(fakeServerOneDevice(deviceSpec)).setOutputPath(outputPath).setOverwriteOutput(true).build().execute();
    assertThat(outputPath.toFile().length()).isGreaterThan(0L);
}
Also used : DeviceSpec(com.android.bundle.Devices.DeviceSpec) Path(java.nio.file.Path) Test(org.junit.Test)

Example 87 with DeviceSpec

use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.

the class GetDeviceSpecCommandTest method overwriteNotSet_outputFileExists_throws.

@Test
public void overwriteNotSet_outputFileExists_throws() throws Exception {
    DeviceSpec deviceSpec = mergeSpecs(sdkVersion(21), density(480), abis("x86"), locales("en-US"));
    Path outputPath = tmp.getRoot().toPath().resolve("device.json");
    Files.createFile(outputPath);
    GetDeviceSpecCommand command = GetDeviceSpecCommand.builder().setAdbPath(adbPath).setAdbServer(fakeServerOneDevice(deviceSpec)).setOutputPath(outputPath).build();
    Throwable exception = assertThrows(IllegalArgumentException.class, () -> command.execute());
    assertThat(exception).hasMessageThat().contains("File '" + outputPath + "' already exists.");
}
Also used : DeviceSpec(com.android.bundle.Devices.DeviceSpec) Path(java.nio.file.Path) Test(org.junit.Test)

Example 88 with DeviceSpec

use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.

the class GetSizeCommandTest method builderAndFlagsConstruction_optionalDeviceSpec_inJavaViaApi_equivalent.

@Test
public void builderAndFlagsConstruction_optionalDeviceSpec_inJavaViaApi_equivalent() throws Exception {
    DeviceSpec deviceSpec = deviceWithSdk(21);
    Path deviceSpecFile = createDeviceSpecFile(deviceSpec, tmpDir.resolve("device.json"));
    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.
    "--device-spec=" + deviceSpecFile));
    GetSizeCommand fromBuilderApi = GetSizeCommand.builder().setApksArchivePath(apksArchiveFile).setDeviceSpec(deviceSpec).setGetSizeSubCommand(GetSizeSubcommand.TOTAL).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 89 with DeviceSpec

use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.

the class GetSizeCommandTest method checkFlagsConstructionWithDeviceSpec.

@Test
@Theory
public void checkFlagsConstructionWithDeviceSpec(@FromDataPoints("deviceSpecs") String deviceSpecPath) throws Exception {
    DeviceSpec.Builder expectedDeviceSpecBuilder = DeviceSpec.newBuilder();
    try (Reader reader = TestData.openReader(deviceSpecPath)) {
        JsonFormat.parser().merge(reader, expectedDeviceSpecBuilder);
    }
    DeviceSpec expectedDeviceSpec = expectedDeviceSpecBuilder.build();
    BuildApksResult tableOfContentsProto = BuildApksResult.getDefaultInstance();
    Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
    Path deviceSpecFile = copyToTempDir(deviceSpecPath);
    GetSizeCommand command = GetSizeCommand.fromFlags(new FlagParser().parse("get-size", "total", "--device-spec=" + deviceSpecFile, "--apks=" + apksArchiveFile));
    assertThat(command.getDeviceSpec()).isEqualTo(expectedDeviceSpec);
}
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) Reader(java.io.Reader) FlagParser(com.android.tools.build.bundletool.flags.FlagParser) Test(org.junit.Test) Theory(org.junit.experimental.theories.Theory)

Example 90 with DeviceSpec

use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.

the class GetSizeCommandTest 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 = BuildApksResult.getDefaultInstance();
    Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
    ParsedFlags flags = new FlagParser().parse("get-size", "total", "--device-spec=" + deviceSpecFile, "--apks=" + apksArchiveFile);
    Throwable exception = assertThrows(InvalidDeviceSpecException.class, () -> GetSizeCommand.fromFlags(flags));
    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) ParsedFlags(com.android.tools.build.bundletool.flags.ParsedFlags) FlagParser(com.android.tools.build.bundletool.flags.FlagParser) Test(org.junit.Test)

Aggregations

DeviceSpec (com.android.bundle.Devices.DeviceSpec)124 Test (org.junit.Test)113 Path (java.nio.file.Path)71 BuildApksResult (com.android.bundle.Commands.BuildApksResult)68 ZipPath (com.android.tools.build.bundletool.model.ZipPath)64 FakeAdbServer (com.android.tools.build.bundletool.testing.FakeAdbServer)19 FlagParser (com.android.tools.build.bundletool.flags.FlagParser)18 AdbServer (com.android.tools.build.bundletool.device.AdbServer)15 ImmutableSet (com.google.common.collect.ImmutableSet)14 Theory (org.junit.experimental.theories.Theory)13 IncompatibleDeviceException (com.android.tools.build.bundletool.model.exceptions.IncompatibleDeviceException)12 Variant (com.android.bundle.Commands.Variant)11 InvalidCommandException (com.android.tools.build.bundletool.model.exceptions.InvalidCommandException)11 ZipFile (java.util.zip.ZipFile)11 ApkSet (com.android.bundle.Commands.ApkSet)10 ImmutableList (com.google.common.collect.ImmutableList)9 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)9 ImmutableMap (com.google.common.collect.ImmutableMap)8 SystemEnvironmentProvider (com.android.tools.build.bundletool.model.utils.SystemEnvironmentProvider)7 PrintStream (java.io.PrintStream)7