Bazel build for STC runs

Change-Id: I75806c0cb5b71402b7e3519a84498f8e05a9cf8a
diff --git a/apps/dhcprelay/BUILD b/apps/dhcprelay/BUILD
new file mode 100644
index 0000000..956419e
--- /dev/null
+++ b/apps/dhcprelay/BUILD
@@ -0,0 +1,30 @@
+COMPILE_DEPS = CORE_DEPS + JACKSON + KRYO + CLI + [
+    "//core/store/serializers:onos-core-serializers",
+    "//apps/route-service/api:onos-apps-route-service-api",
+    "//apps/routing/fpm/api:onos-apps-routing-fpm-api",
+]
+
+TEST_DEPS = TEST + [
+    "//apps/route-service/api:onos-apps-route-service-api-tests",
+    "//core/api:onos-api-tests",
+]
+
+BUNDLES = [
+    "//apps/dhcprelay:onos-apps-dhcprelay",
+    "//apps/routing/fpm/api:onos-apps-routing-fpm-api",
+]
+
+osgi_jar_with_tests(
+    test_deps = TEST_DEPS,
+    deps = COMPILE_DEPS,
+)
+
+onos_app(
+    app_name = "org.onosproject.dhcprelay",
+    category = "Utility",
+    description = "DHCP Relay Agent Application.",
+    included_bundles = BUNDLES,
+    required_apps = ["org.onosproject.route-service"],
+    title = "DHCP Relay Agent",
+    url = "http://onosproject.org",
+)
diff --git a/apps/pathpainter/BUILD b/apps/pathpainter/BUILD
new file mode 100644
index 0000000..3da6a0e
--- /dev/null
+++ b/apps/pathpainter/BUILD
@@ -0,0 +1,17 @@
+COMPILE_DEPS = CORE_DEPS + JACKSON
+
+osgi_jar_with_tests(
+    resources = glob(["src/main/resources/**"]),
+    resources_root = "src/main/resources",
+    deps = COMPILE_DEPS,
+)
+
+onos_app(
+    category = "GUI",
+    description = "Extends the GUI topology view by adding an overlay that allows the operator " +
+                  "to visualize topology paths using various forms of path-finding algorithms such as " +
+                  "the Dijkstra shortest path using default link metric (ONOS default), using geographic " +
+                  "distances, disjoint paths, etc.",
+    title = "Path Visualization",
+    url = "http://onosproject.org",
+)
diff --git a/apps/proxyarp/BUILD b/apps/proxyarp/BUILD
new file mode 100644
index 0000000..907c556
--- /dev/null
+++ b/apps/proxyarp/BUILD
@@ -0,0 +1,14 @@
+COMPILE_DEPS = CORE_DEPS + [
+    "//incubator/api:onos-incubator-api",
+]
+
+osgi_jar(
+    deps = COMPILE_DEPS,
+)
+
+onos_app(
+    category = "Traffic Engineering",
+    description = "Proxy ARP/NDP application.",
+    title = "Proxy ARP/NDP",
+    url = "http://onosproject.org",
+)
diff --git a/apps/routeradvertisement/BUILD b/apps/routeradvertisement/BUILD
new file mode 100644
index 0000000..abca366
--- /dev/null
+++ b/apps/routeradvertisement/BUILD
@@ -0,0 +1,15 @@
+COMPILE_DEPS = CORE_DEPS + JACKSON + CLI + [
+    "//incubator/api:onos-incubator-api",
+]
+
+osgi_jar_with_tests(
+    test_deps = TEST_ADAPTERS,
+    deps = COMPILE_DEPS,
+)
+
+onos_app(
+    category = "Traffic Engineering",
+    description = "Application for generating IPv6 RAs",
+    title = "IPv6 RA Generator",
+    url = "http://onosproject.org",
+)
diff --git a/apps/routing-api/BUILD b/apps/routing-api/BUILD
new file mode 100644
index 0000000..80eba67
--- /dev/null
+++ b/apps/routing-api/BUILD
@@ -0,0 +1,8 @@
+COMPILE_DEPS = CORE_DEPS + JACKSON + [
+    "//incubator/api:onos-incubator-api",
+]
+
+osgi_jar_with_tests(
+    test_deps = TEST_ADAPTERS,
+    deps = COMPILE_DEPS,
+)
diff --git a/apps/routing/common/BUILD b/apps/routing/common/BUILD
new file mode 100644
index 0000000..0792ed9
--- /dev/null
+++ b/apps/routing/common/BUILD
@@ -0,0 +1,17 @@
+COMPILE_DEPS = CORE_DEPS + NETTY + JACKSON + CLI + [
+    "@netty//jar",
+    "//incubator/api:onos-incubator-api",
+    "//apps/routing-api:onos-apps-routing-api",
+    "//apps/route-service/api:onos-apps-route-service-api",
+    "//core/common:onos-core-common",
+]
+
+TEST_DEPS = TEST_ADAPTERS + [
+    "//incubator/api:onos-incubator-api-tests",
+    "//apps/routing-api:onos-apps-routing-api-tests",
+]
+
+osgi_jar_with_tests(
+    test_deps = TEST_DEPS,
+    deps = COMPILE_DEPS,
+)
diff --git a/apps/routing/fpm/BUILD b/apps/routing/fpm/BUILD
new file mode 100644
index 0000000..bcf45df
--- /dev/null
+++ b/apps/routing/fpm/BUILD
@@ -0,0 +1,16 @@
+BUNDLES = [
+    "//apps/routing/common:onos-apps-routing-common",
+    "//apps/routing-api:onos-apps-routing-api",
+    "//apps/routing/fpm/api:onos-apps-routing-fpm-api",
+    "//apps/routing/fpm/app:onos-apps-routing-fpm-app",
+]
+
+onos_app(
+    app_name = "org.onosproject.fpm",
+    category = "Utility",
+    description = "Receives/Transmits routes from external routing daemon over FPM protocol",
+    included_bundles = BUNDLES,
+    required_apps = ["org.onosproject.route-service"],
+    title = "FIB Push Manager (FPM) Route Receiver",
+    url = "http://onosproject.org",
+)
diff --git a/apps/routing/fpm/api/BUILD b/apps/routing/fpm/api/BUILD
new file mode 100644
index 0000000..01d59ae
--- /dev/null
+++ b/apps/routing/fpm/api/BUILD
@@ -0,0 +1,3 @@
+osgi_jar(
+    deps = CORE_DEPS,
+)
diff --git a/apps/routing/fpm/app/BUILD b/apps/routing/fpm/app/BUILD
new file mode 100644
index 0000000..7dc29f6
--- /dev/null
+++ b/apps/routing/fpm/app/BUILD
@@ -0,0 +1,13 @@
+COMPILE_DEPS = CORE_DEPS + NETTY + KRYO + CLI + [
+    "@netty//jar",
+    "//incubator/api:onos-incubator-api",
+    "//apps/routing-api:onos-apps-routing-api",
+    "//apps/route-service/api:onos-apps-route-service-api",
+    "//core/store/serializers:onos-core-serializers",
+    "//apps/routing/fpm/api:onos-apps-routing-fpm-api",
+]
+
+osgi_jar_with_tests(
+    test_deps = TEST_ADAPTERS,
+    deps = COMPILE_DEPS,
+)
diff --git a/apps/test/distributed-primitives/BUILD b/apps/test/distributed-primitives/BUILD
new file mode 100644
index 0000000..09ab1c4
--- /dev/null
+++ b/apps/test/distributed-primitives/BUILD
@@ -0,0 +1,17 @@
+COMPILE_DEPS = CORE_DEPS + KRYO + CLI + [
+    "@javax_ws_rs_api//jar",
+    "//utils/rest:onlab-rest",
+    "//core/store/serializers:onos-core-serializers",
+]
+
+osgi_jar(
+    deps = COMPILE_DEPS,
+)
+
+onos_app(
+    app_name = "org.onosproject.distributedprimitives",
+    category = "Test Utility",
+    description = "ONOS app to test distributed primitives.",
+    title = "Distributed Primitives Test",
+    url = "http://onosproject.org",
+)
diff --git a/modules.bzl b/modules.bzl
index 223cc9b..1d74543 100644
--- a/modules.bzl
+++ b/modules.bzl
@@ -147,7 +147,7 @@
 ONOS_APPS = [
     # Apps
     "//apps/dhcp:onos-apps-dhcp-oar",
-    #"//apps/dhcprelay:onos-apps-dhcprelay-oar",
+    "//apps/dhcprelay:onos-apps-dhcprelay-oar",
     "//apps/fwd:onos-apps-fwd-oar",
     #"//apps/packet-stats:onos-apps-packet-stats-oar",
     "//apps/acl:onos-apps-acl-oar",
@@ -155,7 +155,7 @@
     "//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/proxyarp:onos-apps-proxyarp-oar",
     "//apps/segmentrouting:onos-apps-segmentrouting-oar",
     #"//apps/gangliametrics:onos-apps-gangliametrics-oar",
     #"//apps/graphitemetrics:onos-apps-graphitemetrics-oar",
@@ -170,7 +170,7 @@
     #"//apps/newoptical:onos-apps-newoptical-oar",
     "//apps/optical-model:onos-apps-optical-model-oar",
     #"//apps/optical-rest:onos-apps-optical-rest-oar",
-    #"//apps/pathpainter:onos-apps-pathpainter-oar",
+    "//apps/pathpainter:onos-apps-pathpainter-oar",
     "//apps/pcep-api:onos-apps-pcep-api-oar",
     #"//apps/pim:onos-apps-pim-oar",
     #"//apps/linkprops:onos-apps-linkprops-oar",
@@ -179,7 +179,7 @@
     #"//apps/sdnip:onos-apps-sdnip-oar",
     #"//apps/test/cluster-ha:onos-apps-test-cluster-ha-oar",
     #"//apps/test/demo:onos-apps-test-demo-oar",
-    #"//apps/test/distributed-primitives:onos-apps-test-distributed-primitives-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",
@@ -194,7 +194,7 @@
     #"//apps/vrouter:onos-apps-vrouter-oar",
     #"//apps/routing/fibinstaller:onos-apps-routing-fibinstaller-oar",
     #"//apps/routing/cpr:onos-apps-routing-cpr-oar",
-    #"//apps/routing/fpm:onos-apps-routing-fpm-oar",
+    "//apps/routing/fpm:onos-apps-routing-fpm-oar",
     #"//apps/vtn:onos-apps-vtn-oar",
     "//apps/faultmanagement:onos-apps-faultmanagement-oar",
     #"//apps/openstacknode:onos-apps-openstacknode-oar",
@@ -234,7 +234,7 @@
     #"//apps/p4-tutorial/pipeconf:onos-apps-p4-tutorial-pipeconf-oar",
     #"//apps/p4-tutorial/mytunnel:onos-apps-p4-tutorial-mytunnel-oar",
     #"//apps/cfm:onos-apps-cfm-oar",
-    #"//apps/routeradvertisement:onos-apps-routeradvertisement-oar",
+    "//apps/routeradvertisement:onos-apps-routeradvertisement-oar",
     #"//apps/powermanagement:onos-apps-powermanagement-oar",
     #"//apps/t3:onos-apps-t3-oar",
     #"//apps/simplefabric:onos-apps-simplefabric-oar",
@@ -278,15 +278,15 @@
 
 APP_JARS = [
     #"//apps/cpman/api:onos-apps-cpman-api",
-    #"//apps/routing-api:onos-apps-routing-api",
+    "//apps/routing-api:onos-apps-routing-api",
     "//apps/dhcp/api:onos-apps-dhcp-api",
     "//apps/dhcp/app:onos-apps-dhcp-app",
     #"//apps/imr/api:onos-apps-imr-api",
     #"//apps/imr/app:onos-apps-imr-app",
-    #"//apps/dhcprelay:onos-apps-dhcprelay",
+    "//apps/dhcprelay:onos-apps-dhcprelay",
     "//apps/fwd:onos-apps-fwd",
     #"//apps/iptopology-api:onos-apps-iptopology-api",
-    #"//apps/routing/common:onos-apps-routing-common",
+    "//apps/routing/common:onos-apps-routing-common",
     #"//apps/vtn/vtnrsc:onos-apps-vtn-vtnrsc",
     #"//apps/vtn/sfcmgr:onos-apps-vtn-sfcmgr",
     #"//apps/vtn/vtnmgr:onos-apps-vtn-vtnmgr",
@@ -310,4 +310,4 @@
 ]
 
 APPS = ONOS_DRIVERS + ONOS_PROVIDERS + ONOS_APPS + MODELS + PIPELINES + \
-       PROTOCOL_APPS
+       PROTOCOL_APPS + APP_JARS
diff --git a/tools/build/envDefaults b/tools/build/envDefaults
index d87acbc..190f7de 100644
--- a/tools/build/envDefaults
+++ b/tools/build/envDefaults
@@ -33,10 +33,15 @@
 export ONOS_TAR=$ONOS_STAGE.tar.gz
 export ONOS_ZIP=$ONOS_STAGE.zip
 
-# If the BUCK-built bits are newer than the Maven-built bits, use the former.
+# If the bazel-built bits are newer than the buck-built bits, use the former.
 BUCK_TAR=$ONOS_ROOT/buck-out/gen/tools/package/onos-package/onos.tar.gz
-if [ -f $BUCK_TAR ] && [ $BUCK_TAR -nt $ONOS_TAR ]; then
-    rm -f $ONOS_TAR >/dev/null; ln -s $BUCK_TAR $ONOS_TAR
+BAZEL_TAR=$ONOS_ROOT/bazel-bin/onos.tar.gz
+if [ -f $BAZEL_TAR ] && [ $BAZEL_TAR -nt $ONOS_TAR ]; then
+    rm -f $ONOS_TAR >/dev/null; ln -s $BAZEL_TAR $ONOS_TAR
+else
+    if [ -f $BUCK_TAR ] && [ $BUCK_TAR -nt $ONOS_TAR ]; then
+        rm -f $ONOS_TAR >/dev/null; ln -s $BUCK_TAR $ONOS_TAR
+    fi
 fi
 
 # ONOS test bits (onos-test.tar.gz) staging environment
diff --git a/tools/test/bin/onos-check-bits b/tools/test/bin/onos-check-bits
index 2b0acd3..1196e27 100755
--- a/tools/test/bin/onos-check-bits
+++ b/tools/test/bin/onos-check-bits
@@ -6,18 +6,17 @@
 [ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
 . $ONOS_ROOT/tools/build/envDefaults
 
-# If the BUCK-built bits are newer than the Maven-built bits, use the former.
+# If the bazel-built bits are newer than the buck-built bits, use the former.
 BUCK_TAR=$ONOS_ROOT/buck-out/gen/tools/package/onos-package/onos.tar.gz
-if [ -f $BUCK_TAR ] && [ $BUCK_TAR -nt $ONOS_TAR ]; then
-  rm -f $ONOS_TAR >/dev/null; ln -s $BUCK_TAR $ONOS_TAR
+BAZEL_TAR=$ONOS_ROOT/bazel-bin/onos.tar.gz
+if [ -f $BAZEL_TAR ] && [ $BAZEL_TAR -nt $ONOS_TAR ]; then
+    rm -f $ONOS_TAR >/dev/null; ln -s $BAZEL_TAR $ONOS_TAR
+else
+    if [ -f $BUCK_TAR ] && [ $BUCK_TAR -nt $ONOS_TAR ]; then
+        rm -f $ONOS_TAR >/dev/null; ln -s $BUCK_TAR $ONOS_TAR
+    fi
 fi
 
-# If the Bazel-built bits are newer than the BUCK-built bits, use the former.
-# BAZEL_TAR=$ONOS_ROOT/bazel-bin/tools/package/onos.tar.gz
-# if [ -f $BAZEL_TAR ] && [ $BAZEL_TAR -nt $BUCK_TAR ]; then
-#   rm -f $ONOS_TAR >/dev/null; ln -s $BAZEL_TAR $ONOS_TAR
-# fi
-
 ls -lL $ONOS_TAR  && cksum $ONOS_TAR
 if [ $? -ne 0 ]; then
   echo "ONOS archive is unreadable" && exit 1
diff --git a/tools/test/bin/onos-push-bits b/tools/test/bin/onos-push-bits
index 38e2877..2187edc 100755
--- a/tools/test/bin/onos-push-bits
+++ b/tools/test/bin/onos-push-bits
@@ -87,6 +87,7 @@
   if [ -n "$locHash" ] && [ "$locHash" = "$remHash" ]; then
       echo "ONOS bits $ONOS_TAR already up-to-date on $node..."
   else
+      ssh $remote rm -f $ONOS_TAR
       scp -q $ONOS_TAR $remote_with_bracket:/tmp
   fi
 fi
diff --git a/tools/test/bin/onos-push-bits-through-proxy b/tools/test/bin/onos-push-bits-through-proxy
index b983af2..978174b 100755
--- a/tools/test/bin/onos-push-bits-through-proxy
+++ b/tools/test/bin/onos-push-bits-through-proxy
@@ -19,6 +19,7 @@
 ssh $remote "
   for other in ${others//$'\n'/ } ; do
     echo \"Pushing to \$other ...\";
+    ssh -o StrictHostKeyChecking=no $ONOS_USER@\$other rm -rf /tmp/\$(basename $ONOS_TAR) &&
     scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
         /tmp/\$(basename $ONOS_TAR) \
         $ONOS_USER@[\$other]:/tmp/\$(basename $ONOS_TAR)