Search in sources :

Example 46 with FlagParser

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.");
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) InvalidCommandException(com.android.tools.build.bundletool.model.exceptions.InvalidCommandException) FlagParser(com.android.tools.build.bundletool.flags.FlagParser) Test(org.junit.Test)

Example 47 with FlagParser

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.");
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) FlagParser(com.android.tools.build.bundletool.flags.FlagParser) TestUtils.expectMissingRequiredBuilderPropertyException(com.android.tools.build.bundletool.testing.TestUtils.expectMissingRequiredBuilderPropertyException) InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) TestUtils.expectMissingRequiredFlagException(com.android.tools.build.bundletool.testing.TestUtils.expectMissingRequiredFlagException) IOException(java.io.IOException) InvalidCommandException(com.android.tools.build.bundletool.model.exceptions.InvalidCommandException) Test(org.junit.Test)

Example 48 with FlagParser

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");
}
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 49 with FlagParser

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)));
}
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 50 with FlagParser

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);
}
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)

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