1+ #! /bin/bash
2+
3+ APPEND_ARG=" "
4+ FOLDER=" ./"
5+ LINE_FLAG=" =============================================="
6+ TARGET_FILE=" ./license-list.txt"
7+
8+ red=` tput setaf 1`
9+ green=` tput setaf 2`
10+ reset=` tput sgr0`
11+
12+
13+ if [ -n " $1 " ]; then
14+ echo " checking module $1 "
15+ APPEND_ARG=" -f $1 "
16+ FOLDER=" $1 "
17+ else
18+ echo " checking whole project"
19+ fi
20+
21+ echo " Running command: ./mvnw clean package -DskipTests=true -PlicenseCheck $APPEND_ARG "
22+
23+ ./mvnw clean package -DskipTests=true -PlicenseCheck $APPEND_ARG
24+
25+ status=$?
26+ if [ $status -eq 0 ]; then
27+ echo " mvn command exec success"
28+ else
29+ echo " ${red} mvn command exec fail${reset} "
30+ exit 1
31+ fi
32+
33+
34+ # contact and generate license file
35+ rm -rf $TARGET_FILE
36+ LICENSE_FILES=` find $FOLDER -type f -name " THIRD-PARTY.txt" | grep generated-sources`
37+
38+ echo " Find license files:"
39+ echo " $LICENSE_FILES "
40+
41+ for i in $LICENSE_FILES
42+ do
43+ echo " $LINE_FLAG " >> $TARGET_FILE
44+ echo $i >> $TARGET_FILE
45+ cat $i >> $TARGET_FILE
46+ done
47+
48+ echo " license files generated at $TARGET_FILE "
49+
50+ # fix missing license dependencies
51+ missingLicense=(
52+ " (Unknown license) jsr173_api:(Apache License, Version 2.0) jsr173_api"
53+ " (Unknown license) \" Java Concurrency in Practice\" book annotations:(BEA licensed) \" Java Concurrency in Practice\" book annotations"
54+ " (Unknown license) Java Portlet Specification V2.0:(Apache License, Version 2.0) Java Portlet Specification V2.0"
55+ )
56+
57+ for i in " ${missingLicense[@]} " ; do
58+ search=` echo $i | awk -F: ' {print $1}' `
59+ replace=` echo $i | awk -F: ' {print $2}' `
60+ sed -i -e ' s/' " $search " ' /' " $replace " ' /g' $TARGET_FILE
61+ done
62+
63+ check_unknown_license=` cat $TARGET_FILE | grep " Unknown license" `
64+
65+ # checking unknown license
66+ if grep -q " Unknown license" $TARGET_FILE
67+ then
68+ echo " ${red} Find unknown license${reset} "
69+ echo " $check_unknown_license "
70+ exit 1
71+ fi
72+
73+ allowLicense=(
74+ " CDDL"
75+ " Apache"
76+ " Common Development and Distribution License"
77+ " Eclipse Public License"
78+ " MIT"
79+ " The 3-Clause BSD License"
80+ " Public domain"
81+ )
82+
83+ # filter allow license
84+ license_need_check=` cat $TARGET_FILE | grep -v " generated-sources/license/THIRD-PARTY.txt" | grep -v " third-party dependencies" | grep -v $LINE_FLAG `
85+
86+ for i in " ${allowLicense[@]} " ; do
87+ license_need_check=` echo " $license_need_check " | grep -vi " $i " `
88+ done
89+
90+ if test -z " $license_need_check "
91+ then
92+ echo " ${green} All dependencies license looks good${reset} "
93+ else
94+ echo " ${red} Please check below license${reset} "
95+ echo " $license_need_check "
96+ fi
0 commit comments