Search in sources :

Example 11 with FakeSystemEnvironmentProvider

use of com.android.tools.build.bundletool.testing.FakeSystemEnvironmentProvider in project bundletool by google.

the class InstallMultiApksCommandTest method setUp.

@Before
public void setUp() throws IOException {
    tmpDir = tmp.getRoot().toPath();
    sdkDirPath = Files.createDirectory(tmpDir.resolve("android-sdk"));
    adbPath = sdkDirPath.resolve("platform-tools").resolve("adb");
    Files.createDirectories(adbPath.getParent());
    Files.createFile(adbPath);
    adbPath.toFile().setExecutable(true);
    systemEnvironmentProvider = new FakeSystemEnvironmentProvider(ImmutableMap.of(ANDROID_HOME, sdkDirPath.toString(), ANDROID_SERIAL, DEVICE_ID));
    device = FakeDevice.fromDeviceSpec(DEVICE_ID, DeviceState.ONLINE, qDeviceWithLocales("en-US"));
    adbCommandExecuted = false;
}
Also used : FakeSystemEnvironmentProvider(com.android.tools.build.bundletool.testing.FakeSystemEnvironmentProvider) Before(org.junit.Before)

Example 12 with FakeSystemEnvironmentProvider

use of com.android.tools.build.bundletool.testing.FakeSystemEnvironmentProvider 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 13 with FakeSystemEnvironmentProvider

use of com.android.tools.build.bundletool.testing.FakeSystemEnvironmentProvider 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 14 with FakeSystemEnvironmentProvider

use of com.android.tools.build.bundletool.testing.FakeSystemEnvironmentProvider 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)

Example 15 with FakeSystemEnvironmentProvider

use of com.android.tools.build.bundletool.testing.FakeSystemEnvironmentProvider in project bundletool by google.

the class BuildApksCommandTest method noKeystoreProvidedPrintsWarning_debugKeystore.

@Test
public void noKeystoreProvidedPrintsWarning_debugKeystore() throws Exception {
    Path debugKeystorePath = tmpDir.resolve(".android").resolve("debug.keystore");
    FileUtils.createParentDirectories(debugKeystorePath);
    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.fromFlags(new FlagParser().parse("--bundle=" + bundlePath, "--output=" + outputFilePath, "--aapt2=" + AAPT2_PATH), new PrintStream(output), provider, fakeAdbServer);
    assertThat(new String(output.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) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FlagParser(com.android.tools.build.bundletool.flags.FlagParser) Test(org.junit.Test)

Aggregations

FakeSystemEnvironmentProvider (com.android.tools.build.bundletool.testing.FakeSystemEnvironmentProvider)15 Test (org.junit.Test)11 Path (java.nio.file.Path)9 FlagParser (com.android.tools.build.bundletool.flags.FlagParser)6 SystemEnvironmentProvider (com.android.tools.build.bundletool.model.utils.SystemEnvironmentProvider)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 PrintStream (java.io.PrintStream)5 ZipPath (com.android.tools.build.bundletool.model.ZipPath)4 Before (org.junit.Before)4 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