Adding a bucklet to compile XSD in to Java

Change-Id: I760ad7a5c926ee65d7b922bd337f9e3abb1339a7
diff --git a/bucklets/jaxb2.bucklet b/bucklets/jaxb2.bucklet
new file mode 100644
index 0000000..f3bb9fb
--- /dev/null
+++ b/bucklets/jaxb2.bucklet
@@ -0,0 +1,64 @@
+#
+# Copyright 2017-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.
+#
+# Bucklet to create Java Code from XSD using the 'xjc' tool from the JAXB API v2.
+# The genrule() creates the Java code, zips it and puts it in the output of jaxb2-xjc
+# The osgi_jar_with_tests() takes the sources in this ZIP and adds them to what ever
+# sources were used in the call to this method, and compiles all of them and adds
+# them to a JAR file in the output folder
+
+include_defs('//onos.defs')
+include_defs('//bucklets/onos.bucklet')
+
+def _get_name():
+    base_path = get_base_path()
+    return ONOS_ARTIFACT_BASE + base_path.replace('/', '-') #TODO Unix-separator
+
+def jaxb2_xjc_osgi_jar(
+    name,
+    srcs,
+    xsd,
+    bindinfo=None,
+    destdir='.',
+    deps=[],
+    test_deps=[],
+    visibility = [],
+    **kwargs
+    ):
+    if name is None:
+          name = _get_name()
+
+    cmd = 'xjc '+xsd
+    if bindinfo is not None:
+        cmd=cmd+' -b '+bindinfo
+        cmd=cmd+' -d '+destdir
+
+    genrule(
+        name = 'jaxb2-xjc',
+        srcs = glob(['src/main/resources/*.xsd','src/main/resources/*.xjb']),
+        bash = cmd + ' && zip $OUT -r *',
+        out = name+'.src.zip',
+        visibility = [ ],
+    )
+
+    osgi_jar_with_tests (
+        deps = [":jaxb2-xjc"] + deps,
+        srcs = [':jaxb2-xjc'] + srcs,
+        test_deps = test_deps,
+        do_javadocs = False,
+        do_checkstyle = False,
+        **kwargs
+    )
+