This is an automated email from the ASF dual-hosted git repository.

chia7712 pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/kafka.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 630857c29cb MINOR: Add Gradle task to verify ASF license header in 
JSON files (#20825)
630857c29cb is described below

commit 630857c29cb0c0d1f998974e02ee760d6baa955f
Author: Ming-Yen Chung <[email protected]>
AuthorDate: Tue Dec 2 17:39:25 2025 +0800

    MINOR: Add Gradle task to verify ASF license header in JSON files (#20825)
    
    As
    
    
[discussed](https://github.com/apache/kafka/pull/20800#issuecomment-3479696451),
    typo in license header sometimes can be found like #20800.  To address
    this, add a Gradle task to verify ASF license header in JSON files under
    `src/main/resources`
    
    If a JSON file’s header does not match `gradle/LICENSE.json`, the task
    will fail.
    For example:
    ```
    ❯ ./gradlew clean build -x test
    ...
    > Task :clients:checkJsonLicenseHeader FAILED
    
     clients: Incorrect ASF license header in JSON files:
    
     -
    
/Users/ming/code/kafka/clients/src/main/resources/common/message/AddOffsetsToTxnRequest.json
    
    [Incubating] Problems report is available at:
    file:///Users/ming/code/kafka/build/reports/problems/problems-report.html
    
    FAILURE: Build failed with an exception.
    
    * Where:
    Build file '/Users/ming/code/kafka/build.gradle' line: 895
    
    * What went wrong:
    Execution failed for task ':clients:checkJsonLicenseHeader'.
    > Project 'clients' has 1 JSON files with incorrect ASF license header.
    ...
    ```
    
    Reviewers: Ken Huang <[email protected]>, Chia-Ping Tsai
     <[email protected]>
---
 build.gradle        | 23 +++++++++++++++++++++++
 gradle/LICENSE.json | 14 ++++++++++++++
 2 files changed, 37 insertions(+)

diff --git a/build.gradle b/build.gradle
index bc0eead2f8c..6a83f8cbf70 100644
--- a/build.gradle
+++ b/build.gradle
@@ -875,6 +875,29 @@ subprojects {
       removeUnusedImports()
     }
   }
+
+  tasks.register("checkJsonLicenseHeader") {
+    group = "Verification"
+    description = "Verify ASF License header in JSON files"
+
+    doLast {
+      def asfHeader = 
file("${rootProject.projectDir}/gradle/LICENSE.json").readLines()*.trim()
+
+      def incorrectFiles = fileTree(projectDir) {
+        include 'src/main/resources/**/*.json'
+        include 'src/test/resources/**/*.json'
+      }.findAll { f ->
+        f.readLines().take(asfHeader.size())*.trim() != asfHeader
+      }
+
+      if (incorrectFiles) {
+        println "\n${project.name}: Incorrect ASF license header in JSON 
files:"
+        incorrectFiles.each { println "  - $it" }
+        throw new GradleException("${incorrectFiles.size()} JSON files with 
incorrect ASF license header")
+      }
+    }
+  }
+  check.dependsOn("checkJsonLicenseHeader")
 }
 
 gradle.taskGraph.whenReady { taskGraph ->
diff --git a/gradle/LICENSE.json b/gradle/LICENSE.json
new file mode 100644
index 00000000000..dafec903c0f
--- /dev/null
+++ b/gradle/LICENSE.json
@@ -0,0 +1,14 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements.  See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//    http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
\ No newline at end of file

Reply via email to