blob: 70162c6f666317ecd4ffd67c71ce9cbfe639795e [file] [log] [blame]
Chinthakayala, Sheshashailavas (sc2914)d1569972017-08-28 05:25:46 -09001if [ -z "$PROJECT_HOME" ]
2then
3 export PROJECT_HOME=$(pwd)/..
4fi
5
6toolsDir=$PROJECT_HOME/tools
7rm -rf ${toolsDir}/tmpws
8mkdir ${toolsDir}/tmpws
9mkdir ${toolsDir}/tmpws/logs
10mkdir ${toolsDir}/tmpws/jars
11mkdir ${toolsDir}/tmpws/tmp
12if [ "$#" != "1" ]
13then
14 echo "Command line:$0 $*" >${toolsDir}/tmpws/logs/err.log
15 echo "Usage: $0 yangFile" >>${toolsDir}/tmpws/logs/err.log
16 exit
17fi
18
19isZipFile="N"
20echo "$1" | grep "\.zip$" >/dev/null 2>&1
21if [ "$?" -eq "0" ]
22then
23 isZipFile="Y"
24fi
25
26if [ "$isZipFile" = "Y" ]
27then
28 #zip file of yangs provided
29 zipFile=$(basename $1)
30 unzip -o -d $PROJECT_HOME/tools/tmpws/tmp $1 >/dev/null 2>&1
31 rm $1 >/dev/null 2>&1
32 cd $PROJECT_HOME/tools/tmpws/tmp
33 fName="${zipFile}"
34 extension="${fName##*.}"
35 moduleName="${fName%.*}"
36 #echo "ModuleName is :$moduleName"
37 rm -rf $PROJECT_HOME/yangFiles/$moduleName
38 mkdir $PROJECT_HOME/yangFiles/$moduleName
39 mv *.yang $PROJECT_HOME/yangFiles/$moduleName
40 cd $PROJECT_HOME/tools
41 yangFilesFullPath=${PROJECT_HOME}/yangFiles/$moduleName
42 cd ${toolsDir}/tmpws
43 mkdir -p yangApp/model/src/main/yang
44 mkdir -p yangApp/model/src/main/yang-gen-sal
45 cp -r ${yangFilesFullPath}/* yangApp/model/src/main/yang
46 cp ${toolsDir}/pom.xml_base yangApp/model/pom.xml
47 cd ${toolsDir}/tmpws/yangApp/model
48
49 #Maven Compile
50 mvn clean install >${toolsDir}/tmpws/logs/mvn_install.log 2>${toolsDir}/tmpws/logs/err.log
51 yangApp_model_jar="yangApp-model-1.0.0-SNAPSHOT.jar"
52
53 #Copy the built jar to jars directory
54 cp ${toolsDir}/tmpws/yangApp/model/target/${yangApp_model_jar} ${toolsDir}/tmpws/jars
55 . ${toolsDir}/setClasspath
56
57 mv ${toolsDir}/output_js/${moduleName}_inputs.js ${toolsDir}/output_js/${moduleName}_inputs_prev.js >/dev/null 2>&1
58
59 ${toolsDir}/getRpcsClassFromYang.sh ${yangFilesFullPath}/${moduleName}.yang ${toolsDir}/tmpws/yangApp/model/target/${yangApp_model_jar} > ${toolsDir}/output_js/${moduleName}.js
60
61 node ${toolsDir}/dot_to_json.js ${toolsDir}/output_js/${moduleName}.js $moduleName >${toolsDir}/output_js/${moduleName}_inputs.js
62
63 cp ${toolsDir}/output_js/${moduleName}_inputs.js $PROJECT_HOME/generatedJS
64else
65 #Single yang provided
66 yangFileFullPath=$1
67 cd ${toolsDir}/tmpws
68 mkdir -p yangApp/model/src/main/yang
69 mkdir -p yangApp/model/src/main/yang-gen-sal
70 cp ${yangFileFullPath} yangApp/model/src/main/yang
71 cp ${toolsDir}/pom.xml_base yangApp/model/pom.xml
72 cd ${toolsDir}/tmpws/yangApp/model
73
74 #Maven Compile
75 mvn clean install >${toolsDir}/tmpws/logs/mvn_install.log 2>${toolsDir}/tmpws/logs/err.log
76 yangApp_model_jar="yangApp-model-1.0.0-SNAPSHOT.jar"
77
78 #Copy the built jar to jars directory
79 cp ${toolsDir}/tmpws/yangApp/model/target/${yangApp_model_jar} ${toolsDir}/tmpws/jars
80 . ${toolsDir}/setClasspath
81
82 moduleName=$(cat $yangFileFullPath|egrep "module .*{"|cut -d' ' -f2|cut -d'{' -f1)
83
84 mv ${toolsDir}/output_js/${moduleName}_inputs.js ${toolsDir}/output_js/${moduleName}_inputs_prev.js >/dev/null 2>&1
85
86 ${toolsDir}/getRpcsClassFromYang.sh ${yangFileFullPath} ${toolsDir}/tmpws/yangApp/model/target/${yangApp_model_jar} > ${toolsDir}/output_js/${moduleName}.js
87
88 node ${toolsDir}/dot_to_json.js ${toolsDir}/output_js/${moduleName}.js $moduleName >${toolsDir}/output_js/${moduleName}_inputs.js
89
90 cp ${toolsDir}/output_js/${moduleName}_inputs.js $PROJECT_HOME/generatedJS
91
92
93fi
94
95echo "Done..."
96