Update configuration for copyright headers to use "<year>-present" pattern

Historically, we have used `<introduction year>-<modification year>` as
the pattern for copyright headers.

For example: `Copyright 2002-2025 the original author or authors.`

However, we have been encouraged to use `present` as the modification
year.

In light of that, this commit updates the following to enforce the new
pattern.

- The patterns in our SpringHeaderCheck Checkstyle rules
- The `Copyright 2002-${year}` template in org.eclipse.jdt.ui.prefs
- The update_copyright_headers.sh script

See gh-35070
This commit is contained in:
Sam Brannen 2025-06-17 11:08:15 +02:00
parent 696692f1ed
commit 89140789b9
4 changed files with 11 additions and 16 deletions

View File

@ -6,7 +6,7 @@
<module name="io.spring.javaformat.checkstyle.check.SpringHeaderCheck">
<property name="fileExtensions" value="java"/>
<property name="headerType" value="apache2"/>
<property name="headerCopyrightPattern" value="20\d\d-20\d\d"/>
<property name="headerCopyrightPattern" value="20\d\d-present"/>
<property name="packageInfoHeaderType" value="none"/>
</module>
<module name="com.puppycrawl.tools.checkstyle.checks.NewlineAtEndOfFileCheck"/>

View File

@ -11,7 +11,7 @@
<module name="io.spring.javaformat.checkstyle.check.SpringHeaderCheck">
<property name="fileExtensions" value="java"/>
<property name="headerType" value="apache2"/>
<property name="headerCopyrightPattern" value="20\d\d-20\d\d"/>
<property name="headerCopyrightPattern" value="20\d\d-present"/>
<property name="packageInfoHeaderType" value="none"/>
</module>
<module name="com.puppycrawl.tools.checkstyle.checks.NewlineAtEndOfFileCheck"/>

File diff suppressed because one or more lines are too long

View File

@ -1,21 +1,16 @@
#!/bin/sh
#
# This shell script updates the copyright headers in source code files
# in the current branch that have been added or modified during the
# current year (at least as much as the `git diff` command supports the
# date range in terms of log history).
# in the current branch so that the headers conform to the pattern:
# <start-year>-present.
#
# For example, "Copyright 2002-2025" will be replaced with
# "Copyright 2002-current".
#
# This has only been tested on mac OS.
current_year=$(date +'%Y')
echo Updating copyright headers in Java, Kotlin, and Groovy source code for year $current_year
echo Updating copyright headers in Java, Kotlin, and Groovy source code
# Added/Modified this year and committed
for file in $(git --no-pager diff --name-only --diff-filter=AM @{$current_year-01-01}..@{$current_year-12-31} | egrep "^.+\.(java|kt|groovy)$" | uniq); do
sed -i '' -E "s/Copyright 2002-[0-9]{4}/Copyright 2002-$current_year/g" $file;
done
# Added/Modified and staged but not yet committed
for file in $(git --no-pager diff --name-only --diff-filter=AM --cached | egrep "^.+\.(java|kt|groovy)$" | uniq); do
sed -i '' -E "s/Copyright 2002-[0-9]{4}/Copyright 2002-$current_year/g" $file;
for file in $(find -E . -type f -regex '.+\.(java|kt|groovy)$' | uniq); do
sed -i '' -E "s/Copyright ([0-9]{4})-[0-9]{4}/Copyright \1-present/g" $file;
done