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);
}
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");
}
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)));
}
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");
}
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());
}
Aggregations