Search in sources :

Example 1 with FakeSystemEnvironmentProvider

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

the class BuildApksConnectedDeviceTest method setUp.

@Before
public void setUp() throws Exception {
    tmpDir = tmp.getRoot().toPath();
    bundlePath = tmpDir.resolve("bundle");
    outputDir = tmp.newFolder("output").toPath();
    outputFilePath = outputDir.resolve("app.apks");
    sdkDirPath = Files.createDirectory(tmpDir.resolve("android-sdk"));
    setUpAdb(sdkDirPath);
    this.androidHomeProvider = new FakeSystemEnvironmentProvider(ImmutableMap.of(ANDROID_HOME, sdkDirPath.toString()));
}
Also used : FakeSystemEnvironmentProvider(com.android.tools.build.bundletool.testing.FakeSystemEnvironmentProvider) Before(org.junit.Before)

Example 2 with FakeSystemEnvironmentProvider

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

the class InstallApksCommandTest method setUp.

@Before
public void setUp() throws Exception {
    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);
    simpleApksPath = createApksArchiveFile(createSimpleTableOfContent(ZipPath.create("base-master.apk")), tmpDir.resolve("simple-bundle.apks"));
    this.systemEnvironmentProvider = new FakeSystemEnvironmentProvider(ImmutableMap.of(ANDROID_HOME, sdkDirPath.toString(), ANDROID_SERIAL, DEVICE_ID));
}
Also used : FakeSystemEnvironmentProvider(com.android.tools.build.bundletool.testing.FakeSystemEnvironmentProvider) Before(org.junit.Before)

Example 3 with FakeSystemEnvironmentProvider

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

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

the class DebugKeystoreUtilsTest method debugKeystore_userHome_secondPreference.

@Test
public void debugKeystore_userHome_secondPreference() throws Exception {
    Path androidSdkHome = tmpDir.resolve("androidSdkHome");
    Files.createDirectories(androidSdkHome);
    Path homeDir = tmpDir.resolve("home");
    Path homeDebugKey = homeDir.resolve(".android").resolve("debug.keystore");
    FileUtils.createParentDirectories(homeDebugKey);
    Files.write(homeDebugKey, new byte[0]);
    Path homeEnvDir = tmpDir.resolve("homeEnv");
    Path homeEnvDebugKey = homeEnvDir.resolve(".android").resolve("debug.keystore");
    FileUtils.createParentDirectories(homeEnvDebugKey);
    Files.write(homeEnvDebugKey, new byte[0]);
    FakeSystemEnvironmentProvider fakeEnvironmentVariableProvider = new FakeSystemEnvironmentProvider(/* variables= */
    ImmutableMap.of("ANDROID_SDK_HOME", androidSdkHome.toString(), "HOME", homeEnvDir.toString()), /* properties= */
    ImmutableMap.of(USER_HOME.key(), homeDir.toString()));
    assertThat(DebugKeystoreUtils.DEBUG_KEYSTORE_CACHE.get(fakeEnvironmentVariableProvider)).hasValue(homeDebugKey);
}
Also used : Path(java.nio.file.Path) FakeSystemEnvironmentProvider(com.android.tools.build.bundletool.testing.FakeSystemEnvironmentProvider) Test(org.junit.Test)

Example 5 with FakeSystemEnvironmentProvider

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

the class DebugKeystoreUtilsTest method debugKeystore_notFound.

@Test
public void debugKeystore_notFound() throws Exception {
    Path androidSdkHome = tmpDir.resolve("androidSdkHome").resolve(".android");
    Files.createDirectories(androidSdkHome);
    Path homeDir = tmpDir.resolve("home");
    Files.createDirectories(homeDir);
    FakeSystemEnvironmentProvider fakeEnvironmentVariableProvider = new FakeSystemEnvironmentProvider(/* variables= */
    ImmutableMap.of("ANDROID_SDK_HOME", tmpDir.resolve("androidSdkHome").toString(), "HOME", homeDir.toString()), /* properties= */
    ImmutableMap.of(USER_HOME.key(), homeDir.toString()));
    assertThat(DebugKeystoreUtils.DEBUG_KEYSTORE_CACHE.get(fakeEnvironmentVariableProvider)).isEmpty();
}
Also used : Path(java.nio.file.Path) FakeSystemEnvironmentProvider(com.android.tools.build.bundletool.testing.FakeSystemEnvironmentProvider) 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