Adding means to build java source jars.

Change-Id: Idceb84b503dad9fe12c73e153328226b9cfeb2cf
diff --git a/tools/build/bazel/java_sources.bzl b/tools/build/bazel/java_sources.bzl
new file mode 100644
index 0000000..3a47569
--- /dev/null
+++ b/tools/build/bazel/java_sources.bzl
@@ -0,0 +1,42 @@
+# Copyright 2015 The Bazel Authors. All rights reserved.
+#
+# 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.
+
+def _impl(ctx):
+  jar = ctx.outputs.jar
+
+  src_list = ""
+  for src in ctx.files.srcs:
+    if src.path.endswith(".srcjar"):
+      src_list += " " + src.path
+
+  cmd = [
+      "for sj in %s; do jar xf $sj; done" % src_list,
+      "dir=$(find . -type d -name java)",
+      "[ -n \"$dir\" -a -d \"$dir\" ] && jar cf %s -C $dir ." % jar.path,
+  ]
+
+  ctx.action(
+      inputs = ctx.files.srcs,
+      outputs = [jar],
+      progress_message = "Generating source jar for %s" %  ctx.attr.name,
+      command = ";\n".join(cmd)
+  )
+
+java_sources = rule(
+    attrs = {
+        "srcs": attr.label_list(allow_files = True),
+    },
+    implementation = _impl,
+    outputs = {"jar" : "%{name}.jar"},
+)
\ No newline at end of file
diff --git a/tools/build/bazel/javadoc.bzl b/tools/build/bazel/javadoc.bzl
index 3c01502..09d3d0f 100644
--- a/tools/build/bazel/javadoc.bzl
+++ b/tools/build/bazel/javadoc.bzl
@@ -34,6 +34,7 @@
   ctx.action(
       inputs = ctx.files.srcs + ctx.files.deps,
       outputs = [jar],
+      progress_message = "Generating javadocs jar for %s" %  ctx.attr.name,
       command = ";\n".join(cmd)
   )
 
diff --git a/tools/build/bazel/osgi_java_library.bzl b/tools/build/bazel/osgi_java_library.bzl
index c135991..5ba5e91 100644
--- a/tools/build/bazel/osgi_java_library.bzl
+++ b/tools/build/bazel/osgi_java_library.bzl
@@ -18,6 +18,7 @@
 load("//tools/build/bazel:variables.bzl", "ONOS_VERSION")
 load("//tools/build/bazel:generate_test_rules.bzl", "generate_test_rules")
 load("//tools/build/bazel:checkstyle.bzl", "checkstyle_test")
+load("//tools/build/bazel:java_sources.bzl", "java_sources")
 load("//tools/build/bazel:javadoc.bzl", "javadoc")
 
 def _all_java_sources():
@@ -463,6 +464,10 @@
         include_resources = _include_resources_to_string(include_resources),
     )
 
+    # rule for building source jars
+    if not suppress_javadocs:
+      java_sources(name = name + "-sources", srcs = srcs, visibility = visibility)
+
     # rule for building javadocs
     if not suppress_javadocs:
       javadoc(name = name + "-javadocs", deps = deps, srcs = srcs, visibility = visibility)