Skip to content

Commit dc46eee

Browse files
authored
[Firebase Segmentation] Add custom installation id cache layer and tests for it. (#524)
* Add type arguments in StorageTaskManager (#517) * Output artifact list during local publishing. (#515) This effort replaces #494. * Implement Firebase segmentation SDK device local cache * fix functions (#523) * fix functions * update minsdk version * remove idea * Set test type to release only in CI. (#522) * Set test type to release only in CI. This fixes Android Studio issue, where it is impossible to run integration tests in debug mode. Additionally move build type configuration to FirebaseLibraryPlugin to avoid projects.all configuration in gradle. * Add comment back. * [Firebase Segmentation] Add custom installation id cache layer and tests for it. * Add test for updating cache * Switch to use SQLiteOpenHelper * Minor fix to error message to match the admin sdk. (#525) * Minor fix to error message to match the admin sdk. In particular, it *is* allowed to have slashes, etc in field paths. * Added clean task to smoke tests. (#527) This change allows the smoke tests to clean all build variants created by the infrastructure. * Update deps to post-androidx gms versions. (#526) * Update deps to post-androidx gms versions. Additionally configure sources.jar for SDKs. * Update functions-ktx deps * Fix versions. * unbump fiam version in fiamui-app * Switch to use SharedPreferences from SQLite. * Change the cache class to be singleton * Copy firebase-firestore-ktx dependencies on firestore into its own subfolder (#528) * Wrap shared pref commit in a async task. * Address comments * Bump firestore version for release (#530) Additionally fix pom filter to exclude multidex from deps. * Google format fix
1 parent 0d05282 commit dc46eee

File tree

43 files changed

+1320
-121
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1320
-121
lines changed

buildSrc/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ dependencies {
3737
implementation 'org.jsoup:jsoup:1.11.2'
3838
implementation 'digital.wup:android-maven-publish:3.6.2'
3939
implementation 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.20'
40+
implementation 'org.json:json:20180813'
4041

4142
implementation 'io.opencensus:opencensus-api:0.18.0'
4243
implementation 'io.opencensus:opencensus-exporter-stats-stackdriver:0.18.0'
4344
runtime 'io.opencensus:opencensus-impl:0.18.0'
4445

4546
implementation 'com.android.tools.build:gradle:3.2.1'
4647
testImplementation 'junit:junit:4.12'
47-
testImplementation 'org.json:json:20180813'
4848
testImplementation('org.spockframework:spock-core:1.1-groovy-2.4') {
4949
exclude group: 'org.codehaus.groovy'
5050
}

buildSrc/src/main/groovy/com/google/firebase/gradle/plugins/FirebaseLibraryPlugin.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import com.google.firebase.gradle.plugins.ci.device.FirebaseTestServer;
2121
import org.gradle.api.Plugin;
2222
import org.gradle.api.Project;
23-
import org.gradle.api.tasks.bundling.Jar;
2423
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile;
2524

2625
public class FirebaseLibraryPlugin implements Plugin<Project> {
@@ -33,6 +32,28 @@ public void apply(Project project) {
3332

3433
LibraryExtension android = project.getExtensions().getByType(LibraryExtension.class);
3534

35+
// In the case of and android library signing config only affects instrumentation test APK.
36+
// We need it signed with default debug credentials in order for FTL to accept the APK.
37+
android.buildTypes(
38+
types ->
39+
types
40+
.getByName("release")
41+
.setSigningConfig(types.getByName("debug").getSigningConfig()));
42+
43+
// skip debug tests in CI
44+
// TODO(vkryachko): provide ability for teams to control this if needed
45+
if (System.getenv().containsKey("FIREBASE_CI")) {
46+
android.setTestBuildType("release");
47+
project
48+
.getTasks()
49+
.all(
50+
task -> {
51+
if ("testDebugUnitTest".equals(task.getName())) {
52+
task.setEnabled(false);
53+
}
54+
});
55+
}
56+
3657
android.testServer(new FirebaseTestServer(project, firebaseLibrary.testLab));
3758

3859
// reduce the likelihood of kotlin module files colliding.

buildSrc/src/main/groovy/com/google/firebase/gradle/plugins/ci/AffectedProjectFinder.groovy

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ class AffectedProjectFinder {
2525
Set<String> changedPaths;
2626

2727
@Builder
28+
AffectedProjectFinder(Project project, List<Pattern> ignorePaths) {
29+
this(project, changedPaths(project.rootDir), ignorePaths)
30+
}
31+
2832
AffectedProjectFinder(Project project,
2933
Set<String> changedPaths,
3034
List<Pattern> ignorePaths) {
@@ -49,6 +53,13 @@ class AffectedProjectFinder {
4953
return project.subprojects
5054
}
5155

56+
private static Set<String> changedPaths(File workDir) {
57+
return 'git diff --name-only --submodule=diff HEAD@{0} HEAD@{1}'
58+
.execute([], workDir)
59+
.text
60+
.readLines()
61+
}
62+
5263
/**
5364
* Performs a post-order project tree traversal and returns a set of projects that own the
5465
* 'changedPaths'.

buildSrc/src/main/groovy/com/google/firebase/gradle/plugins/ci/ContinuousIntegrationPlugin.groovy

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ class ContinuousIntegrationPlugin implements Plugin<Project> {
9797

9898
def affectedProjects = AffectedProjectFinder.builder()
9999
.project(project)
100-
.changedPaths(changedPaths(project.rootDir))
101100
.ignorePaths(extension.ignorePaths)
102101
.build()
103102
.find()
@@ -143,13 +142,6 @@ class ContinuousIntegrationPlugin implements Plugin<Project> {
143142
}
144143
}
145144

146-
private static Set<String> changedPaths(File workDir) {
147-
return 'git diff --name-only --submodule=diff HEAD@{0} HEAD@{1}'
148-
.execute([], workDir)
149-
.text
150-
.readLines()
151-
}
152-
153145
private static final ANDROID_PLUGINS = ["com.android.application", "com.android.library",
154146
"com.android.test"]
155147

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
// Copyright 2018 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.google.firebase.gradle.plugins.ci
16+
17+
import com.google.firebase.gradle.plugins.FirebaseLibraryExtension
18+
import com.google.firebase.gradle.plugins.ci.AffectedProjectFinder
19+
import org.gradle.api.Plugin
20+
import org.gradle.api.Project
21+
import org.gradle.api.artifacts.ProjectDependency
22+
import org.json.JSONArray
23+
import org.json.JSONObject
24+
25+
/** Builds Firebase libraries for consumption by the smoke tests. */
26+
class SmokeTestsPlugin implements Plugin<Project> {
27+
@Override
28+
public void apply(Project project) {
29+
def assembleAllTask = project.task("assembleAllForSmokeTests")
30+
31+
// Wait until after the projects have been evaluated or else we might skip projects.
32+
project.gradle.projectsEvaluated {
33+
def changedProjects = getChangedProjects(project)
34+
def changedArtifacts = new HashSet<String>()
35+
def allArtifacts = new HashSet<String>()
36+
37+
// Visit each project and add the artifacts to the appropriate sets.
38+
project.subprojects {
39+
def firebaseLibrary = it.extensions.findByType(FirebaseLibraryExtension)
40+
if (firebaseLibrary == null) {
41+
return
42+
}
43+
44+
def groupId = firebaseLibrary.groupId.get()
45+
def artifactId = firebaseLibrary.artifactId.get()
46+
def artifact = "$groupId:$artifactId:$it.version-SNAPSHOT"
47+
allArtifacts.add(artifact)
48+
49+
if (changedProjects.contains(it)) {
50+
changedArtifacts.add(artifact)
51+
}
52+
}
53+
54+
// Reuse the publish task for building the libraries.
55+
def publishAllTask = project.tasks.getByPath("publishAllToBuildDir")
56+
assembleAllTask.dependsOn(publishAllTask)
57+
58+
// Generate a JSON file listing the artifacts after everything is complete.
59+
assembleAllTask.doLast {
60+
def changed = new JSONArray()
61+
changedArtifacts.each { changed.put(it) }
62+
63+
def all = new JSONArray()
64+
allArtifacts.each { all.put(it) }
65+
66+
def json = new JSONObject()
67+
json.put("all", all)
68+
json.put("changed", changed)
69+
70+
def path = project.buildDir.toPath()
71+
path.resolve("m2repository/changed-artifacts.json").write(json.toString())
72+
}
73+
}
74+
}
75+
76+
private static Set<Project> getChangedProjects(Project p) {
77+
Set<Project> roots = new AffectedProjectFinder(p, []).find()
78+
HashSet<Project> changed = new HashSet<>()
79+
80+
getChangedProjectsLoop(roots, changed)
81+
return changed
82+
}
83+
84+
private static void getChangedProjectsLoop(Collection<Project> projects, Set<Project> changed) {
85+
for (Project p : projects) {
86+
// Skip project if it is not a Firebase library.
87+
if (p.extensions.findByType(FirebaseLibraryExtension) == null) {
88+
continue;
89+
}
90+
91+
// Skip processing and recursion if this project has already been added to the set.
92+
if (!changed.add(p)) {
93+
continue;
94+
}
95+
96+
// Find all (head) dependencies to other projects in this respository.
97+
def all = p.configurations.releaseRuntimeClasspath.allDependencies
98+
def affected =
99+
all.findAll { it instanceof ProjectDependency }.collect { it.getDependencyProject() }
100+
101+
// Recurse with the new dependencies.
102+
getChangedProjectsLoop(affected, changed)
103+
}
104+
}
105+
}

buildSrc/src/main/groovy/com/google/firebase/gradle/plugins/publish/Publisher.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class Publisher {
7474
pom.dependencies.dependency.each {
7575
// remove multidex as it is supposed to be added by final applications and is needed for
7676
// some libraries only for instrumentation tests to build.
77-
if (it.groupId.text() in ['com.android.support', 'androidx'] && it.artifactId.text() == 'multidex') {
77+
if (it.groupId.text() in ['com.android.support', 'androidx.multidex'] && it.artifactId.text() == 'multidex') {
7878
it.parent().remove(it)
7979
}
8080
it.appendNode('type', [:], deps["${it.groupId.text()}:${it.artifactId.text()}"])

fiamui-app/fiamui-app.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ android {
5353

5454
dependencies {
5555
implementation project(path: ":firebase-inappmessaging-display")
56-
implementation "com.google.firebase:firebase-measurement-connector:17.0.1"
56+
implementation "com.google.firebase:firebase-measurement-connector:18.0.0"
5757
implementation('com.google.firebase:firebase-inappmessaging:17.0.3') {
5858
exclude group: 'com.google.firebase', module: 'firebase-common'
5959
}
60-
implementation('com.google.firebase:firebase-analytics:16.0.4') {
60+
implementation('com.google.firebase:firebase-analytics:17.0.0') {
6161
exclude group: 'com.google.firebase', module: 'firebase-common'
6262
}
6363

@@ -67,7 +67,7 @@ dependencies {
6767
implementation "com.google.code.findbugs:jsr305:3.0.2"
6868
implementation "com.squareup.okhttp:okhttp:2.7.5"
6969
implementation "com.google.auto.value:auto-value-annotations:1.6.5"
70-
implementation "com.google.android.gms:play-services-basement:16.2.0"
70+
implementation "com.google.android.gms:play-services-basement:17.0.0"
7171

7272
// The following dependencies are not required to use the FIAM UI library.
7373
// They are used to make some aspects of the demo app implementation simpler for

firebase-common/firebase-common.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ android {
5858
}
5959

6060
dependencies {
61-
implementation 'com.google.android.gms:play-services-basement:16.2.0'
62-
implementation "com.google.android.gms:play-services-tasks:16.0.1"
61+
implementation 'com.google.android.gms:play-services-basement:17.0.0'
62+
implementation "com.google.android.gms:play-services-tasks:17.0.0"
6363

6464
api 'com.google.auto.value:auto-value-annotations:1.6.5'
6565
compileOnly 'com.google.code.findbugs:jsr305:3.0.2'

firebase-common/gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
version=17.1.1
2-
latestReleasedVersion=17.1.0
1+
version=18.0.1
2+
latestReleasedVersion=18.0.0

firebase-database-collection/firebase-database-collection.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ android {
2929
}
3030

3131
dependencies {
32-
implementation 'com.google.android.gms:play-services-base:16.1.0'
32+
implementation 'com.google.android.gms:play-services-base:17.0.0'
3333

3434
testImplementation 'junit:junit:4.12'
3535
testImplementation 'net.java:quickcheck:0.6'
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
version=16.0.2
2-
latestReleasedVersion=16.0.1
1+
version=17.0.1
2+
latestReleasedVersion=17.0.0

firebase-database/firebase-database.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ dependencies {
7373
implementation project(':firebase-common')
7474
implementation project(':firebase-database-collection')
7575

76-
implementation 'com.google.android.gms:play-services-basement:16.2.0'
77-
implementation 'com.google.android.gms:play-services-base:16.1.0'
78-
implementation 'com.google.android.gms:play-services-tasks:16.0.1'
79-
implementation('com.google.firebase:firebase-auth-interop:17.0.0') {
76+
implementation 'com.google.android.gms:play-services-basement:17.0.0'
77+
implementation 'com.google.android.gms:play-services-base:17.0.0'
78+
implementation 'com.google.android.gms:play-services-tasks:17.0.0'
79+
implementation('com.google.firebase:firebase-auth-interop:18.0.0') {
8080
exclude group: "com.google.firebase", module: "firebase-common"
8181
}
8282

firebase-database/gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
version=17.0.0
16-
latestReleasedVersion=16.1.0
15+
version=18.0.1
16+
latestReleasedVersion=18.0.0
1717
android.enableUnitTestBinaryResources=true
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
version=16.0.1
2-
latestReleasedVersion=16.0.0
1+
version=17.0.1
2+
latestReleasedVersion=17.0.0
33
android.enableUnitTestBinaryResources=true

firebase-firestore/firebase-firestore.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,13 @@ dependencies {
106106
implementation 'io.grpc:grpc-protobuf-lite:1.21.0'
107107
implementation 'io.grpc:grpc-okhttp:1.21.0'
108108
implementation 'io.grpc:grpc-android:1.21.0'
109-
implementation 'com.google.android.gms:play-services-basement:16.2.0'
110-
implementation 'com.google.android.gms:play-services-tasks:16.0.1'
111-
implementation 'com.google.android.gms:play-services-base:16.1.0'
109+
implementation 'com.google.android.gms:play-services-basement:17.0.0'
110+
implementation 'com.google.android.gms:play-services-tasks:17.0.0'
111+
implementation 'com.google.android.gms:play-services-base:17.0.0'
112112
implementation 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava'
113113

114114
implementation 'com.squareup.okhttp:okhttp:2.7.5'
115-
implementation('com.google.firebase:firebase-auth-interop:17.0.0') {
115+
implementation('com.google.firebase:firebase-auth-interop:18.0.0') {
116116
exclude group: "com.google.firebase", module: "firebase-common"
117117
}
118118

firebase-firestore/gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
version=19.0.2
2-
latestReleasedVersion=19.0.1
1+
version=20.1.0
2+
latestReleasedVersion=20.0.0

firebase-firestore/ktx/ktx.gradle

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ plugins {
1919

2020
firebaseLibrary {
2121
releaseWith project(':firebase-firestore')
22+
publishSources = true
2223
}
2324

2425
android {
25-
compileSdkVersion project.targetSdkVersion
26+
compileSdkVersion 28
2627
defaultConfig {
2728
minSdkVersion project.minSdkVersion
2829
multiDexEnabled true
@@ -33,21 +34,22 @@ android {
3334
main.java.srcDirs += 'src/main/kotlin'
3435
test.java {
3536
srcDir 'src/test/kotlin'
36-
srcDir '../src/testUtil/java'
37-
srcDir '../src/roboUtil/java'
37+
srcDir 'src/test/java'
3838
}
3939
}
4040
testOptions.unitTests.includeAndroidResources = true
41+
compileOptions {
42+
sourceCompatibility JavaVersion.VERSION_1_8
43+
targetCompatibility JavaVersion.VERSION_1_8
44+
}
4145
}
4246

4347
dependencies {
4448
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
45-
4649
implementation project(':firebase-common')
4750
implementation project(':firebase-common:ktx')
4851
implementation project(':firebase-firestore')
4952
implementation 'androidx.annotation:annotation:1.1.0'
50-
5153
testImplementation project(':firebase-database-collection')
5254
testImplementation 'org.mockito:mockito-core:2.25.0'
5355
testImplementation 'com.fasterxml.jackson.core:jackson-databind:2.9.8'
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2018 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.google.firebase.firestore;
16+
17+
import com.google.firebase.firestore.model.DocumentKey;
18+
19+
public final class TestAccessHelper {
20+
21+
/** Makes the DocumentReference constructor accessible. */
22+
public static DocumentReference createDocumentReference(DocumentKey documentKey) {
23+
// We can use null here because the tests only use this as a wrapper for documentKeys.
24+
return new DocumentReference(documentKey, null);
25+
}
26+
27+
/** Makes the getKey() method accessible. */
28+
public static DocumentKey referenceKey(DocumentReference documentReference) {
29+
return documentReference.getKey();
30+
}
31+
}

0 commit comments

Comments
 (0)