Search in sources :

Example 6 with Password

use of com.android.tools.build.bundletool.model.Password in project bundletool by google.

the class FlagTest method passwordFlag_inFile_withCarriageReturnAndLineFeedAtTheEnd.

@Test
public void passwordFlag_inFile_withCarriageReturnAndLineFeedAtTheEnd() throws Exception {
    Path passwordFile = tempFolder.getRoot().toPath().resolve("myPassword.txt");
    Files.write(passwordFile, new String("hello\r\n").getBytes(UTF_8));
    Flag<Password> flag = Flag.password("testFlag");
    ParsedFlags parsedFlags = new FlagParser().parse("--testFlag=file:" + passwordFile);
    String password = new String(flag.getRequiredValue(parsedFlags).getValue().getPassword());
    assertThat(password).isEqualTo("hello");
}
Also used : Path(java.nio.file.Path) Password(com.android.tools.build.bundletool.model.Password) Test(org.junit.Test)

Example 7 with Password

use of com.android.tools.build.bundletool.model.Password in project bundletool by google.

the class BuildApksCommand method populateSigningConfigurationFromFlags.

private static void populateSigningConfigurationFromFlags(Builder buildApksCommand, ParsedFlags flags, PrintStream out, SystemEnvironmentProvider systemEnvironmentProvider) {
    // Signing-related arguments.
    Optional<Path> keystorePath = KEYSTORE_FLAG.getValue(flags);
    Optional<String> keyAlias = KEY_ALIAS_FLAG.getValue(flags);
    Optional<Password> keystorePassword = KEYSTORE_PASSWORD_FLAG.getValue(flags);
    Optional<Password> keyPassword = KEY_PASSWORD_FLAG.getValue(flags);
    Optional<Integer> minV3RotationApi = MINIMUM_V3_ROTATION_API_VERSION_FLAG.getValue(flags);
    Optional<Integer> rotationMinSdkVersion = ROTATION_MINIMUM_SDK_VERSION_FLAG.getValue(flags);
    if (keystorePath.isPresent() && keyAlias.isPresent()) {
        SignerConfig signerConfig = SignerConfig.extractFromKeystore(keystorePath.get(), keyAlias.get(), keystorePassword, keyPassword);
        SigningConfiguration.Builder builder = SigningConfiguration.builder().setSignerConfig(signerConfig).setMinimumV3RotationApiVersion(minV3RotationApi).setRotationMinSdkVersion(rotationMinSdkVersion);
        populateLineageFromFlags(builder, flags);
        buildApksCommand.setSigningConfiguration(builder.build());
    } else if (keystorePath.isPresent() && !keyAlias.isPresent()) {
        throw InvalidCommandException.builder().withInternalMessage("Flag --ks-key-alias is required when --ks is set.").build();
    } else if (!keystorePath.isPresent() && keyAlias.isPresent()) {
        throw InvalidCommandException.builder().withInternalMessage("Flag --ks is required when --ks-key-alias is set.").build();
    } else {
        // Try to use debug keystore if present.
        Optional<SigningConfiguration> debugConfig = DebugKeystoreUtils.getDebugSigningConfiguration(systemEnvironmentProvider);
        if (debugConfig.isPresent()) {
            out.printf("INFO: The APKs will be signed with the debug keystore found at '%s'.%n", DebugKeystoreUtils.DEBUG_KEYSTORE_CACHE.getUnchecked(systemEnvironmentProvider).get());
            buildApksCommand.setSigningConfiguration(debugConfig.get());
        } else {
            out.println("WARNING: The APKs won't be signed and thus not installable unless you also pass a " + "keystore via the flag --ks. See the command help for more information.");
        }
    }
}
Also used : Path(java.nio.file.Path) SigningConfiguration(com.android.tools.build.bundletool.model.SigningConfiguration) SignerConfig(com.android.tools.build.bundletool.model.SignerConfig) Password(com.android.tools.build.bundletool.model.Password)

Example 8 with Password

use of com.android.tools.build.bundletool.model.Password in project bundletool by google.

the class AddTransparencyCommand method fromFlagsInDefaultMode.

private static AddTransparencyCommand fromFlagsInDefaultMode(ParsedFlags flags) {
    Path keystorePath = KEYSTORE_FLAG.getRequiredValue(flags);
    String keyAlias = KEY_ALIAS_FLAG.getRequiredValue(flags);
    Optional<Password> keystorePassword = KEYSTORE_PASSWORD_FLAG.getValue(flags);
    Optional<Password> keyPassword = KEY_PASSWORD_FLAG.getValue(flags);
    SignerConfig signerConfig = SignerConfig.extractFromKeystore(keystorePath, keyAlias, keystorePassword, keyPassword);
    AddTransparencyCommand.Builder addTransparencyCommandBuilder = AddTransparencyCommand.builder().setMode(Mode.DEFAULT).setBundlePath(BUNDLE_LOCATION_FLAG.getRequiredValue(flags)).setOutputPath(OUTPUT_FLAG.getRequiredValue(flags)).setDexMergingChoice(DEX_MERGING_CHOICE_FLAG.getValue(flags).orElse(DexMergingChoice.ASK_IN_CONSOLE)).setSignerConfig(signerConfig);
    flags.checkNoUnknownFlags();
    return addTransparencyCommandBuilder.build();
}
Also used : Path(java.nio.file.Path) SignerConfig(com.android.tools.build.bundletool.model.SignerConfig) Password(com.android.tools.build.bundletool.model.Password)

Aggregations

Password (com.android.tools.build.bundletool.model.Password)8 Path (java.nio.file.Path)8 Test (org.junit.Test)4 SignerConfig (com.android.tools.build.bundletool.model.SignerConfig)3 SigningConfiguration (com.android.tools.build.bundletool.model.SigningConfiguration)3