Remove all references to java_library in the source BUCK build.

Change-Id: Ie0e8753b62aeff9c4b5476b0108d05e92e3decdb
diff --git a/BUCK b/BUCK
index 1f34f9b..1c501a8 100644
--- a/BUCK
+++ b/BUCK
@@ -97,12 +97,16 @@
     '//apps/aaa:onos-apps-aaa-oar',
     '//apps/acl:onos-apps-acl-oar',
     '//apps/bgprouter:onos-apps-bgprouter-oar',
+    '//apps/cip:onos-apps-cip-oar',
+    '//apps/drivermatrix:onos-apps-drivermatrix-oar',
+    '//apps/events:onos-apps-events-oar',
     '//apps/proxyarp:onos-apps-proxyarp-oar',
     '//apps/segmentrouting:onos-apps-segmentrouting-oar',
     '//apps/gangliametrics:onos-apps-gangliametrics-oar',
     '//apps/graphitemetrics:onos-apps-graphitemetrics-oar',
     '//apps/igmp:onos-apps-igmp-oar',
     '//apps/cordmcast:onos-apps-cordmcast-oar',
+    '//apps/flowanalyzer:onos-apps-flowanalyzer-oar',
     '//apps/olt:onos-apps-olt-oar',
     '//apps/influxdbmetrics:onos-apps-influxdbmetrics-oar',
     '//apps/metrics:onos-apps-metrics-oar',
@@ -119,6 +123,13 @@
     '//apps/pim:onos-apps-pim-oar',
     '//apps/reactive-routing:onos-apps-reactive-routing-oar',
     '//apps/sdnip:onos-apps-sdnip-oar',
+    '//apps/test/demo:onos-apps-test-demo-oar',
+    '//apps/test/distributed-primitives:onos-apps-test-distributed-primitives-oar',
+    '//apps/test/election:onos-apps-test-election-oar',
+    '//apps/test/flow-perf:onos-apps-test-flow-perf-oar',
+    '//apps/test/intent-perf:onos-apps-test-intent-perf-oar',
+    '//apps/test/loadtest:onos-apps-test-loadtest-oar',
+    '//apps/test/messaging-perf:onos-apps-test-messaging-perf-oar',
     '//apps/virtualbng:onos-apps-virtualbng-oar',
     '//apps/cordvtn:onos-apps-cordvtn-oar',
     '//apps/vpls:onos-apps-vpls-oar',
@@ -134,18 +145,13 @@
 APP_JARS = [
     '//apps/cpman/api:onos-apps-cpman-api',
     '//apps/routing-api:onos-apps-routing-api',
-    '//apps/cip:onos-app-cip',
     '//apps/dhcp/api:onos-apps-dhcp-api',
     '//apps/dhcp/app:onos-apps-dhcp-app',
-    '//apps/drivermatrix:onos-app-drivermatrix',
-    '//apps/events:onos-app-events',
-    '//apps/flowanalyzer:onos-app-flowanalyzer',
     '//apps/fwd:onos-apps-fwd',
     '//apps/olt:onos-apps-olt-api',
     '//apps/iptopology-api:onos-apps-iptopology-api',
     '//apps/openstacknode:onos-apps-openstacknode',
     '//apps/routing:onos-apps-routing',
-    '//apps/test:onos-app-test',
     '//apps/vtn/vtnrsc:onos-apps-vtn-vtnrsc',
     '//apps/vtn/sfcmgr:onos-apps-vtn-sfcmgr',
     '//apps/vtn/vtnmgr:onos-apps-vtn-vtnmgr',
diff --git a/apps/cip/BUCK b/apps/cip/BUCK
index aba9512..9afbab3 100644
--- a/apps/cip/BUCK
+++ b/apps/cip/BUCK
@@ -1,29 +1,14 @@
-SRC = 'src/main/java/org/onosproject/**/'
-TEST = 'src/test/java/org/onosproject/**/'
-
-CURRENT_NAME = 'onos-app-cip'
-CURRENT_TARGET = ':' + CURRENT_NAME
-
 COMPILE_DEPS = [
     '//lib:CORE_DEPS',
 ]
 
-TEST_DEPS = [
-    '//lib:TEST',
-]
-
-java_library(
-    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],
+onos_app (
+    title = 'Cluster IP alias App',
+    category = 'Utility',
+    url = 'http://onosproject.org',
+    description = 'ONOS Cluster IP alias application.',
 )
diff --git a/apps/drivermatrix/BUCK b/apps/drivermatrix/BUCK
index 0dccec6..0151d40 100644
--- a/apps/drivermatrix/BUCK
+++ b/apps/drivermatrix/BUCK
@@ -1,33 +1,19 @@
-SRC = 'src/main/java/org/onosproject/**/'
-TEST = 'src/test/java/org/onosproject/**/'
-
-CURRENT_NAME = 'onos-app-drivermatrix'
-CURRENT_TARGET = ':' + CURRENT_NAME
-
 COMPILE_DEPS = [
     '//lib:CORE_DEPS',
     '//lib:org.apache.karaf.shell.console',
     '//cli:onos-cli',
 ]
 
-TEST_DEPS = [
-    '//lib:TEST',
-]
-
-java_library(
-    name = CURRENT_NAME,
-    srcs = glob([SRC + '/*.java']),
+osgi_jar_with_tests (
     deps = COMPILE_DEPS,
-    visibility = ['PUBLIC'],
     resources_root = 'src/main/resources',
     resources = glob(['src/main/resources/**']),
 )
 
-java_test(
-    name = 'tests',
-    srcs = glob([TEST + '/*.java']),
-    deps = COMPILE_DEPS +
-           TEST_DEPS +
-           [CURRENT_TARGET],
-    source_under_test = [CURRENT_TARGET],
+onos_app (
+    title = 'Driver Support Matrix',
+    category = 'Utility',
+    url = 'http://onosproject.org',
+    description = 'Driver behaviour support matrix.',
 )
+
diff --git a/apps/events/BUCK b/apps/events/BUCK
index c7049a6..3b95037 100644
--- a/apps/events/BUCK
+++ b/apps/events/BUCK
@@ -1,33 +1,18 @@
-SRC = 'src/main/java/org/onosproject/**/'
-TEST = 'src/test/java/org/onosproject/**/'
-
-CURRENT_NAME = 'onos-app-events'
-CURRENT_TARGET = ':' + CURRENT_NAME
-
 COMPILE_DEPS = [
     '//lib:CORE_DEPS',
     '//lib:org.apache.karaf.shell.console',
     '//cli:onos-cli',
 ]
 
-TEST_DEPS = [
-    '//lib:TEST',
-]
-
-java_library(
-    name = CURRENT_NAME,
-    srcs = glob([SRC + '/*.java']),
+osgi_jar_with_tests (
     deps = COMPILE_DEPS,
-    visibility = ['PUBLIC'],
     resources_root = 'src/main/resources',
     resources = glob(['src/main/resources/**']),
 )
 
-java_test(
-    name = 'tests',
-    srcs = glob([TEST + '/*.java']),
-    deps = COMPILE_DEPS +
-           TEST_DEPS +
-           [CURRENT_TARGET],
-    source_under_test = [CURRENT_TARGET],
+onos_app (
+    title = 'Event History App',
+    category = 'Utility',
+    url = 'http://onosproject.org',
+    description = 'App to display ONOS event history.',
 )
diff --git a/apps/flowanalyzer/BUCK b/apps/flowanalyzer/BUCK
index a47701d..b09e7d4 100644
--- a/apps/flowanalyzer/BUCK
+++ b/apps/flowanalyzer/BUCK
@@ -1,9 +1,3 @@
-SRC = 'src/main/java/org/onosproject/**/'
-TEST = 'src/test/java/org/onosproject/**/'
-
-CURRENT_NAME = 'onos-app-flowanalyzer'
-CURRENT_TARGET = ':' + CURRENT_NAME
-
 COMPILE_DEPS = [
     '//lib:CORE_DEPS',
     '//lib:org.apache.karaf.shell.console',
@@ -14,20 +8,16 @@
     '//lib:TEST_ADAPTERS',
 ]
 
-java_library(
-    name = CURRENT_NAME,
-    srcs = glob([SRC + '/*.java']),
+osgi_jar_with_tests (
     deps = COMPILE_DEPS,
-    visibility = ['PUBLIC'],
+    test_deps = TEST_DEPS,
     resources_root = 'src/main/resources',
     resources = glob(['src/main/resources/**']),
 )
 
-java_test(
-    name = 'tests',
-    srcs = glob([TEST + '/*.java']),
-    deps = COMPILE_DEPS +
-           TEST_DEPS +
-           [CURRENT_TARGET],
-    source_under_test = [CURRENT_TARGET],
+onos_app (
+    title = 'Flow Space Analysis App',
+    category = 'Monitoring',
+    url = 'http://onosproject.org',
+    description = 'Simple flow space analyzer.',
 )
diff --git a/apps/test/BUCK b/apps/test/BUCK
deleted file mode 100644
index 8e97d9b..0000000
--- a/apps/test/BUCK
+++ /dev/null
@@ -1,137 +0,0 @@
-SRC = 'src/main/java/org/onosproject/**/'
-#FIXME there are some tests in main
-TEST = 'src/test/java/org/onosproject/**/'
-
-COMPILE_DEPS = [
-    '//lib:CORE_DEPS',
-    '//lib:org.apache.karaf.shell.console',
-    '//cli:onos-cli',
-    '//utils/rest:onlab-rest',
-    '//lib:javax.ws.rs-api',
-    '//core/store/serializers:onos-core-serializers',
-]
-
-TEST_DEPS = [
-    '//lib:TEST',
-]
-
-java_library(
-   name = 'onos-app-test',
-   visibility = ['PUBLIC'],
-   deps = [':onos-app-demo',
-           ':onos-app-distributed-primitives',
-           ':onos-app-election',
-           ':onos-app-intent-perf',
-           ':onos-app-loadtest',
-           ':onos-app-messaging-perf',
-   ],
-)
-
-# demo
-
-java_library(
-    name = 'onos-app-demo',
-    srcs = glob(['demo/' + SRC + '*.java']),
-    deps = COMPILE_DEPS,
-    visibility = ['PUBLIC'],
-)
-
-java_test(
-    name = 'onos-app-demo-tests',
-    srcs = glob(['demo/' + TEST + '*.java']),
-    deps = COMPILE_DEPS +
-           TEST_DEPS +
-           [':onos-app-demo'],
-    source_under_test = [':onos-app-demo'],
-)
-
-# distributed-primitives
-
-java_library(
-    name = 'onos-app-distributed-primitives',
-    srcs = glob(['distributed-primitives/' + SRC + '*.java']),
-    deps = COMPILE_DEPS,
-    visibility = ['PUBLIC'],
-)
-
-java_test(
-    name = 'onos-app-distributed-primitives-tests',
-    srcs = glob(['distributed-primitives/' + TEST + '*.java']),
-    deps = COMPILE_DEPS +
-           TEST_DEPS +
-           [':onos-app-distributed-primitives'],
-    source_under_test = [':onos-app-distributed-primitives'],
-)
-
-# election
-
-java_library(
-    name = 'onos-app-election',
-    srcs = glob(['election/' + SRC + '*.java']),
-    deps = COMPILE_DEPS,
-    visibility = ['PUBLIC'],
-)
-
-java_test(
-    name = 'onos-app-election-tests',
-    srcs = glob(['election/' + TEST + '*.java']),
-    deps = COMPILE_DEPS +
-           TEST_DEPS +
-           [':onos-app-election'],
-    source_under_test = [':onos-app-election'],
-)
-
-# intent-perf
-
-java_library(
-    name = 'onos-app-intent-perf',
-    srcs = glob(['intent-perf/' + SRC + '*.java']),
-    deps = COMPILE_DEPS,
-    visibility = ['PUBLIC'],
-)
-
-java_test(
-    name = 'onos-app-intent-perf-tests',
-    srcs = glob(['intent-perf/' + TEST + '*.java']),
-    deps = COMPILE_DEPS +
-           TEST_DEPS +
-           [':onos-app-intent-perf'],
-    source_under_test = [':onos-app-intent-perf'],
-)
-
-# loadtest
-
-java_library(
-    name = 'onos-app-loadtest',
-    srcs = glob(['loadtest/' + SRC + '*.java']),
-    deps = COMPILE_DEPS,
-    visibility = ['PUBLIC'],
-)
-
-java_test(
-    name = 'onos-app-loadtest-tests',
-    srcs = glob(['loadtest/' + TEST + '*.java']),
-    deps = COMPILE_DEPS +
-           TEST_DEPS +
-           [':onos-app-loadtest'],
-    source_under_test = [':onos-app-loadtest'],
-)
-
-# messaging-perf
-
-java_library(
-    name = 'onos-app-messaging-perf',
-    srcs = glob(['messaging-perf/' + SRC + '*.java']),
-    deps = COMPILE_DEPS,
-    visibility = ['PUBLIC'],
-)
-
-java_test(
-    name = 'onos-app-messaging-perf-tests',
-    srcs = glob(['messaging-perf/' + TEST + '*.java']),
-    deps = COMPILE_DEPS +
-           TEST_DEPS +
-           [':onos-app-messaging-perf'],
-    source_under_test = [':onos-app-messaging-perf'],
-)
-
diff --git a/apps/test/demo/BUCK b/apps/test/demo/BUCK
new file mode 100644
index 0000000..0993ed4
--- /dev/null
+++ b/apps/test/demo/BUCK
@@ -0,0 +1,19 @@
+COMPILE_DEPS = [
+    '//lib:CORE_DEPS',
+    '//lib:org.apache.karaf.shell.console',
+    '//cli:onos-cli',
+    '//utils/rest:onlab-rest',
+    '//lib:javax.ws.rs-api',
+    '//core/store/serializers:onos-core-serializers',
+]
+
+osgi_jar_with_tests (
+    deps = COMPILE_DEPS,
+)
+
+onos_app (
+    title = 'Flow Throughput Demo App',
+    category = 'Test',
+    url = 'http://onosproject.org',
+    description = 'Flow throughput test application.',
+)
diff --git a/apps/test/distributed-primitives/BUCK b/apps/test/distributed-primitives/BUCK
new file mode 100644
index 0000000..f50042f
--- /dev/null
+++ b/apps/test/distributed-primitives/BUCK
@@ -0,0 +1,19 @@
+COMPILE_DEPS = [
+    '//lib:CORE_DEPS',
+    '//lib:org.apache.karaf.shell.console',
+    '//cli:onos-cli',
+    '//utils/rest:onlab-rest',
+    '//lib:javax.ws.rs-api',
+    '//core/store/serializers:onos-core-serializers',
+]
+
+osgi_jar_with_tests (
+    deps = COMPILE_DEPS,
+)
+
+onos_app (
+    title = 'Distributed Primitives Test App',
+    category = 'Test',
+    url = 'http://onosproject.org',
+    description = 'ONOS app to test distributed primitives.',
+)
diff --git a/apps/test/election/BUCK b/apps/test/election/BUCK
new file mode 100644
index 0000000..9822348
--- /dev/null
+++ b/apps/test/election/BUCK
@@ -0,0 +1,19 @@
+COMPILE_DEPS = [
+    '//lib:CORE_DEPS',
+    '//lib:org.apache.karaf.shell.console',
+    '//cli:onos-cli',
+    '//utils/rest:onlab-rest',
+    '//lib:javax.ws.rs-api',
+    '//core/store/serializers:onos-core-serializers',
+]
+
+osgi_jar_with_tests (
+    deps = COMPILE_DEPS,
+)
+
+onos_app (
+    title = 'Master Election Test App',
+    category = 'Test',
+    url = 'http://onosproject.org',
+    description = 'Master election test application.',
+)
diff --git a/apps/test/flow-perf/BUCK b/apps/test/flow-perf/BUCK
new file mode 100644
index 0000000..f065aab
--- /dev/null
+++ b/apps/test/flow-perf/BUCK
@@ -0,0 +1,19 @@
+COMPILE_DEPS = [
+    '//lib:CORE_DEPS',
+    '//lib:org.apache.karaf.shell.console',
+    '//cli:onos-cli',
+    '//utils/rest:onlab-rest',
+    '//lib:javax.ws.rs-api',
+    '//core/store/serializers:onos-core-serializers',
+]
+
+osgi_jar_with_tests (
+    deps = COMPILE_DEPS,
+)
+
+onos_app (
+    title = 'Flow Performance Test App',
+    category = 'Test',
+    url = 'http://onosproject.org',
+    description = 'Messaging performance test application.',
+)
diff --git a/apps/test/intent-perf/BUCK b/apps/test/intent-perf/BUCK
new file mode 100644
index 0000000..a57a16a
--- /dev/null
+++ b/apps/test/intent-perf/BUCK
@@ -0,0 +1,19 @@
+COMPILE_DEPS = [
+    '//lib:CORE_DEPS',
+    '//lib:org.apache.karaf.shell.console',
+    '//cli:onos-cli',
+    '//utils/rest:onlab-rest',
+    '//lib:javax.ws.rs-api',
+    '//core/store/serializers:onos-core-serializers',
+]
+
+osgi_jar_with_tests (
+    deps = COMPILE_DEPS,
+)
+
+onos_app (
+    title = 'Intent Performance Test App',
+    category = 'Test',
+    url = 'http://onosproject.org',
+    description = 'Intent performance test application.',
+)
diff --git a/apps/test/loadtest/BUCK b/apps/test/loadtest/BUCK
new file mode 100644
index 0000000..933cbce
--- /dev/null
+++ b/apps/test/loadtest/BUCK
@@ -0,0 +1,19 @@
+COMPILE_DEPS = [
+    '//lib:CORE_DEPS',
+    '//lib:org.apache.karaf.shell.console',
+    '//cli:onos-cli',
+    '//utils/rest:onlab-rest',
+    '//lib:javax.ws.rs-api',
+    '//core/store/serializers:onos-core-serializers',
+]
+
+osgi_jar_with_tests (
+    deps = COMPILE_DEPS,
+)
+
+onos_app (
+    title = 'Distributed Load Test App',
+    category = 'Test',
+    url = 'http://onosproject.org',
+    description = 'Distributed consensus load test application.',
+)
diff --git a/apps/test/messaging-perf/BUCK b/apps/test/messaging-perf/BUCK
new file mode 100644
index 0000000..766a707
--- /dev/null
+++ b/apps/test/messaging-perf/BUCK
@@ -0,0 +1,19 @@
+COMPILE_DEPS = [
+    '//lib:CORE_DEPS',
+    '//lib:org.apache.karaf.shell.console',
+    '//cli:onos-cli',
+    '//utils/rest:onlab-rest',
+    '//lib:javax.ws.rs-api',
+    '//core/store/serializers:onos-core-serializers',
+]
+
+osgi_jar_with_tests (
+    deps = COMPILE_DEPS,
+)
+
+onos_app (
+    title = 'Messaging Performance Test App',
+    category = 'Test',
+    url = 'http://onosproject.org',
+    description = 'Messaging performance test application.',
+)
diff --git a/apps/xos-integration/BUCK b/apps/xos-integration/BUCK
index 198cc6b..c1fb6c7 100644
--- a/apps/xos-integration/BUCK
+++ b/apps/xos-integration/BUCK
@@ -1,9 +1,3 @@
-SRC = 'src/main/java/org/onosproject/**/'
-TEST = 'src/test/java/org/onosproject/**/'
-
-CURRENT_NAME = 'onos-app-xos-integration'
-CURRENT_TARGET = ':' + CURRENT_NAME
-
 COMPILE_DEPS = [
     '//lib:CORE_DEPS',
     '//lib:jersey-client',
@@ -13,24 +7,16 @@
     '//utils/rest:onlab-rest',
 ]
 
-TEST_DEPS = [
-    '//lib:TEST',
-]
-
-java_library(
-    name = CURRENT_NAME,
-    srcs = glob([SRC + '/*.java']),
+osgi_jar_with_tests (
     deps = COMPILE_DEPS,
-    visibility = ['PUBLIC'],
+    import_packages = '*,org.onosproject.cli.net',
     resources_root = 'src/main/resources',
     resources = glob(['src/main/resources/**']),
 )
 
-java_test(
-    name = 'tests',
-    srcs = glob([TEST + '/*.java']),
-    deps = COMPILE_DEPS +
-           TEST_DEPS +
-           [CURRENT_TARGET],
-    source_under_test = [CURRENT_TARGET],
+onos_app (
+    title = 'ONOS XOS Integration App',
+    category = 'Utility',
+    url = 'http://onosproject.org',
+    description = 'ONOS XOS integration application.',
 )