summaryrefslogtreecommitdiffstats
path: root/yang-compiler
diff options
context:
space:
mode:
Diffstat (limited to 'yang-compiler')
-rw-r--r--yang-compiler/README.md8
-rw-r--r--yang-compiler/build.json40
-rw-r--r--yang-compiler/src/main/java/org/onap/modeling/yangkit/compiler/PluginInfo.java37
-rw-r--r--yang-compiler/src/main/java/org/onap/modeling/yangkit/compiler/PluginParameterInfo.java12
-rw-r--r--yang-compiler/src/main/java/org/onap/modeling/yangkit/compiler/YangCompiler.java13
-rw-r--r--yang-compiler/src/main/java/org/onap/modeling/yangkit/compiler/app/YangCompilerRunner.java2
-rw-r--r--yang-compiler/src/main/java/org/onap/modeling/yangkit/compiler/plugin/yangtree/YangTreeGenerator.java2
-rw-r--r--yang-compiler/src/main/resources/plugins.json8
8 files changed, 87 insertions, 35 deletions
diff --git a/yang-compiler/README.md b/yang-compiler/README.md
index 264d2f1..e151cfc 100644
--- a/yang-compiler/README.md
+++ b/yang-compiler/README.md
@@ -142,7 +142,7 @@ The plugin system of Yang compiler support built-in plugin and external plugin.
"name": "validator_plugin",
- "class": "org.yangcentral.yangkit.compiler.plugin.validator.YangValidator",
+ "class": "org.onap.modelling.yangkit.compiler.plugin.validator.YangValidator",
"description": "a plugin for validating yang files",
@@ -179,12 +179,12 @@ The plugin system of Yang compiler support built-in plugin and external plugin.
{
"name": "yang_comparator",
"class-path": "yang-comparator/yang-comparator-1.0-SNAPSHOT.jar",
- "class": "com.huawei.yang.comparator.YangComparatorPlugin",
+ "class": "org.onap.modelling.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",
@@ -307,7 +307,7 @@ The plugin system of Yang compiler support built-in plugin and external plugin.
```
###  Commandline
```
-# java -jar yang-compiler-1.0-SNAPSHOT.jar [option=<_build.json_>] [install]
+# java -jar yang-compiler-1.0.0-SNAPSHOT.jar [option=<_build.json_>] [install]
```
#### &emsp;&emsp;Parameters
1. option: optional, specify the build option. It's the path of build.json, if not present, the build.json in current directory will be used.
diff --git a/yang-compiler/build.json b/yang-compiler/build.json
index 43d258e..2625c76 100644
--- a/yang-compiler/build.json
+++ b/yang-compiler/build.json
@@ -1,22 +1,7 @@
{
"yang": {
- "module": [
- {
- "name": "ietf-interfaces",
- "revision": ""
- },
- {
- "name": "huawei-ifm",
- "revision": "2022-08-06"
- },
- {
- "name": "huawei-bgp",
- "revision": ""
- },
- {
- "name": "huawei-network-instance",
- "revision": ""
- }
+ "dir" : [
+ "C:\\Users\\Administrator\\IdeaProjects\\huawei-yang\\network-router\\8.21.0\\atn-980b"
]
},
"plugin": [
@@ -34,6 +19,27 @@
]
},
{
+ "name": "yang_comparator",
+ "parameter": [
+ {
+ "name": "old-yang",
+ "value": {
+ "dir" : [
+ "C:\\Users\\Administrator\\IdeaProjects\\huawei-yang\\network-router\\8.20.0\\atn980b"
+ ]
+ }
+ },
+ {
+ "name": "compare-type",
+ "value": "stmt"
+ },
+ {
+ "name" : "result",
+ "value" : "out/diff_stmt.xml"
+ }
+ ]
+ },
+ {
"name": "yang_statistics",
"parameter" : [
{
diff --git a/yang-compiler/src/main/java/org/onap/modeling/yangkit/compiler/PluginInfo.java b/yang-compiler/src/main/java/org/onap/modeling/yangkit/compiler/PluginInfo.java
index 63b82ef..628f72b 100644
--- a/yang-compiler/src/main/java/org/onap/modeling/yangkit/compiler/PluginInfo.java
+++ b/yang-compiler/src/main/java/org/onap/modeling/yangkit/compiler/PluginInfo.java
@@ -38,6 +38,8 @@ import org.onap.modeling.yangkit.compiler.plugin.YangCompilerPlugin;
@SuppressWarnings("ALL")
public class PluginInfo {
private final String pluginName;
+
+ private URLClassLoader classLoader;
private final YangCompilerPlugin plugin;
private String description;
@@ -63,6 +65,14 @@ public class PluginInfo {
return pluginName;
}
+ public URLClassLoader getClassLoader() {
+ return classLoader;
+ }
+
+ public void setClassLoader(URLClassLoader classLoader) {
+ this.classLoader = classLoader;
+ }
+
/**
* get the plugin.
*
@@ -118,6 +128,7 @@ public class PluginInfo {
public static PluginInfo parse(File pluginFile, JsonElement jsonElement) {
JsonObject jsonObject = jsonElement.getAsJsonObject();
String pluginName = jsonObject.get("name").getAsString();
+ URLClassLoader classLoader = null;
String classPath = null;
JsonElement classPathElement = jsonObject.get("class-path");
if (classPathElement != null) {
@@ -139,11 +150,10 @@ public class PluginInfo {
return null;
}
URL[] cp = {file.toURI().toURL()};
- try (URLClassLoader classLoader = new URLClassLoader(cp)) {
- pluginClass = (Class<? extends YangCompilerPlugin>) classLoader.loadClass(className);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
+ classLoader = new URLClassLoader(cp);
+
+ pluginClass = (Class<? extends YangCompilerPlugin>) classLoader.loadClass(className);
+
} else {
pluginClass = (Class<? extends YangCompilerPlugin>) Class.forName(className);
}
@@ -151,6 +161,7 @@ public class PluginInfo {
Constructor<? extends YangCompilerPlugin> constructor = pluginClass.getConstructor();
YangCompilerPlugin yangCompilerPlugin = constructor.newInstance();
PluginInfo pluginInfo = new PluginInfo(pluginName, yangCompilerPlugin);
+ pluginInfo.setClassLoader(classLoader);
if (jsonObject.get("description") != null) {
String description = jsonObject.get("description").getAsString();
pluginInfo.setDescription(description);
@@ -185,4 +196,20 @@ public class PluginInfo {
throw new RuntimeException(e);
}
}
+
+ @Override
+ public String toString() {
+ return "PluginInfo{"
+ + "pluginName='"
+ + pluginName
+ + '\''
+ + ", plugin="
+ + plugin
+ + ", description='"
+ + description
+ + '\''
+ + ", parameters="
+ + parameters
+ + '}';
+ }
}
diff --git a/yang-compiler/src/main/java/org/onap/modeling/yangkit/compiler/PluginParameterInfo.java b/yang-compiler/src/main/java/org/onap/modeling/yangkit/compiler/PluginParameterInfo.java
index 526b94a..aa34b9d 100644
--- a/yang-compiler/src/main/java/org/onap/modeling/yangkit/compiler/PluginParameterInfo.java
+++ b/yang-compiler/src/main/java/org/onap/modeling/yangkit/compiler/PluginParameterInfo.java
@@ -56,4 +56,16 @@ public class PluginParameterInfo {
public void setDescription(String description) {
this.description = description;
}
+
+ @Override
+ public String toString() {
+ return "PluginParameterInfo{"
+ + "name='"
+ + name
+ + '\''
+ + ", description='"
+ + description
+ + '\''
+ + '}';
+ }
}
diff --git a/yang-compiler/src/main/java/org/onap/modeling/yangkit/compiler/YangCompiler.java b/yang-compiler/src/main/java/org/onap/modeling/yangkit/compiler/YangCompiler.java
index ccbfcbc..d5823fb 100644
--- a/yang-compiler/src/main/java/org/onap/modeling/yangkit/compiler/YangCompiler.java
+++ b/yang-compiler/src/main/java/org/onap/modeling/yangkit/compiler/YangCompiler.java
@@ -17,7 +17,6 @@ limitations under the License.
package org.onap.modeling.yangkit.compiler;
-
import java.io.File;
import java.util.ArrayList;
import java.util.List;
@@ -121,12 +120,13 @@ public class YangCompiler {
/**
* build schema context from build option.
+ *
* @return yang schema context
*/
public YangSchemaContext buildSchemaContext() {
YangSchemaContext schemaContext = null;
try {
- schemaContext = YangCompilerUtil.buildSchemaContext(buildOption.getSources(),getSettings());
+ schemaContext = YangCompilerUtil.buildSchemaContext(buildOption.getSources(), getSettings());
return schemaContext;
} catch (YangCompilerException e) {
@@ -189,6 +189,12 @@ public class YangCompiler {
continue;
}
YangCompilerPlugin plugin = pluginInfo.getPlugin();
+ ClassLoader curClassLoader = Thread.currentThread().getContextClassLoader();
+ ClassLoader pluginClassLoader = curClassLoader;
+ if (pluginInfo.getClassLoader() != null) {
+ pluginClassLoader = pluginInfo.getClassLoader();
+ Thread.currentThread().setContextClassLoader(pluginClassLoader);
+ }
try {
List<YangCompilerPluginParameter> parameters = new ArrayList<>();
if (!pluginBuilder.getParameters().isEmpty()) {
@@ -206,6 +212,9 @@ public class YangCompiler {
} catch (YangCompilerException e) {
logger.error(e.getMessage());
}
+ if (pluginClassLoader != curClassLoader) {
+ Thread.currentThread().setContextClassLoader(curClassLoader);
+ }
}
ValidatorResultBuilder validatorResultBuilder = new ValidatorResultBuilder();
List<ValidatorRecord<?, ?>> records = validatorResult.getRecords();
diff --git a/yang-compiler/src/main/java/org/onap/modeling/yangkit/compiler/app/YangCompilerRunner.java b/yang-compiler/src/main/java/org/onap/modeling/yangkit/compiler/app/YangCompilerRunner.java
index 217ffad..11736bb 100644
--- a/yang-compiler/src/main/java/org/onap/modeling/yangkit/compiler/app/YangCompilerRunner.java
+++ b/yang-compiler/src/main/java/org/onap/modeling/yangkit/compiler/app/YangCompilerRunner.java
@@ -64,12 +64,10 @@ public class YangCompilerRunner {
.toURI());
File pluginsDir = new File(programDir.getParentFile(), "plugins");
if (!pluginsDir.exists()) {
- System.out.println("[WARNING]plugins dir:" + pluginsDir.getAbsolutePath() + " is not exists");
return;
}
File pluginsFile = new File(pluginsDir, "plugins.json");
if (pluginsFile.exists()) {
- System.out.println("[INFO]reading the information of plugins from:" + pluginsFile.getAbsolutePath());
List<PluginInfo> pluginInfos = parsePlugins(pluginsFile, FileUtil.readFile2String(pluginsFile));
for (PluginInfo pluginInfo : pluginInfos) {
yangCompiler.addPluginInfo(pluginInfo);
diff --git a/yang-compiler/src/main/java/org/onap/modeling/yangkit/compiler/plugin/yangtree/YangTreeGenerator.java b/yang-compiler/src/main/java/org/onap/modeling/yangkit/compiler/plugin/yangtree/YangTreeGenerator.java
index b5b5643..6561ab4 100644
--- a/yang-compiler/src/main/java/org/onap/modeling/yangkit/compiler/plugin/yangtree/YangTreeGenerator.java
+++ b/yang-compiler/src/main/java/org/onap/modeling/yangkit/compiler/plugin/yangtree/YangTreeGenerator.java
@@ -396,7 +396,7 @@ public class YangTreeGenerator implements YangCompilerPlugin {
SchemaNodeContainer parent = dataNode.getClosestAncestorNode();
if (parent instanceof YangList) {
YangList list = (YangList) parent;
- if (list.getKey().getKeyNode(dataNode.getIdentifier()) != null) {
+ if (list.getKey() != null && list.getKey().getKeyNode(dataNode.getIdentifier()) != null) {
return true;
}
}
diff --git a/yang-compiler/src/main/resources/plugins.json b/yang-compiler/src/main/resources/plugins.json
index afd32f0..a984d08 100644
--- a/yang-compiler/src/main/resources/plugins.json
+++ b/yang-compiler/src/main/resources/plugins.json
@@ -4,7 +4,7 @@
{
"name": "schema_validator",
"class-path": "",
- "class": "org.yangcentral.yangkit.compiler.plugin.validator.YangValidator",
+ "class": "org.onap.modeling.yangkit.compiler.plugin.validator.YangValidator",
"description": "a plugin for validating yang files",
"parameter": [
{
@@ -16,7 +16,7 @@
{
"name": "yang_statistics",
"class-path": "",
- "class": "org.yangcentral.yangkit.compiler.plugin.stat.YangStatistics",
+ "class": "org.onap.modeling.yangkit.compiler.plugin.stat.YangStatistics",
"description": "a plugin for retrieving yang statistics",
"parameter": [
{
@@ -27,7 +27,7 @@
},
{
"name": "yangtree_generator",
- "class": "org.yangcentral.yangkit.compiler.plugin.yangtree.YangTreeGenerator",
+ "class": "org.onap.modeling.yangkit.compiler.plugin.yangtree.YangTreeGenerator",
"description": "a plugin for generating yang tree",
"parameter": [
{
@@ -46,7 +46,7 @@
},
{
"name": "yangpackage_generator",
- "class": "org.yangcentral.yangkit.compiler.plugin.yangpackage.YangPackageGenerator",
+ "class": "org.onap.modeling.yangkit.compiler.plugin.yangpackage.YangPackageGenerator",
"description": "a plugin for generating yang package",
"parameter": [
{