Skip to content

Commit 3fc6909

Browse files
htynknralf0131
authored andcommitted
Add dependencies check script (#3941)
* add plugin to do dependencies check * remove third-party properties file * polish config * polish config * use missing info in bash
1 parent 956d28b commit 3fc6909

File tree

3 files changed

+135
-1
lines changed

3 files changed

+135
-1
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,7 @@ Thumbs.db
3131
*.orig
3232

3333
# flatten ignore
34-
.flattened-pom.xml
34+
.flattened-pom.xml
35+
36+
# license check result
37+
license-list.txt

licenseCheck.sh

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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

pom.xml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,41 @@
302302
</plugins>
303303
</build>
304304
</profile>
305+
<profile>
306+
<id>licenseCheck</id>
307+
<build>
308+
<plugins>
309+
<plugin>
310+
<groupId>org.codehaus.mojo</groupId>
311+
<artifactId>license-maven-plugin</artifactId>
312+
<version>1.20</version>
313+
<executions>
314+
<execution>
315+
<id>license-check</id>
316+
<phase>generate-sources</phase>
317+
<goals>
318+
<goal>add-third-party</goal>
319+
</goals>
320+
<configuration>
321+
<includeOptional>false</includeOptional>
322+
<useMissingFile>false</useMissingFile>
323+
<failOnMissing>false</failOnMissing>
324+
<licenseMerges>
325+
<licenseMerge>Apache License, Version 2.0|The Apache Software License, Version
326+
2.0|ASF 2.0|Apache 2|Apache-2.0|Apache 2.0 License|Apache 2.0|Apache License v2.0|Apache License 2.0|The Apache License, Version 2.0|The Apache Software License, Version 2.0
327+
</licenseMerge>
328+
<licenseMerge>The MIT License|MIT License</licenseMerge>
329+
<licenseMerge>The 3-Clause BSD License|New BSD License|3-Clause BSD
330+
License|BSD|3-Clause BSD License|The New BSD License
331+
</licenseMerge>
332+
</licenseMerges>
333+
</configuration>
334+
</execution>
335+
</executions>
336+
</plugin>
337+
</plugins>
338+
</build>
339+
</profile>
305340
</profiles>
306341

307342
<build>

0 commit comments

Comments
 (0)