Skip to content

Commit 26cc04d

Browse files
authored
Enable errorprone only by request. (#1461)
* Enable errorprone only by request. The motivation is that errorprone produces different bytecode than javac this confuses retrolambda's desugaring where it fails to correctly desugar try-with-resources. To enable errorprone one needs to run: ``` ./gradlew :mylib:mytask withErrorProne ``` * Fix JDK java8 issue
1 parent 41ad413 commit 26cc04d

File tree

5 files changed

+64
-45
lines changed

5 files changed

+64
-45
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ Firebase Android libraries exercise all three types of tests recommended by the
6363
Depending on the requirements of the specific project, some or all of these
6464
tests may be used to support changes.
6565

66+
> :warning: **Running tests with errorprone**
67+
>
68+
> To run with errorprone add `withErrorProne` to the command line, e.g.
69+
>
70+
> `./gradlew :<firebase-project>:check withErrorProne`.
71+
6672
### Unit Testing
6773

6874
These are tests that run on your machine's local Java Virtual Machine (JVM). At

build.gradle

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,11 @@ buildscript {
4343
}
4444

4545
apply from: 'sdkProperties.gradle'
46+
apply from: "gradle/errorProne.gradle"
4647

4748
ext {
4849
playServicesVersion = '16.0.1'
4950
supportAnnotationsVersion = '28.0.0'
50-
errorproneVersion = '2.3.2'
51-
errorproneJavacVersion = '9+181-r4173-1'
5251
googleTruthVersion = '0.45'
5352
robolectricVersion = '4.3.1'
5453
}
@@ -72,12 +71,7 @@ configure(subprojects) {
7271
jcenter()
7372
mavenLocal()
7473
}
75-
apply plugin: 'net.ltgt.errorprone'
76-
dependencies {
77-
errorprone "com.google.errorprone:error_prone_core:$errorproneVersion"
78-
errorproneJavac "com.google.errorprone:javac:$errorproneJavacVersion"
7974

80-
}
8175
apply plugin: 'com.github.sherter.google-java-format'
8276
googleJavaFormat {
8377
toolVersion = '1.7'
@@ -99,10 +93,6 @@ configure(subprojects) {
9993
exclude '**/package-info.java'
10094
}
10195

102-
tasks.withType(JavaCompile) {
103-
options.errorprone.excludedPaths = '.*/build/generated/.*'
104-
}
105-
10696
apply plugin: "org.jlleitschuh.gradle.ktlint"
10797
}
10898

firebase-abt/src/main/java/com/google/firebase/abt/FirebaseABTesting.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
package com.google.firebase.abt;
1616

1717
import static com.google.firebase.abt.AbtExperimentInfo.validateAbtExperimentInfo;
18-
import static com.google.firebase.abt.FirebaseABTesting.OriginService.INAPP_MESSAGING;
19-
import static com.google.firebase.abt.FirebaseABTesting.OriginService.REMOTE_CONFIG;
2018

2119
import android.content.Context;
2220
import androidx.annotation.Nullable;
@@ -67,7 +65,7 @@ public class FirebaseABTesting {
6765
* Select keys of fields in the experiment descriptions returned from the Firebase Remote Config
6866
* server.
6967
*/
70-
@StringDef({REMOTE_CONFIG, INAPP_MESSAGING})
68+
@StringDef({OriginService.REMOTE_CONFIG, OriginService.INAPP_MESSAGING})
7169
@Retention(RetentionPolicy.SOURCE)
7270
public @interface OriginService {
7371

firebase-config/src/main/java/com/google/firebase/remoteconfig/RemoteConfigConstants.java

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,6 @@
1414

1515
package com.google.firebase.remoteconfig;
1616

17-
import static com.google.firebase.remoteconfig.RemoteConfigConstants.ExperimentDescriptionFieldKey.EXPERIMENT_ID;
18-
import static com.google.firebase.remoteconfig.RemoteConfigConstants.ExperimentDescriptionFieldKey.VARIANT_ID;
19-
import static com.google.firebase.remoteconfig.RemoteConfigConstants.RequestFieldKey.ANALYTICS_USER_PROPERTIES;
20-
import static com.google.firebase.remoteconfig.RemoteConfigConstants.RequestFieldKey.APP_ID;
21-
import static com.google.firebase.remoteconfig.RemoteConfigConstants.RequestFieldKey.APP_VERSION;
22-
import static com.google.firebase.remoteconfig.RemoteConfigConstants.RequestFieldKey.COUNTRY_CODE;
23-
import static com.google.firebase.remoteconfig.RemoteConfigConstants.RequestFieldKey.INSTANCE_ID;
24-
import static com.google.firebase.remoteconfig.RemoteConfigConstants.RequestFieldKey.INSTANCE_ID_TOKEN;
25-
import static com.google.firebase.remoteconfig.RemoteConfigConstants.RequestFieldKey.LANGUAGE_CODE;
26-
import static com.google.firebase.remoteconfig.RemoteConfigConstants.RequestFieldKey.PACKAGE_NAME;
27-
import static com.google.firebase.remoteconfig.RemoteConfigConstants.RequestFieldKey.PLATFORM_VERSION;
28-
import static com.google.firebase.remoteconfig.RemoteConfigConstants.RequestFieldKey.SDK_VERSION;
29-
import static com.google.firebase.remoteconfig.RemoteConfigConstants.RequestFieldKey.TIME_ZONE;
30-
import static com.google.firebase.remoteconfig.RemoteConfigConstants.ResponseFieldKey.ENTRIES;
31-
import static com.google.firebase.remoteconfig.RemoteConfigConstants.ResponseFieldKey.EXPERIMENT_DESCRIPTIONS;
32-
import static com.google.firebase.remoteconfig.RemoteConfigConstants.ResponseFieldKey.STATE;
33-
3417
import androidx.annotation.StringDef;
3518
import java.lang.annotation.Retention;
3619
import java.lang.annotation.RetentionPolicy;
@@ -41,7 +24,7 @@
4124
* @author Lucas Png
4225
* @hide
4326
*/
44-
public class RemoteConfigConstants {
27+
public final class RemoteConfigConstants {
4528
public static final String FETCH_REGEX_URL =
4629
"https://firebaseremoteconfig.googleapis.com/v1/projects/%s/namespaces/%s:fetch";
4730

@@ -50,17 +33,17 @@ public class RemoteConfigConstants {
5033
* server.
5134
*/
5235
@StringDef({
53-
INSTANCE_ID,
54-
INSTANCE_ID_TOKEN,
55-
APP_ID,
56-
COUNTRY_CODE,
57-
LANGUAGE_CODE,
58-
PLATFORM_VERSION,
59-
TIME_ZONE,
60-
APP_VERSION,
61-
PACKAGE_NAME,
62-
SDK_VERSION,
63-
ANALYTICS_USER_PROPERTIES
36+
RequestFieldKey.INSTANCE_ID,
37+
RequestFieldKey.INSTANCE_ID_TOKEN,
38+
RequestFieldKey.APP_ID,
39+
RequestFieldKey.COUNTRY_CODE,
40+
RequestFieldKey.LANGUAGE_CODE,
41+
RequestFieldKey.PLATFORM_VERSION,
42+
RequestFieldKey.TIME_ZONE,
43+
RequestFieldKey.APP_VERSION,
44+
RequestFieldKey.PACKAGE_NAME,
45+
RequestFieldKey.SDK_VERSION,
46+
RequestFieldKey.ANALYTICS_USER_PROPERTIES
6447
})
6548
@Retention(RetentionPolicy.SOURCE)
6649
public @interface RequestFieldKey {
@@ -78,7 +61,11 @@ public class RemoteConfigConstants {
7861
}
7962

8063
/** Keys of fields in the Fetch response body from the Firebase Remote Config server. */
81-
@StringDef({ENTRIES, EXPERIMENT_DESCRIPTIONS, STATE})
64+
@StringDef({
65+
ResponseFieldKey.ENTRIES,
66+
ResponseFieldKey.EXPERIMENT_DESCRIPTIONS,
67+
ResponseFieldKey.STATE
68+
})
8269
@Retention(RetentionPolicy.SOURCE)
8370
public @interface ResponseFieldKey {
8471
String ENTRIES = "entries";
@@ -90,7 +77,10 @@ public class RemoteConfigConstants {
9077
* Select keys of fields in the experiment descriptions returned from the Firebase Remote Config
9178
* server.
9279
*/
93-
@StringDef({EXPERIMENT_ID, VARIANT_ID})
80+
@StringDef({
81+
ExperimentDescriptionFieldKey.EXPERIMENT_ID,
82+
ExperimentDescriptionFieldKey.VARIANT_ID
83+
})
9484
@Retention(RetentionPolicy.SOURCE)
9585
public @interface ExperimentDescriptionFieldKey {
9686
String EXPERIMENT_ID = "experimentId";

gradle/errorProne.gradle

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2020 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+
def isErrorProneRequested = getGradle().getStartParameter().getTaskNames().contains("withErrorProne")
16+
17+
def errorproneVersion = '2.3.2'
18+
def errorproneJavacVersion = '9+181-r4173-1'
19+
20+
if (isErrorProneRequested) {
21+
configure(subprojects) {
22+
apply plugin: 'net.ltgt.errorprone'
23+
dependencies {
24+
errorprone "com.google.errorprone:error_prone_core:$errorproneVersion"
25+
errorproneJavac "com.google.errorprone:javac:$errorproneJavacVersion"
26+
27+
}
28+
tasks.withType(JavaCompile) {
29+
options.errorprone.excludedPaths = '.*/build/generated/.*'
30+
}
31+
}
32+
}
33+
34+
// marker task to enable errorprone diagnostics.
35+
task withErrorProne {}

0 commit comments

Comments
 (0)