Implement OSGI wrappers for proto jar files

Change-Id: Ic30d162093c383edc4abf5e9e9b96df669d804c8
diff --git a/protocols/p4runtime/model/BUILD b/protocols/p4runtime/model/BUILD
index 3ac33b6..f29c84c 100644
--- a/protocols/p4runtime/model/BUILD
+++ b/protocols/p4runtime/model/BUILD
@@ -2,7 +2,6 @@
 
 COMPILE_DEPS = CORE_DEPS + [
     "//protocols/p4runtime/proto:p4_runtime_java_proto",
-    "//protocols/p4runtime/proto:p4_config_java_proto",
     "@com_google_protobuf//:protobuf_java",
 ]
 
diff --git a/protocols/p4runtime/proto/BUILD b/protocols/p4runtime/proto/BUILD
index 51da262..73c65b0 100644
--- a/protocols/p4runtime/proto/BUILD
+++ b/protocols/p4runtime/proto/BUILD
@@ -1,23 +1,22 @@
 java_proto_library(
-    name = "p4_types_java_proto",
-    visibility = ["//visibility:public"],
-    deps = ["@p4lang_pi//:p4types_proto"],
-)
-
-java_proto_library(
-    name = "p4_config_java_proto",
-    visibility = ["//visibility:public"],
-    deps = ["@p4lang_pi//:p4config_proto"],
-)
-
-java_proto_library(
-    name = "p4_tmp_config_java_proto",
-    visibility = ["//visibility:public"],
-    deps = ["@p4lang_pi//:p4_tmp_config_proto"],
-)
-
-java_proto_library(
     name = "p4_runtime_java_proto",
     visibility = ["//visibility:public"],
     deps = ["@p4lang_pi//:p4_runtime_proto"],
 )
+
+wrapped_osgi_library(
+    name = "rpc_java_proto-osgi",
+    jar = "@google_rpc//:rpc_java_proto",
+    visibility = ["//visibility:public"],
+    deps = CORE_DEPS + ["@protobuf_java_3_2_0//jar"],
+)
+
+wrapped_osgi_library(
+    name = "p4_runtime_java_proto-osgi",
+    jar = ":p4_runtime_java_proto",
+    visibility = ["//visibility:public"],
+    deps = CORE_DEPS + [
+        "@protobuf_java_3_2_0//jar",
+        "@google_rpc//:rpc_java_proto",
+    ],
+)
diff --git a/tools/build/bazel/google_RPC_BUILD b/tools/build/bazel/google_RPC_BUILD
index 698693b..76de8fd 100644
--- a/tools/build/bazel/google_RPC_BUILD
+++ b/tools/build/bazel/google_RPC_BUILD
@@ -1,17 +1,17 @@
 package(default_visibility = ["//visibility:public"])
 
 proto_library(
-    name = "status_proto",
-    srcs = [ "//:google/rpc/status.proto" ],
+    name = "rpc_proto",
+    srcs = [ "//:google/rpc/code.proto", "//:google/rpc/status.proto" ],
     deps = [
         "@com_google_protobuf//:any_proto",
     ],
 )
 
-proto_library(
-    name = "code_proto",
-    srcs = [ "//:google/rpc/code.proto" ],
-    deps = [
-        "@com_google_protobuf//:any_proto",
-    ],
+java_proto_library(
+    name = "rpc_java_proto",
+    visibility = ["//visibility:public"],
+    deps = [":rpc_proto"],
 )
+
+
diff --git a/tools/build/bazel/osgi-java-library.bzl b/tools/build/bazel/osgi-java-library.bzl
index c3ed9b3..274ed25 100644
--- a/tools/build/bazel/osgi-java-library.bzl
+++ b/tools/build/bazel/osgi-java-library.bzl
@@ -1,3 +1,19 @@
+"""
+ Copyright 2018-present Open Networking Foundation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+"""
+
 load("//tools/build/bazel:generate_workspace.bzl", "COMPILE", "TEST")
 load("//tools/build/bazel:variables.bzl", "ONOS_VERSION")
 load("//tools/build/bazel:generate_test_rules.bzl", "generate_test_rules")
@@ -19,9 +35,20 @@
 
 # Implementation of the rule to call bnd to make an OSGI jar file
 def _bnd_impl(ctx):
-    jar = ctx.file.source.path
+    if (len(ctx.files.source) == 1):
+        input_file = ctx.files.source[0]
+    else:
+        # this is a list of inputs. The one we want is the last one
+        # in the list that isn't a source jar
+        for file in reversed(ctx.files.source):
+            if ("-src" in file.path):
+                continue
+            else:
+                input_file = file
+                break
+
+    jar = input_file.path
     output = ctx.outputs.osgi_jar.path
-    cp = ""
     name = ctx.attr.source.label.name
     group = ctx.attr.package_name_root
     version = ctx.attr.version
@@ -31,8 +58,9 @@
     includeResources = ""
     webContext = "NONE"
     dynamicimportPackages = ""
+    cp = ""
 
-    inputDependencies = [ctx.file.source]
+    inputDependencies = [input_file]
 
     # determine the dependencies and build the class path
     for dep in ctx.attr.deps:
@@ -47,7 +75,7 @@
         inputDependencies = inputDependencies + [file]
 
     # extract the class files for use by bnd
-    classes = ctx.actions.declare_file("classes")
+    classes = ctx.actions.declare_file("classes" + ctx.label.name.replace("/", "-"))
     classesPath = classes.path
     jarCommand = "mkdir -p %s && cp %s %s && cd %s && jar xf *.jar" % (classesPath, jar, classesPath, classesPath)
     ctx.actions.run_shell(
@@ -87,7 +115,7 @@
         "deps": attr.label_list(),
         "version": attr.string(),
         "package_name_root": attr.string(),
-        "source": attr.label(allow_single_file = True),
+        "source": attr.label(),
         "_bnd_exe": attr.label(
             executable = True,
             cfg = "host",
diff --git a/tools/build/bazel/p4lang_BUILD b/tools/build/bazel/p4lang_BUILD
index 52d7082..4850082 100644
--- a/tools/build/bazel/p4lang_BUILD
+++ b/tools/build/bazel/p4lang_BUILD
@@ -1,40 +1,15 @@
 package(default_visibility = ["//visibility:public"])
 
 proto_library(
-    name = "p4types_proto",
-    srcs = [ "//:p4/p4types.proto" ],
-    deps = [
-        "@com_google_protobuf//:any_proto",
-    ],
-)
-
-proto_library(
-    name = "p4config_proto",
-    srcs = [ "//:p4/config/p4info.proto" ],
-    deps = [
-        "@com_google_protobuf//:any_proto",
-        ":p4types_proto",
-    ],
-)
-
-proto_library(
-    name = "p4_tmp_config_proto",
-    srcs = [ "//:p4/tmp/p4config.proto" ],
-    deps = [
-        "@com_google_protobuf//:any_proto",
-        ":p4types_proto",
-    ],
-)
-
-proto_library(
     name = "p4_runtime_proto",
-    srcs = [ "//:p4/p4runtime.proto" ],
+    srcs = [
+            "//:p4/p4types.proto",
+            "//:p4/config/p4info.proto",
+            "//:p4/tmp/p4config.proto",
+            "//:p4/p4runtime.proto",
+    ],
     deps = [
         "@com_google_protobuf//:any_proto",
-        "@google_rpc//:status_proto",
-        "@google_rpc//:code_proto",
-        ":p4types_proto",
-        ":p4config_proto",
-        ":p4_tmp_config_proto",
+        "@google_rpc//:rpc_proto",
     ],
 )
\ No newline at end of file