Skip to content

Commit 0c78807

Browse files
committed
feat(protocol): optimize protoLint performance and caching
1 parent f8c5fb0 commit 0c78807

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

protocol/protoLint.gradle

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ task protoLint {
3434
group = "verification"
3535
description = "Validate Protobuf Enums using buf generated JSON AST. Enforces 'UNKNOWN_' prefix for index 0 to ensure JSON serialization backward compatibility."
3636

37-
// Explicitly declare dependency to avoid Gradle implicit dependency warnings
38-
// because generateProto outputs to the parent 'src' directory.
39-
dependsOn 'generateProto'
37+
// Explicitly depend on extractIncludeProto to ensure external protos
38+
// are available in build/extracted-include-protos/main before buf runs.
39+
dependsOn 'extractIncludeProto'
4040

4141
// Incremental build support: Only run if proto files or the script itself changes
4242
inputs.dir('src/main/protos')
@@ -118,14 +118,14 @@ task protoLint {
118118

119119
// A queue-based (BFS) approach to safely traverse all nested messages and enums
120120
// without using recursion, ensuring support for any nesting depth.
121-
def queue = []
121+
Queue queue = new ArrayDeque()
122122

123123
// Initial seed: top-level enums and messages
124-
protoFile.enumType?.each { queue << [def: it, parentName: ""] }
125-
protoFile.messageType?.each { queue << [def: it, parentName: ""] }
124+
protoFile.enumType?.each { queue.add([def: it, parentName: ""]) }
125+
protoFile.messageType?.each { queue.add([def: it, parentName: ""]) }
126126

127127
while (!queue.isEmpty()) {
128-
def item = queue.remove(0)
128+
def item = queue.poll()
129129
def definition = item.def
130130
def parentName = item.parentName
131131

@@ -152,14 +152,13 @@ task protoLint {
152152

153153
// 4. Report Results
154154
if (!errors.isEmpty()) {
155-
println "\n🚨 [Protocol Design Violation] The following enums violate the java-tron API evolution standard (Issue #6515):"
155+
println "\n [Protocol Design Violation] The following enums violate the java-tron API evolution standard (Issue #6515):"
156156
errors.each { println " - $it" }
157-
println "\n💡 Recommendation: To ensure proto3 JSON serialization backward compatibility, newly defined enums MUST reserve index 0 for an 'UNKNOWN_XXX' field.\n"
158157
throw new GradleException("Proto Enum validation failed. See above for details.")
159158
} else {
160159
println "✅ Proto Enum validation passed!"
161160
// Update marker file for Gradle incremental build cache
162-
markerFile.text = "Success: " + new Date().toString()
161+
markerFile.text = "Success"
163162
}
164163
}
165164
}

0 commit comments

Comments
 (0)