From 598e9d586b68d8000efdeb10e33b601fc0cf5f50 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Tue, 29 Nov 2022 19:30:19 +0100 Subject: [PATCH] Introduce update_copyright_headers.sh shell script In order to automate maintenance of copyright headers in our source code (especially when merging PRs from external contributors), this commit introduces an update_copyright_headers.sh script (tested on mac OS) that will update the copyright headers of all Java, Kotlin, and Groovy source files that have been added or modified this year (or at least as far back as the git log history supports it). For example, running this script currently outputs the following. Updating copyright headers in Java, Kotlin, and Groovy source code for year 2022 warning: log for 'main' only goes back to Tue, 16 Aug 2022 16:24:55 +0200 --- update_copyright_headers.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100755 update_copyright_headers.sh diff --git a/update_copyright_headers.sh b/update_copyright_headers.sh new file mode 100755 index 00000000000..0f40cce2524 --- /dev/null +++ b/update_copyright_headers.sh @@ -0,0 +1,15 @@ +#!/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). +# +# 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 + +for file in $(git --no-pager diff --name-only --diff-filter=AM @{$current_year-01-01}..@{$current_year-12-31} | egrep "^.+\.(java|kotlin|groovy)$" | uniq); do + sed -i '' -E "s/Copyright 2002-[0-9]{4}/Copyright 2002-$current_year/g" $file; +done