Skip to content

Add FIS Kotlin Extensions SDK. #1901

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions firebase-installations/ktx/api.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Signature format: 2.0
package com.google.firebase.installations.ktx {

public final class InstallationsKt {
ctor public InstallationsKt();
method @NonNull public static com.google.firebase.installations.FirebaseInstallations getInstallations(@NonNull com.google.firebase.ktx.Firebase);
method @NonNull public static com.google.firebase.installations.FirebaseInstallations installations(@NonNull com.google.firebase.ktx.Firebase, @NonNull com.google.firebase.FirebaseApp app);
}

}

55 changes: 55 additions & 0 deletions firebase-installations/ktx/ktx.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

plugins {
id 'firebase-library'
id 'kotlin-android'
}

firebaseLibrary {
releaseWith project(':firebase-installations')
publishJavadoc = true
publishSources = true
}

android {
compileSdkVersion project.targetSdkVersion
defaultConfig {
minSdkVersion project.minSdkVersion
multiDexEnabled true
targetSdkVersion project.targetSdkVersion
versionName version
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
test.java.srcDirs += 'src/test/kotlin'
androidTest.java.srcDirs += 'src/androidTest/kotlin'
}
testOptions.unitTests.includeAndroidResources = true
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"

implementation project(':firebase-common')
implementation project(':firebase-common:ktx')
implementation project(':firebase-components')
implementation project(':firebase-installations')
implementation project(':firebase-installations-interop')

testImplementation "org.robolectric:robolectric:$robolectricVersion"
testImplementation 'junit:junit:4.13'
testImplementation "com.google.truth:truth:$googleTruthVersion"
}
13 changes: 13 additions & 0 deletions firebase-installations/ktx/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.firebase.installations.ktx">
<application>
<service
android:name="com.google.firebase.components.ComponentDiscoveryService"
android:exported="false">
<meta-data
android:name="com.google.firebase.components:com.google.firebase.installations.ktx.FirebaseInstallationsKtxRegistrar"
android:value="com.google.firebase.components.ComponentRegistrar" />
</service>
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.firebase.installations.ktx

import com.google.firebase.FirebaseApp
import com.google.firebase.components.Component
import com.google.firebase.components.ComponentRegistrar
import com.google.firebase.installations.FirebaseInstallations
import com.google.firebase.ktx.Firebase
import com.google.firebase.platforminfo.LibraryVersionComponent

/** Returns the [FirebaseInstallations] instance of the default [FirebaseApp]. */
val Firebase.installations: FirebaseInstallations
get() = FirebaseInstallations.getInstance()

/** Returns the [FirebaseInstallations] instance of a given [FirebaseApp]. */
fun Firebase.installations(app: FirebaseApp): FirebaseInstallations =
FirebaseInstallations.getInstance(app)

internal const val LIBRARY_NAME: String = "fire-installations-ktx"

/** @suppress */
class FirebaseInstallationsKtxRegistrar : ComponentRegistrar {
override fun getComponents(): List<Component<*>> =
listOf(LibraryVersionComponent.create(LIBRARY_NAME, BuildConfig.VERSION_NAME))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.firebase.installations.ktx

import com.google.common.truth.Truth
import com.google.firebase.FirebaseApp
import com.google.firebase.FirebaseOptions
import com.google.firebase.installations.FirebaseInstallations
import com.google.firebase.ktx.Firebase
import com.google.firebase.ktx.app
import com.google.firebase.ktx.initialize
import com.google.firebase.platforminfo.UserAgentPublisher
import org.junit.After
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment

const val APP_ID = "APP_ID"
const val API_KEY = "API_KEY"

const val EXISTING_APP = "existing"

abstract class BaseTestCase {
@Before
fun setUp() {
Firebase.initialize(
RuntimeEnvironment.application,
FirebaseOptions.Builder()
.setApplicationId(APP_ID)
.setApiKey(API_KEY)
.setProjectId("123")
.build()
)

Firebase.initialize(
RuntimeEnvironment.application,
FirebaseOptions.Builder()
.setApplicationId(APP_ID)
.setApiKey(API_KEY)
.setProjectId("123")
.build(),
EXISTING_APP
)
}

@After
fun cleanUp() {
FirebaseApp.clearInstancesForTest()
}
}

@RunWith(RobolectricTestRunner::class)
class FunctionsTests : BaseTestCase() {
@Test
fun `installations should delegate to FirebaseFunctions#getInstance()`() {
Truth.assertThat(Firebase.installations).isSameInstanceAs(FirebaseInstallations.getInstance())
}

@Test
fun `functions(app) should delegate to FirebaseFunctions#getInstance(FirebaseApp)`() {
val app = Firebase.app(EXISTING_APP)
Truth.assertThat(Firebase.installations(app)).isSameInstanceAs(FirebaseInstallations.getInstance(app))
}
}

@RunWith(RobolectricTestRunner::class)
class LibraryVersionTest : BaseTestCase() {
@Test
fun `library version should be registered with runtime`() {
val publisher = Firebase.app.get(UserAgentPublisher::class.java)
Truth.assertThat(publisher.userAgent).contains(LIBRARY_NAME)
}
}
1 change: 1 addition & 0 deletions subprojects.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ firebase-inappmessaging-display:ktx
firebase-installations-interop
firebase-installations
firebase-installations:customer-lint-checks
firebase-installations:ktx
firebase-segmentation
firebase-storage
firebase-storage:ktx
Expand Down