From ac6aaa191340059c520b6903425bd69c42eda479 Mon Sep 17 00:00:00 2001 From: Tran Ngoc Nhan Date: Wed, 14 May 2025 04:08:06 +0700 Subject: [PATCH] Update copyright task Signed-off-by: Tran Ngoc Nhan --- CONTRIBUTING.adoc | 4 ++-- build.gradle | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.adoc b/CONTRIBUTING.adoc index e0706cea23f..9cf5a4b8af8 100644 --- a/CONTRIBUTING.adoc +++ b/CONTRIBUTING.adoc @@ -79,7 +79,7 @@ See https://github.com/spring-projects/spring-security/tree/main#building-from-s The wiki pages https://github.com/spring-projects/spring-framework/wiki/Code-Style[Code Style] and https://github.com/spring-projects/spring-framework/wiki/IntelliJ-IDEA-Editor-Settings[IntelliJ IDEA Editor Settings] define the source file coding standards we use along with some IDEA editor settings we customize. -To format the code as well as check the style, run `./gradlew format && ./gradlew check`. +To format the code as well as check the style, run `./gradlew format && ./gradlew updateCopyrights && ./gradlew check`. [[submit-a-pull-request]] === Submit a Pull Request @@ -104,7 +104,7 @@ If this is for an issue, consider a branch name with the issue number, like `gh- 6. [[update-copyright]] In all files you edited, if the copyright header is of the form 2002-20xx, update the final copyright year to the current year. 7. [[add-since]] If on `main`, add `@since` JavaDoc attributes to new public APIs that your PR adds 8. [[change-rnc]] If you are updating the XSD, please instead update the RNC file and then run `./gradlew :spring-security-config:rncToXsd`. -9. [[format-code]] For each commit, build the code using `./gradlew format && ./gradlew check`. +9. [[format-code]] For each commit, build the code using `./gradlew format && ./gradlew updateCopyrights && ./gradlew check`. This command ensures the code meets most of <>; a notable exception is import order. 10. [[commit-atomically]] Choose the granularity of your commits consciously and squash commits that represent multiple edits or corrections of the same logical change. diff --git a/build.gradle b/build.gradle index aee73839861..14a02e2048e 100644 --- a/build.gradle +++ b/build.gradle @@ -120,6 +120,32 @@ tasks.register('cloneRepository', IncludeRepoTask) { outputDirectory = project.hasProperty("cloneOutputDirectory") ? project.file("$cloneOutputDirectory") : defaultDirectory } +tasks.register('updateCopyrights') { + + def now = Calendar.instance.get(Calendar.YEAR) as String + def branch = project.hasProperty("branch") ? project.property("branch") : "origin/main" + def gitOutput = ["git", "diff", "--diff-filter=M", "--name-only", branch, "--", "*.java"].execute().text + gitOutput.readLines() + .collect { new File(it) } + .each { file -> + def line + file.withReader { reader -> + while (line = reader.readLine()) { + def matcher = line =~ /Copyright (20\d\d)-?(20\d\d)? the original author or authors.$/ + if (matcher.count) { + def beginningYear = matcher[0][1] + if (now != beginningYear && now != matcher[0][2]) { + def sourceCode = file.getText('UTF-8') + sourceCode = sourceCode.replaceFirst(/20\d\d(-20\d\d)?/, "$beginningYear-$now") + file.text = sourceCode + println "Update copyright for file: $file" + } + } + } + } + } +} + wrapperUpgrade { gradle { 'spring-security' {