Skip to content

Commit 24a07db

Browse files
authored
Extract core encoders api into a separate library. (#1930)
* Extract core encoders api into a separate library. This decouples the api from the json implementation, enabling creation of other formats in the future. This is modeled as a breaking change even though it won't have any developer impact. * Fix java-library classpath. * Added explanation for separate configuration. * Not required after the java-library classpath fix. * add new line
1 parent 2056bfc commit 24a07db

File tree

30 files changed

+151
-110
lines changed

30 files changed

+151
-110
lines changed

buildSrc/src/main/java/com/google/firebase/gradle/plugins/Dokka.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,12 @@ static void configure(
5656
FirebaseLibraryExtension firebaseLibrary) {
5757

5858
Configuration javadocClasspath = project.getConfigurations().create("javadocClasspath");
59-
javadocClasspath
60-
.getAttributes()
61-
.attribute(
62-
BuildTypeAttr.ATTRIBUTE, project.getObjects().named(BuildTypeAttr.class, "release"));
59+
if (android != null) {
60+
javadocClasspath
61+
.getAttributes()
62+
.attribute(
63+
BuildTypeAttr.ATTRIBUTE, project.getObjects().named(BuildTypeAttr.class, "release"));
64+
}
6365

6466
project.afterEvaluate(
6567
p -> {

encoders/firebase-encoders-json/api.txt

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,4 @@
11
// Signature format: 2.0
2-
package com.google.firebase.encoders {
3-
4-
public interface DataEncoder {
5-
method public void encode(@NonNull Object, @NonNull java.io.Writer) throws java.io.IOException;
6-
method @NonNull public String encode(@NonNull Object);
7-
}
8-
9-
public final class EncodingException extends java.lang.RuntimeException {
10-
ctor public EncodingException(@NonNull String);
11-
ctor public EncodingException(@NonNull String, @NonNull Exception);
12-
}
13-
14-
public final class FieldDescriptor {
15-
method @NonNull public static com.google.firebase.encoders.FieldDescriptor.Builder builder(@NonNull String);
16-
method @NonNull public String getName();
17-
method @Nullable public <T extends java.lang.annotation.Annotation> T getProperty(@NonNull Class<T>);
18-
}
19-
20-
public static final class FieldDescriptor.Builder {
21-
method @NonNull public com.google.firebase.encoders.FieldDescriptor build();
22-
method @NonNull public <T extends java.lang.annotation.Annotation> com.google.firebase.encoders.FieldDescriptor.Builder withProperty(@NonNull T);
23-
}
24-
25-
public interface ObjectEncoder<T> {
26-
}
27-
28-
public interface ObjectEncoderContext {
29-
method @NonNull public com.google.firebase.encoders.ObjectEncoderContext add(@NonNull String, @Nullable Object) throws java.io.IOException;
30-
method @NonNull public com.google.firebase.encoders.ObjectEncoderContext add(@NonNull String, double) throws java.io.IOException;
31-
method @NonNull public com.google.firebase.encoders.ObjectEncoderContext add(@NonNull String, int) throws java.io.IOException;
32-
method @NonNull public com.google.firebase.encoders.ObjectEncoderContext add(@NonNull String, long) throws java.io.IOException;
33-
method @NonNull public com.google.firebase.encoders.ObjectEncoderContext add(@NonNull String, boolean) throws java.io.IOException;
34-
method @NonNull public com.google.firebase.encoders.ObjectEncoderContext inline(@Nullable Object) throws java.io.IOException;
35-
method @NonNull public com.google.firebase.encoders.ObjectEncoderContext nested(@NonNull String) throws java.io.IOException;
36-
}
37-
38-
public interface ValueEncoder<T> {
39-
}
40-
41-
public interface ValueEncoderContext {
42-
method @NonNull public com.google.firebase.encoders.ValueEncoderContext add(@Nullable String) throws java.io.IOException;
43-
method @NonNull public com.google.firebase.encoders.ValueEncoderContext add(double) throws java.io.IOException;
44-
method @NonNull public com.google.firebase.encoders.ValueEncoderContext add(int) throws java.io.IOException;
45-
method @NonNull public com.google.firebase.encoders.ValueEncoderContext add(long) throws java.io.IOException;
46-
method @NonNull public com.google.firebase.encoders.ValueEncoderContext add(boolean) throws java.io.IOException;
47-
method @NonNull public com.google.firebase.encoders.ValueEncoderContext add(@NonNull byte[]) throws java.io.IOException;
48-
}
49-
50-
}
51-
52-
package com.google.firebase.encoders.annotations {
53-
54-
@java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE) @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME) public @interface Encodable {
55-
}
56-
57-
@java.lang.annotation.Target(java.lang.annotation.ElementType.METHOD) @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME) public static @interface Encodable.Field {
58-
method public abstract boolean inline() default false;
59-
method public abstract String name() default "";
60-
}
61-
62-
@java.lang.annotation.Target(java.lang.annotation.ElementType.METHOD) @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME) public static @interface Encodable.Ignore {
63-
}
64-
65-
@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME) @java.lang.annotation.Target(java.lang.annotation.ElementType.ANNOTATION_TYPE) public @interface ExtraProperty {
66-
method public abstract Class<?>[] allowedTypes() default {};
67-
}
68-
69-
}
70-
71-
package com.google.firebase.encoders.config {
72-
73-
public interface Configurator {
74-
method public void configure(@NonNull com.google.firebase.encoders.config.EncoderConfig<?>);
75-
}
76-
77-
public interface EncoderConfig<T extends com.google.firebase.encoders.config.EncoderConfig<T>> {
78-
method @NonNull public <U> T registerEncoder(@NonNull Class<U>, @NonNull com.google.firebase.encoders.ObjectEncoder<? super U>);
79-
method @NonNull public <U> T registerEncoder(@NonNull Class<U>, @NonNull com.google.firebase.encoders.ValueEncoder<? super U>);
80-
}
81-
82-
}
83-
842
package com.google.firebase.encoders.json {
853

864
public final class JsonDataEncoderBuilder implements com.google.firebase.encoders.config.EncoderConfig<com.google.firebase.encoders.json.JsonDataEncoderBuilder> {

encoders/firebase-encoders-json/firebase-encoders-json.gradle

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,18 @@ android {
3939
includeAndroidResources = true
4040
}
4141
}
42-
43-
sourceSets.main.java {
44-
srcDir 'src/json/java'
45-
}
4642
}
4743

4844
dependencies {
4945
implementation 'androidx.annotation:annotation:1.1.0'
46+
implementation project(':encoders:firebase-encoders')
5047

51-
testImplementation 'androidx.test:runner:1.2.0'
52-
testImplementation 'androidx.test.ext:junit:1.1.1'
48+
testImplementation 'androidx.test:runner:1.3.0'
49+
testImplementation 'androidx.test.ext:junit:1.1.2'
5350
testImplementation "org.robolectric:robolectric:$robolectricVersion"
54-
testImplementation 'junit:junit:4.13-rc-1'
55-
testImplementation "com.google.truth:truth:$googleTruthVersion"
56-
testImplementation 'org.mockito:mockito-core:2.25.0'
51+
testImplementation 'junit:junit:4.13'
52+
testImplementation "com.google.truth:truth:1.0.1"
53+
testImplementation 'org.mockito:mockito-core:3.3.3'
5754

5855
}
5956

encoders/firebase-encoders-json/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
version=16.1.1
15+
version=17.0.0
1616
latestReleasedVersion=16.1.0

encoders/firebase-encoders-processor/firebase-encoders-processor.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,21 @@ def jvm = org.gradle.internal.jvm.Jvm.current()
2020

2121

2222
dependencies {
23-
implementation project(':encoders:firebase-encoders-processor:test-support')
23+
implementation project(':encoders:firebase-encoders')
2424
implementation 'com.google.auto.service:auto-service-annotations:1.0-rc6'
25-
implementation 'com.squareup:javapoet:1.11.1'
25+
implementation 'com.squareup:javapoet:1.13.0'
2626
compileOnly 'javax.annotation:javax.annotation-api:1.3.2'
2727
implementation 'com.google.guava:guava:28.1-jre'
2828

29-
implementation "com.google.auto.value:auto-value-annotations:1.6.5"
29+
implementation "com.google.auto.value:auto-value-annotations:1.6.6"
3030

31-
annotationProcessor "com.google.auto.value:auto-value:1.6.2"
31+
annotationProcessor "com.google.auto.value:auto-value:1.6.5"
3232

3333
annotationProcessor 'com.google.auto.service:auto-service:1.0-rc6'
3434

3535
testImplementation 'com.google.testing.compile:compile-testing:0.18'
3636
if (jvm.getToolsJar() != null) testImplementation files(jvm.getToolsJar())
37-
testImplementation 'com.google.truth:truth:1.0'
37+
testImplementation 'com.google.truth:truth:1.0.1'
3838

3939
}
4040

encoders/firebase-encoders-processor/test-support/src/main/java/com

Lines changed: 0 additions & 1 deletion
This file was deleted.

encoders/firebase-encoders-reflective/firebase-encoders-reflective.gradle

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,14 @@ android {
4343

4444
dependencies {
4545
implementation 'androidx.annotation:annotation:1.1.0'
46+
implementation project(':encoders:firebase-encoders')
4647
implementation project(':encoders:firebase-encoders-json')
4748

48-
testImplementation 'androidx.test:runner:1.2.0'
49-
testImplementation 'androidx.test.ext:junit:1.1.1'
49+
testImplementation 'androidx.test:runner:1.3.0'
50+
testImplementation 'androidx.test.ext:junit:1.1.2'
5051
testImplementation "org.robolectric:robolectric:$robolectricVersion"
51-
testImplementation 'junit:junit:4.13-rc-1'
52-
testImplementation "com.google.truth:truth:$googleTruthVersion"
53-
testImplementation 'org.mockito:mockito-core:2.25.0'
52+
testImplementation 'junit:junit:4.13'
53+
testImplementation 'com.google.truth:truth:1.0.1'
54+
testImplementation 'org.mockito:mockito-core:3.3.3'
5455

5556
}

encoders/firebase-encoders/api.txt

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// Signature format: 2.0
2+
package com.google.firebase.encoders {
3+
4+
public interface DataEncoder {
5+
method public void encode(@NonNull Object, @NonNull Writer);
6+
method @NonNull public String encode(@NonNull Object);
7+
}
8+
9+
public final class EncodingException {
10+
ctor public EncodingException(@NonNull String);
11+
ctor public EncodingException(@NonNull String, @NonNull Exception);
12+
}
13+
14+
public final class FieldDescriptor {
15+
method @NonNull public static com.google.firebase.encoders.FieldDescriptor.Builder builder(@NonNull String);
16+
method public boolean equals(Object);
17+
method @NonNull public String getName();
18+
method @Nullable public <T extends Annotation> T getProperty(@NonNull Class<T>);
19+
method public int hashCode();
20+
method @NonNull public String toString();
21+
}
22+
23+
public static final class FieldDescriptor.Builder {
24+
method @NonNull public com.google.firebase.encoders.FieldDescriptor build();
25+
method @NonNull public <T extends Annotation> com.google.firebase.encoders.FieldDescriptor.Builder withProperty(@NonNull T);
26+
}
27+
28+
public interface ObjectEncoder<T> {
29+
}
30+
31+
public interface ObjectEncoderContext {
32+
method @NonNull public com.google.firebase.encoders.ObjectEncoderContext add(@NonNull String, @Nullable Object);
33+
method @NonNull public com.google.firebase.encoders.ObjectEncoderContext add(@NonNull String, double);
34+
method @NonNull public com.google.firebase.encoders.ObjectEncoderContext add(@NonNull String, int);
35+
method @NonNull public com.google.firebase.encoders.ObjectEncoderContext add(@NonNull String, long);
36+
method @NonNull public com.google.firebase.encoders.ObjectEncoderContext add(@NonNull String, boolean);
37+
method @NonNull public com.google.firebase.encoders.ObjectEncoderContext inline(@Nullable Object);
38+
method @NonNull public com.google.firebase.encoders.ObjectEncoderContext nested(@NonNull String);
39+
}
40+
41+
public interface ValueEncoder<T> {
42+
}
43+
44+
public interface ValueEncoderContext {
45+
method @NonNull public com.google.firebase.encoders.ValueEncoderContext add(@Nullable String);
46+
method @NonNull public com.google.firebase.encoders.ValueEncoderContext add(double);
47+
method @NonNull public com.google.firebase.encoders.ValueEncoderContext add(int);
48+
method @NonNull public com.google.firebase.encoders.ValueEncoderContext add(long);
49+
method @NonNull public com.google.firebase.encoders.ValueEncoderContext add(boolean);
50+
method @NonNull public com.google.firebase.encoders.ValueEncoderContext add(@NonNull byte[]);
51+
}
52+
53+
}
54+
55+
package com.google.firebase.encoders.annotations {
56+
57+
@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.CLASS) public @interface Encodable {
58+
}
59+
60+
@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.CLASS) public static @interface Encodable.Field {
61+
method public abstract boolean inline() default false;
62+
method public abstract String name() default "";
63+
}
64+
65+
@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.CLASS) public static @interface Encodable.Ignore {
66+
}
67+
68+
@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.CLASS) public @interface ExtraProperty {
69+
method public abstract Class<?>[] allowedTypes() default {};
70+
}
71+
72+
}
73+
74+
package com.google.firebase.encoders.config {
75+
76+
public interface Configurator {
77+
method public void configure(@NonNull com.google.firebase.encoders.config.EncoderConfig<?>);
78+
}
79+
80+
public interface EncoderConfig<T extends com.google.firebase.encoders.config.EncoderConfig<T>> {
81+
method @NonNull public <U> T registerEncoder(@NonNull Class<U>, @NonNull com.google.firebase.encoders.ObjectEncoder<? super U>);
82+
method @NonNull public <U> T registerEncoder(@NonNull Class<U>, @NonNull com.google.firebase.encoders.ValueEncoder<? super U>);
83+
}
84+
85+
}
86+

encoders/firebase-encoders-processor/test-support/test-support.gradle renamed to encoders/firebase-encoders/firebase-encoders.gradle

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,28 @@
1313
// limitations under the License.
1414

1515
plugins {
16-
id 'java-library'
16+
id 'firebase-java-library'
1717
}
1818

19+
firebaseLibrary {
20+
publishSources = true
21+
publishJavadoc = false
22+
}
23+
24+
java {
25+
sourceCompatibility JavaVersion.VERSION_1_8
26+
targetCompatibility JavaVersion.VERSION_1_8
27+
}
28+
29+
1930
dependencies {
2031
implementation 'androidx.annotation:annotation:1.1.0'
21-
}
32+
33+
testImplementation 'junit:junit:4.13'
34+
testImplementation "com.google.truth:truth:$googleTruthVersion"
35+
36+
}
37+
38+
tasks.withType(JavaCompile) {
39+
options.compilerArgs << "-Werror"
40+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
version=16.0.0

firebase-crashlytics/firebase-crashlytics.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ thirdPartyLicenses {
5656
dependencies {
5757
compileOnly 'com.google.auto.value:auto-value-annotations:1.6.5'
5858

59+
implementation project(':encoders:firebase-encoders')
5960
implementation project(':encoders:firebase-encoders-json')
6061
implementation project(':firebase-common')
6162
implementation project(':firebase-components')

firebase-messaging-directboot/firebase-messaging-directboot.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ dependencies {
5252
implementation project(':transport:transport-api')
5353
implementation project(':transport:transport-runtime')
5454
implementation project(':transport:transport-backend-cct')
55+
implementation project(':encoders:firebase-encoders')
5556
implementation project(':encoders:firebase-encoders-json')
5657

5758
implementation 'androidx.annotation:annotation:1.1.0'

firebase-messaging/firebase-messaging.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ dependencies {
5353
implementation project(':transport:transport-api')
5454
implementation project(':transport:transport-runtime')
5555
implementation project(':transport:transport-backend-cct')
56+
implementation project(':encoders:firebase-encoders')
5657
implementation project(':encoders:firebase-encoders-json')
5758

5859
implementation 'androidx.annotation:annotation:1.1.0'

subprojects.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ firebase-storage:test-app
3737
protolite-well-known-types
3838

3939
encoders
40+
encoders:firebase-encoders
4041
encoders:firebase-encoders-json
4142
encoders:firebase-encoders-processor
42-
encoders:firebase-encoders-processor:test-support
4343
encoders:firebase-encoders-reflective
4444
encoders:firebase-decoders-json
4545

transport/transport-backend-cct/transport-backend-cct.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ android {
5353
dependencies {
5454
implementation project(':transport:transport-api')
5555
implementation project(':transport:transport-runtime')
56+
implementation project(':encoders:firebase-encoders')
5657
implementation project(':encoders:firebase-encoders-json')
5758
implementation 'androidx.annotation:annotation:1.1.0'
5859

0 commit comments

Comments
 (0)