Skip to content

Update copyright task #17100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CONTRIBUTING.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 <<code-style,the style guide>>; 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.
Expand Down
26 changes: 26 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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' {
Expand Down