Use released versions of maven artifacts
[ccsdk/distribution.git] / dgbuilder / tools / generate_props_from_yang.sh
1 if [ -z "$PROJECT_HOME" ] 
2 then
3         export PROJECT_HOME=$(pwd)/..
4 fi
5
6 toolsDir=$PROJECT_HOME/tools
7 rm -rf ${toolsDir}/tmpws 
8 mkdir ${toolsDir}/tmpws
9 mkdir ${toolsDir}/tmpws/logs
10 mkdir ${toolsDir}/tmpws/jars
11 mkdir ${toolsDir}/tmpws/tmp
12 if [ "$#" != "1" ]
13 then
14         echo "Command line:$0 $*" >${toolsDir}/tmpws/logs/err.log
15         echo "Usage: $0 yangFile" >>${toolsDir}/tmpws/logs/err.log
16         exit
17 fi
18
19 isZipFile="N"
20 echo "$1" | grep "\.zip$" >/dev/null 2>&1
21 if [ "$?" -eq "0" ]
22 then
23         isZipFile="Y"
24 fi
25
26 if [ "$isZipFile" = "Y" ]
27 then 
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
64 else
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
93 fi
94
95 echo "Done..."
96

© 2017 ONAP. Copyright © The Linux Foundation ®. All Rights Reserved.
The Linux Foundation has registered trademarks and uses trademarks.
For a list of trademarks of The Linux Foundation, please see our Trademark Usage page.
Linux is a registered trademark of Linus Torvalds.
Privacy Policy and Terms of Use