Updating Buck files to build OSGi jars

- Using osgi_jar for all modules except apps
- Adding target for installation of core modules to .m2 repo

Change-Id: I65d9e3a9567918e275191724842d7d9b1f485128
diff --git a/BUCK b/BUCK
index 7be55b1..2fed8c3 100644
--- a/BUCK
+++ b/BUCK
@@ -3,15 +3,22 @@
     '//utils/junit:onlab-junit',
     '//utils/misc:onlab-misc',
     '//utils/rest:onlab-rest',
+
     '//core/api:onos-api',
-    '//incubator/api:onos-incubator-api',
-    '//incubator/net:onos-incubator-net',
     '//core/net:onos-core-net',
+    '//core/common:onos-core-common',
     '//core/store/primitives:onos-core-primitives',
     '//core/store/serializers:onos-core-serializers',
     '//core/store/dist:onos-core-dist',
     '//core/security:onos-security',
     '//core/store/persistence:onos-core-persistence',
+
+    '//incubator/api:onos-incubator-api',
+    '//incubator/net:onos-incubator-net',
+    '//incubator/core:onos-incubator-core',
+    '//incubator/store:onos-incubator-store',
+    '//incubator/rpc:onos-incubator-rpc',
+
     '//cli:onos-cli',
 
     '//protocols/rest/api:onos-restsb-api',
@@ -122,3 +129,35 @@
    visibility = ['PUBLIC'],
    deps = DEPS
 )
+
+INSTALL = [
+    '//utils/misc:onlab-misc-install',
+    '//utils/osgi:onlab-osgi-install',
+    '//utils/rest:onlab-rest-install',
+
+    '//core/api:onos-api-install',
+    '//incubator/api:onos-incubator-api-install',
+
+    '//core/net:onos-core-net-install',
+    '//core/common:onos-core-common-install',
+    '//core/store/dist:onos-core-dist-install',
+    '//core/store/primitives:onos-core-primitives-install',
+    '//core/store/persistence:onos-core-persistence-install',
+    '//core/store/serializers:onos-core-serializers-install',
+
+    '//incubator/net:onos-incubator-net-install',
+    '//incubator/core:onos-incubator-core-install',
+    '//incubator/store:onos-incubator-store-install',
+    '//incubator/rpc:onos-incubator-rpc-install',
+
+    '//core/security:onos-security-install',
+
+    '//web/api:onos-rest-install',
+    '//web/gui:onos-gui-install',
+    '//cli:onos-cli-install',
+]
+java_library(
+    name = 'install',
+    visibility = ['PUBLIC'],
+    deps = INSTALL
+)
\ No newline at end of file
diff --git a/bucklets/onos.bucklet b/bucklets/onos.bucklet
index 8bb6811..c7837b3 100644
--- a/bucklets/onos.bucklet
+++ b/bucklets/onos.bucklet
@@ -1,3 +1,4 @@
+import random
 
 DEBUG_ARG='JAVA_TOOL_OPTIONS="-Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=5005,suspend=y"'
 
@@ -82,16 +83,18 @@
   )
 
   ### .m2 Install
-  mvn_cmd = ' '.join(('mvn install:install-file',
-                      '-Dfile=$(location :%s)' % name,
-                      '-DgroupId=%s' % group_id,
-                      '-DartifactId=%s' % name,
-                      '-Dversion=%s' % version,
-                      '-Dpackaging=jar'
-                      ))
+  mvn_cmd = ' '.join(( 'mvn install:install-file',
+                       '-Dfile=$(location :%s)' % name,
+                       '-DgroupId=%s' % group_id,
+                       '-DartifactId=%s' % name,
+                       '-Dversion=%s' % version,
+                       '-Dpackaging=jar' ))
+  # TODO This rule must be run every time, adding random number as rule input.
+  #      We should make this configurable, perhaps with a flag.
+  cmd = 'FOO=%s ' % random.random() + mvn_cmd + ' > $OUT'
   genrule(
     name = name + '-install',
-    bash = mvn_cmd + ' > $OUT',
+    bash = cmd,
     out = 'install.log',
     visibility = visibility,
   )
diff --git a/cli/BUCK b/cli/BUCK
index 521be31..fe1d102 100644
--- a/cli/BUCK
+++ b/cli/BUCK
@@ -11,7 +11,7 @@
     '//core/common:onos-core-common',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/core/api/BUCK b/core/api/BUCK
index 387c502..f4d5eb7 100644
--- a/core/api/BUCK
+++ b/core/api/BUCK
@@ -14,7 +14,7 @@
     '//lib:TEST',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/core/common/BUCK b/core/common/BUCK
index cbe9efc..70ea817 100644
--- a/core/common/BUCK
+++ b/core/common/BUCK
@@ -13,7 +13,7 @@
     '//core/api:onos-api-tests',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = SRC_DEPS,
diff --git a/core/net/BUCK b/core/net/BUCK
index 9ec8907..07139f9 100644
--- a/core/net/BUCK
+++ b/core/net/BUCK
@@ -12,7 +12,7 @@
     '//lib:TEST',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/core/security/BUCK b/core/security/BUCK
index 3618496..2f692bd 100644
--- a/core/security/BUCK
+++ b/core/security/BUCK
@@ -12,7 +12,7 @@
     '//lib:TEST',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/core/store/dist/BUCK b/core/store/dist/BUCK
index 8653ad5..c9bd95c 100644
--- a/core/store/dist/BUCK
+++ b/core/store/dist/BUCK
@@ -22,7 +22,7 @@
      '//core/common:onos-core-common-tests',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/core/store/persistence/BUCK b/core/store/persistence/BUCK
index 3caf6ea..0791c14 100644
--- a/core/store/persistence/BUCK
+++ b/core/store/persistence/BUCK
@@ -13,7 +13,7 @@
     '//lib:TEST',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/core/store/primitives/BUCK b/core/store/primitives/BUCK
index 1e77e32..ffdb294 100644
--- a/core/store/primitives/BUCK
+++ b/core/store/primitives/BUCK
@@ -32,7 +32,7 @@
     '//core/api:onos-api-tests',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/core/store/serializers/BUCK b/core/store/serializers/BUCK
index 050269d..f5d9ced 100644
--- a/core/store/serializers/BUCK
+++ b/core/store/serializers/BUCK
@@ -12,7 +12,7 @@
     '//lib:TEST',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/drivers/bti/BUCK b/drivers/bti/BUCK
index a9a69f3..17861a1 100644
--- a/drivers/bti/BUCK
+++ b/drivers/bti/BUCK
@@ -9,7 +9,7 @@
     '//incubator/api:onos-incubator-api'
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/drivers/ciena/BUCK b/drivers/ciena/BUCK
index ec8a793..a366702 100644
--- a/drivers/ciena/BUCK
+++ b/drivers/ciena/BUCK
@@ -11,7 +11,7 @@
     '//protocols/rest/api:onos-restsb-api',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/drivers/cisco/BUCK b/drivers/cisco/BUCK
index 3d25bff..0b538d7 100644
--- a/drivers/cisco/BUCK
+++ b/drivers/cisco/BUCK
@@ -9,7 +9,7 @@
     '//protocols/netconf/api:onos-netconf-api',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/drivers/default/BUCK b/drivers/default/BUCK
index fa0a893..1491498 100644
--- a/drivers/default/BUCK
+++ b/drivers/default/BUCK
@@ -16,7 +16,7 @@
     '//lib:TEST',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/drivers/fujitsu/BUCK b/drivers/fujitsu/BUCK
index 512cc2b..373b7d9 100644
--- a/drivers/fujitsu/BUCK
+++ b/drivers/fujitsu/BUCK
@@ -9,7 +9,7 @@
     '//protocols/netconf/api:onos-netconf-api',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/drivers/lumentum/BUCK b/drivers/lumentum/BUCK
index 0d8c328..50c1c26 100644
--- a/drivers/lumentum/BUCK
+++ b/drivers/lumentum/BUCK
@@ -9,7 +9,7 @@
     '//drivers/utilities:onos-drivers-utilities',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/drivers/netconf/BUCK b/drivers/netconf/BUCK
index c292fa6..bec65c4 100644
--- a/drivers/netconf/BUCK
+++ b/drivers/netconf/BUCK
@@ -9,7 +9,7 @@
     '//protocols/netconf/api:onos-netconf-api',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/drivers/ovsdb/BUCK b/drivers/ovsdb/BUCK
index d1ec756..d63c6b7 100644
--- a/drivers/ovsdb/BUCK
+++ b/drivers/ovsdb/BUCK
@@ -10,7 +10,7 @@
     '//protocols/ovsdb/rfc:onos-ovsdb-rfc',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/drivers/utilities/BUCK b/drivers/utilities/BUCK
index 09c6916..80ec633 100644
--- a/drivers/utilities/BUCK
+++ b/drivers/utilities/BUCK
@@ -12,7 +12,7 @@
     '//lib:TEST',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/incubator/api/BUCK b/incubator/api/BUCK
index f2a0cd5..e1d3ede 100644
--- a/incubator/api/BUCK
+++ b/incubator/api/BUCK
@@ -11,7 +11,7 @@
     '//lib:TEST',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/incubator/core/BUCK b/incubator/core/BUCK
new file mode 100644
index 0000000..aa3a537
--- /dev/null
+++ b/incubator/core/BUCK
@@ -0,0 +1,29 @@
+SRC = 'src/main/java/org/onosproject/incubator/**/'
+TEST = 'src/test/java/org/onosproject/incubator/**/'
+CURRENT_NAME = 'onos-incubator-core'
+CURRENT_TARGET = ':' + CURRENT_NAME
+
+COMPILE_DEPS = [
+    '//lib:CORE_DEPS',
+    '//incubator/api:onos-incubator-api',
+]
+
+TEST_DEPS = [
+    '//lib:TEST',
+]
+
+osgi_jar(
+    name = CURRENT_NAME,
+    srcs = glob([SRC + '/*.java']),
+    deps = COMPILE_DEPS,
+    visibility = ['PUBLIC'],
+)
+
+java_test(
+    name = 'tests',
+    srcs = glob([TEST + '/*.java']),
+    deps = COMPILE_DEPS +
+           TEST_DEPS +
+           [CURRENT_TARGET],
+    source_under_test = [CURRENT_TARGET],
+)
diff --git a/incubator/net/BUCK b/incubator/net/BUCK
index a2e336f..430f32d 100644
--- a/incubator/net/BUCK
+++ b/incubator/net/BUCK
@@ -12,7 +12,7 @@
     '//lib:TEST',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/incubator/rpc/BUCK b/incubator/rpc/BUCK
new file mode 100644
index 0000000..52945d8
--- /dev/null
+++ b/incubator/rpc/BUCK
@@ -0,0 +1,29 @@
+SRC = 'src/main/java/org/onosproject/incubator/**/'
+TEST = 'src/test/java/org/onosproject/incubator/**/'
+CURRENT_NAME = 'onos-incubator-rpc'
+CURRENT_TARGET = ':' + CURRENT_NAME
+
+COMPILE_DEPS = [
+    '//lib:CORE_DEPS',
+    '//incubator/api:onos-incubator-api',
+]
+
+TEST_DEPS = [
+    '//lib:TEST',
+]
+
+osgi_jar(
+    name = CURRENT_NAME,
+    srcs = glob([SRC + '/*.java']),
+    deps = COMPILE_DEPS,
+    visibility = ['PUBLIC'],
+)
+
+java_test(
+    name = 'tests',
+    srcs = glob([TEST + '/*.java']),
+    deps = COMPILE_DEPS +
+           TEST_DEPS +
+           [CURRENT_TARGET],
+    source_under_test = [CURRENT_TARGET],
+)
diff --git a/incubator/store/BUCK b/incubator/store/BUCK
new file mode 100644
index 0000000..59d6983
--- /dev/null
+++ b/incubator/store/BUCK
@@ -0,0 +1,31 @@
+SRC = 'src/main/java/org/onosproject/incubator/**/'
+TEST = 'src/test/java/org/onosproject/incubator/**/'
+CURRENT_NAME = 'onos-incubator-store'
+CURRENT_TARGET = ':' + CURRENT_NAME
+
+COMPILE_DEPS = [
+    '//lib:CORE_DEPS',
+    '//incubator/api:onos-incubator-api',
+    '//core/store/dist:onos-core-dist',
+    '//core/store/serializers:onos-core-serializers',
+]
+
+TEST_DEPS = [
+    '//lib:TEST',
+]
+
+osgi_jar(
+    name = CURRENT_NAME,
+    srcs = glob([SRC + '/*.java']),
+    deps = COMPILE_DEPS,
+    visibility = ['PUBLIC'],
+)
+
+java_test(
+    name = 'tests',
+    srcs = glob([TEST + '/*.java']),
+    deps = COMPILE_DEPS +
+           TEST_DEPS +
+           [CURRENT_TARGET],
+    source_under_test = [CURRENT_TARGET],
+)
diff --git a/protocols/bgp/api/BUCK b/protocols/bgp/api/BUCK
index 5f295c9..7b7ac98 100644
--- a/protocols/bgp/api/BUCK
+++ b/protocols/bgp/api/BUCK
@@ -8,7 +8,7 @@
     '//protocols/bgp/bgpio:onos-bgpio',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/protocols/bgp/bgpio/BUCK b/protocols/bgp/bgpio/BUCK
index 645be9e..3d6b280 100644
--- a/protocols/bgp/bgpio/BUCK
+++ b/protocols/bgp/bgpio/BUCK
@@ -11,7 +11,7 @@
     '//lib:TEST',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/protocols/bgp/ctl/BUCK b/protocols/bgp/ctl/BUCK
index e4d653c..6336f97 100644
--- a/protocols/bgp/ctl/BUCK
+++ b/protocols/bgp/ctl/BUCK
@@ -17,7 +17,7 @@
     '//lib:TEST',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/protocols/isis/BUCK b/protocols/isis/BUCK
index 966b1e7..77dba5a 100644
--- a/protocols/isis/BUCK
+++ b/protocols/isis/BUCK
@@ -4,13 +4,6 @@
 COMPILE_DEPS = [
     '//lib:CORE_DEPS',
     '//lib:netty-buffer',
-    #'//lib:netty-'
-    #'//lib:org.apache.karaf.shell.console',
-    #'//cli:onos-cli',
-    #'//utils/rest:onlab-rest',
-    #'//lib:javax.ws.rs-api',
-    #'//core/store/serializers:onos-core-serializers',
-    #'//incubator/api:onos-incubator-api',
 ]
 
 TEST_DEPS = [
@@ -27,7 +20,7 @@
 
 # onos-isis-api
 
-java_library(
+osgi_jar(
     name = 'onos-isis-api',
     srcs = glob(['api/' + SRC + '*.java']),
     deps = COMPILE_DEPS,
@@ -45,7 +38,7 @@
 
 # onos-isis-isisio
 
-java_library(
+osgi_jar(
     name = 'onos-isis-isisio',
     srcs = glob(['isisio/' + SRC + '*.java']),
     deps = COMPILE_DEPS + [':onos-isis-api'],
diff --git a/protocols/netconf/api/BUCK b/protocols/netconf/api/BUCK
index 6625366..28ac267 100644
--- a/protocols/netconf/api/BUCK
+++ b/protocols/netconf/api/BUCK
@@ -7,7 +7,7 @@
     '//lib:CORE_DEPS',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/protocols/netconf/ctl/BUCK b/protocols/netconf/ctl/BUCK
index dae0d7c..8ff5134 100644
--- a/protocols/netconf/ctl/BUCK
+++ b/protocols/netconf/ctl/BUCK
@@ -13,7 +13,7 @@
     '//lib:TEST',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/protocols/openflow/api/BUCK b/protocols/openflow/api/BUCK
index cdd21c3..c681174 100644
--- a/protocols/openflow/api/BUCK
+++ b/protocols/openflow/api/BUCK
@@ -13,7 +13,7 @@
     '//core/api:onos-api-tests',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/protocols/openflow/ctl/BUCK b/protocols/openflow/ctl/BUCK
index 3c2cd91..94dbbda 100644
--- a/protocols/openflow/ctl/BUCK
+++ b/protocols/openflow/ctl/BUCK
@@ -14,7 +14,7 @@
     '//core/api:onos-api-tests',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/protocols/ospf/api/BUCK b/protocols/ospf/api/BUCK
index e9f3762..92c6555 100644
--- a/protocols/ospf/api/BUCK
+++ b/protocols/ospf/api/BUCK
@@ -11,7 +11,7 @@
     '//lib:TEST',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/protocols/ospf/ctl/BUCK b/protocols/ospf/ctl/BUCK
index df0e85b..5da15ee 100644
--- a/protocols/ospf/ctl/BUCK
+++ b/protocols/ospf/ctl/BUCK
@@ -13,7 +13,7 @@
     '//lib:TEST',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/protocols/ospf/protocol/BUCK b/protocols/ospf/protocol/BUCK
index ee5bc2e..2c4cc5f 100644
--- a/protocols/ospf/protocol/BUCK
+++ b/protocols/ospf/protocol/BUCK
@@ -12,7 +12,7 @@
     '//lib:TEST',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/protocols/ovsdb/api/BUCK b/protocols/ovsdb/api/BUCK
index a3a2279..04d088c 100644
--- a/protocols/ovsdb/api/BUCK
+++ b/protocols/ovsdb/api/BUCK
@@ -13,7 +13,7 @@
     '//lib:TEST',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/protocols/ovsdb/ctl/BUCK b/protocols/ovsdb/ctl/BUCK
index 500358c..f360c0e 100644
--- a/protocols/ovsdb/ctl/BUCK
+++ b/protocols/ovsdb/ctl/BUCK
@@ -17,7 +17,7 @@
     '//lib:TEST',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/protocols/ovsdb/rfc/BUCK b/protocols/ovsdb/rfc/BUCK
index 75edeb3..66e623b 100644
--- a/protocols/ovsdb/rfc/BUCK
+++ b/protocols/ovsdb/rfc/BUCK
@@ -9,7 +9,7 @@
     '//lib:netty-codec',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/protocols/pcep/api/BUCK b/protocols/pcep/api/BUCK
index a3f344e..83c98ae 100644
--- a/protocols/pcep/api/BUCK
+++ b/protocols/pcep/api/BUCK
@@ -8,7 +8,7 @@
     '//protocols/pcep/pcepio:onos-pcep-pcepio',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/protocols/pcep/ctl/BUCK b/protocols/pcep/ctl/BUCK
index a3c8e66..58fc0c9 100644
--- a/protocols/pcep/ctl/BUCK
+++ b/protocols/pcep/ctl/BUCK
@@ -9,7 +9,7 @@
     '//protocols/pcep/api:onos-pcep-controller-api',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/protocols/pcep/pcepio/BUCK b/protocols/pcep/pcepio/BUCK
index 1fb7c5b..559e9a8 100644
--- a/protocols/pcep/pcepio/BUCK
+++ b/protocols/pcep/pcepio/BUCK
@@ -11,7 +11,7 @@
     '//lib:TEST',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/protocols/rest/api/BUCK b/protocols/rest/api/BUCK
index f3116ad..509253b 100644
--- a/protocols/rest/api/BUCK
+++ b/protocols/rest/api/BUCK
@@ -9,7 +9,7 @@
     '//utils/rest:onlab-rest',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/protocols/rest/ctl/BUCK b/protocols/rest/ctl/BUCK
index 1fc0618..613ac99 100644
--- a/protocols/rest/ctl/BUCK
+++ b/protocols/rest/ctl/BUCK
@@ -21,7 +21,7 @@
     '//lib:TEST',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/protocols/snmp/api/BUCK b/protocols/snmp/api/BUCK
index d2e504b..4ff8c0f 100644
--- a/protocols/snmp/api/BUCK
+++ b/protocols/snmp/api/BUCK
@@ -13,7 +13,7 @@
     '//lib:mibs-rfc',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/protocols/snmp/ctl/BUCK b/protocols/snmp/ctl/BUCK
index 0c83b08..eff20ce 100644
--- a/protocols/snmp/ctl/BUCK
+++ b/protocols/snmp/ctl/BUCK
@@ -18,7 +18,7 @@
     '//lib:TEST',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/providers/bgp/cfg/BUCK b/providers/bgp/cfg/BUCK
index 8c5b713..3156e95 100644
--- a/providers/bgp/cfg/BUCK
+++ b/providers/bgp/cfg/BUCK
@@ -8,7 +8,7 @@
     '//protocols/bgp/api:onos-bgp-api',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/providers/bgp/flow/BUCK b/providers/bgp/flow/BUCK
index b900d14..ba18ec5 100644
--- a/providers/bgp/flow/BUCK
+++ b/providers/bgp/flow/BUCK
@@ -8,7 +8,7 @@
     '//protocols/bgp/api:onos-bgp-api',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/providers/bgp/topology/BUCK b/providers/bgp/topology/BUCK
index 6ea4e5b..59e56f6 100644
--- a/providers/bgp/topology/BUCK
+++ b/providers/bgp/topology/BUCK
@@ -14,7 +14,7 @@
     '//lib:TEST',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/providers/host/BUCK b/providers/host/BUCK
index f8bedb1..80f921c 100644
--- a/providers/host/BUCK
+++ b/providers/host/BUCK
@@ -7,7 +7,7 @@
     '//lib:CORE_DEPS',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/providers/lldp/BUCK b/providers/lldp/BUCK
index dcc091f..3e40240 100644
--- a/providers/lldp/BUCK
+++ b/providers/lldp/BUCK
@@ -13,7 +13,7 @@
     '//lib:TEST',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/providers/lldpcommon/BUCK b/providers/lldpcommon/BUCK
index 2053e29..f4b3b21 100644
--- a/providers/lldpcommon/BUCK
+++ b/providers/lldpcommon/BUCK
@@ -12,7 +12,7 @@
     '//lib:TEST',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/providers/netcfghost/BUCK b/providers/netcfghost/BUCK
index d548290..c0341d1 100644
--- a/providers/netcfghost/BUCK
+++ b/providers/netcfghost/BUCK
@@ -12,7 +12,7 @@
     '//lib:TEST',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/providers/netcfglinks/BUCK b/providers/netcfglinks/BUCK
index 1a92055..e30244e 100644
--- a/providers/netcfglinks/BUCK
+++ b/providers/netcfglinks/BUCK
@@ -13,7 +13,7 @@
     '//lib:TEST',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/providers/netconf/device/BUCK b/providers/netconf/device/BUCK
index 6206f12..74307dd 100644
--- a/providers/netconf/device/BUCK
+++ b/providers/netconf/device/BUCK
@@ -9,7 +9,7 @@
     '//protocols/netconf/api:onos-netconf-api',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/providers/null/BUCK b/providers/null/BUCK
index 0922a76..7ac6ee6 100644
--- a/providers/null/BUCK
+++ b/providers/null/BUCK
@@ -14,7 +14,7 @@
     '//lib:TEST',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/providers/openflow/device/BUCK b/providers/openflow/device/BUCK
index c27bda4..56244d1 100644
--- a/providers/openflow/device/BUCK
+++ b/providers/openflow/device/BUCK
@@ -14,7 +14,7 @@
     '//lib:TEST',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/providers/openflow/flow/BUCK b/providers/openflow/flow/BUCK
index 8413106..cc8ac28 100644
--- a/providers/openflow/flow/BUCK
+++ b/providers/openflow/flow/BUCK
@@ -14,7 +14,7 @@
     '//lib:TEST',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/providers/openflow/group/BUCK b/providers/openflow/group/BUCK
index 6e1f55a..2d176ab 100644
--- a/providers/openflow/group/BUCK
+++ b/providers/openflow/group/BUCK
@@ -15,7 +15,7 @@
     '//lib:TEST',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/providers/openflow/message/BUCK b/providers/openflow/message/BUCK
index 721518c..dff2a84 100644
--- a/providers/openflow/message/BUCK
+++ b/providers/openflow/message/BUCK
@@ -15,7 +15,7 @@
     '//lib:TEST',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/providers/openflow/meter/BUCK b/providers/openflow/meter/BUCK
index a9bea90..9eae14a 100644
--- a/providers/openflow/meter/BUCK
+++ b/providers/openflow/meter/BUCK
@@ -14,7 +14,7 @@
     '//lib:TEST',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/providers/openflow/packet/BUCK b/providers/openflow/packet/BUCK
index bc579ee..b209b2b 100644
--- a/providers/openflow/packet/BUCK
+++ b/providers/openflow/packet/BUCK
@@ -14,7 +14,7 @@
     '//lib:TEST',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/providers/ovsdb/device/BUCK b/providers/ovsdb/device/BUCK
index 7206649..7e1832f 100644
--- a/providers/ovsdb/device/BUCK
+++ b/providers/ovsdb/device/BUCK
@@ -14,7 +14,7 @@
     '//lib:TEST',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/providers/ovsdb/host/BUCK b/providers/ovsdb/host/BUCK
index 38d9121..2cfac8a 100644
--- a/providers/ovsdb/host/BUCK
+++ b/providers/ovsdb/host/BUCK
@@ -14,7 +14,7 @@
     '//lib:TEST',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/providers/ovsdb/tunnel/BUCK b/providers/ovsdb/tunnel/BUCK
index d7bee96..b41d04f 100644
--- a/providers/ovsdb/tunnel/BUCK
+++ b/providers/ovsdb/tunnel/BUCK
@@ -15,7 +15,7 @@
     '//lib:TEST',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/providers/pcep/topology/BUCK b/providers/pcep/topology/BUCK
index f5f0119..6f819d1 100644
--- a/providers/pcep/topology/BUCK
+++ b/providers/pcep/topology/BUCK
@@ -15,7 +15,7 @@
     '//lib:TEST',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/providers/pcep/tunnel/BUCK b/providers/pcep/tunnel/BUCK
index 50969c2..f98afa9 100644
--- a/providers/pcep/tunnel/BUCK
+++ b/providers/pcep/tunnel/BUCK
@@ -18,7 +18,7 @@
     '//lib:TEST',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/providers/rest/device/BUCK b/providers/rest/device/BUCK
index 6b4e2a4..92dabe8 100644
--- a/providers/rest/device/BUCK
+++ b/providers/rest/device/BUCK
@@ -18,7 +18,7 @@
     '//lib:TEST',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/providers/snmp/alarm/BUCK b/providers/snmp/alarm/BUCK
index 0630028..7217309 100644
--- a/providers/snmp/alarm/BUCK
+++ b/providers/snmp/alarm/BUCK
@@ -19,7 +19,7 @@
     '//lib:TEST',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/providers/snmp/device/BUCK b/providers/snmp/device/BUCK
index 7cbb381..a0d0a69 100644
--- a/providers/snmp/device/BUCK
+++ b/providers/snmp/device/BUCK
@@ -20,7 +20,7 @@
     '//lib:TEST',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/utils/junit/BUCK b/utils/junit/BUCK
index b5394e5..24bcf72 100644
--- a/utils/junit/BUCK
+++ b/utils/junit/BUCK
@@ -13,7 +13,7 @@
     '//lib:guava-testlib',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = SRC_DEPS,
diff --git a/utils/misc/BUCK b/utils/misc/BUCK
index 0832322..72dacf1 100644
--- a/utils/misc/BUCK
+++ b/utils/misc/BUCK
@@ -11,7 +11,7 @@
     '//lib:TEST',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
@@ -26,3 +26,4 @@
            [CURRENT_TARGET],
     source_under_test = [CURRENT_TARGET],
 )
+
diff --git a/utils/osgi/BUCK b/utils/osgi/BUCK
index 195bf3d..ef9ac97 100644
--- a/utils/osgi/BUCK
+++ b/utils/osgi/BUCK
@@ -11,7 +11,7 @@
     '//lib:TEST',
 ]
 
-java_library(
+osgi_jar(
   name = CURRENT_NAME,
   srcs = glob([SRC + '/*.java']),
   deps = COMPILE_DEPS,
diff --git a/utils/rest/BUCK b/utils/rest/BUCK
index d070641..8748675 100644
--- a/utils/rest/BUCK
+++ b/utils/rest/BUCK
@@ -15,7 +15,7 @@
     '//lib:TEST',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
diff --git a/web/api/BUCK b/web/api/BUCK
index 4932fca..bf2d6c3 100644
--- a/web/api/BUCK
+++ b/web/api/BUCK
@@ -1,25 +1,30 @@
 SRC = 'src/main/java/org/onosproject/**/'
 TEST = 'src/test/java/org/onosproject/**/'
+RESOURCES_ROOT = 'src/main/resources/'
 
 CURRENT_NAME = 'onos-rest'
 CURRENT_TARGET = ':' + CURRENT_NAME
 
 COMPILE_DEPS = [
     '//lib:CORE_DEPS',
+    '//incubator/api:onos-incubator-api',
     '//lib:javax.ws.rs-api',
     '//utils/rest:onlab-rest',
-    '//incubator/api:onos-incubator-api',
 ]
 
 TEST_DEPS = [
     '//lib:TEST',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
+    resources = glob([RESOURCES_ROOT + '**']),
+    resources_root = RESOURCES_ROOT,
     deps = COMPILE_DEPS,
     visibility = ['PUBLIC'],
+    debug = False,
+    web_context = '/onos/v1'
 )
 
 java_test(
diff --git a/web/gui/BUCK b/web/gui/BUCK
index 5301057..12ffbd0 100644
--- a/web/gui/BUCK
+++ b/web/gui/BUCK
@@ -1,5 +1,6 @@
 SRC = 'src/main/java/org/onosproject/**/'
 TEST = 'src/test/java/org/onosproject/**/'
+RESOURCES_ROOT = 'src/main/resources/'
 
 CURRENT_NAME = 'onos-gui'
 CURRENT_TARGET = ':' + CURRENT_NAME
@@ -21,13 +22,13 @@
     '//lib:TEST',
 ]
 
-java_library(
+osgi_jar(
     name = CURRENT_NAME,
     srcs = glob([SRC + '/*.java']),
+    resources = glob([RESOURCES_ROOT + '**']),
+    resources_root = RESOURCES_ROOT,
     deps = COMPILE_DEPS,
     visibility = ['PUBLIC'],
-    resources_root = 'src/main/resources',
-    resources = glob(['src/main/resources/**']),
 )
 
 java_test(