blob: f3ce4c8172c20f8ba9916b23938a66e8e0b4eba6 [file] [log] [blame]
Timoney, Daniel (dt5972)324ee362017-02-15 10:37:53 -05001toolsDir=$PROJECT_HOME/tools
2. ${toolsDir}/setClasspath
3if [ "$#" != "2" ]
4then
5 echo "Usage $0 yang_file generated_jar_file"
6 echo "example $0 /home/users/sdnc/src/appName/model/src/main/yang/app.yang /home/users/sdnc/src/appName/model/target/appName.model-2.0.0.jar"
7 exit
8fi
9yangFile="$1"
10jarFile="$2"
11module=$(cat $yangFile|egrep "module .*{"|awk '{print $2}'|sed -e 's/{//g')
12#echo " \"$module\" : ["
13rpcs=$(grep rpc $yangFile|grep -v leaf|sed -e 's/^\s\+rpc//g'|awk '{print $1}')
14for i in `find ${toolsDir}/yangToolsJars -name "*.jar" -print`
15do
16#echo $i
17export CLASSPATH=$CLASSPATH:$i
18done
19export CLASSPATH=$2:$CLASSPATH:.:${toolsDir}/slf4j-api-1.7.2.jar:${toolsDir}/guava-14.0.1.jar:${toolsDir}/printYangToProp.jar
20allProps=""
21for rpc in $rpcs
22do
23rpcVal=$(echo $rpc|sed -e "s/\b\(.\)/\u\1/g"|sed s/\-//g)
24#echo $rpcVal
25className=$(jar -tvf ${jarFile}|grep "org/opendaylight/yang/gen/"|grep -w "${rpcVal}Input.class"|grep -v grep|awk '{print $NF}'|sed -e 's/\//./g'|sed -e 's/.class$//g')
26#echo $className
27inputProps=""
28if [ "$className" != "" ]
29then
30 #java -cp $CLASSPATH PrintYangToProp $className 2>/dev/null|grep '*' |cut -d'*' -f2|sed -e "s/^[ \t]*//g"|sed -e "s/^/\t\t\"/g"|sed -e "s/$/\",/g"
31 inputProps=$(java -cp $CLASSPATH PrintYangToProp $className 2>${toolsDir}/tmpws/logs/err.log)
32fi
33className=$(jar -tvf ${jarFile}|grep "org/opendaylight/yang/gen/"|grep -w "${rpcVal}Output"|grep -v grep|awk '{print $NF}'|sed -e 's/\//./g'|sed -e 's/.class$//g')
34#echo $inputProps
35#echo $className
36outputProps=""
37if [ "$className" != "" ]
38then
39 #java -cp $CLASSPATH PrintYangToProp $className 2>/dev/null|grep '*' |cut -d'*' -f2|sed -e "s/^[ \t]*//g"|sed -e "s/^/\t\t\"/g"|sed -e "s/$/\",/g"
40 outputProps=$(java -cp $CLASSPATH PrintYangToProp $className 2>${toolsDir}/tmpws/logs/err.log)
41fi
42if [ -z "$allProps" ]
43then
44 allProps=$(echo ${inputProps}${outputProps}|sed -e s/,$//g)
45else
46 allProps=$(echo ${allProps},${inputProps}${outputProps}|sed -e s/,$//g)
47fi
48done
49#echo $allProps
50#OIFS=$IFS
51#IFS=','
52#arr2=$allProps
53#for x in $arr2
54#do
55# echo "$x"
56#done
57#IFS=$OIFS
58#echo " ]"
59echo "module.exports = {"
60echo "\"moduleName\" : \"${module}\","
61echo "'${module}_VALUES' : "
62echo "[ $allProps ]"|python -m json.tool
63echo ","
64echo "'${module}_RPCS' : ["
65
66cnt=0
67#numOfRpcs=${#rpcs[@]}
68numOfRpcs=0;
69for rpc in $rpcs
70do
71 numOfRpcs=$((numOfRpcs+1))
72done
73
74for rpc in $rpcs
75do
76 cnt=$((cnt+1))
77 if [ $cnt -eq $numOfRpcs ]
78 then
79 echo " \"$rpc\""
80 else
81 echo " \"$rpc\","
82 fi
83done
84echo " ]"
85echo "}"