Search in sources :

Example 41 with FlagParser

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

the class GetSizeCommandTest method builderAndFlagsConstruction_optionalModules_equivalent.

@Test
public void builderAndFlagsConstruction_optionalModules_equivalent() 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.
    "--modules=base"));
    GetSizeCommand fromBuilderApi = GetSizeCommand.builder().setApksArchivePath(apksArchiveFile).setModules(ImmutableSet.of("base")).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)

Example 42 with FlagParser

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

the class GetSizeCommandTest method nonExistentApksArchiveFile_throws.

@Test
public void nonExistentApksArchiveFile_throws() throws Exception {
    Path deviceSpecFile = createDeviceSpecFile(DeviceSpec.getDefaultInstance(), tmpDir.resolve("device.json"));
    ParsedFlags flags = new FlagParser().parse("get-size", "total", "--device-spec=" + deviceSpecFile, "--apks=nonexistent");
    Throwable exception = assertThrows(IllegalArgumentException.class, () -> GetSizeCommand.fromFlags(flags));
    assertThat(exception).hasMessageThat().contains("File 'nonexistent' was not found");
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) ParsedFlags(com.android.tools.build.bundletool.flags.ParsedFlags) FlagParser(com.android.tools.build.bundletool.flags.FlagParser) Test(org.junit.Test)

Example 43 with FlagParser

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

the class BuildBundleCommandTest method modulesNotSet_throws.

@Test
public void modulesNotSet_throws() throws Exception {
    expectMissingRequiredBuilderPropertyException("modulesPaths", () -> BuildBundleCommand.builder().setOutputPath(bundlePath).build());
    expectMissingRequiredFlagException("modules", () -> BuildBundleCommand.fromFlags(new FlagParser().parse("--output=" + bundlePath)));
}
Also used : FlagParser(com.android.tools.build.bundletool.flags.FlagParser) Test(org.junit.Test)

Example 44 with FlagParser

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

the class BuildBundleCommandTest method duplicateMetadataFiles_throws.

@Test
public void duplicateMetadataFiles_throws() throws Exception {
    Path baseModulePath = buildSimpleModule("base");
    Path metadataFile1 = Files.createFile(tmpDir.resolve("metadata1.txt"));
    Path metadataFile2 = Files.createFile(tmpDir.resolve("metadata2.txt"));
    IllegalArgumentException exceptionViaApi = assertThrows(IllegalArgumentException.class, () -> BuildBundleCommand.builder().setOutputPath(bundlePath).setModulesPaths(ImmutableList.of(baseModulePath)).addMetadataFile("com.some.namespace", "duplicate", metadataFile1).addMetadataFile("com.some.namespace", "duplicate", metadataFile2).build().execute());
    assertThat(exceptionViaApi).hasMessageThat().contains("Multiple entries with same key");
    IllegalArgumentException exceptionViaFlags = assertThrows(IllegalArgumentException.class, () -> BuildBundleCommand.fromFlags(new FlagParser().parse("--output=" + bundlePath, "--modules=" + baseModulePath, "--metadata-file=com.some.namespace/duplicate:" + metadataFile1, "--metadata-file=com.some.namespace/duplicate:" + metadataFile2)).execute());
    assertThat(exceptionViaFlags).hasMessageThat().contains("Multiple entries with same key");
}
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 45 with FlagParser

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

the class BuildBundleCommandTest method buildingViaFlagsAndBuilderHasSameResult_optionalMetadata.

@Test
public void buildingViaFlagsAndBuilderHasSameResult_optionalMetadata() throws Exception {
    Path baseModulePath = buildSimpleModule("base");
    Path featureModulePath = buildSimpleModule("feature");
    Path metadataFileAPath = Files.createFile(tmpDir.resolve("metadata-A.txt"));
    Path metadataFileBPath = Files.createFile(tmpDir.resolve("metadata-B.txt"));
    BuildBundleCommand commandViaBuilder = BuildBundleCommand.builder().setOutputPath(bundlePath).setModulesPaths(ImmutableList.of(baseModulePath, featureModulePath)).addMetadataFile("com.some.namespace", "metadata-A.txt", metadataFileAPath).addMetadataFile("com.some.namespace", "metadata-B.txt", metadataFileBPath).build();
    BuildBundleCommand commandViaFlags = BuildBundleCommand.fromFlags(new FlagParser().parse("--output=" + bundlePath, "--modules=" + baseModulePath + "," + featureModulePath, // Optional values.
    "--metadata-file=com.some.namespace/metadata-A.txt:" + metadataFileAPath, "--metadata-file=com.some.namespace/metadata-B.txt:" + metadataFileBPath));
    // Cannot compare the command objects directly, because the ByteSource instances in
    // BundleMetadata would not compare equal.
    assertThat(commandViaBuilder.getBundleMetadata().getFileContentMap().keySet()).containsExactlyElementsIn(commandViaFlags.getBundleMetadata().getFileContentMap().keySet());
}
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