bucklet for yang based OSGI libraries

Change-Id: Ieeef6357250c4e74e9c78310a65c809b3edd102b
diff --git a/apps/tenbi/BUCK b/apps/tenbi/BUCK
index 30ed481..461fddd 100644
--- a/apps/tenbi/BUCK
+++ b/apps/tenbi/BUCK
@@ -11,8 +11,8 @@
     url = 'http://onosproject.org',
     included_bundles = BUNDLES,
     description = 'TE YANG NBI.',
-    required_apps = [ 'org.onosproject.onos-app-tetopology',
-                      'org.onosproject.onos-app-tetunnel',
-                      'org.onosproject.onos-app-yms' ],
+    required_apps = [ 'org.onosproject.tetopology',
+                      'org.onosproject.tetunnel',
+                      'org.onosproject.yms' ],
 )
 
diff --git a/apps/tenbi/yangmodel/BUCK b/apps/tenbi/yangmodel/BUCK
index 4422110..3ee4e7d 100644
--- a/apps/tenbi/yangmodel/BUCK
+++ b/apps/tenbi/yangmodel/BUCK
@@ -2,7 +2,7 @@
   '//lib:CORE_DEPS'
 ]
 
-yang_library(
+yang_osgi_jar(
   deps = COMPILE_DEPS,
   name = 'onos-apps-tenbi-yangmodel',
   srcs = glob(['src/main/**/*.yang']),
diff --git a/apps/yms/app/pom.xml b/apps/yms/app/pom.xml
index 5da851d..1b6f0d4 100644
--- a/apps/yms/app/pom.xml
+++ b/apps/yms/app/pom.xml
@@ -57,7 +57,7 @@
         <dependency>
             <groupId>org.onosproject</groupId>
             <artifactId>onos-yang-utils-generator</artifactId>
-            <version>1.10</version>
+            <version>1.11</version>
         </dependency>
     </dependencies>
 
diff --git a/apps/yms/pom.xml b/apps/yms/pom.xml
index a351876..1c1b65e 100644
--- a/apps/yms/pom.xml
+++ b/apps/yms/pom.xml
@@ -39,7 +39,7 @@
         <dependency>
             <groupId>org.onosproject</groupId>
             <artifactId>onos-yang-datamodel</artifactId>
-            <version>1.10</version>
+            <version>1.11</version>
         </dependency>
     </dependencies>
 
diff --git a/buck-tools/default.defs b/buck-tools/default.defs
index 9c72161..0c55630 100644
--- a/buck-tools/default.defs
+++ b/buck-tools/default.defs
@@ -2,6 +2,7 @@
 include_defs('//bucklets/maven_jar.bucklet')
 include_defs('//bucklets/onos.bucklet')
 include_defs('//bucklets/onos_app.bucklet')
+include_defs('//bucklets/yang.bucklet')
 include_defs('//bucklets/remote_jar.bucklet')
 
 BASE_DEPS = [
diff --git a/bucklets/yang.bucklet b/bucklets/yang.bucklet
new file mode 100644
index 0000000..9c15a51
--- /dev/null
+++ b/bucklets/yang.bucklet
@@ -0,0 +1,51 @@
+include_defs('//onos.defs')
+
+def _get_name():
+    base_path = get_base_path()
+    return ONOS_ARTIFACT_BASE + base_path.replace('/', '-') #TODO Unix-separator
+
+def yang_osgi_jar(
+    name = None,
+    srcs = None,
+    group_id = ONOS_GROUP_ID,
+    version = ONOS_VERSION,
+    deps = [],
+    visibility = ['PUBLIC'],
+    license = 'NONE',
+    **kwargs
+    ):
+
+    if name is None:
+        name = _get_name()
+
+    yang_jar = name + '-yang'
+    bnd_jar = name + '-bnd'
+
+    args = { 'group':group_id, 'artifact':name, 'version':version }
+
+    yang_library(
+      deps = deps,
+      name = yang_jar,
+      srcs = srcs,
+      visibility = [ ],
+    )
+
+    cmd = 'java -jar $(location //lib:bndexe) wrap -o $OUT '
+    cmd += '-b %(group)s.%(artifact)s ' % args
+    cmd += '-v ' + version.replace('-', '.') + ' '
+    cmd += '$(location :%s) ' % yang_jar
+    cmd += ' >/dev/null 2>&1'
+
+    genrule(
+         name = bnd_jar,
+         bash = cmd,
+         out = name + '.jar',
+         visibility = [],
+    )
+
+    prebuilt_jar(
+        name = name,
+        binary_jar = ':' + bnd_jar,
+        maven_coords = '%(group)s:%(artifact)s:%(version)s'%args,
+        visibility = visibility,
+    )
diff --git a/lib/BUCK b/lib/BUCK
index 26a4910..907270b 100644
--- a/lib/BUCK
+++ b/lib/BUCK
@@ -1,4 +1,4 @@
-# ***** This file was auto-generated at Fri Dec 02 15:14:44 IST 2016. Do not edit this file manually. *****
+# ***** This file was auto-generated at Fri Dec 16 13:24:41 PST 2016. Do not edit this file manually. *****
 osgi_feature_group(
   name = 'COMPILE',
   visibility = ['PUBLIC'],
@@ -1026,6 +1026,14 @@
 )
 
 remote_jar (
+  name = 'bndexe',
+  out = 'biz.aQute.bnd-3.1.0.jar',
+  url = 'http://onlab.vicci.org/onos/third-party/biz.aQute.bnd-3.1.0.jar',
+  sha1 = 'ebd6c2af025b66ea94a9fcb217c2699ba23d3ca2',
+  visibility = [ 'PUBLIC' ],
+)
+
+remote_jar (
   name = 'cord-config',
   out = 'cord-config-1.0-b1.jar',
   url = 'mvn:org.onosproject:cord-config:jar:1.0-b1',
diff --git a/lib/deps.json b/lib/deps.json
index 6b4ee73..b9710ed 100644
--- a/lib/deps.json
+++ b/lib/deps.json
@@ -189,6 +189,7 @@
     "checkstyle": "mvn:com.puppycrawl.tools:checkstyle:6.11.2",
     "apache-karaf": "http://onlab.vicci.org/onos/third-party/apache-karaf-3.0.5-offline-20161115.tar.gz",
     "bndlib": "mvn:biz.aQute.bnd:biz.aQute.bndlib:jar:3.1.0",
+    "bndexe": "http://onlab.vicci.org/onos/third-party/biz.aQute.bnd-3.1.0.jar",
     "cord-config": "mvn:org.onosproject:cord-config:1.0-b1",
     "libthrift": "mvn:org.apache.thrift:libthrift:0.9.3",
     "qdox": "mvn:com.thoughtworks.qdox:qdox:2.0-M3",