Add check to maven pom.xml for verifying integrity of ui-react-lib
[clamp.git] / src / main / script / checkLibIndex.sh
1 #!/bin/bash
2 ###
3 # ============LICENSE_START=======================================================
4 # ONAP CLAMP
5 # ================================================================================
6 # Copyright (C) 2020 AT&T Intellectual Property. All rights
7 #                             reserved.
8 # ================================================================================
9 # Licensed under the Apache License, Version 2.0 (the "License");
10 # you may not use this file except in compliance with the License.
11 # You may obtain a copy of the License at
12 #
13 # http://www.apache.org/licenses/LICENSE-2.0
14 #
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS,
17 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 # See the License for the specific language governing permissions and
19 # limitations under the License.
20 # ============LICENSE_END============================================
21 # ===================================================================
22 #
23 ###
24
25 baseDir=$(git rev-parse --show-toplevel)
26
27 if [[ ! -d $baseDir ]]
28 then
29         echo "[ERROR] failed to determine git base directory"
30         exit 1
31 fi
32
33 tmpSrcFileList=/tmp/upldateLibIndex.$$.list
34 reactUiBaseDir="${baseDir}/ui-react"
35 reactLibIndexFile="ui-react-lib/libIndex.js"
36 exclusionList="ui-react-lib/libExportExclusions.dat"
37
38
39 if [[ ! -d "$reactUiBaseDir" ]]
40 then
41         echo "[ERROR] reacUiBaseDir=$reacUiBaseDir is not accessible"
42         exit 1
43 fi
44
45 if [[ ! -d "$baseDir/$reactLibBaseDir" ]]
46 then
47         echo "[ERROR] reactLibBaseDir=$baseDir/$reactLibBaseDir is not accessible"
48         exit 1
49 fi
50
51 if [[ ! -r "$baseDir/$reactLibIndexFile" ]]
52 then
53         echo "[ERROR] file reactLibIndexFile=$baseDir/$reactLibIndexFile is not accessible"
54         exit 1
55 fi
56
57
58 if ! cd $reactUiBaseDir
59 then
60         echo "[ERROR] could not cd to reactUiBaseDir=$reactUiBaseDir"
61         exit 1
62 fi
63
64 find ./src -name \*.js | egrep -v "__snapshot|\.test\." 2>/dev/null | sed 's/.js$//' > $tmpSrcFileList
65
66 if [[ ! -s $tmpSrcFileList ]]
67 then
68         echo "[ERROR] no source files found in reactUiBaseDir=$reactUiBaseDir"
69         rm -f $tmpSrcFileList
70         exit 1
71 fi
72
73 export nErrors=0
74
75 # Verify that any .js file found within ui-react/src other than test related files
76 # is also referenced in ui-react-lib/libIndex.js
77
78 for srcFileName in `<$tmpSrcFileList`
79 do
80         if [[ -r "$baseDir/$exclusionList" ]]
81         then
82                 if grep $srcFileName $baseDir/$exclusionList >/dev/null 2>&1
83                 then
84                         continue
85                 fi
86         fi
87
88         if ! grep $srcFileName "$baseDir/$reactLibIndexFile" > /dev/null 2>&1
89         then
90                 echo "[ERROR] file=${srcFileName}.js is not declared in $reactLibIndexFile"
91                 echo "[ERROR] and not found in exclsionList=${exclusionList}."
92                 echo "[ERROR] Please either add it to $reactLibIndexFile"
93                 echo "[ERROR] or to the exclusion list in ${exclusionList}."
94                 echo ""
95                 (( nErrors++ ))
96         fi
97 done
98
99 # Verify for each entry in ui-react-lib/libIndex.js, that the referenced source file exists
100 # in ui-react/src; if not, developer probably forgot to remove it from libIndex.js.
101
102 egrep '^export ' $baseDir/$reactLibIndexFile |\
103 sed -e "s+.*\./src+./src+" -e "s+'.*+.js+" >  $tmpSrcFileList
104
105 for srcFileName in `<$tmpSrcFileList`
106 do
107         if [[ ! -r "$srcFileName" ]]
108         then
109                 echo "[ERROR] source file=$srcFileName in libIndex.js is not accessible"
110                 (( nErrors++ ))
111         fi
112 done
113
114 rm -f $tmpSrcFileList
115
116 if (( nErrors == 0 ))
117 then
118         echo "[INFO] $reactLibIndexFile passes sanity check"
119         exit 0
120 fi
121
122 exit $nErrors