Search in sources :

Example 1 with SystemEnvironmentProvider

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

the class BuildSdkApksCommandTest method noKeystoreProvidedPrintsInfo_debugKeystore.

@Test
public void noKeystoreProvidedPrintsInfo_debugKeystore() throws Exception {
    SystemEnvironmentProvider provider = new FakeSystemEnvironmentProvider(/* variables= */
    ImmutableMap.of(ANDROID_HOME, "/android/home", ANDROID_SERIAL, DEVICE_ID), /* properties= */
    ImmutableMap.of(USER_HOME.key(), tmpDir.toString()));
    Path debugKeystorePath = tmpDir.resolve(".android").resolve("debug.keystore");
    FileUtils.createParentDirectories(debugKeystorePath);
    createDebugKeystore(debugKeystorePath, DEBUG_KEYSTORE_PASSWORD, DEBUG_KEY_ALIAS, DEBUG_KEY_PASSWORD);
    try (ByteArrayOutputStream outputByteArrayStream = new ByteArrayOutputStream();
        PrintStream outputPrintStream = new PrintStream(outputByteArrayStream)) {
        BuildSdkApksCommand.fromFlags(getDefaultFlagsWithAdditionalFlags(), outputPrintStream, provider);
        assertThat(new String(outputByteArrayStream.toByteArray(), UTF_8)).contains("INFO: The APKs will be signed with the debug keystore");
    }
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) PrintStream(java.io.PrintStream) FakeSystemEnvironmentProvider(com.android.tools.build.bundletool.testing.FakeSystemEnvironmentProvider) FakeSystemEnvironmentProvider(com.android.tools.build.bundletool.testing.FakeSystemEnvironmentProvider) SystemEnvironmentProvider(com.android.tools.build.bundletool.model.utils.SystemEnvironmentProvider) DefaultSystemEnvironmentProvider(com.android.tools.build.bundletool.model.utils.DefaultSystemEnvironmentProvider) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 2 with SystemEnvironmentProvider

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

the class GetDeviceSpecCommandTest method fromFlagsEquivalentToBuilder_noDeviceId.

@Test
public void fromFlagsEquivalentToBuilder_noDeviceId() {
    SystemEnvironmentProvider androidHomeProvider = new FakeSystemEnvironmentProvider(ImmutableMap.of(ANDROID_HOME, sdkDirPath.toString()));
    Path outputPath = tmpDir.resolve("device.json");
    GetDeviceSpecCommand commandViaFlags = GetDeviceSpecCommand.fromFlags(new FlagParser().parse("--adb=" + adbPath, "--output=" + outputPath), androidHomeProvider, fakeServerOneDevice(lDeviceWithLocales("en-US")));
    GetDeviceSpecCommand commandViaBuilder = GetDeviceSpecCommand.builder().setAdbPath(adbPath).setOutputPath(outputPath).setAdbServer(commandViaFlags.getAdbServer()).build();
    assertThat(commandViaFlags).isEqualTo(commandViaBuilder);
}
Also used : Path(java.nio.file.Path) FakeSystemEnvironmentProvider(com.android.tools.build.bundletool.testing.FakeSystemEnvironmentProvider) FakeSystemEnvironmentProvider(com.android.tools.build.bundletool.testing.FakeSystemEnvironmentProvider) SystemEnvironmentProvider(com.android.tools.build.bundletool.model.utils.SystemEnvironmentProvider) FlagParser(com.android.tools.build.bundletool.flags.FlagParser) Test(org.junit.Test)

Example 3 with SystemEnvironmentProvider

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

the class BuildApksCommandTest method noKeystoreProvidedPrintsWarning.

@Test
public void noKeystoreProvidedPrintsWarning() {
    SystemEnvironmentProvider provider = new FakeSystemEnvironmentProvider(/* variables= */
    ImmutableMap.of(ANDROID_HOME, "/android/home", ANDROID_SERIAL, DEVICE_ID), /* properties= */
    ImmutableMap.of(USER_HOME.key(), "/"));
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    BuildApksCommand.fromFlags(new FlagParser().parse("--bundle=" + bundlePath, "--output=" + outputFilePath, "--aapt2=" + AAPT2_PATH), new PrintStream(output), provider, fakeAdbServer);
    assertThat(new String(output.toByteArray(), UTF_8)).contains("WARNING: The APKs won't be signed");
}
Also used : PrintStream(java.io.PrintStream) FakeSystemEnvironmentProvider(com.android.tools.build.bundletool.testing.FakeSystemEnvironmentProvider) FakeSystemEnvironmentProvider(com.android.tools.build.bundletool.testing.FakeSystemEnvironmentProvider) SystemEnvironmentProvider(com.android.tools.build.bundletool.model.utils.SystemEnvironmentProvider) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FlagParser(com.android.tools.build.bundletool.flags.FlagParser) Test(org.junit.Test)

Example 4 with SystemEnvironmentProvider

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

the class BuildApksCommandTest method stampKeystoreFlags_noKeystore_fails.

@Test
public void stampKeystoreFlags_noKeystore_fails() throws Exception {
    SystemEnvironmentProvider provider = new FakeSystemEnvironmentProvider(/* variables= */
    ImmutableMap.of(ANDROID_HOME, "/android/home", ANDROID_SERIAL, DEVICE_ID), /* properties= */
    ImmutableMap.of(USER_HOME.key(), "/"));
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    InvalidCommandException e = assertThrows(InvalidCommandException.class, () -> BuildApksCommand.fromFlags(new FlagParser().parse("--bundle=" + bundlePath, "--output=" + outputFilePath, "--aapt2=" + AAPT2_PATH, "--create-stamp=" + true), new PrintStream(output), provider, fakeAdbServer));
    assertThat(e).hasMessageThat().isEqualTo("No key was found to sign the stamp.");
}
Also used : PrintStream(java.io.PrintStream) InvalidCommandException(com.android.tools.build.bundletool.model.exceptions.InvalidCommandException) FakeSystemEnvironmentProvider(com.android.tools.build.bundletool.testing.FakeSystemEnvironmentProvider) FakeSystemEnvironmentProvider(com.android.tools.build.bundletool.testing.FakeSystemEnvironmentProvider) SystemEnvironmentProvider(com.android.tools.build.bundletool.model.utils.SystemEnvironmentProvider) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FlagParser(com.android.tools.build.bundletool.flags.FlagParser) Test(org.junit.Test)

Example 5 with SystemEnvironmentProvider

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

the class BuildApksCommandTest method buildingViaFlagsAndBuilderHasSameResult_stamp_debugKey.

@Test
public void buildingViaFlagsAndBuilderHasSameResult_stamp_debugKey() throws Exception {
    Path debugKeystorePath = tmpDir.resolve(".android").resolve("debug.keystore");
    FileUtils.createParentDirectories(debugKeystorePath);
    SigningConfiguration signingConfiguration = createDebugKeystore(debugKeystorePath, DEBUG_KEYSTORE_PASSWORD, DEBUG_KEY_ALIAS, DEBUG_KEY_PASSWORD);
    SystemEnvironmentProvider provider = new FakeSystemEnvironmentProvider(/* variables= */
    ImmutableMap.of(ANDROID_HOME, "/android/home", ANDROID_SERIAL, DEVICE_ID), /* properties= */
    ImmutableMap.of(USER_HOME.key(), tmpDir.toString()));
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    BuildApksCommand commandViaFlags = BuildApksCommand.fromFlags(new FlagParser().parse("--bundle=" + bundlePath, "--output=" + outputFilePath, "--aapt2=" + AAPT2_PATH, "--create-stamp=" + true), new PrintStream(output), provider, fakeAdbServer);
    BuildApksCommand commandViaBuilder = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).setSigningConfiguration(signingConfiguration).setSourceStamp(SourceStamp.builder().setSigningConfiguration(signingConfiguration).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 : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) PrintStream(java.io.PrintStream) ApksigSigningConfiguration(com.android.tools.build.bundletool.model.ApksigSigningConfiguration) SigningConfiguration(com.android.tools.build.bundletool.model.SigningConfiguration) FakeSystemEnvironmentProvider(com.android.tools.build.bundletool.testing.FakeSystemEnvironmentProvider) FakeSystemEnvironmentProvider(com.android.tools.build.bundletool.testing.FakeSystemEnvironmentProvider) SystemEnvironmentProvider(com.android.tools.build.bundletool.model.utils.SystemEnvironmentProvider) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FlagParser(com.android.tools.build.bundletool.flags.FlagParser) Test(org.junit.Test)

Aggregations

SystemEnvironmentProvider (com.android.tools.build.bundletool.model.utils.SystemEnvironmentProvider)6 FakeSystemEnvironmentProvider (com.android.tools.build.bundletool.testing.FakeSystemEnvironmentProvider)6 Test (org.junit.Test)6 FlagParser (com.android.tools.build.bundletool.flags.FlagParser)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 PrintStream (java.io.PrintStream)5 Path (java.nio.file.Path)4 ZipPath (com.android.tools.build.bundletool.model.ZipPath)3 ApksigSigningConfiguration (com.android.tools.build.bundletool.model.ApksigSigningConfiguration)1 SigningConfiguration (com.android.tools.build.bundletool.model.SigningConfiguration)1 InvalidCommandException (com.android.tools.build.bundletool.model.exceptions.InvalidCommandException)1 DefaultSystemEnvironmentProvider (com.android.tools.build.bundletool.model.utils.DefaultSystemEnvironmentProvider)1