Search in sources :

Example 76 with FlagParser

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

the class BuildSdkApksCommandTest method buildingCommandViaFlags_sdkBundlePathNotSet.

@Test
public void buildingCommandViaFlags_sdkBundlePathNotSet() {
    Throwable e = assertThrows(RequiredFlagNotSetException.class, () -> BuildSdkApksCommand.fromFlags(new FlagParser().parse("")));
    assertThat(e).hasMessageThat().contains("Missing the required --sdk-bundle flag");
}
Also used : FlagParser(com.android.tools.build.bundletool.flags.FlagParser) Test(org.junit.Test)

Example 77 with FlagParser

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

the class ExtractApksCommandTest method permanentlyMergedModule.

@Test
public void permanentlyMergedModule() 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)))).addPermanentlyFusedModules(PermanentlyFusedModule.newBuilder().setName("permanent").build()).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=permanent"));
    ImmutableList<Path> matchedApks = command.execute();
    assertThat(matchedApks.stream().map(apk -> apk.getFileName().toString())).containsExactly("apkL-base.apk");
}
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 78 with FlagParser

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

the class ExtractApksCommandTest method builderAndFlagsConstruction_inJavaViaFiles_equivalent.

@Test
public void builderAndFlagsConstruction_inJavaViaFiles_equivalent() throws Exception {
    Path deviceSpecFile = createDeviceSpecFile(deviceWithSdk(21), 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));
    ExtractApksCommand fromBuilderApi = ExtractApksCommand.builder().setApksArchivePath(apksArchiveFile).setDeviceSpec(deviceSpecFile).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)

Example 79 with FlagParser

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

the class ExtractApksCommandTest method deviceSpecFromPbJson.

@Test
public void deviceSpecFromPbJson() throws Exception {
    DeviceSpec.Builder expectedDeviceSpecBuilder = DeviceSpec.newBuilder();
    try (Reader reader = TestData.openReader("testdata/device/pixel2_spec.json")) {
        JsonFormat.parser().merge(reader, expectedDeviceSpecBuilder);
    }
    DeviceSpec expectedDeviceSpec = expectedDeviceSpecBuilder.build();
    BuildApksResult tableOfContentsProto = minimalApkSet();
    Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
    Path deviceSpecFile = copyToTempDir("testdata/device/pixel2_spec.json");
    ExtractApksCommand command = ExtractApksCommand.fromFlags(new FlagParser().parse("--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)

Example 80 with FlagParser

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

the class ExtractApksCommandTest method nonExistentDeviceSpecFile_throws.

@Test
public void nonExistentDeviceSpecFile_throws() throws Exception {
    Path apksArchiveFile = createApksArchiveFile(minimalApkSet(), tmpDir.resolve("bundle.apks"));
    Throwable exception = assertThrows(IllegalArgumentException.class, () -> ExtractApksCommand.fromFlags(new FlagParser().parse("--device-spec=not-found.pb", "--apks=" + apksArchiveFile)));
    assertThat(exception).hasMessageThat().contains("File 'not-found.pb' 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