Search in sources :

Example 11 with FlagParser

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

the class BuildApksCommandTest method buildingViaFlagsAndBuilderHasSameResult_optionalOverwrite.

@Test
public void buildingViaFlagsAndBuilderHasSameResult_optionalOverwrite() throws Exception {
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    BuildApksCommand commandViaFlags = BuildApksCommand.fromFlags(new FlagParser().parse("--bundle=" + bundlePath, "--output=" + outputFilePath, "--aapt2=" + AAPT2_PATH, // Optional values.
    "--overwrite"), new PrintStream(output), systemEnvironmentProvider, fakeAdbServer);
    BuildApksCommand.Builder commandViaBuilder = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).setOverwriteOutput(true).setAapt2Command(commandViaFlags.getAapt2Command().get()).setExecutorServiceInternal(commandViaFlags.getExecutorService()).setExecutorServiceCreatedByBundleTool(true).setOutputPrintStream(commandViaFlags.getOutputPrintStream().get());
    DebugKeystoreUtils.getDebugSigningConfiguration(systemEnvironmentProvider).ifPresent(commandViaBuilder::setSigningConfiguration);
    assertThat(commandViaBuilder.build()).isEqualTo(commandViaFlags);
}
Also used : PrintStream(java.io.PrintStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FlagParser(com.android.tools.build.bundletool.flags.FlagParser) Test(org.junit.Test)

Example 12 with FlagParser

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

the class BuildApksCommandTest method missingBundleFile_throws.

@Test
public void missingBundleFile_throws() throws Exception {
    Path bundlePath = tmpDir.resolve("bundle.aab");
    ParsedFlags flags = new FlagParser().parse("--bundle=" + bundlePath, "--output=" + outputFilePath);
    BuildApksCommand command = BuildApksCommand.fromFlags(flags, fakeAdbServer);
    Exception e = assertThrows(IllegalArgumentException.class, command::execute);
    assertThat(e).hasMessageThat().contains("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) FlagParseException(com.android.tools.build.bundletool.flags.FlagParser.FlagParseException) IOException(java.io.IOException) CommandExecutionException(com.android.tools.build.bundletool.model.exceptions.CommandExecutionException) JoseException(org.jose4j.lang.JoseException) 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) InvalidCommandException(com.android.tools.build.bundletool.model.exceptions.InvalidCommandException) Test(org.junit.Test)

Example 13 with FlagParser

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

the class BuildApksCommandTest method buildingViaFlagsAndBuilderHasSameResult_stamp_source.

@Test
public void buildingViaFlagsAndBuilderHasSameResult_stamp_source() throws Exception {
    BuildApksCommand commandViaFlags = BuildApksCommand.fromFlags(new FlagParser().parse("--bundle=" + bundlePath, "--output=" + outputFilePath, "--aapt2=" + AAPT2_PATH, // Optional values.
    "--ks=" + keystorePath, "--ks-key-alias=" + KEY_ALIAS, "--ks-pass=pass:" + KEYSTORE_PASSWORD, "--key-pass=pass:" + KEY_PASSWORD, "--create-stamp=" + true, "--stamp-source=" + STAMP_SOURCE), fakeAdbServer);
    SigningConfiguration signingConfiguration = SigningConfiguration.builder().setSignerConfig(privateKey, certificate).build();
    BuildApksCommand commandViaBuilder = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).setSigningConfiguration(signingConfiguration).setSourceStamp(SourceStamp.builder().setSigningConfiguration(signingConfiguration).setSource(STAMP_SOURCE).build()).setAapt2Command(commandViaFlags.getAapt2Command().get()).setExecutorServiceInternal(commandViaFlags.getExecutorService()).setExecutorServiceCreatedByBundleTool(true).setOutputPrintStream(commandViaFlags.getOutputPrintStream().get()).build();
    assertThat(commandViaBuilder.getSourceStamp()).isEqualTo(commandViaFlags.getSourceStamp());
    assertThat(commandViaBuilder.getSigningConfiguration()).isEqualTo(commandViaFlags.getSigningConfiguration());
}
Also used : ApksigSigningConfiguration(com.android.tools.build.bundletool.model.ApksigSigningConfiguration) SigningConfiguration(com.android.tools.build.bundletool.model.SigningConfiguration) FlagParser(com.android.tools.build.bundletool.flags.FlagParser) Test(org.junit.Test)

Example 14 with FlagParser

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

the class BuildApksCommandTest method stampKeystoreFlags_noKeyAlias_fails.

@Test
public void stampKeystoreFlags_noKeyAlias_fails() {
    InvalidCommandException e = assertThrows(InvalidCommandException.class, () -> BuildApksCommand.fromFlags(new FlagParser().parse("--bundle=" + bundlePath, "--output=" + outputFilePath, "--aapt2=" + AAPT2_PATH, "--create-stamp=" + true, "--stamp-ks=" + keystorePath), fakeAdbServer));
    assertThat(e).hasMessageThat().isEqualTo("Flag --stamp-key-alias or --ks-key-alias are required when --stamp-ks or --ks are" + " set.");
}
Also used : InvalidCommandException(com.android.tools.build.bundletool.model.exceptions.InvalidCommandException) FlagParser(com.android.tools.build.bundletool.flags.FlagParser) Test(org.junit.Test)

Example 15 with FlagParser

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

the class BuildApksCommandTest method buildingViaFlagsAndBuilderHasSameResult_optionalVerbose.

@Test
public void buildingViaFlagsAndBuilderHasSameResult_optionalVerbose() throws Exception {
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    BuildApksCommand commandViaFlags = BuildApksCommand.fromFlags(new FlagParser().parse("--bundle=" + bundlePath, "--output=" + outputFilePath, "--aapt2=" + AAPT2_PATH, // Optional values.
    "--verbose"), new PrintStream(output), systemEnvironmentProvider, fakeAdbServer);
    BuildApksCommand.Builder commandViaBuilder = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).setVerbose(true).setAapt2Command(commandViaFlags.getAapt2Command().get()).setExecutorServiceInternal(commandViaFlags.getExecutorService()).setExecutorServiceCreatedByBundleTool(true).setOutputPrintStream(commandViaFlags.getOutputPrintStream().get());
    DebugKeystoreUtils.getDebugSigningConfiguration(systemEnvironmentProvider).ifPresent(commandViaBuilder::setSigningConfiguration);
    assertThat(commandViaBuilder.build()).isEqualTo(commandViaFlags);
}
Also used : PrintStream(java.io.PrintStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) 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