Skip to content

Commit cb12927

Browse files
committed
[FAB-5431] Adopt Go SDK's check_license.sh
Per Troy's suggestion on FAB-5431, this changes the check_license.sh script to the one used in the Go SDK. This version doesn't return an error if the SPDX Id is not used but will return an error if no Apache license is found. Change-Id: I731b6b7e8a84aebb10052371de2c241867ae9f33 Signed-off-by: Arnaud J Le Hors <lehors@us.ibm.com>
1 parent b02e9f4 commit cb12927

File tree

1 file changed

+31
-9
lines changed

1 file changed

+31
-9
lines changed

scripts/check_license.sh

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,33 @@
11
#!/bin/bash
22
#
3-
# Copyright IBM Corp. All Rights Reserved.
3+
# Copyright IBM Corp, SecureKey Technologies Inc. All Rights Reserved.
44
#
55
# SPDX-License-Identifier: Apache-2.0
66
#
77

8-
CHECK=$(git diff --name-only HEAD * | grep -v .png$ | grep -v .rst$ | grep -v .git \
9-
| grep -v .md$ | grep -v ^vendor/ | grep -v ^build/ | grep -v .pb.go$ | grep -v .txt | sort -u)
8+
function filterExcludedFiles {
9+
CHECK=`echo "$CHECK" | grep -v .png$ | grep -v .rst$ | grep -v ^.git/ \
10+
| grep -v .pem$ | grep -v .block$ | grep -v .tx$ | grep -v ^LICENSE$ | grep -v _sk$ \
11+
| grep -v .key$ | grep -v \\.gen.go$ | grep -v ^Gopkg.lock$ \
12+
| grep -v .md$ | grep -v ^vendor/ | grep -v ^build/ | grep -v .pb.go$ | sort -u`
13+
}
14+
15+
CHECK=$(git diff --name-only HEAD --diff-filter=ACMRTUXB *)
16+
filterExcludedFiles
1017

1118
if [[ -z "$CHECK" ]]; then
12-
CHECK=$(git diff-tree --no-commit-id --name-only -r $(git log -2 \
13-
--pretty=format:"%h") | grep -v .png$ | grep -v .rst$ | grep -v .git \
14-
| grep -v .md$ | grep -v ^vendor/ | grep -v ^build/ | grep -v .pb.go$ | grep -v .txt | sort -u)
19+
CHECK=$(git diff-tree --no-commit-id --name-only --diff-filter=ACMRTUXB -r $(git log -2 \
20+
--pretty=format:"%h"))
21+
filterExcludedFiles
22+
fi
23+
24+
if [[ -z "$CHECK" ]]; then
25+
echo "All files are excluded from having license headers"
26+
exit 0
1527
fi
1628

17-
echo "Checking committed files for SPDX-License-Identifier headers ..."
18-
missing=`echo $CHECK | xargs grep -L "SPDX-License-Identifier"`
19-
if [ -z "$missing" ]; then
29+
missing=`echo "$CHECK" | xargs ls -d 2>/dev/null | xargs grep -L "SPDX-License-Identifier"`
30+
if [[ -z "$missing" ]]; then
2031
echo "All files have SPDX-License-Identifier headers"
2132
exit 0
2233
fi
@@ -25,4 +36,15 @@ echo "$missing"
2536
echo
2637
echo "Please replace the Apache license header comment text with:"
2738
echo "SPDX-License-Identifier: Apache-2.0"
39+
40+
echo
41+
echo "Checking committed files for traditional Apache License headers ..."
42+
missing=`echo "$missing" | xargs ls -d 2>/dev/null | xargs grep -L "http://www.apache.org/licenses/LICENSE-2.0"`
43+
if [[ -z "$missing" ]]; then
44+
echo "All remaining files have Apache 2.0 headers"
45+
exit 0
46+
fi
47+
echo "The following files are missing traditional Apache 2.0 headers:"
48+
echo "$missing"
49+
echo "Fatal Error - All files must have a license header"
2850
exit 1

0 commit comments

Comments
 (0)