Fix p4runtime runtime dependencies when building with Bazel

A convenient macro for packaging together all proto and gRPC libraries
in an OSGi jar is provided. Also re-packaging of gRPC core (to avoid OSGi
split problem) is simplified by depending on a patched fork of grpc-java.

Change-Id: Idb79a5bea8ae0bc57b146bda1fc47a4568d12c60
diff --git a/protocols/p4runtime/BUILD b/protocols/p4runtime/BUILD
index 407aa46..48e4708 100644
--- a/protocols/p4runtime/BUILD
+++ b/protocols/p4runtime/BUILD
@@ -2,13 +2,7 @@
     "//protocols/p4runtime/api:onos-protocols-p4runtime-api",
     "//protocols/p4runtime/ctl:onos-protocols-p4runtime-ctl",
     "//protocols/p4runtime/model:onos-protocols-p4runtime-model",
-    "//protocols/p4runtime/proto:p4runtime_java_grpc",
-    "//protocols/p4runtime/proto:p4config_java_proto",
-    "//protocols/p4runtime/proto:p4data_java_proto",
-    "//protocols/p4runtime/proto:p4info_java_proto",
-    "//protocols/p4runtime/proto:p4runtime_java_proto",
-    "//protocols/p4runtime/proto:p4types_java_proto",
-    "//protocols/p4runtime/proto:status_java_proto",
+    "//protocols/p4runtime/proto:onos-protocols-p4runtime-proto",
 ]
 
 onos_app(
diff --git a/protocols/p4runtime/ctl/BUILD b/protocols/p4runtime/ctl/BUILD
index 13554c7..e060275 100644
--- a/protocols/p4runtime/ctl/BUILD
+++ b/protocols/p4runtime/ctl/BUILD
@@ -2,18 +2,12 @@
     "//core/store/serializers:onos-core-serializers",
     "//protocols/grpc/api:onos-protocols-grpc-api",
     "//protocols/p4runtime/api:onos-protocols-p4runtime-api",
-    "//protocols/p4runtime/proto:p4config_java_proto",
-    "//protocols/p4runtime/proto:p4data_java_proto",
-    "//protocols/p4runtime/proto:p4info_java_proto",
-    "//protocols/p4runtime/proto:p4runtime_java_grpc",
-    "//protocols/p4runtime/proto:p4runtime_java_proto",
-    "//protocols/p4runtime/proto:status_java_proto",
+    "//protocols/p4runtime/proto:onos-protocols-p4runtime-proto",
     "@com_google_protobuf//:protobuf_java",
-    "@io_grpc_grpc_java//context",
-    "@io_grpc_grpc_java//core",
+    "//protocols/grpc:grpc-core-repkg",
     "@io_grpc_grpc_java//netty",
     "@io_grpc_grpc_java//stub",
-    "@io_grpc_grpc_java_core_repkg//:internal",
+    "@com_google_api_grpc_proto_google_common_protos//jar",
 ]
 
 TEST_DEPS = TEST + [
diff --git a/protocols/p4runtime/model/BUILD b/protocols/p4runtime/model/BUILD
index 1e7b506..619d8ee 100644
--- a/protocols/p4runtime/model/BUILD
+++ b/protocols/p4runtime/model/BUILD
@@ -1,5 +1,5 @@
 COMPILE_DEPS = CORE_DEPS + [
-    "//protocols/p4runtime/proto:p4info_java_proto",
+    "//protocols/p4runtime/proto:onos-protocols-p4runtime-proto",
     "@com_google_protobuf//:protobuf_java",
 ]
 
diff --git a/protocols/p4runtime/proto/BUILD b/protocols/p4runtime/proto/BUILD
index 4c99b0d..3a9435c 100644
--- a/protocols/p4runtime/proto/BUILD
+++ b/protocols/p4runtime/proto/BUILD
@@ -1,61 +1,19 @@
-load("//tools/build/bazel:osgi_java_library.bzl", "wrapped_osgi_jar")
-load("@io_grpc_grpc_java//:java_grpc_library.bzl", "java_grpc_library")
+load("//tools/build/bazel:osgi_java_library.bzl", "osgi_proto_jar")
 
-GRPC_DEPS = [
-    "@io_grpc_grpc_java//stub",
-    "@io_grpc_grpc_java//core",
-    "@io_grpc_grpc_java//protobuf",
+PROTOS = [
+    "@com_github_p4lang_p4runtime//:" + p for p in [
+        "p4info_proto",
+        "p4types_proto",
+        "p4data_proto",
+        "p4runtime_proto",
+]] + [
+    "@com_github_p4lang_pi//:p4config_proto"
 ]
 
-PROTOBUF_DEPS = [
-    "@com_google_protobuf//:protobuf_java",
-]
-
-wrapped_osgi_jar(
-    name = "p4config_java_proto",
-    jar = "@com_github_p4lang_pi//:p4config_java_proto_native",
-    deps = PROTOBUF_DEPS,
-    visibility = ["//visibility:public"],
-)
-
-wrapped_osgi_jar(
-    name = "p4data_java_proto",
-    jar = "@com_github_p4lang_p4runtime//:p4data_java_proto_native",
-    deps = PROTOBUF_DEPS,
-    visibility = ["//visibility:public"],
-)
-
-wrapped_osgi_jar(
-    name = "p4types_java_proto",
-    jar = "@com_github_p4lang_p4runtime//:p4types_java_proto_native",
-    deps = PROTOBUF_DEPS,
-    visibility = ["//visibility:public"],
-)
-
-wrapped_osgi_jar(
-    name = "p4info_java_proto",
-    jar = "@com_github_p4lang_p4runtime//:p4info_java_proto_native",
-    deps = PROTOBUF_DEPS,
-    visibility = ["//visibility:public"],
-)
-
-wrapped_osgi_jar(
-    name = "p4runtime_java_proto",
-    jar = "@com_github_p4lang_p4runtime//:p4runtime_java_proto_native",
-    deps = PROTOBUF_DEPS,
-    visibility = ["//visibility:public"],
-)
-
-wrapped_osgi_jar(
-    name = "p4runtime_java_grpc",
-    jar = "@com_github_p4lang_p4runtime//:p4runtime_java_grpc_native",
-    deps = GRPC_DEPS,
-    visibility = ["//visibility:public"],
-)
-
-wrapped_osgi_jar(
-    name = "status_java_proto",
-    jar = "@com_github_googleapis//:status_java_proto_native",
-    deps = PROTOBUF_DEPS,
-    visibility = ["//visibility:public"],
+osgi_proto_jar(
+    proto_libs = PROTOS,
+    grpc_proto_lib = "@com_github_p4lang_p4runtime//:p4runtime_proto",
+    deps = [
+        "@com_google_api_grpc_proto_google_common_protos//jar",
+    ]
 )