@@ -4,6 +4,46 @@ repo_root="$(cd "${script_dir}/.." && pwd)"
44
55filesWithOutCopyright=()
66filesWithOutSPDX=()
7+ filesWithInvalidHeader=()
8+ filesWithAdunaYearAfter2020=()
9+ expectedHeader=(
10+ " /*******************************************************************************"
11+ " __YEAR__"
12+ " *"
13+ " * All rights reserved. This program and the accompanying materials"
14+ " * are made available under the terms of the Eclipse Distribution License v1.0"
15+ " * which accompanies this distribution, and is available at"
16+ " * http://www.eclipse.org/org/documents/edl-v10.php."
17+ " *"
18+ " * SPDX-License-Identifier: BSD-3-Clause"
19+ " *******************************************************************************/"
20+ )
21+
22+ rewrite_header () {
23+ local file=" $1 "
24+ local year_line=" $2 "
25+ local tmp_file
26+ local mode
27+ mode=$( stat -f %Lp " $file " 2> /dev/null || stat -c %a " $file " )
28+ tmp_file=" $( mktemp) "
29+ {
30+ echo " ${expectedHeader[0]} "
31+ echo " $year_line "
32+ echo " ${expectedHeader[2]} "
33+ echo " ${expectedHeader[3]} "
34+ echo " ${expectedHeader[4]} "
35+ echo " ${expectedHeader[5]} "
36+ echo " ${expectedHeader[6]} "
37+ echo " ${expectedHeader[7]} "
38+ echo " ${expectedHeader[8]} "
39+ echo " ${expectedHeader[9]} "
40+ tail -n +11 " $file "
41+ } > " $tmp_file "
42+ if [ -n " $mode " ]; then
43+ chmod " $mode " " $tmp_file "
44+ fi
45+ mv " $tmp_file " " $file "
46+ }
747
848for i in $( find " ${repo_root} " -name pom.xml) ; do
949 if [[ " $i " == " ${repo_root} /core/queryparser/sparql/JavaCC/" * ]]; then
@@ -21,11 +61,63 @@ for i in $(find "${repo_root}" -name pom.xml); do
2161 # and not in package-info
2262 dir=" ${i/ pom.xml/ } src/"
2363 if [ -d " $dir " ]; then
24- for c in $( find " ${dir} " -name * .java -not -name package-info.java -exec grep -L Copyright {} \; ) ; do
25- # skip a file that is generated by.
26- f=$( grep -L ' Generated By:' $c )
27- if [ ! -z $f ]; then
28- filesWithOutCopyright+=(" $f " )
64+ for c in $( find " ${dir} " -name * .java -not -name package-info.java) ; do
65+ if grep -q ' Generated By:' " $c " ; then
66+ continue
67+ fi
68+
69+ header_lines=()
70+ while IFS= read -r line; do
71+ line=" ${line% $' \r ' } "
72+ header_lines+=(" $line " )
73+ done < <( head -n 10 " $c " )
74+
75+ has_copyright=false
76+ if grep -q " Copyright" " $c " ; then
77+ has_copyright=true
78+ fi
79+
80+ if [ ${# header_lines[@]} -lt 10 ]; then
81+ if [ " $has_copyright " = true ]; then
82+ filesWithInvalidHeader+=(" $c " )
83+ else
84+ filesWithOutCopyright+=(" $c " )
85+ fi
86+ continue
87+ fi
88+
89+ has_valid_year_line=false
90+ if [[ " ${header_lines[1]} " =~ ^\ \*\ Copyright\ \( c\)\ ([0-9]{4})\ Eclipse\ RDF4J\ contributors\. $ ]]; then
91+ has_valid_year_line=true
92+ elif [[ " ${header_lines[1]} " =~ ^\ \*\ Copyright\ \( c\)\ ([0-9]{4})\ Eclipse\ RDF4J\ contributors,\ Aduna,\ and\ others\. $ ]]; then
93+ has_valid_year_line=true
94+ aduna_year=" ${BASH_REMATCH[1]} "
95+ if [ " $aduna_year " -gt 2020 ]; then
96+ filesWithAdunaYearAfter2020+=(" $c " )
97+ fi
98+ fi
99+
100+ match_count=0
101+ for idx in 0 2 3 4 5 6 7 8 9; do
102+ if [[ " ${header_lines[$idx]} " == " ${expectedHeader[$idx]} " ]]; then
103+ match_count=$(( match_count + 1 ))
104+ fi
105+ done
106+
107+ if [ " $match_count " -ge 4 ]; then
108+ if [ " $match_count " -lt 9 ]; then
109+ rewrite_header " $c " " ${header_lines[1]} "
110+ fi
111+ fi
112+
113+ if [ " $has_valid_year_line " = false ]; then
114+ if [ " $has_copyright " = true ]; then
115+ filesWithInvalidHeader+=(" $c " )
116+ else
117+ filesWithOutCopyright+=(" $c " )
118+ fi
119+ elif [ " $match_count " -lt 4 ]; then
120+ filesWithInvalidHeader+=(" $c " )
29121 fi
30122 done
31123 for c in $( find " ${dir} " -name * .java -not -name package-info.java -exec grep -L ' SPDX-License-Identifier: BSD-3-Clause' {} \; ) ; do
@@ -37,10 +129,16 @@ done
37129for f in " ${filesWithOutCopyright[@]} " ; do
38130 echo " Missing copyright: $f "
39131done
132+ for f in " ${filesWithInvalidHeader[@]} " ; do
133+ echo " Invalid copyright header: $f "
134+ done
135+ for f in " ${filesWithAdunaYearAfter2020[@]} " ; do
136+ echo " Aduna header year must be 2020 or earlier: $f "
137+ done
40138for f in " ${filesWithOutSPDX[@]} " ; do
41139 echo " Missing SPDX line in: $f "
42140done
43- if [ ${# filesWithOutCopyright[@]} -ne 0 ]; then
141+ if [ ${# filesWithOutCopyright[@]} -ne 0 ] || [ ${ # filesWithInvalidHeader[@]} -ne 0 ] || [ ${ # filesWithAdunaYearAfter2020[@]} -ne 0 ] ; then
44142 exit 1
45143fi
46144if [ ${# filesWithOutSPDX[@]} -ne 0 ]; then
0 commit comments