Skip to content

Commit b4e11e9

Browse files
committed
Merge branch 'master' of github.com:firebase/firebase-android-sdk into floc-master
2 parents a79cae2 + ac5b05d commit b4e11e9

File tree

97 files changed

+2394
-671
lines changed

Some content is hidden

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

97 files changed

+2394
-671
lines changed

buildSrc/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ dependencies {
4343
implementation 'io.opencensus:opencensus-exporter-stats-stackdriver:0.18.0'
4444
runtime 'io.opencensus:opencensus-impl:0.18.0'
4545

46-
implementation 'com.android.tools.build:gradle:3.2.1'
46+
implementation 'com.android.tools.build:gradle:3.4.1'
4747
testImplementation 'junit:junit:4.12'
4848
testImplementation('org.spockframework:spock-core:1.1-groovy-2.4') {
4949
exclude group: 'org.codehaus.groovy'

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ public class FirebaseLibraryExtension {
3838
/** Indicates whether sources are published alongside the library. */
3939
public boolean publishSources;
4040

41+
/** Static analysis configuration. */
42+
public final FirebaseStaticAnalysis staticAnalysis = new FirebaseStaticAnalysis();
43+
4144
/** Firebase Test Lab configuration/ */
4245
public final FirebaseTestLabExtension testLab;
4346

@@ -126,4 +129,8 @@ public void applyPomCustomization(MavenPom pom) {
126129
customizePomAction.execute(pom);
127130
}
128131
}
132+
133+
public void staticAnalysis(Action<FirebaseStaticAnalysis> action) {
134+
action.execute(staticAnalysis);
135+
}
129136
}

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,23 @@
1717
import com.android.build.gradle.LibraryExtension;
1818
import com.google.common.collect.ImmutableList;
1919
import com.google.common.collect.ImmutableMap;
20+
import com.google.common.collect.ImmutableSet;
2021
import com.google.firebase.gradle.plugins.ci.device.FirebaseTestServer;
2122
import org.gradle.api.Plugin;
2223
import org.gradle.api.Project;
2324
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile;
2425

26+
import java.util.Set;
27+
2528
public class FirebaseLibraryPlugin implements Plugin<Project> {
29+
30+
private static final Set<String> KOTLIN_CHECKS =
31+
ImmutableSet.of(
32+
"FirebaseNoHardKeywords",
33+
"FirebaseLambdaLast",
34+
"FirebaseUnknownNullness",
35+
"FirebaseKotlinPropertyAccess");
36+
2637
@Override
2738
public void apply(Project project) {
2839
project.apply(ImmutableMap.of("plugin", "com.android.library"));
@@ -56,6 +67,8 @@ public void apply(Project project) {
5667

5768
android.testServer(new FirebaseTestServer(project, firebaseLibrary.testLab));
5869

70+
setupStaticAnalysis(project, android, firebaseLibrary);
71+
5972
// reduce the likelihood of kotlin module files colliding.
6073
project
6174
.getTasks()
@@ -68,6 +81,39 @@ public void apply(Project project) {
6881
ImmutableList.of("-module-name", kotlinModuleName(project))));
6982
}
7083

84+
private static void setupStaticAnalysis(
85+
Project project, LibraryExtension android, FirebaseLibraryExtension library) {
86+
project.afterEvaluate(
87+
p ->
88+
project
89+
.getConfigurations()
90+
.all(
91+
c -> {
92+
if ("annotationProcessor".equals(c.getName())) {
93+
for (String checkProject : library.staticAnalysis.errorproneCheckProjects) {
94+
project
95+
.getDependencies()
96+
.add("annotationProcessor", project.project(checkProject));
97+
}
98+
}
99+
if ("lintChecks".equals(c.getName())) {
100+
for (String checkProject :
101+
library.staticAnalysis.androidLintCheckProjects) {
102+
project
103+
.getDependencies()
104+
.add("lintChecks", project.project(checkProject));
105+
}
106+
}
107+
}));
108+
109+
library.staticAnalysis.subscribeToKotlinInteropLintDisabled(
110+
() ->
111+
android.lintOptions(
112+
lintOptions -> lintOptions.disable(KOTLIN_CHECKS.toArray(new String[0]))));
113+
114+
project.getTasks().register("firebaseLint", task -> task.dependsOn("lint"));
115+
}
116+
71117
private static String kotlinModuleName(Project project) {
72118

73119
String fullyQualifiedProjectPath = project.getPath().replaceAll(":", "-");
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright 2019 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;
16+
17+
import com.google.common.collect.ImmutableSet;
18+
19+
import java.util.HashSet;
20+
import java.util.Set;
21+
import java.util.function.Consumer;
22+
23+
public class FirebaseStaticAnalysis {
24+
public Set<String> errorproneCheckProjects;
25+
public Set<String> androidLintCheckProjects;
26+
27+
28+
private boolean disableKotlinInteropLint;
29+
30+
private final Set<Runnable> kotlinInteropLintDisabledSubscribers = new HashSet<>();
31+
32+
public FirebaseStaticAnalysis() {
33+
this(ImmutableSet.of(":tools:errorprone"), ImmutableSet.of(":tools:lint"));
34+
}
35+
36+
public FirebaseStaticAnalysis(Set<String> errorproneCheckProjects, Set<String> androidLintCheckProjects) {
37+
this.errorproneCheckProjects = errorproneCheckProjects;
38+
this.androidLintCheckProjects = androidLintCheckProjects;
39+
}
40+
41+
/** Indicates whether Kotlin Interop Lint checks are enabled for public APIs of the library. */
42+
public void disableKotlinInteropLint() {
43+
if (disableKotlinInteropLint) {
44+
return;
45+
}
46+
disableKotlinInteropLint = true;
47+
for (Runnable subscription : kotlinInteropLintDisabledSubscribers) {
48+
subscription.run();
49+
}
50+
}
51+
52+
void subscribeToKotlinInteropLintDisabled(Runnable subscription) {
53+
this.kotlinInteropLintDisabledSubscribers.add(subscription);
54+
if (disableKotlinInteropLint) {
55+
subscription.run();
56+
}
57+
}
58+
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,10 @@ class PublishingPlugin implements Plugin<Project> {
140140
def buildMavenZip = project.task('buildMavenZip', type: Zip) {
141141
dependsOn publishProjectsToBuildDir
142142

143+
archiveFileName = 'm2repository.zip'
144+
destinationDirectory = project.buildDir
145+
143146
from "$project.buildDir/m2repository"
144-
archiveName "$project.buildDir/m2repository.zip"
145147
}
146148

147149
def info = project.task('publishPrintInfo') {

buildSrc/src/test/groovy/com/google/firebase/gradle/plugins/publish/PublishingPluginSpec.groovy

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ class PublishingPluginSpec extends Specification {
2929
plugins {
3030
id 'firebase-library'
3131
}
32+
firebaseLibrary {
33+
staticAnalysis {
34+
errorproneCheckProjects = []
35+
androidLintCheckProjects = []
36+
}
37+
}
3238
group = '${group}'
3339
version = '${version}'
3440
<% if (latestReleasedVersion) println "ext.latestReleasedVersion = $latestReleasedVersion" %>

firebase-abt/firebase-abt.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ plugins {
2020
firebaseLibrary {
2121
testLab.enabled = false
2222
publishSources = true
23+
staticAnalysis.disableKotlinInteropLint()
2324
}
2425

2526
// TODO(issue/568): Remove this once legacy logic is removed from Remote Config.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
plugins {
16+
id 'com.android.application'
17+
}
18+
19+
android {
20+
adbOptions {
21+
timeOutInMs 60 * 1000
22+
}
23+
24+
compileSdkVersion project.targetSdkVersion
25+
defaultConfig {
26+
minSdkVersion project.minSdkVersion
27+
targetSdkVersion project.targetSdkVersion
28+
versionName version
29+
multiDexEnabled true
30+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
31+
}
32+
compileOptions {
33+
sourceCompatibility JavaVersion.VERSION_1_8
34+
targetCompatibility JavaVersion.VERSION_1_8
35+
}
36+
testOptions {
37+
unitTests {
38+
includeAndroidResources = true
39+
}
40+
}
41+
}
42+
43+
dependencies {
44+
implementation project(':firebase-common')
45+
testImplementation 'androidx.test:runner:1.2.0'
46+
testImplementation 'androidx.test.ext:junit:1.1.1'
47+
testImplementation "org.robolectric:robolectric:$robolectricVersion"
48+
testImplementation 'com.google.auto.value:auto-value-annotations:1.6.5'
49+
testImplementation 'junit:junit:4.12'
50+
testImplementation "com.google.truth:truth:$googleTruthVersion"
51+
testImplementation 'org.mockito:mockito-core:2.25.0'
52+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Copyright 2019 Google LLC -->
3+
<!-- -->
4+
<!-- Licensed under the Apache License, Version 2.0 (the "License"); -->
5+
<!-- you may not use this file except in compliance with the License. -->
6+
<!-- You may obtain a copy of the License at -->
7+
<!-- -->
8+
<!-- http://www.apache.org/licenses/LICENSE-2.0 -->
9+
<!-- -->
10+
<!-- Unless required by applicable law or agreed to in writing, software -->
11+
<!-- distributed under the License is distributed on an "AS IS" BASIS, -->
12+
<!-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -->
13+
<!-- See the License for the specific language governing permissions and -->
14+
<!-- limitations under the License. -->
15+
16+
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.google.firebase.datacollectiontests">
17+
<application>
18+
<meta-data android:name="firebase_data_collection_default_enabled"
19+
android:value="false" />
20+
21+
<service android:name="com.google.firebase.components.ComponentDiscoveryService" android:exported="false">
22+
<meta-data
23+
android:name="com.google.firebase.components:com.google.firebase.DataCollectionDefaultChangeRegistrar"
24+
android:value="com.google.firebase.components.ComponentRegistrar" />
25+
</service>
26+
</application>
27+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright 2019 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;
16+
17+
import com.google.firebase.components.Component;
18+
import com.google.firebase.components.ComponentRegistrar;
19+
import com.google.firebase.components.Dependency;
20+
import com.google.firebase.events.Subscriber;
21+
import java.util.ArrayList;
22+
import java.util.Collections;
23+
import java.util.List;
24+
25+
public class DataCollectionDefaultChangeRegistrar implements ComponentRegistrar {
26+
@Override
27+
public List<Component<?>> getComponents() {
28+
return Collections.singletonList(
29+
Component.builder(ChangeListener.class)
30+
.add(Dependency.required(Subscriber.class))
31+
.alwaysEager()
32+
.factory(c -> new ChangeListener(c.get(Subscriber.class)))
33+
.build());
34+
}
35+
36+
public static class ChangeListener {
37+
public List<Boolean> changes = new ArrayList<>();
38+
39+
ChangeListener(Subscriber subscriber) {
40+
subscriber.subscribe(
41+
DataCollectionDefaultChange.class, change -> changes.add(change.getPayload().enabled));
42+
}
43+
}
44+
}

firebase-common/src/test/java/com/google/firebase/DataCollectionDefaultDisabledTest.java renamed to firebase-common/data-collection-tests/src/test/java/com/google/firebase/DataCollectionDefaultDisabledTest.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2018 Google LLC
1+
// Copyright 2019 Google LLC
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -20,14 +20,12 @@
2020
import static com.google.firebase.DataCollectionTestUtil.withApp;
2121

2222
import android.content.SharedPreferences;
23+
import androidx.test.ext.junit.runners.AndroidJUnit4;
2324
import com.google.firebase.internal.DataCollectionConfigStorage;
2425
import org.junit.Test;
2526
import org.junit.runner.RunWith;
26-
import org.robolectric.RobolectricTestRunner;
27-
import org.robolectric.annotation.Config;
2827

29-
@RunWith(RobolectricTestRunner.class)
30-
@Config(manifest = "NoAutoDataCollectionAndroidManifest.xml")
28+
@RunWith(AndroidJUnit4.class)
3129
public class DataCollectionDefaultDisabledTest {
3230

3331
@Test

0 commit comments

Comments
 (0)