Refactor protocol BUCK files to use more modern rules and format

Change-Id: I9262fdeef12cfd098afefc711d995ffc76b9efb1
diff --git a/protocols/bgp/api/BUCK b/protocols/bgp/api/BUCK
index 7b7ac98..2a195f0 100644
--- a/protocols/bgp/api/BUCK
+++ b/protocols/bgp/api/BUCK
@@ -1,16 +1,8 @@
-SRC = 'src/main/java/org/onosproject/**/'
-
-CURRENT_NAME = 'onos-bgp-api'
-CURRENT_TARGET = ':' + CURRENT_NAME
-
 COMPILE_DEPS = [
     '//lib:CORE_DEPS',
-    '//protocols/bgp/bgpio:onos-bgpio',
+    '//protocols/bgp/bgpio:onos-protocols-bgp-bgpio',
 ]
 
-osgi_jar(
-    name = CURRENT_NAME,
-    srcs = glob([SRC + '/*.java']),
+osgi_jar_with_tests (
     deps = COMPILE_DEPS,
-    visibility = ['PUBLIC'],
 )
diff --git a/protocols/bgp/bgpio/BUCK b/protocols/bgp/bgpio/BUCK
index 3d6b280..2b27800 100644
--- a/protocols/bgp/bgpio/BUCK
+++ b/protocols/bgp/bgpio/BUCK
@@ -1,28 +1,7 @@
-SRC = 'src/main/java/org/onosproject/**/'
-TEST = 'src/test/java/org/onosproject/**/'
-CURRENT_NAME = 'onos-bgpio'
-CURRENT_TARGET = ':' + CURRENT_NAME
-
 COMPILE_DEPS = [
     '//lib:CORE_DEPS',
 ]
 
-TEST_DEPS = [
-    '//lib:TEST',
-]
-
-osgi_jar(
-    name = CURRENT_NAME,
-    srcs = glob([SRC + '/*.java']),
+osgi_jar_with_tests (
     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/ctl/BUCK b/protocols/bgp/ctl/BUCK
index 6336f97..68aa0cd 100644
--- a/protocols/bgp/ctl/BUCK
+++ b/protocols/bgp/ctl/BUCK
@@ -1,34 +1,13 @@
-SRC = 'src/main/java/org/onosproject/**/'
-TEST = 'src/test/java/org/onosproject/**/'
-CURRENT_NAME = 'onos-bgp-ctl'
-CURRENT_TARGET = ':' + CURRENT_NAME
-
 COMPILE_DEPS = [
     '//lib:CORE_DEPS',
     '//lib:jersey-client',
     '//lib:httpclient-osgi',
     '//lib:httpcore-osgi',
     '//lib:javax.ws.rs-api',
-    '//protocols/bgp/api:onos-bgp-api',
-    '//protocols/bgp/bgpio:onos-bgpio',
+    '//protocols/bgp/api:onos-protocols-bgp-api',
+    '//protocols/bgp/bgpio:onos-protocols-bgp-bgpio',
 ]
 
-TEST_DEPS = [
-    '//lib:TEST',
-]
-
-osgi_jar(
-    name = CURRENT_NAME,
-    srcs = glob([SRC + '/*.java']),
+osgi_jar_with_tests (
     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/isis/BUCK b/protocols/isis/BUCK
deleted file mode 100644
index 77dba5a..0000000
--- a/protocols/isis/BUCK
+++ /dev/null
@@ -1,56 +0,0 @@
-SRC = 'src/main/java/org/onosproject/**/'
-TEST = 'src/test/java/org/onosproject/**/'
-
-COMPILE_DEPS = [
-    '//lib:CORE_DEPS',
-    '//lib:netty-buffer',
-]
-
-TEST_DEPS = [
-    '//lib:TEST',
-]
-
-java_library(
-   name = 'onos-isis',
-   visibility = ['PUBLIC'],
-   deps = [':onos-isis-api',
-           ':onos-isis-isisio',
-   ],
-)
-
-# onos-isis-api
-
-osgi_jar(
-    name = 'onos-isis-api',
-    srcs = glob(['api/' + SRC + '*.java']),
-    deps = COMPILE_DEPS,
-    visibility = ['PUBLIC'],
-)
-
-java_test(
-    name = 'onos-isis-api-tests',
-    srcs = glob(['api/' + TEST + '*.java']),
-    deps = COMPILE_DEPS +
-           TEST_DEPS +
-           [':onos-isis-api'],
-    source_under_test = [':onos-isis-api'],
-)
-
-# onos-isis-isisio
-
-osgi_jar(
-    name = 'onos-isis-isisio',
-    srcs = glob(['isisio/' + SRC + '*.java']),
-    deps = COMPILE_DEPS + [':onos-isis-api'],
-    visibility = ['PUBLIC'],
-)
-
-java_test(
-    name = 'onos-isis-isisio-tests',
-    srcs = glob(['isisio/' + TEST + '*.java']),
-    deps = COMPILE_DEPS +
-           TEST_DEPS +
-           [':onos-isis-isisio'],
-    source_under_test = [':onos-isis-isisio'],
-)
-
diff --git a/protocols/isis/api/BUCK b/protocols/isis/api/BUCK
new file mode 100644
index 0000000..3cc9301
--- /dev/null
+++ b/protocols/isis/api/BUCK
@@ -0,0 +1,8 @@
+COMPILE_DEPS = [
+    '//lib:CORE_DEPS',
+]
+
+osgi_jar_with_tests (
+    deps = COMPILE_DEPS,
+)
+
diff --git a/protocols/isis/ctl/BUCK b/protocols/isis/ctl/BUCK
new file mode 100644
index 0000000..b491fe9
--- /dev/null
+++ b/protocols/isis/ctl/BUCK
@@ -0,0 +1,9 @@
+COMPILE_DEPS = [
+    '//lib:CORE_DEPS',
+    '//protocols/isis/api:onos-protocols-isis-api',
+    '//protocols/isis/isisio:onos-protocols-isis-isisio',
+]
+
+osgi_jar_with_tests (
+    deps = COMPILE_DEPS,
+)
diff --git a/protocols/isis/isisio/BUCK b/protocols/isis/isisio/BUCK
new file mode 100644
index 0000000..a8795b9
--- /dev/null
+++ b/protocols/isis/isisio/BUCK
@@ -0,0 +1,8 @@
+COMPILE_DEPS = [
+    '//lib:CORE_DEPS',
+    '//protocols/isis/api:onos-protocols-isis-api',
+]
+
+osgi_jar_with_tests (
+    deps = COMPILE_DEPS,
+)
diff --git a/protocols/netconf/api/BUCK b/protocols/netconf/api/BUCK
index 943b11d..2b27800 100644
--- a/protocols/netconf/api/BUCK
+++ b/protocols/netconf/api/BUCK
@@ -2,6 +2,6 @@
     '//lib:CORE_DEPS',
 ]
 
-osgi_jar(
+osgi_jar_with_tests (
     deps = COMPILE_DEPS,
 )
diff --git a/protocols/openflow/api/BUCK b/protocols/openflow/api/BUCK
index bca8133f..0af0b23 100644
--- a/protocols/openflow/api/BUCK
+++ b/protocols/openflow/api/BUCK
@@ -9,7 +9,6 @@
 ]
 
 osgi_jar_with_tests (
-    name = 'onos-of-api',
     deps = COMPILE_DEPS,
     test_deps = TEST_DEPS,
 )
diff --git a/protocols/openflow/ctl/BUCK b/protocols/openflow/ctl/BUCK
index 94dbbda..62f40af 100644
--- a/protocols/openflow/ctl/BUCK
+++ b/protocols/openflow/ctl/BUCK
@@ -1,12 +1,7 @@
-SRC = 'src/main/java/org/onosproject/**/'
-TEST = 'src/test/java/org/onosproject/**/'
-CURRENT_NAME = 'onos-of-ctl'
-CURRENT_TARGET = ':' + CURRENT_NAME
-
 COMPILE_DEPS = [
     '//lib:CORE_DEPS',
     '//lib:openflowj',
-    '//protocols/openflow/api:onos-of-api'
+    '//protocols/openflow/api:onos-protocols-openflow-api'
 ]
 
 TEST_DEPS = [
@@ -14,18 +9,7 @@
     '//core/api:onos-api-tests',
 ]
 
-osgi_jar(
-    name = CURRENT_NAME,
-    srcs = glob([SRC + '/*.java']),
+osgi_jar_with_tests (
     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],
+    test_deps = TEST_DEPS,
 )
diff --git a/protocols/ospf/api/BUCK b/protocols/ospf/api/BUCK
index 92c6555..3cc9301 100644
--- a/protocols/ospf/api/BUCK
+++ b/protocols/ospf/api/BUCK
@@ -1,28 +1,8 @@
-SRC = 'src/main/java/org/onosproject/**/'
-TEST = 'src/test/java/org/onosproject/**/'
-CURRENT_NAME = 'onos-ospf-api'
-CURRENT_TARGET = ':' + CURRENT_NAME
-
 COMPILE_DEPS = [
     '//lib:CORE_DEPS',
 ]
 
-TEST_DEPS = [
-    '//lib:TEST',
-]
-
-osgi_jar(
-    name = CURRENT_NAME,
-    srcs = glob([SRC + '/*.java']),
+osgi_jar_with_tests (
     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/ospf/ctl/BUCK b/protocols/ospf/ctl/BUCK
index 5da15ee..f381e3e 100644
--- a/protocols/ospf/ctl/BUCK
+++ b/protocols/ospf/ctl/BUCK
@@ -1,30 +1,10 @@
-SRC = 'src/main/java/org/onosproject/**/'
-TEST = 'src/test/java/org/onosproject/**/'
-CURRENT_NAME = 'onos-ospf-ctl'
-CURRENT_TARGET = ':' + CURRENT_NAME
-
 COMPILE_DEPS = [
     '//lib:CORE_DEPS',
-    '//protocols/ospf/api:onos-ospf-api',
-    '//protocols/ospf/protocol:onos-ospf-protocol',
+    '//protocols/ospf/api:onos-protocols-ospf-api',
+    '//protocols/ospf/protocol:onos-protocols-ospf-protocol',
 ]
 
-TEST_DEPS = [
-    '//lib:TEST',
-]
-
-osgi_jar(
-    name = CURRENT_NAME,
-    srcs = glob([SRC + '/*.java']),
+osgi_jar_with_tests (
     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/ospf/protocol/BUCK b/protocols/ospf/protocol/BUCK
index 2c4cc5f..bae8403 100644
--- a/protocols/ospf/protocol/BUCK
+++ b/protocols/ospf/protocol/BUCK
@@ -1,29 +1,8 @@
-SRC = 'src/main/java/org/onosproject/**/'
-TEST = 'src/test/java/org/onosproject/**/'
-CURRENT_NAME = 'onos-ospf-protocol'
-CURRENT_TARGET = ':' + CURRENT_NAME
-
 COMPILE_DEPS = [
     '//lib:CORE_DEPS',
-    '//protocols/ospf/api:onos-ospf-api',
+    '//protocols/ospf/api:onos-protocols-ospf-api',
 ]
 
-TEST_DEPS = [
-    '//lib:TEST',
-]
-
-osgi_jar(
-    name = CURRENT_NAME,
-    srcs = glob([SRC + '/*.java']),
+osgi_jar_with_tests (
     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/ovsdb/api/BUCK b/protocols/ovsdb/api/BUCK
index f715e91..5c9a19d 100644
--- a/protocols/ovsdb/api/BUCK
+++ b/protocols/ovsdb/api/BUCK
@@ -1,31 +1,10 @@
-SRC = 'src/main/java/org/onosproject/**/'
-TEST = 'src/test/java/org/onosproject/**/'
-CURRENT_NAME = 'onos-ovsdb-api'
-CURRENT_TARGET = ':' + CURRENT_NAME
-
 COMPILE_DEPS = [
     '//lib:CORE_DEPS',
     '//lib:netty-transport',
-    '//protocols/ovsdb/rfc:onos-ovsdb-rfc',
+    '//protocols/ovsdb/rfc:onos-protocols-ovsdb-rfc',
 ]
 
-TEST_DEPS = [
-    '//lib:TEST',
-]
-
-osgi_jar(
-    name = CURRENT_NAME,
-    srcs = glob([SRC + '/*.java']),
+osgi_jar_with_tests (
     deps = COMPILE_DEPS,
-    visibility = ['PUBLIC'],
 )
 
-java_test(
-    name = 'onos-protocols-ovsdb-tests',
-    srcs = glob([TEST + '/*.java']),
-    deps = COMPILE_DEPS +
-           TEST_DEPS +
-           [CURRENT_TARGET],
-    source_under_test = [CURRENT_TARGET],
-    visibility = ['PUBLIC'],
-)
diff --git a/protocols/ovsdb/ctl/BUCK b/protocols/ovsdb/ctl/BUCK
index f360c0e..7433c2b 100644
--- a/protocols/ovsdb/ctl/BUCK
+++ b/protocols/ovsdb/ctl/BUCK
@@ -1,34 +1,14 @@
-SRC = 'src/main/java/org/onosproject/**/'
-TEST = 'src/test/java/org/onosproject/**/'
-CURRENT_NAME = 'onos-ovsdb-ctl'
-CURRENT_TARGET = ':' + CURRENT_NAME
-
 COMPILE_DEPS = [
     '//lib:CORE_DEPS',
     '//lib:netty-transport',
     '//lib:netty-buffer',
     '//lib:netty-codec',
     '//lib:netty-handler',
-    '//protocols/ovsdb/rfc:onos-ovsdb-rfc',
-    '//protocols/ovsdb/api:onos-ovsdb-api',
+    '//protocols/ovsdb/rfc:onos-protocols-ovsdb-rfc',
+    '//protocols/ovsdb/api:onos-protocols-ovsdb-api',
 ]
 
-TEST_DEPS = [
-    '//lib:TEST',
-]
-
-osgi_jar(
-    name = CURRENT_NAME,
-    srcs = glob([SRC + '/*.java']),
+osgi_jar_with_tests (
     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/ovsdb/rfc/BUCK b/protocols/ovsdb/rfc/BUCK
index 66e623b..5184298 100644
--- a/protocols/ovsdb/rfc/BUCK
+++ b/protocols/ovsdb/rfc/BUCK
@@ -1,18 +1,10 @@
-SRC = 'src/main/java/org/onosproject/**/'
-
-CURRENT_NAME = 'onos-ovsdb-rfc'
-CURRENT_TARGET = ':' + CURRENT_NAME
-
 COMPILE_DEPS = [
     '//lib:CORE_DEPS',
     '//lib:netty-buffer',
     '//lib:netty-codec',
 ]
 
-osgi_jar(
-    name = CURRENT_NAME,
-    srcs = glob([SRC + '/*.java']),
+osgi_jar_with_tests (
     deps = COMPILE_DEPS,
-    visibility = ['PUBLIC'],
 )
 
diff --git a/protocols/pcep/api/BUCK b/protocols/pcep/api/BUCK
index 83c98ae..ae80b3a 100644
--- a/protocols/pcep/api/BUCK
+++ b/protocols/pcep/api/BUCK
@@ -1,17 +1,9 @@
-SRC = 'src/main/java/org/onosproject/**/'
-
-CURRENT_NAME = 'onos-pcep-controller-api'
-CURRENT_TARGET = ':' + CURRENT_NAME
-
 COMPILE_DEPS = [
     '//lib:CORE_DEPS',
-    '//protocols/pcep/pcepio:onos-pcep-pcepio',
+    '//protocols/pcep/pcepio:onos-protocols-pcep-pcepio',
 ]
 
-osgi_jar(
-    name = CURRENT_NAME,
-    srcs = glob([SRC + '/*.java']),
+osgi_jar_with_tests (
     deps = COMPILE_DEPS,
-    visibility = ['PUBLIC'],
 )
 
diff --git a/protocols/pcep/ctl/BUCK b/protocols/pcep/ctl/BUCK
index 58fc0c9..dd7e29c 100644
--- a/protocols/pcep/ctl/BUCK
+++ b/protocols/pcep/ctl/BUCK
@@ -1,18 +1,10 @@
-SRC = 'src/main/java/org/onosproject/**/'
-
-CURRENT_NAME = 'onos-pcep-ctl'
-CURRENT_TARGET = ':' + CURRENT_NAME
-
 COMPILE_DEPS = [
     '//lib:CORE_DEPS',
-    '//protocols/pcep/pcepio:onos-pcep-pcepio',
-    '//protocols/pcep/api:onos-pcep-controller-api',
+    '//protocols/pcep/pcepio:onos-protocols-pcep-pcepio',
+    '//protocols/pcep/api:onos-protocols-pcep-api',
 ]
 
-osgi_jar(
-    name = CURRENT_NAME,
-    srcs = glob([SRC + '/*.java']),
+osgi_jar_with_tests (
     deps = COMPILE_DEPS,
-    visibility = ['PUBLIC'],
 )
 
diff --git a/protocols/pcep/pcepio/BUCK b/protocols/pcep/pcepio/BUCK
index 559e9a8..3cc9301 100644
--- a/protocols/pcep/pcepio/BUCK
+++ b/protocols/pcep/pcepio/BUCK
@@ -1,28 +1,8 @@
-SRC = 'src/main/java/org/onosproject/**/'
-TEST = 'src/test/java/org/onosproject/**/'
-CURRENT_NAME = 'onos-pcep-pcepio'
-CURRENT_TARGET = ':' + CURRENT_NAME
-
 COMPILE_DEPS = [
     '//lib:CORE_DEPS',
 ]
 
-TEST_DEPS = [
-    '//lib:TEST',
-]
-
-osgi_jar(
-    name = CURRENT_NAME,
-    srcs = glob([SRC + '/*.java']),
+osgi_jar_with_tests (
     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/rest/ctl/BUCK b/protocols/rest/ctl/BUCK
index c6ef03d..c289b01 100644
--- a/protocols/rest/ctl/BUCK
+++ b/protocols/rest/ctl/BUCK
@@ -12,10 +12,6 @@
     '//protocols/rest/api:onos-protocols-rest-api',
 ]
 
-TEST_DEPS = [
-    '//lib:TEST',
-]
-
 osgi_jar_with_tests (
     deps = COMPILE_DEPS,
 )
diff --git a/protocols/snmp/api/BUCK b/protocols/snmp/api/BUCK
index 4ff8c0f..eec6b2f 100644
--- a/protocols/snmp/api/BUCK
+++ b/protocols/snmp/api/BUCK
@@ -1,8 +1,3 @@
-SRC = 'src/main/java/org/onosproject/**/'
-
-CURRENT_NAME = 'onos-snmp-api'
-CURRENT_TARGET = ':' + CURRENT_NAME
-
 COMPILE_DEPS = [
     '//lib:CORE_DEPS',
     '//incubator/api:onos-incubator-api',
@@ -13,9 +8,6 @@
     '//lib:mibs-rfc',
 ]
 
-osgi_jar(
-    name = CURRENT_NAME,
-    srcs = glob([SRC + '/*.java']),
+osgi_jar_with_tests (
     deps = COMPILE_DEPS,
-    visibility = ['PUBLIC'],
 )
diff --git a/protocols/snmp/ctl/BUCK b/protocols/snmp/ctl/BUCK
index eff20ce..7ba20f6 100644
--- a/protocols/snmp/ctl/BUCK
+++ b/protocols/snmp/ctl/BUCK
@@ -1,12 +1,7 @@
-SRC = 'src/main/java/org/onosproject/**/'
-TEST = 'src/test/java/org/onosproject/**/'
-CURRENT_NAME = 'onos-snmp-ctl'
-CURRENT_TARGET = ':' + CURRENT_NAME
-
 COMPILE_DEPS = [
     '//lib:CORE_DEPS',
     '//incubator/api:onos-incubator-api',
-    '//protocols/snmp/api:onos-snmp-api',
+    '//protocols/snmp/api:onos-protocols-snmp-api',
     '//lib:org.apache.servicemix.bundles.snmp4j',
     '//lib:snmp-core',
     '//lib:bti7000',
@@ -14,22 +9,7 @@
     '//lib:mibs-rfc',
 ]
 
-TEST_DEPS = [
-    '//lib:TEST',
-]
-
-osgi_jar(
-    name = CURRENT_NAME,
-    srcs = glob([SRC + '/*.java']),
+osgi_jar_with_tests (
     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],
-)