Skip to content

Commit 1770050

Browse files
authored
chore: Update codebase formatting tool and introduce metalava (#1695)
This PR includes: * A new tools module that is only used to run metalava and generate api.txt. * Introduce spotless plugin to run auto format for potential kotlin files.
1 parent 093a007 commit 1770050

File tree

12 files changed

+1249
-13
lines changed

12 files changed

+1249
-13
lines changed

.kokoro/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ test)
5252
RETURN_CODE=$?
5353
;;
5454
lint)
55-
mvn com.coveo:fmt-maven-plugin:check -B -ntp
55+
mvn com.coveo:fmt-maven-plugin:check -B -ntp && mvn -pl google-cloud-firestore spotless:check -B -ntp
5656
RETURN_CODE=$?
5757
;;
5858
javadoc)

google-cloud-firestore/pom.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,24 @@
214214
<groupId>org.codehaus.mojo</groupId>
215215
<artifactId>flatten-maven-plugin</artifactId>
216216
</plugin>
217+
<plugin>
218+
<groupId>com.diffplug.spotless</groupId>
219+
<artifactId>spotless-maven-plugin</artifactId>
220+
<version>2.43.0</version>
221+
<configuration>
222+
<kotlin>
223+
<includes>
224+
<include>src/main/java/**/*.kt</include>
225+
<include>src/test/java/**/*.kt</include>
226+
</includes>
227+
228+
<ktfmt>
229+
<version>0.46</version> <!-- optional -->
230+
<style>GOOGLE</style> <!-- optional, other options are DROPBOX, GOOGLE and KOTLINLANG -->
231+
</ktfmt>
232+
</kotlin>
233+
</configuration>
234+
</plugin>
217235
</plugins>
218236
</build>
219237

google-cloud-firestore/src/main/java/com/google/cloud/firestore/GeoPoint.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ LatLng toProto() {
7676
public String toString() {
7777
return "GeoPoint { latitude=" + this.latitude + ", longitude=" + this.longitude + " }";
7878
}
79+
7980
/**
8081
* Returns true if this GeoPoint is equal to the provided object.
8182
*

google-cloud-firestore/src/main/java/com/google/cloud/firestore/QuerySnapshot.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ public int hashCode() {
151151
}
152152
};
153153
}
154+
154155
/**
155156
* Returns the query for the snapshot.
156157
*

google-cloud-firestore/src/main/java/com/google/cloud/firestore/ReadTimeTransaction.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public boolean hasTransactionId() {
5757
public ApiFuture<DocumentSnapshot> get(@Nonnull DocumentReference documentRef) {
5858
Tracing.getTracer().getCurrentSpan().addAnnotation(TraceUtil.SPAN_NAME_GETDOCUMENT);
5959
return ApiFutures.transform(
60-
firestore.getAll(new DocumentReference[] {documentRef}, /*fieldMask=*/ null, readTime),
60+
firestore.getAll(new DocumentReference[] {documentRef}, /* fieldMask= */ null, readTime),
6161
snapshots -> snapshots.isEmpty() ? null : snapshots.get(0),
6262
MoreExecutors.directExecutor());
6363
}
@@ -66,14 +66,14 @@ public ApiFuture<DocumentSnapshot> get(@Nonnull DocumentReference documentRef) {
6666
@Override
6767
public ApiFuture<List<DocumentSnapshot>> getAll(
6868
@Nonnull DocumentReference... documentReferences) {
69-
return firestore.getAll(documentReferences, /*fieldMask=*/ null, readTime);
69+
return firestore.getAll(documentReferences, /* fieldMask= */ null, readTime);
7070
}
7171

7272
@Nonnull
7373
@Override
7474
public ApiFuture<List<DocumentSnapshot>> getAll(
7575
@Nonnull DocumentReference[] documentReferences, @Nullable FieldMask fieldMask) {
76-
return firestore.getAll(documentReferences, /*fieldMask=*/ null, readTime);
76+
return firestore.getAll(documentReferences, /* fieldMask= */ null, readTime);
7777
}
7878

7979
@Nonnull

google-cloud-firestore/src/main/java/com/google/cloud/firestore/ServerSideTransaction.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,9 @@ public ApiFuture<DocumentSnapshot> get(@Nonnull DocumentReference documentRef) {
151151
return ApiFutures.transform(
152152
firestore.getAll(
153153
new DocumentReference[] {documentRef},
154-
/*fieldMask=*/ null,
154+
/* fieldMask= */ null,
155155
transactionId,
156-
/*readTime=*/ null),
156+
/* readTime= */ null),
157157
snapshots -> snapshots.isEmpty() ? null : snapshots.get(0),
158158
MoreExecutors.directExecutor());
159159
}
@@ -170,7 +170,7 @@ public ApiFuture<List<DocumentSnapshot>> getAll(
170170
@Nonnull DocumentReference... documentReferences) {
171171
Preconditions.checkState(isEmpty(), READ_BEFORE_WRITE_ERROR_MSG);
172172
return firestore.getAll(
173-
documentReferences, /*fieldMask=*/ null, transactionId, /*readTime=*/ null);
173+
documentReferences, /* fieldMask= */ null, transactionId, /* readTime= */ null);
174174
}
175175

176176
/**
@@ -186,7 +186,7 @@ public ApiFuture<List<DocumentSnapshot>> getAll(
186186
public ApiFuture<List<DocumentSnapshot>> getAll(
187187
@Nonnull DocumentReference[] documentReferences, @Nullable FieldMask fieldMask) {
188188
Preconditions.checkState(isEmpty(), READ_BEFORE_WRITE_ERROR_MSG);
189-
return firestore.getAll(documentReferences, fieldMask, transactionId, /*readTime=*/ null);
189+
return firestore.getAll(documentReferences, fieldMask, transactionId, /* readTime= */ null);
190190
}
191191

192192
/**
@@ -199,7 +199,7 @@ public ApiFuture<List<DocumentSnapshot>> getAll(
199199
@Nonnull
200200
public ApiFuture<QuerySnapshot> get(@Nonnull Query query) {
201201
Preconditions.checkState(isEmpty(), READ_BEFORE_WRITE_ERROR_MSG);
202-
return query.get(transactionId, /*readTime=*/ null);
202+
return query.get(transactionId, /* readTime= */ null);
203203
}
204204

205205
/**

google-cloud-firestore/src/main/java/com/google/cloud/firestore/ServerSideTransactionRunner.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ private static boolean isRetryableTransactionError(ApiException exception) {
251251
return false;
252252
}
253253
}
254+
254255
/** Rolls the transaction back and returns the error. */
255256
private ApiFuture<T> rollbackAndReject(final Throwable throwable) {
256257
final SettableApiFuture<T> failedTransaction = SettableApiFuture.create();

google-cloud-firestore/src/test/java/com/google/cloud/firestore/LocalFirestoreHelper.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ public static Answer<RunAggregationQueryResponse> countQueryResponse(
375375
new RunAggregationQueryResponse[] {
376376
createCountQueryResponse(count, readTime),
377377
},
378-
/*throwable=*/ null);
378+
/* throwable= */ null);
379379
}
380380

381381
public static Answer<RunAggregationQueryResponse> countQueryResponse(Throwable throwable) {
@@ -388,7 +388,7 @@ public static Answer<RunAggregationQueryResponse> aggregationQueryResponses(
388388
new RunAggregationQueryResponse[] {
389389
createCountQueryResponse(count1, null), createCountQueryResponse(count2, null),
390390
},
391-
/*throwable=*/ null);
391+
/* throwable= */ null);
392392
}
393393

394394
public static Answer<RunAggregationQueryResponse> aggregationQueryResponses(
@@ -1209,6 +1209,7 @@ public RequestResponsePair(
12091209
this.response = response;
12101210
}
12111211
}
1212+
12121213
/**
12131214
* Contains a map of request/response pairs that are used to create stub responses when
12141215
* `sendRequest()` is called.

google-cloud-firestore/src/test/java/com/google/cloud/firestore/MapperTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -949,11 +949,11 @@ public void setValue(String value) {
949949
}
950950

951951
private static <T> T deserialize(String jsonString, Class<T> clazz) {
952-
return deserialize(jsonString, clazz, /*docRef=*/ null);
952+
return deserialize(jsonString, clazz, /* docRef= */ null);
953953
}
954954

955955
private static <T> T deserialize(Map<String, Object> json, Class<T> clazz) {
956-
return deserialize(json, clazz, /*docRef=*/ null);
956+
return deserialize(json, clazz, /* docRef= */ null);
957957
}
958958

959959
private static <T> T deserialize(String jsonString, Class<T> clazz, DocumentReference docRef) {

tools/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
Run below command to generate api.txt
3+
```bash
4+
mvn exec:java -Dexec.mainClass="com.android.tools.metalava.Driver" -Dexec.args="--source-path ../google-cloud-firestore/src/main/java --hide HiddenSuperclass --hide HiddenAbstractMethod --api api.txt --format=v2"
5+
```

0 commit comments

Comments
 (0)