Skip to content

Commit b3dc67e

Browse files
committed
Prototype a lint check for fis.
1 parent 7a925e6 commit b3dc67e

File tree

5 files changed

+135
-0
lines changed

5 files changed

+135
-0
lines changed
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+
plugins {
16+
id 'org.jetbrains.kotlin.jvm'
17+
}
18+
19+
def lintVersion = '26.4.1'
20+
21+
dependencies {
22+
compileOnly "com.android.tools.lint:lint-api:$lintVersion"
23+
compileOnly "com.android.tools.lint:lint-checks:$lintVersion"
24+
25+
testImplementation "junit:junit:4.12"
26+
testImplementation "com.android.tools.lint:lint:$lintVersion"
27+
testImplementation "com.android.tools.lint:lint-tests:$lintVersion"
28+
testImplementation "com.android.tools:testutils:$lintVersion"
29+
}
30+
31+
jar {
32+
manifest {
33+
attributes('Lint-Registry-v2': 'com.google.firebase.installations.lint.Checks')
34+
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
package com.google.firebase.installations.lint.com.google.firebase.installations.lint
16+
17+
import com.android.tools.lint.client.api.IssueRegistry
18+
import com.android.tools.lint.detector.api.Issue
19+
20+
class Checks: IssueRegistry() {
21+
override val issues: List<Issue>
22+
get() = listOf()
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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+
package com.google.firebase.installations.lint.com.google.firebase.installations.lint
16+
17+
import com.android.tools.lint.detector.api.Detector
18+
19+
import com.android.builder.model.MavenCoordinates
20+
import com.android.tools.lint.detector.api.Category
21+
import com.android.tools.lint.detector.api.Context
22+
import com.android.tools.lint.detector.api.Implementation
23+
import com.android.tools.lint.detector.api.Issue
24+
import com.android.tools.lint.detector.api.Location
25+
import com.android.tools.lint.detector.api.Scope
26+
import com.android.tools.lint.detector.api.Severity
27+
28+
class IncompatibleIidVersionDetector : Detector() {
29+
companion object Issues {
30+
private val IMPLEMENTATION = Implementation(
31+
IncompatibleIidVersionDetector::class.java,
32+
Scope.EMPTY
33+
)
34+
35+
@JvmField
36+
val INCOMPATIBLE_IID_VERSION = Issue.create(
37+
id = "IncompatibleIidVersion",
38+
briefDescription = "FirebaseInstanceId version is not compatible with FirebaseInstallations",
39+
40+
explanation = """
41+
Blah-blah-blah, some text for developers.
42+
""",
43+
category = Category.INTEROPERABILITY,
44+
priority = 1,
45+
severity = Severity.ERROR,
46+
implementation = IMPLEMENTATION
47+
)
48+
}
49+
50+
override fun beforeCheckEachProject(context: Context) {
51+
if (!context.project.isGradleProject) {
52+
return
53+
}
54+
55+
for (variant in context.project.gradleProjectModel.variants) {
56+
for (lib in variant.mainArtifact.dependencies.libraries) {
57+
val coordinates = lib.resolvedCoordinates
58+
if (coordinates.groupId == "com.google.firebase" && coordinates.artifactId == "firebase-iid") {
59+
if (isIncompatibleVersion(coordinates)) {
60+
context.report(INCOMPATIBLE_IID_VERSION,
61+
Location.create(context.file),
62+
"Incompatible IID version found in variant ${variant.name}: ${lib.name}")
63+
}
64+
}
65+
}
66+
}
67+
}
68+
69+
private fun isIncompatibleVersion(coordinates: MavenCoordinates): Boolean {
70+
// TODO: implement version check
71+
return coordinates.version != "0.0.0"
72+
}
73+
}

firebase-installations/firebase-installations.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ dependencies {
4949
compileOnly "com.google.auto.value:auto-value-annotations:1.6.5"
5050
annotationProcessor "com.google.auto.value:auto-value:1.6.2"
5151

52+
// ship the check within the SDK
53+
lintPublish project(':firebase-installations:customer-lint-checks')
54+
5255
testImplementation 'androidx.test:core:1.2.0'
5356
testImplementation 'junit:junit:4.12'
5457
testImplementation "org.robolectric:robolectric:$robolectricVersion"

subprojects.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ firebase-inappmessaging-display
2525
firebase-inappmessaging-display:ktx
2626
firebase-installations-interop
2727
firebase-installations
28+
firebase-installations:customer-lint-checks
2829
firebase-segmentation
2930
firebase-storage
3031
firebase-storage:ktx

0 commit comments

Comments
 (0)