summaryrefslogtreecommitdiffstats
path: root/yang-comparator/src/main
diff options
context:
space:
mode:
authorfrank feng <frank.fengchong@huawei.com>2023-09-15 11:10:27 +0800
committerfrank feng <frank.fengchong@huawei.com>2023-09-15 11:10:41 +0800
commitcc0fc052c1204a36dd997d4ce6d67a26ef80b361 (patch)
tree3270c52800c3d8bc3bbbe1207e0229827d533244 /yang-comparator/src/main
parentc591d5e079dee38969ddd6366481bb1b476aaa31 (diff)
modify yang-comparator and yang-compiler for external plugin call, and fix bug for yang-tree-generator plugin
Issue-ID: MODELING-680 Change-Id: I8ccbfdce79344c4734fe10931fa818601701f350 Signed-off-by: frank feng <frank.fengchong@huawei.com>
Diffstat (limited to 'yang-comparator/src/main')
-rw-r--r--yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/app/YangComparatorPlugin.java52
-rw-r--r--yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/app/YangComparatorPluginParameter.java61
-rw-r--r--yang-comparator/src/main/resources/plugins.json6
3 files changed, 78 insertions, 41 deletions
diff --git a/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/app/YangComparatorPlugin.java b/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/app/YangComparatorPlugin.java
index a46b97d..45b3941 100644
--- a/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/app/YangComparatorPlugin.java
+++ b/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/app/YangComparatorPlugin.java
@@ -18,6 +18,7 @@ package org.onap.modeling.yangkit.comparator.app;
import com.google.gson.JsonElement;
+import java.io.File;
import java.io.IOException;
import java.util.List;
@@ -47,44 +48,8 @@ import org.yangcentral.yangkit.utils.xml.XmlWriter;
*/
public class YangComparatorPlugin implements YangCompilerPlugin {
@Override
- public YangCompilerPluginParameter getParameter(String name, JsonElement value)
- throws YangCompilerException {
- if (!name.equals("old-yang") && !name.equals("settings")
- && !name.equals("compare-type") && !name.equals("rule")
- && !name.equals("result")) {
- throw new YangCompilerException("unrecognized parameter:" + name);
- }
- if (name.equals("old-yang") || name.equals("compare-type")) {
- YangCompilerPluginParameter yangCompilerPluginParameter = new YangCompilerPluginParameter() {
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public Object getValue() throws YangCompilerException {
- if (name.equals("old-yang")) {
- return BuildOption.parseSources(value);
- }
-
- if (name.equals("compare-type")) {
- if (value.equals("stmt")) {
- return CompareType.STMT;
- } else if (value.equals("tree")) {
- return CompareType.TREE;
- } else if (value.equals("compatible-check")) {
- return CompareType.COMPATIBLE_CHECK;
- }
- throw new YangCompilerException("unrecognized value:" + value);
- }
- return null;
- }
-
- };
- return yangCompilerPluginParameter;
- }
- return YangCompilerPlugin.super.getParameter(name, value);
-
+ public YangCompilerPluginParameter getParameter(String name, JsonElement value) {
+ return new YangComparatorPluginParameter(name,value);
}
@Override
@@ -124,6 +89,17 @@ public class YangComparatorPlugin implements YangCompilerPlugin {
if (resultPath == null) {
throw new YangCompilerException("missing mandatory parameter:result");
}
+ File outputFile = new File(resultPath);
+ if (!outputFile.exists()) {
+ if (outputFile.getParentFile() != null && !outputFile.getParentFile().exists()) {
+ outputFile.getParentFile().mkdirs();
+ }
+ try {
+ outputFile.createNewFile();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
YangSchemaContext oldSchemaContext = YangCompilerUtil.buildSchemaContext(sources, settings);
ValidatorResult oldResult = oldSchemaContext.validate();
if (!oldResult.isOk()) {
diff --git a/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/app/YangComparatorPluginParameter.java b/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/app/YangComparatorPluginParameter.java
new file mode 100644
index 0000000..7f78022
--- /dev/null
+++ b/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/app/YangComparatorPluginParameter.java
@@ -0,0 +1,61 @@
+/*
+Copyright 2023 Huawei Technologies
+
+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.onap.modeling.yangkit.comparator.app;
+
+import com.google.gson.JsonElement;
+import org.onap.modeling.yangkit.comparator.CompareType;
+import org.onap.modeling.yangkit.compiler.BuildOption;
+import org.onap.modeling.yangkit.compiler.YangCompilerException;
+import org.onap.modeling.yangkit.compiler.plugin.YangCompilerPluginParameter;
+
+public class YangComparatorPluginParameter implements YangCompilerPluginParameter {
+ private String name;
+ private JsonElement value;
+
+ public YangComparatorPluginParameter(String name, JsonElement value) {
+ this.name = name;
+ this.value = value;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public Object getValue() throws YangCompilerException {
+ if (!name.equals("old-yang") && !name.equals("settings")
+ && !name.equals("compare-type") && !name.equals("rule")
+ && !name.equals("result")) {
+ throw new YangCompilerException("unrecognized parameter:" + name);
+ }
+ if (name.equals("old-yang")) {
+ return BuildOption.parseSources(value);
+ } else if (name.equals("compare-type")) {
+ if (value.getAsString().equals("stmt")) {
+ return CompareType.STMT;
+ } else if (value.getAsString().equals("tree")) {
+ return CompareType.TREE;
+ } else if (value.getAsString().equals("compatible-check")) {
+ return CompareType.COMPATIBLE_CHECK;
+ }
+ throw new YangCompilerException("unrecognized value:" + value + " for parameter:" + name);
+ } else {
+ return value.getAsString();
+ }
+ }
+}
diff --git a/yang-comparator/src/main/resources/plugins.json b/yang-comparator/src/main/resources/plugins.json
index 4534d4d..39d196d 100644
--- a/yang-comparator/src/main/resources/plugins.json
+++ b/yang-comparator/src/main/resources/plugins.json
@@ -3,13 +3,13 @@
"plugin": [
{
"name": "yang_comparator",
- "class-path": "yang-comparator-1.0-SNAPSHOT.jar",
- "class": "com.huawei.yang.comparator.app.YangComparatorPlugin",
+ "class-path": "yang-comparator/yang-comparator-1.0.0-SNAPSHOT.jar",
+ "class": "org.onap.modeling.yangkit.comparator.app.YangComparatorPlugin",
"description": "a plugin for comparing two yang schema.",
"parameter": [
{
"name": "old-yang",
- "description": "mandatory,the old version yang directory."
+ "description": "mandatory,the old version yang sources."
},
{
"name": "settings",