Skip to content

Commit 62e22dd

Browse files
committed
address comments
1 parent 45af5f9 commit 62e22dd

File tree

2 files changed

+49
-59
lines changed

2 files changed

+49
-59
lines changed

buildSrc/src/main/java/com/google/firebase/gradle/plugins/semver/ApiDiffer.kt

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -55,44 +55,44 @@ abstract class ApiDiffer : DefaultTask() {
5555
}
5656
val afterJar = readApi(currentJar.get())
5757
val beforeJar = readApi(previousJar.get())
58-
val apiDeltas = mutableListOf<Delta>()
5958
val classKeys = afterJar.keys union beforeJar.keys
60-
val apiDeltas =
59+
val apiDeltas =
6160
classKeys
6261
.map { className -> Pair(beforeJar.get(className), afterJar.get(className)) }
6362
.flatMap { (before, after) ->
6463
DeltaType.values().flatMap { it.getViolations(before, after) }
6564
}
66-
var deltaViolations: List<Delta> = mutableListOf()
67-
if (curVersionDelta == VersionDelta.MINOR) {
68-
deltaViolations = apiDeltas.filter { it.versionDelta == VersionDelta.MAJOR }
69-
} else if (curVersionDelta == VersionDelta.PATCH) {
70-
deltaViolations = apiDeltas
71-
}
72-
if (apiDeltas.size != 0) {
73-
println(
74-
"Here is a list of all the minor/major version bump changes which are made since the last release"
75-
)
76-
apiDeltas.forEach { println("[${it.versionDelta}] ${it.description}") }
65+
val deltaViolations: List<Delta> =
66+
if (curVersionDelta == VersionDelta.MINOR)
67+
apiDeltas.filter { it.versionDelta == VersionDelta.MAJOR }
68+
else if (curVersionDelta == VersionDelta.PATCH) apiDeltas else mutableListOf()
69+
if (!apiDeltas.isEmpty()) {
70+
val printString =
71+
apiDeltas.joinToString(
72+
prefix =
73+
"Here is a list of all the minor/major version bump changes which are made since the last release.\n",
74+
separator = "\n"
75+
) {
76+
"[${it.versionDelta}] ${it.description}"
77+
}
78+
println(printString)
7779
}
78-
if (deltaViolations.size != 0) {
79-
var outputString =
80-
"Here is a list of all the violations which needs to be fixed before we could release.\n"
81-
deltaViolations.forEach { outputString += "[${it.versionDelta}] ${it.description}\n" }
80+
if (!deltaViolations.isEmpty()) {
81+
val outputString =
82+
deltaViolations.joinToString(
83+
prefix =
84+
"Here is a list of all the violations which needs to be fixed before we could release.\n",
85+
separator = "\n"
86+
) {
87+
"[${it.versionDelta}] ${it.description}"
88+
}
8289
throw GradleException(outputString)
8390
}
8491
}
8592

8693
private fun readApi(jarPath: String): Map<String, ClassInfo> {
8794
val classes: Map<String, ClassNode> = readClassNodes(Paths.get(jarPath))
88-
var classInfoDict = mutableMapOf<String, ClassInfo>()
89-
for (classNodeInfo in classes) {
90-
classInfoDict[classNodeInfo.key] = ClassInfo(classNodeInfo.value, classes)
91-
}
92-
for (classNodeInfo in classes) {
93-
classInfoDict[classNodeInfo.key] = ClassInfo(classNodeInfo.value, classes)
94-
}
95-
return classInfoDict
95+
return classes.entries.associate { (key, value) -> key to ClassInfo(value, classes) }
9696
}
9797

9898
/** Returns true if the class is local or anonymous. */

buildSrc/src/main/java/com/google/firebase/gradle/plugins/semver/ClassInfo.kt

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -33,32 +33,23 @@ class ClassInfo(val _node: ClassNode, val _classNodes: Map<String, ClassNode>) {
3333
this.methods = getAllMethods(_node, _classNodes)
3434
}
3535

36-
fun getAllFields(node: ClassNode): Map<String, FieldNode> {
37-
var fields: MutableMap<String, FieldNode> = mutableMapOf()
38-
for (field in node.fields) {
39-
val descriptor = AccessDescriptor(field.access)
40-
if (descriptor.isSynthetic() || UtilityClass.isObfuscatedSymbol(field.name)) continue
41-
fields.put("${field.name}-${field.desc}", field)
42-
}
43-
return fields
44-
}
36+
fun getAllFields(node: ClassNode): Map<String, FieldNode> =
37+
node.fields
38+
.filterNot {
39+
AccessDescriptor(it.access).isSynthetic() || UtilityClass.isObfuscatedSymbol(it.name)
40+
}
41+
.associate { field -> "${field.name}-${field.desc}" to field }
4542

46-
fun getAllMethods(node: ClassNode, classNodes: Map<String, ClassNode>): Map<String, MethodNode> {
47-
return getAllStaticMethods(node) + getAllNonStaticMethods(node, classNodes)
48-
}
43+
fun getAllMethods(node: ClassNode, classNodes: Map<String, ClassNode>): Map<String, MethodNode> =
44+
getAllStaticMethods(node) + getAllNonStaticMethods(node, classNodes)
4945

50-
fun getAllStaticMethods(node: ClassNode): Map<String, MethodNode> {
51-
var staticMethods: MutableMap<String, MethodNode> = mutableMapOf()
52-
for (method in node.methods) {
53-
val descriptor = AccessDescriptor(method.access)
54-
if (!descriptor.isStatic() || descriptor.isSynthetic()) continue
55-
if (UtilityClass.isObfuscatedSymbol(method.name) || method.name.equals("<clint>")) {
56-
continue
46+
fun getAllStaticMethods(node: ClassNode): Map<String, MethodNode> =
47+
node.methods
48+
.filterNot {
49+
!AccessDescriptor(it.access).isStatic() || AccessDescriptor(it.access).isSynthetic()
5750
}
58-
staticMethods.put("${method.name}-${method.desc}", method)
59-
}
60-
return staticMethods
61-
}
51+
.filterNot { UtilityClass.isObfuscatedSymbol(it.name) || it.name.equals("<clint>") }
52+
.associate { method -> "${method.name}-${method.desc}" to method }
6253

6354
fun getAllNonStaticMethods(
6455
node: ClassNode?,
@@ -70,17 +61,16 @@ class ClassInfo(val _node: ClassNode, val _classNodes: Map<String, ClassNode>) {
7061
if (methodsCache.containsKey(node.name)) {
7162
return methodsCache.get(node.name)!!
7263
}
73-
var result = mutableMapOf<String, MethodNode>()
74-
for (method in node.methods) {
75-
var descriptor = AccessDescriptor(method.access)
76-
if (descriptor.isSynthetic() || descriptor.isBridge() || descriptor.isStatic()) {
77-
continue
78-
}
79-
if (UtilityClass.isObfuscatedSymbol(method.name)) {
80-
continue
81-
}
82-
result.put("${method.name}-${method.desc}", method)
83-
}
64+
var result =
65+
node.methods
66+
.filterNot {
67+
(AccessDescriptor(it.access).isSynthetic() ||
68+
AccessDescriptor(it.access).isBridge() ||
69+
AccessDescriptor(it.access).isStatic())
70+
}
71+
.filterNot { UtilityClass.isObfuscatedSymbol(it.name) }
72+
.associate { method -> "${method.name}-${method.desc}" to method }
73+
8474
if (node.superName != null) {
8575
result =
8676
(result + getAllNonStaticMethods(classNodes.get(node.superName), classNodes))

0 commit comments

Comments
 (0)