Search in sources :

Example 6 with FlagParser

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

the class AddTransparencyCommandTest method buildingCommandViaFlags_injectSignatureMode_unrecognizedFlag.

@Test
public void buildingCommandViaFlags_injectSignatureMode_unrecognizedFlag() {
    Throwable e = assertThrows(UnknownFlagsException.class, () -> AddTransparencyCommand.fromFlags(new FlagParser().parse("--mode=inject_signature", "--bundle=" + bundlePath, "--output=" + outputBundlePath, "--transparency-signature=" + transparencySignatureFilePath, "--transparency-key-certificate=" + transparencyKeyCertificatePath, "--ks=" + keystorePath)));
    assertThat(e).hasMessageThat().contains("Unrecognized flags");
}
Also used : FlagParser(com.android.tools.build.bundletool.flags.FlagParser) Test(org.junit.Test)

Example 7 with FlagParser

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

the class AddTransparencyCommandTest method buildingCommandViaFlags_defaultMode_unknownFlag.

@Test
public void buildingCommandViaFlags_defaultMode_unknownFlag() {
    Throwable e = assertThrows(UnknownFlagsException.class, () -> AddTransparencyCommand.fromFlags(new FlagParser().parse("--bundle=" + bundlePath, "--output=" + outputBundlePath, "--ks=" + keystorePath, "--ks-key-alias=" + KEY_ALIAS, "--ks-pass=pass:" + KEYSTORE_PASSWORD, "--key-pass=pass:" + KEY_PASSWORD, "--unknownFlag=hello")));
    assertThat(e).hasMessageThat().contains("Unrecognized flags");
}
Also used : FlagParser(com.android.tools.build.bundletool.flags.FlagParser) Test(org.junit.Test)

Example 8 with FlagParser

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

the class BuildApksCommandTest method populateLineage_apkFile.

@Test
public void populateLineage_apkFile() throws Exception {
    SigningCertificateLineage.SignerConfig signerConfig = new SigningCertificateLineage.SignerConfig.Builder(privateKey, certificate).build();
    SigningCertificateLineage.SignerConfig oldestSignerConfig = new SigningCertificateLineage.SignerConfig.Builder(oldestSignerPrivateKey, oldestSignerCertificate).build();
    SigningCertificateLineage lineage = new SigningCertificateLineage.Builder(oldestSignerConfig, signerConfig).build();
    com.android.tools.build.bundletool.model.SignerConfig oldestSigner = com.android.tools.build.bundletool.model.SignerConfig.builder().setPrivateKey(oldestSignerPrivateKey).setCertificates(ImmutableList.of(oldestSignerCertificate)).build();
    TestComponent.useTestModule(this, TestModule.builder().withSigningConfig(SigningConfiguration.builder().setSignerConfig(privateKey, certificate).setSigningCertificateLineage(lineage).setOldestSigner(oldestSigner).build()).build());
    File lineageFile = createMinimalistSignedApkFile().toFile();
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    BuildApksCommand commandViaFlags = BuildApksCommand.fromFlags(new FlagParser().parse("--bundle=" + bundlePath, "--output=" + outputFilePath, "--aapt2=" + AAPT2_PATH, "--ks=" + keystorePath, "--ks-key-alias=" + KEY_ALIAS, "--ks-pass=pass:" + KEYSTORE_PASSWORD, "--key-pass=pass:" + KEY_PASSWORD, "--lineage=" + lineageFile, "--oldest-signer=" + oldestSignerPropertiesPath), new PrintStream(output), systemEnvironmentProvider, fakeAdbServer);
    SigningConfiguration signingConfiguration = commandViaFlags.getSigningConfiguration().get();
    assertThat(signingConfiguration.getSigningCertificateLineage().get().getCertificatesInLineage()).containsExactly(oldestSignerCertificate, certificate);
    assertThat(signingConfiguration.getOldestSigner().get().getPrivateKey()).isEqualTo(oldestSignerConfig.getPrivateKey());
    assertThat(signingConfiguration.getOldestSigner().get().getCertificates()).containsExactly(oldestSignerConfig.getCertificate());
}
Also used : PrintStream(java.io.PrintStream) ApksigSigningConfiguration(com.android.tools.build.bundletool.model.ApksigSigningConfiguration) SigningConfiguration(com.android.tools.build.bundletool.model.SigningConfiguration) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SigningCertificateLineage(com.android.apksig.SigningCertificateLineage) SignerConfig(com.android.tools.build.bundletool.model.SignerConfig) SignerConfig(com.android.tools.build.bundletool.model.SignerConfig) FlagParser(com.android.tools.build.bundletool.flags.FlagParser) DeviceFactory.createDeviceSpecFile(com.android.tools.build.bundletool.testing.DeviceFactory.createDeviceSpecFile) File(java.io.File) CodeRelatedFile(com.android.bundle.CodeTransparencyOuterClass.CodeRelatedFile) Test(org.junit.Test)

Example 9 with FlagParser

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

the class BuildApksCommandTest method buildingViaFlagsAndBuilderHasSameResult_optionalUniversal.

@Test
public void buildingViaFlagsAndBuilderHasSameResult_optionalUniversal() throws Exception {
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    BuildApksCommand commandViaFlags = BuildApksCommand.fromFlags(new FlagParser().parse("--bundle=" + bundlePath, "--output=" + outputFilePath, "--aapt2=" + AAPT2_PATH, // Optional values.
    "--mode=UNIVERSAL"), new PrintStream(output), systemEnvironmentProvider, fakeAdbServer);
    BuildApksCommand.Builder commandViaBuilder = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).setApkBuildMode(UNIVERSAL).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 10 with FlagParser

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

the class BuildApksCommandTest method buildingViaFlagsAndBuilderHasSameResult_stamp_separateKeystore.

@Test
public void buildingViaFlagsAndBuilderHasSameResult_stamp_separateKeystore() throws Exception {
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    BuildApksCommand commandViaFlags = BuildApksCommand.fromFlags(new FlagParser().parse("--bundle=" + bundlePath, "--output=" + outputFilePath, "--aapt2=" + AAPT2_PATH, "--ks=" + keystorePath, "--ks-key-alias=" + KEY_ALIAS, "--ks-pass=pass:" + KEYSTORE_PASSWORD, "--key-pass=pass:" + KEY_PASSWORD, "--create-stamp=" + true, "--stamp-ks=" + stampKeystorePath, "--stamp-ks-pass=pass:" + STAMP_KEYSTORE_PASSWORD), new PrintStream(output), systemEnvironmentProvider, fakeAdbServer);
    SigningConfiguration signingConfiguration = SigningConfiguration.builder().setSignerConfig(privateKey, certificate).build();
    SigningConfiguration stampSigningConfiguration = SigningConfiguration.builder().setSignerConfig(stampPrivateKey, stampCertificate).build();
    BuildApksCommand.Builder commandViaBuilder = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).setSigningConfiguration(signingConfiguration).setSourceStamp(SourceStamp.builder().setSigningConfiguration(stampSigningConfiguration).build()).setAapt2Command(commandViaFlags.getAapt2Command().get()).setExecutorServiceInternal(commandViaFlags.getExecutorService()).setExecutorServiceCreatedByBundleTool(true).setOutputPrintStream(commandViaFlags.getOutputPrintStream().get());
    DebugKeystoreUtils.getDebugSigningConfiguration(systemEnvironmentProvider).ifPresent(commandViaBuilder::setSigningConfiguration);
    assertThat(commandViaBuilder.build().getSourceStamp()).isEqualTo(commandViaFlags.getSourceStamp());
    assertThat(commandViaBuilder.build().getSigningConfiguration()).isEqualTo(commandViaFlags.getSigningConfiguration());
}
Also used : PrintStream(java.io.PrintStream) ApksigSigningConfiguration(com.android.tools.build.bundletool.model.ApksigSigningConfiguration) SigningConfiguration(com.android.tools.build.bundletool.model.SigningConfiguration) 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