use of com.android.tools.build.bundletool.flags.FlagParser in project bundletool by google.
the class BuildBundleCommandTest method metadataFileDoesNotExist_throws.
@Test
public void metadataFileDoesNotExist_throws() throws Exception {
Path baseModulePath = buildSimpleModule("base");
Path nonExistentFilePath = tmpDir.resolve("metadata.txt");
InvalidCommandException exceptionViaApi = assertThrows(InvalidCommandException.class, () -> BuildBundleCommand.builder().setOutputPath(bundlePath).setModulesPaths(ImmutableList.of(baseModulePath)).addMetadataFile("com.some.namespace", "file-name", nonExistentFilePath).build().execute());
assertThat(exceptionViaApi).hasMessageThat().matches("Metadata file .* does not exist.");
InvalidCommandException exceptionViaFlags = assertThrows(InvalidCommandException.class, () -> BuildBundleCommand.fromFlags(new FlagParser().parse("--output=" + bundlePath, "--modules=" + baseModulePath, "--metadata-file=com.some.namespace/file-name:" + nonExistentFilePath)));
assertThat(exceptionViaFlags).hasMessageThat().matches("Metadata file .* does not exist.");
}
use of com.android.tools.build.bundletool.flags.FlagParser in project bundletool by google.
the class BuildBundleCommandTest method bundleConfig_invalidJsonFile_throws.
@Test
public void bundleConfig_invalidJsonFile_throws() throws Exception {
Path modulePath = createSimpleBaseModule();
Path bundleConfigJsonPath = tmp.newFile("BundleConfig.pb.json").toPath();
Files.write(bundleConfigJsonPath, "{ \"compression\": { \"uncompressedGlob\": \"foo\" } }".getBytes(UTF_8));
Exception e = assertThrows(InvalidCommandException.class, () -> BuildBundleCommand.fromFlags(new FlagParser().parse("--output=" + bundlePath, "--modules=" + modulePath, "--config=" + bundleConfigJsonPath)));
assertThat(e).hasMessageThat().matches("The file '.*' is not a valid BundleConfig JSON file.");
}
use of com.android.tools.build.bundletool.flags.FlagParser in project bundletool by google.
the class BuildBundleCommandTest method metadataNamespaceInvalid_throws.
@Test
public void metadataNamespaceInvalid_throws() throws Exception {
Path baseModulePath = buildSimpleModule("base");
Path metadataFilePath = Files.createFile(tmpDir.resolve("metadata.txt"));
IllegalArgumentException exceptionViaApi = assertThrows(IllegalArgumentException.class, () -> BuildBundleCommand.builder().setOutputPath(bundlePath).setModulesPaths(ImmutableList.of(baseModulePath)).addMetadataFile("not_namespace_dir", "file-name", metadataFilePath).build().execute());
assertThat(exceptionViaApi).hasMessageThat().contains("Top-level directories for metadata files must be namespaced");
IllegalArgumentException exceptionViaFlags = assertThrows(IllegalArgumentException.class, () -> BuildBundleCommand.fromFlags(new FlagParser().parse("--output=" + bundlePath, "--modules=" + baseModulePath, "--metadata-file=not_namespace_dir/file-name:" + metadataFilePath)));
assertThat(exceptionViaFlags).hasMessageThat().contains("Top-level directories for metadata files must be namespaced");
}
use of com.android.tools.build.bundletool.flags.FlagParser in project bundletool by google.
the class BuildBundleCommandTest method outputNotSet_throws.
@Test
public void outputNotSet_throws() throws Exception {
Path baseModulePath = buildSimpleModule("base");
expectMissingRequiredBuilderPropertyException("outputPath", () -> BuildBundleCommand.builder().setModulesPaths(ImmutableList.of(baseModulePath)).build());
expectMissingRequiredFlagException("output", () -> BuildBundleCommand.fromFlags(new FlagParser().parse("--modules=" + baseModulePath)));
}
use of com.android.tools.build.bundletool.flags.FlagParser in project bundletool by google.
the class ExtractApksCommandTest method builderAndFlagsConstruction_inJavaViaProtos_equivalent.
@Test
public void builderAndFlagsConstruction_inJavaViaProtos_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));
ExtractApksCommand fromBuilderApi = ExtractApksCommand.builder().setApksArchivePath(apksArchiveFile).setDeviceSpec(deviceSpec).build();
assertThat(fromFlags).isEqualTo(fromBuilderApi);
}
Aggregations