Adding support for custom model registrator and supporting Java code
to be built and packaged along with the auto-generated artifacts that
represent the YANG model.
Change-Id: I62c121f22680d483df40662da6a73c1bae43826b
diff --git a/apps/yang/src/main/java/org/onosproject/yang/AbstractYangModelRegistrator.java b/apps/yang/src/main/java/org/onosproject/yang/AbstractYangModelRegistrator.java
index 47b46bd..6e3a691 100644
--- a/apps/yang/src/main/java/org/onosproject/yang/AbstractYangModelRegistrator.java
+++ b/apps/yang/src/main/java/org/onosproject/yang/AbstractYangModelRegistrator.java
@@ -41,7 +41,7 @@
@Component
public abstract class AbstractYangModelRegistrator {
- private final Logger log = LoggerFactory.getLogger(getClass());
+ protected final Logger log = LoggerFactory.getLogger(getClass());
private final Class<?> loaderClass;
private Map<YangModuleId, AppModuleInfo> appInfo;
diff --git a/bucklets/yang.bucklet b/bucklets/yang.bucklet
index 5fbf2ab..86a613b 100644
--- a/bucklets/yang.bucklet
+++ b/bucklets/yang.bucklet
@@ -22,6 +22,8 @@
url = 'http://onosproject.org',
description = None,
deps = [],
+ required_apps = [],
+ custom_registrator = False,
**kwargs
):
@@ -49,22 +51,32 @@
out = 'yang'
)
- genrule(
- name = registrator,
- srcs = [ ':' + yangSrcs ],
- cmd = '$(location //buck-tools:yang-registrator) $OUT ' + app_name + ' $SRCS',
- out = 'YangModelRegistrator.java'
- )
-
- osgi_jar(
- name = name,
- srcs = [ ':' + yangSrcs, ':' + registrator ],
- deps = deps + YANG_TOOLS,
- resources = [ ':' + schema ],
- resources_root = ".",
- do_checkstyle = False,
- do_javadocs = False,
- )
+ if custom_registrator:
+ osgi_jar(
+ name = name,
+ srcs = [ ':' + yangSrcs ] + glob(['src/main/java/**/*.java']),
+ deps = deps + YANG_TOOLS,
+ resources = [ ':' + schema ],
+ resources_root = ".",
+ do_checkstyle = False,
+ do_javadocs = False,
+ )
+ else:
+ genrule(
+ name = registrator,
+ srcs = [ ':' + yangSrcs ],
+ cmd = '$(location //buck-tools:yang-registrator) $OUT ' + app_name + ' $SRCS',
+ out = 'YangModelRegistrator.java'
+ )
+ osgi_jar(
+ name = name,
+ srcs = [ ':' + yangSrcs, ':' + registrator ],
+ deps = deps + YANG_TOOLS,
+ resources = [ ':' + schema ],
+ resources_root = ".",
+ do_checkstyle = False,
+ do_javadocs = False,
+ )
onos_app (
app_name = app_name,
diff --git a/models/common/BUCK b/models/common/BUCK
new file mode 100644
index 0000000..a210b1e
--- /dev/null
+++ b/models/common/BUCK
@@ -0,0 +1,7 @@
+
+yang_model (
+ app_name = 'org.onosproject.models.common',
+ title = 'Common YANG Models',
+ custom_registrator = True,
+ deps = [ '//lib:CORE_DEPS' ]
+)
diff --git a/models/common/src/main/java/org/onosproject/models/common/YangModelRegistrator.java b/models/common/src/main/java/org/onosproject/models/common/YangModelRegistrator.java
new file mode 100644
index 0000000..d8f0964
--- /dev/null
+++ b/models/common/src/main/java/org/onosproject/models/common/YangModelRegistrator.java
@@ -0,0 +1,29 @@
+/*
+ * 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.
+ */
+package org.onosproject.models.common;
+
+import org.onosproject.yang.AbstractYangModelRegistrator;
+import org.apache.felix.scr.annotations.Component;
+
+@Component(immediate = true)
+public class YangModelRegistrator extends AbstractYangModelRegistrator {
+ public YangModelRegistrator() {
+ super(YangModelRegistrator.class);
+
+ // TODO: Do some other registration tasks...
+ log.info("Custom model registrator created");
+ }
+}
\ No newline at end of file