summaryrefslogtreecommitdiffstats
path: root/extras/japi/java/jvpp/gen/jvpp_gen.py
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2018-07-30 16:10:14 +0200
committerDave Barach <openvpp@barachs.net>2018-08-01 20:28:53 +0000
commitcc4a5e8089967f0c266e9c5ed319c38c111004cd (patch)
treebc290e03e12a0a02c3fc274740c96eef9e1707c6 /extras/japi/java/jvpp/gen/jvpp_gen.py
parenta14c16674023bd6672ca49e3551c707702711050 (diff)
Move java api to extras/
Change-Id: Ibd5cbbdfb22a235442cddaebc9eae9a3c4e35ec9 Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'extras/japi/java/jvpp/gen/jvpp_gen.py')
-rwxr-xr-xextras/japi/java/jvpp/gen/jvpp_gen.py93
1 files changed, 93 insertions, 0 deletions
diff --git a/extras/japi/java/jvpp/gen/jvpp_gen.py b/extras/japi/java/jvpp/gen/jvpp_gen.py
new file mode 100755
index 00000000000..067a92f86be
--- /dev/null
+++ b/extras/japi/java/jvpp/gen/jvpp_gen.py
@@ -0,0 +1,93 @@
+#!/usr/bin/env python2
+#
+# Copyright (c) 2016,2018 Cisco and/or its affiliates.
+# 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.
+#
+import argparse
+import logging
+import os
+import sys
+
+from jvppgen.types_gen import generate_types
+from jvppgen.enums_gen import generate_enums
+from jvppgen.unions_gen import generate_unions
+from jvppgen.dto_gen import generate_dtos
+from jvppgen.jvpp_ifc_gen import generate_java_ifc
+from jvppgen.jvpp_impl_gen import generate_java_impl
+from jvppgen.callback_gen import generate_callbacks
+from jvppgen.jni_gen import generate_jni
+from jvppgen.notification_gen import generate_notifications
+from jvppgen.jvpp_future_facade_gen import generate_future_facade
+from jvppgen.jvpp_callback_facade_gen import generate_callback_facade
+from jvppgen.jvpp_model import JVppModel
+
+
+def generate_jvpp(root_dir, model, logger):
+ base_dir = "%s/target/%s" % (root_dir, model.plugin_package.replace(".", "/"))
+ generate_types(_work_dir(base_dir, "types"), model, logger)
+ generate_enums(_work_dir(base_dir, "types"), model, logger)
+ generate_unions(_work_dir(base_dir, "types"), model, logger)
+ generate_dtos(_work_dir(base_dir, "dto"), model, logger)
+ generate_java_ifc(_work_dir(base_dir), model, logger)
+ generate_java_impl(_work_dir(base_dir), model, logger)
+ generate_callbacks(_work_dir(base_dir, "callback"), model, logger)
+ generate_jni(root_dir, model, logger)
+ generate_notifications(_work_dir(base_dir, "notification"), model, logger)
+ generate_future_facade(_work_dir(base_dir, "future"), model, logger)
+ generate_callback_facade(_work_dir(base_dir, "callfacade"), model, logger)
+
+
+def _work_dir(work_dir, sub_dir=None):
+ if sub_dir:
+ work_dir = "%s/%s" % (work_dir, sub_dir)
+ try:
+ os.makedirs(work_dir)
+ except OSError:
+ if not os.path.isdir(work_dir):
+ raise
+ return work_dir
+
+
+def _init_logger():
+ try:
+ verbose = int(os.getenv("V", 0))
+ except:
+ verbose = 0
+
+ log_level = logging.WARNING
+ if verbose == 1:
+ log_level = logging.INFO
+ elif verbose >= 2:
+ log_level = logging.DEBUG
+
+ logging.basicConfig(stream=sys.stdout, level=log_level)
+ logger = logging.getLogger("JVPP GEN")
+ logger.setLevel(log_level)
+ return logger
+
+
+if __name__ == '__main__':
+ logger = _init_logger()
+
+ argparser = argparse.ArgumentParser(description="VPP Java API generator")
+ argparser.add_argument('-i', nargs='+', metavar='api_file.json', help="json vpp api file(s)")
+ argparser.add_argument('--plugin_name')
+ argparser.add_argument('--root_dir')
+ args = argparser.parse_args()
+
+ logger.info("Generating Java API for %s" % args.i)
+ logger.debug("plugin_name: %s" % args.plugin_name)
+ logger.debug("root_dir: %s" % args.root_dir)
+
+ model = JVppModel(logger, args.i, args.plugin_name)
+ generate_jvpp(args.root_dir, model, logger)