Repackaging of gRPC 1.3.0 via BUCK build

Needed to solve the OSGI split package issue

Change-Id: Id77e77854afe163e33ed9a3798cb430f507eb27f
diff --git a/incubator/grpc-dependencies/BUCK b/incubator/grpc-dependencies/BUCK
index 8006e27..7179dc9 100644
--- a/incubator/grpc-dependencies/BUCK
+++ b/incubator/grpc-dependencies/BUCK
@@ -1,3 +1,41 @@
 include_defs('//bucklets/grpc.bucklet')
 
-fetch_grpc_plugin(version = '1.3.0')
\ No newline at end of file
+fetch_grpc_plugin(version = '1.3.0')
+
+# Repackaging of gRPC 1.3.0 to solve the OSGI split package issue.
+# If bumping the gRPC version, please write a new rule.
+
+def grpc_core_repkg_130():
+    repkg_deps = [
+        '//lib:COMPILE',
+        '//lib:google-instrumentation-0.3.0',
+        "//lib:google-errorprone-2.0.19"
+    ]
+    remote_file(
+        name = "grpc-src-zip-130",
+        url = "https://github.com/grpc/grpc-java/archive/v1.3.0.zip",
+        sha1 = "aae4368c7e4c4666236238e31be3a529e153cc02",
+    )
+    srcs = []
+    for pkg in ['core', 'context']:
+        name = 'grpc-' + pkg + '-130'
+        genrule(
+            name = name,
+            bash = 'jar xf $(location :grpc-src-zip-130) grpc-java-1.3.0/' + pkg + '/src/main/java '
+            + '&& cd grpc-java-1.3.0/' + pkg + '/src/main/java '
+            + '&& jar -cf $OUT *',
+            out = pkg + '.src.zip',
+        )
+        srcs.append(':' + name)
+    osgi_jar(
+        name = 'grpc-core-repkg-1.3.0',
+        srcs = srcs,
+        deps = repkg_deps,
+        package_name_root = 'io.grpc',
+        import_packages = '!javax.annotation,!com.google.errorprone.annotations,*',
+        export_packages = '*',
+        do_javadocs = False,
+        do_checkstyle = False,
+    )
+
+grpc_core_repkg_130()
\ No newline at end of file