Skip to content

Commit 24538b9

Browse files
Merge
2 parents 47d0230 + a96334f commit 24538b9

File tree

46 files changed

+635
-146
lines changed

Some content is hidden

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

46 files changed

+635
-146
lines changed

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import com.google.common.collect.ImmutableSet;
1818
import com.google.firebase.gradle.plugins.ci.device.FirebaseTestLabExtension;
19+
import java.util.Collections;
1920
import java.util.HashSet;
2021
import java.util.Set;
2122
import java.util.stream.Collectors;
@@ -39,7 +40,7 @@ public class FirebaseLibraryExtension {
3940
public boolean publishSources;
4041

4142
/** Static analysis configuration. */
42-
public final FirebaseStaticAnalysis staticAnalysis = new FirebaseStaticAnalysis();
43+
public final FirebaseStaticAnalysis staticAnalysis;
4344

4445
/** Firebase Test Lab configuration/ */
4546
public final FirebaseTestLabExtension testLab;
@@ -78,6 +79,20 @@ public FirebaseLibraryExtension(Project project) {
7879
artifactId.set(new DefaultProvider<>(project::getName));
7980
groupId.set(new DefaultProvider<>(() -> project.getGroup().toString()));
8081
}
82+
this.staticAnalysis = initializeStaticAnalysis(project);
83+
}
84+
85+
private FirebaseStaticAnalysis initializeStaticAnalysis(Project project) {
86+
return new FirebaseStaticAnalysis(
87+
projectsFromProperty(project, "firebase.checks.errorproneProjects"),
88+
projectsFromProperty(project, "firebase.checks.lintProjects"));
89+
}
90+
91+
private Set<String> projectsFromProperty(Project project, String propertyName) {
92+
if (!project.hasProperty(propertyName)) {
93+
return Collections.emptySet();
94+
}
95+
return ImmutableSet.copyOf(project.property(propertyName).toString().split(",", -1));
8196
}
8297

8398
/** Configure Firebase Test Lab. */

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

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,13 @@
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;
2120
import com.google.firebase.gradle.plugins.ci.device.FirebaseTestServer;
2221
import org.gradle.api.Plugin;
2322
import org.gradle.api.Project;
2423
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile;
2524

26-
import java.util.Set;
27-
2825
public class FirebaseLibraryPlugin implements Plugin<Project> {
2926

30-
private static final Set<String> KOTLIN_CHECKS =
31-
ImmutableSet.of(
32-
"FirebaseNoHardKeywords",
33-
"FirebaseLambdaLast",
34-
"FirebaseUnknownNullness",
35-
"FirebaseKotlinPropertyAccess");
36-
3727
@Override
3828
public void apply(Project project) {
3929
project.apply(ImmutableMap.of("plugin", "com.android.library"));
@@ -106,11 +96,6 @@ private static void setupStaticAnalysis(
10696
}
10797
}));
10898

109-
library.staticAnalysis.subscribeToKotlinInteropLintDisabled(
110-
() ->
111-
android.lintOptions(
112-
lintOptions -> lintOptions.disable(KOTLIN_CHECKS.toArray(new String[0]))));
113-
11499
project.getTasks().register("firebaseLint", task -> task.dependsOn("lint"));
115100
}
116101

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

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,45 +14,15 @@
1414

1515
package com.google.firebase.gradle.plugins;
1616

17-
import com.google.common.collect.ImmutableSet;
18-
19-
import java.util.HashSet;
2017
import java.util.Set;
21-
import java.util.function.Consumer;
2218

2319
public class FirebaseStaticAnalysis {
2420
public Set<String> errorproneCheckProjects;
2521
public Set<String> androidLintCheckProjects;
2622

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) {
23+
public FirebaseStaticAnalysis(
24+
Set<String> errorproneCheckProjects, Set<String> androidLintCheckProjects) {
3725
this.errorproneCheckProjects = errorproneCheckProjects;
3826
this.androidLintCheckProjects = androidLintCheckProjects;
3927
}
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-
}
5828
}

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

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

firebase-common/firebase-common.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ dependencies {
6464
api 'com.google.auto.value:auto-value-annotations:1.6.5'
6565
compileOnly 'com.google.code.findbugs:jsr305:3.0.2'
6666

67+
// needed for Kotlin detection to compile, but not necessarily present at runtime.
68+
compileOnly "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
69+
6770
testImplementation 'androidx.test:runner:1.2.0'
6871
testImplementation 'androidx.test.ext:junit:1.1.1'
6972
testImplementation "org.robolectric:robolectric:$robolectricVersion"

firebase-common/ktx/ktx.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ android {
2727
minSdkVersion project.minSdkVersion
2828
targetSdkVersion project.targetSdkVersion
2929
versionName version
30-
buildConfigField('String', 'KOTLIN_VERSION', "\"$kotlinVersion\"")
3130
}
3231
sourceSets {
3332
main.java.srcDirs += 'src/main/kotlin'

firebase-common/ktx/src/main/kotlin/com/google/firebase/ktx/Firebase.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ internal const val LIBRARY_NAME: String = "fire-core-ktx"
5757
class FirebaseCommonKtxRegistrar : ComponentRegistrar {
5858
override fun getComponents(): List<Component<*>> {
5959
return listOf(
60-
LibraryVersionComponent.create(LIBRARY_NAME, BuildConfig.VERSION_NAME),
61-
LibraryVersionComponent.create("kotlin", BuildConfig.KOTLIN_VERSION))
60+
LibraryVersionComponent.create(LIBRARY_NAME, BuildConfig.VERSION_NAME))
6261
}
6362
}

firebase-common/proguard.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
-dontwarn com.google.firebase.components.Component$Instantiation
22
-dontwarn com.google.firebase.components.Component$ComponentType
3+
-dontwarn com.google.firebase.platforminfo.KotlinDetector
34
-keep class * implements com.google.firebase.components.ComponentRegistrar

firebase-common/src/main/java/com/google/firebase/FirebaseApp.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import com.google.firebase.events.Publisher;
4747
import com.google.firebase.internal.DataCollectionConfigStorage;
4848
import com.google.firebase.platforminfo.DefaultUserAgentPublisher;
49+
import com.google.firebase.platforminfo.KotlinDetector;
4950
import com.google.firebase.platforminfo.LibraryVersionComponent;
5051
import java.nio.charset.Charset;
5152
import java.util.ArrayList;
@@ -100,6 +101,7 @@ public class FirebaseApp {
100101

101102
private static final String FIREBASE_ANDROID = "fire-android";
102103
private static final String FIREBASE_COMMON = "fire-core";
104+
private static final String KOTLIN = "kotlin";
103105

104106
private final Context applicationContext;
105107
private final String name;
@@ -397,6 +399,8 @@ protected FirebaseApp(Context applicationContext, String name, FirebaseOptions o
397399

398400
List<ComponentRegistrar> registrars =
399401
ComponentDiscovery.forContext(applicationContext).discover();
402+
403+
String kotlinVersion = KotlinDetector.detectVersion();
400404
componentRuntime =
401405
new ComponentRuntime(
402406
UI_EXECUTOR,
@@ -406,7 +410,9 @@ protected FirebaseApp(Context applicationContext, String name, FirebaseOptions o
406410
Component.of(options, FirebaseOptions.class),
407411
LibraryVersionComponent.create(FIREBASE_ANDROID, ""),
408412
LibraryVersionComponent.create(FIREBASE_COMMON, BuildConfig.VERSION_NAME),
413+
kotlinVersion != null ? LibraryVersionComponent.create(KOTLIN, kotlinVersion) : null,
409414
DefaultUserAgentPublisher.component());
415+
410416
dataCollectionConfigStorage =
411417
new Lazy<>(
412418
() ->

firebase-common/src/main/java/com/google/firebase/components/ComponentRuntime.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ public ComponentRuntime(
5555
for (ComponentRegistrar registrar : registrars) {
5656
componentsToAdd.addAll(registrar.getComponents());
5757
}
58-
Collections.addAll(componentsToAdd, additionalComponents);
58+
for (Component<?> additionalComponent : additionalComponents) {
59+
if (additionalComponent != null) {
60+
componentsToAdd.add(additionalComponent);
61+
}
62+
}
5963

6064
CycleDetector.detect(componentsToAdd);
6165

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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.platforminfo;
16+
17+
import androidx.annotation.Nullable;
18+
19+
/**
20+
* Detects presence of Kotlin stdlib on the classpath.
21+
*
22+
* <p>If it is present, it is inferred that the application or its subset is written in Kotlin.
23+
*/
24+
public final class KotlinDetector {
25+
private KotlinDetector() {}
26+
27+
/** Returns the version of Kotlin stdlib if found, {@code null} otherwise. */
28+
@Nullable
29+
public static String detectVersion() {
30+
try {
31+
return kotlin.KotlinVersion.CURRENT.toString();
32+
} catch (NoClassDefFoundError ex) {
33+
return null;
34+
}
35+
}
36+
}

firebase-database/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# 19.1.0
2+
- [feature] Added support for the Firebase Database Emulator. To connect to
3+
the emulator, specify "http://<emulatorHost>/?ns=<projectId>" as your
4+
Database URL (via `FirebaseDatabase.getInstance(String)`).
5+
Note that if you are running the Database Emulator on "localhost" and
6+
connecting from an app that is running inside an Android Emulator, the
7+
emulator host will be "10.0.2.2" followed by its port.
8+
19
# 18.0.1
210
- [changed] The SDK now reports the correct version number (via
311
`FirebaseDatabase.getSdkVersion()`).

firebase-database/src/androidTest/java/com/google/firebase/database/DataTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,9 +1081,9 @@ public void urlEncodingAndDecodingWorks()
10811081
new DatabaseReference(
10821082
IntegrationTestValues.getNamespace() + "/a%b&c@d/space: /non-ascii:ø", ctx);
10831083
String result = ref.toString();
1084-
String expected =
1084+
String encoded =
10851085
IntegrationTestValues.getNamespace() + "/a%25b%26c%40d/space%3A%20/non-ascii%3A%C3%B8";
1086-
assertEquals(expected, result);
1086+
assertEquals(encoded, result);
10871087

10881088
String child = "" + new Random().nextInt(100000000);
10891089
new WriteFuture(ref.child(child), "testdata").timedGet();

firebase-database/src/androidTest/java/com/google/firebase/database/FirebaseDatabaseTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public void persistenceSettings() {
170170
config.setPersistenceCacheSizeBytes(1 * 1024 * 1024);
171171

172172
try {
173-
FirebaseDatabase db = new DatabaseReference("", config).getDatabase();
173+
FirebaseDatabase db = new DatabaseReference("http://localhost", config).getDatabase();
174174
db.setPersistenceCacheSizeBytes(1 * 1024 * 1024);
175175
fail("should throw - can't modify after init");
176176
} catch (DatabaseException e) {

firebase-database/src/androidTest/java/com/google/firebase/database/RealtimeTest.java

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
import androidx.test.runner.AndroidJUnit4;
2424
import com.google.firebase.database.core.DatabaseConfig;
2525
import com.google.firebase.database.core.RepoManager;
26-
import com.google.firebase.database.core.utilities.ParsedUrl;
27-
import com.google.firebase.database.core.utilities.Utilities;
2826
import com.google.firebase.database.future.ReadFuture;
2927
import com.google.firebase.database.future.WriteFuture;
3028
import java.util.List;
@@ -48,21 +46,6 @@ public void tearDown() {
4846
IntegrationTestHelpers.failOnFirstUncaughtException();
4947
}
5048

51-
@Test
52-
public void testUrlParsing() throws DatabaseException {
53-
ParsedUrl parsed = Utilities.parseUrl("http://gsoltis.fblocal.com:9000");
54-
assertEquals(parsed.path.toString(), "/");
55-
assertEquals(parsed.repoInfo.host, "gsoltis.fblocal.com:9000");
56-
assertEquals(parsed.repoInfo.internalHost, "gsoltis.fblocal.com:9000");
57-
assertEquals(parsed.repoInfo.secure, false);
58-
59-
parsed = Utilities.parseUrl("http://gsoltis.firebaseio.com/foo/bar");
60-
assertEquals(parsed.path.toString(), "/foo/bar");
61-
assertEquals(parsed.repoInfo.host, "gsoltis.firebaseio.com");
62-
assertEquals(parsed.repoInfo.internalHost, "gsoltis.firebaseio.com");
63-
assertEquals(parsed.repoInfo.secure, true);
64-
}
65-
6649
@Test
6750
public void testOnDisconnectSetWorks()
6851
throws DatabaseException, TestFailure, TimeoutException, InterruptedException {

firebase-database/src/main/java/com/google/firebase/database/core/utilities/DefaultRunLoop.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,20 @@ public static String messageForException(Throwable t) {
128128
+ "https://firebase.google.com/docs/database/ios/structure-data#best_practices_for_data_structure"
129129
+ " and "
130130
+ "https://firebase.google.com/docs/database/android/retrieve-data#filtering_data";
131+
} else if (t instanceof NoClassDefFoundError) {
132+
return "A symbol that the Firebase Database SDK depends on failed to load. This usually "
133+
+ "indicates that your project includes an incompatible version of another Firebase "
134+
+ "dependency. If updating your dependencies to the latest version does not resolve "
135+
+ "this issue, please file a report at https://github.com/firebase/firebase-android-sdk";
131136
} else if (t instanceof DatabaseException) {
132137
// Exception should be self-explanatory and they shouldn't contact support.
133138
return "";
134139
} else {
135140
return "Uncaught exception in Firebase Database runloop ("
136141
+ FirebaseDatabase.getSdkVersion()
137-
+ "). Please report to [email protected]";
142+
+ "). If you are not already on the latest version of the Firebase SDKs, try updating "
143+
+ "your dependencies. Should this problem persist, please file a report at "
144+
+ "https://github.com/firebase/firebase-android-sdk";
138145
}
139146
}
140147
}

firebase-database/src/main/java/com/google/firebase/database/core/utilities/ParsedUrl.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,15 @@ public class ParsedUrl {
2121

2222
public RepoInfo repoInfo;
2323
public Path path;
24+
25+
@Override
26+
public boolean equals(Object o) {
27+
if (this == o) return true;
28+
if (o == null || getClass() != o.getClass()) return false;
29+
30+
ParsedUrl parsedUrl = (ParsedUrl) o;
31+
32+
if (!repoInfo.equals(parsedUrl.repoInfo)) return false;
33+
return path.equals(parsedUrl.path);
34+
}
2435
}

0 commit comments

Comments
 (0)