From c591d5e079dee38969ddd6366481bb1b476aaa31 Mon Sep 17 00:00:00 2001 From: frank feng Date: Wed, 13 Sep 2023 11:40:58 +0800 Subject: modify yang-comparator, such as yang compiler plugin, and some java doc. modify some functions of yang-compiler. Issue-ID: MODELING-680 Change-Id: I37784c6a3511cfffafe0e19bd4ebdb4ba9d9b958 Signed-off-by: frank feng --- pom.xml | 1 + yang-comparator/pom.xml | 4 +- .../yangkit/comparator/AugmentComparator.java | 8 +- .../yangkit/comparator/BaseComparator.java | 6 +- .../modeling/yangkit/comparator/ChangeType.java | 8 +- .../comparator/CommonYangStatementComparator.java | 30 +++--- .../yangkit/comparator/CompatibilityRules.java | 7 +- .../yangkit/comparator/ConfigComparator.java | 10 +- .../yangkit/comparator/DefaultComparator.java | 6 +- .../yangkit/comparator/DescriptionComparator.java | 6 +- .../yangkit/comparator/EnumBitComparator.java | 6 +- .../yangkit/comparator/IdentifierComparator.java | 6 +- .../yangkit/comparator/IfFeatureComparator.java | 6 +- .../yangkit/comparator/MandatoryComparator.java | 10 +- .../yangkit/comparator/MaxElementsComparator.java | 10 +- .../yangkit/comparator/MinElementsComparator.java | 15 +-- .../yangkit/comparator/ModuleComparator.java | 22 +---- .../yangkit/comparator/NamespaceComparator.java | 8 +- .../yangkit/comparator/OperationComparator.java | 12 +-- .../yangkit/comparator/PatternComparator.java | 8 +- .../yangkit/comparator/RangeLengthComparator.java | 15 +-- .../yangkit/comparator/ReferenceComparator.java | 7 -- .../yangkit/comparator/SchemaNodeComparator.java | 28 +----- .../yangkit/comparator/StatusComparator.java | 14 +-- .../yangkit/comparator/UniqueComparator.java | 15 +-- .../yangkit/comparator/UnitsComparator.java | 8 +- .../comparator/ValuePositionComparator.java | 8 +- .../yangkit/comparator/WhenMustComparator.java | 8 +- .../comparator/app/YangComparatorPlugin.java | 90 +++++++++-------- .../modeling/yangkit/compiler/BuildOption.java | 109 ++++++++++++--------- .../modeling/yangkit/compiler/YangCompiler.java | 5 +- .../yangkit/compiler/util/YangCompilerUtil.java | 21 ++++ 32 files changed, 203 insertions(+), 314 deletions(-) diff --git a/pom.xml b/pom.xml index 6f2aae0..0ecc534 100644 --- a/pom.xml +++ b/pom.xml @@ -13,6 +13,7 @@ 1.0.0-SNAPSHOT yang-compiler + yang-comparator pom yangkit diff --git a/yang-comparator/pom.xml b/yang-comparator/pom.xml index 094b6ea..cac954e 100644 --- a/yang-comparator/pom.xml +++ b/yang-comparator/pom.xml @@ -63,9 +63,9 @@ 1.3.5 - io.github.yang-central.yangkit + org.onap.modeling.yangkit yang-compiler - 1.3.1 + 1.0.0-SNAPSHOT org.dom4j diff --git a/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/AugmentComparator.java b/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/AugmentComparator.java index 44fd21b..1870586 100644 --- a/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/AugmentComparator.java +++ b/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/AugmentComparator.java @@ -24,10 +24,10 @@ import org.yangcentral.yangkit.model.api.stmt.Augment; public class AugmentComparator extends SchemaNodeComparator { /** - * - * @param left left statement - * @param right right statement - * @return + * compare the left and right statement. + * @param left left statement + * @param right right statement + * @return list of compare result */ @Override public List compare(Augment left, Augment right) { diff --git a/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/BaseComparator.java b/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/BaseComparator.java index d362fdd..bbb6fd7 100644 --- a/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/BaseComparator.java +++ b/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/BaseComparator.java @@ -24,11 +24,11 @@ import org.yangcentral.yangkit.model.api.stmt.Type; public class BaseComparator extends CommonYangStatementComparator { /** - * + * get the default compatibility from left and right base statements. * @param left left statement * @param right right statement - * @param changeInfo - * @return + * @param changeInfo the change information + * @return default compatibility information */ @Override protected CompatibilityInfo defaultCompatibility(Base left, Base right, diff --git a/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/ChangeType.java b/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/ChangeType.java index 6f7f818..cc04039 100644 --- a/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/ChangeType.java +++ b/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/ChangeType.java @@ -25,16 +25,16 @@ public enum ChangeType { private String description; /** - * - * @param description + * the constructor (private). + * @param description description */ private ChangeType(String description) { this.description = description; } /** - * - * @return + * get the name. + * @return the name */ public String getName() { return this.description; diff --git a/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/CommonYangStatementComparator.java b/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/CommonYangStatementComparator.java index 8be269e..77be97b 100644 --- a/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/CommonYangStatementComparator.java +++ b/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/CommonYangStatementComparator.java @@ -36,10 +36,10 @@ public class CommonYangStatementComparator extends Abst public static final int OPTION_ALL = 3; /** - * + * get then change information between left and right statements. * @param left left statement * @param right right statement - * @return + * @return the change information */ @Override protected List getChangeInfo(T left, T right) { @@ -65,11 +65,7 @@ public class CommonYangStatementComparator extends Abst return changeInfos; } - /** - * - * @param stmt - * @return - */ + private int getIndex(T stmt) { YangStatement parentStmt = stmt.getParentStatement(); if (null == parentStmt) { @@ -89,9 +85,9 @@ public class CommonYangStatementComparator extends Abst } /** - * - * @param changeInfo - * @return + * get the change type from change information. + * @param changeInfo change information + * @return change type */ protected ChangeType getChangeType(CompatibilityRule.ChangeInfo changeInfo) { switch (changeInfo) { @@ -110,11 +106,11 @@ public class CommonYangStatementComparator extends Abst /** - * + * get the default compatibility. * @param left left statement * @param right right statement - * @param changeInfo - * @return + * @param changeInfo change information + * @return default compatibility */ @Override protected CompatibilityInfo defaultCompatibility(T left, T right, CompatibilityRule.ChangeInfo changeInfo) { @@ -147,10 +143,10 @@ public class CommonYangStatementComparator extends Abst } /** - * + * compare the children of left and right statements. * @param left left statement * @param right right statement - * @return + * @return list of compare result */ protected List compareChildren(T left, T right) { List compareResults = @@ -160,10 +156,10 @@ public class CommonYangStatementComparator extends Abst } /** - * + * compare the left and right statements. * @param left left statement * @param right right statement - * @return + * @return list compare result */ @Override public List compare(T left, T right) { diff --git a/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/CompatibilityRules.java b/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/CompatibilityRules.java index cbab987..c7b3d6f 100644 --- a/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/CompatibilityRules.java +++ b/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/CompatibilityRules.java @@ -91,12 +91,7 @@ public class CompatibilityRules { } } - /** - * - * @param left left statement - * @param right right statement - * @return - */ + private boolean matchCondition(CompatibilityRule left, CompatibilityRule.ChangeInfo right) { if (left.getCondition() == CompatibilityRule.ChangeInfo.ANY) { return true; diff --git a/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/ConfigComparator.java b/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/ConfigComparator.java index a0018d7..496978e 100644 --- a/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/ConfigComparator.java +++ b/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/ConfigComparator.java @@ -26,10 +26,10 @@ import org.yangcentral.yangkit.model.api.stmt.SchemaNode; public class ConfigComparator extends CommonYangStatementComparator { /** - * + * get the change information. * @param left left statement * @param right right statement - * @return + * @return list of change information */ @Override protected List getChangeInfo(Config left, Config right) { @@ -60,11 +60,11 @@ public class ConfigComparator extends CommonYangStatementComparator { } /** - * + * get the default compatibility. * @param left left statement * @param right right statement - * @param changeInfo - * @return + * @param changeInfo change information + * @return default compatibility */ @Override protected CompatibilityInfo defaultCompatibility(Config left, Config right, diff --git a/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/DefaultComparator.java b/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/DefaultComparator.java index f7b1c13..f47ac5c 100644 --- a/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/DefaultComparator.java +++ b/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/DefaultComparator.java @@ -22,11 +22,11 @@ import org.yangcentral.yangkit.model.api.stmt.Default; public class DefaultComparator extends CommonYangStatementComparator { /** - * + * get default compatibility. * @param left left statement * @param right right statement - * @param changeInfo - * @return + * @param changeInfo change information. + * @return default compatibility */ @Override protected CompatibilityInfo defaultCompatibility(Default left, Default right, diff --git a/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/DescriptionComparator.java b/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/DescriptionComparator.java index 2b5db1c..ea7b7a3 100644 --- a/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/DescriptionComparator.java +++ b/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/DescriptionComparator.java @@ -22,11 +22,11 @@ import org.yangcentral.yangkit.model.api.stmt.Description; public class DescriptionComparator extends CommonYangStatementComparator { /** - * + * get default compatibility. * @param left left statement * @param right right statement - * @param changeInfo - * @return + * @param changeInfo change information. + * @return default compatibility */ @Override protected CompatibilityInfo defaultCompatibility(Description left, Description right, diff --git a/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/EnumBitComparator.java b/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/EnumBitComparator.java index e0fb3ef..30792b4 100644 --- a/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/EnumBitComparator.java +++ b/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/EnumBitComparator.java @@ -22,11 +22,11 @@ import org.yangcentral.yangkit.model.api.stmt.YangStatement; public class EnumBitComparator extends CommonYangStatementComparator { /** - * + * get default compatibility. * @param left left statement * @param right right statement - * @param changeInfo - * @return + * @param changeInfo change information. + * @return default compatibility */ @Override protected CompatibilityInfo defaultCompatibility(YangStatement left, YangStatement right, diff --git a/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/IdentifierComparator.java b/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/IdentifierComparator.java index 3eff979..6a6aa4e 100644 --- a/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/IdentifierComparator.java +++ b/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/IdentifierComparator.java @@ -22,11 +22,11 @@ import org.yangcentral.yangkit.model.api.stmt.YangStatement; public class IdentifierComparator extends CommonYangStatementComparator { /** - * + * get default compatibility. * @param left left statement * @param right right statement - * @param changeInfo - * @return + * @param changeInfo change information. + * @return default compatibility */ @Override protected CompatibilityInfo defaultCompatibility(YangStatement left, YangStatement right, diff --git a/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/IfFeatureComparator.java b/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/IfFeatureComparator.java index dfa0199..b4e770f 100644 --- a/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/IfFeatureComparator.java +++ b/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/IfFeatureComparator.java @@ -21,11 +21,11 @@ import org.yangcentral.yangkit.model.api.stmt.IfFeature; public class IfFeatureComparator extends CommonYangStatementComparator { /** - * + * get default compatibility. * @param left left statement * @param right right statement - * @param changeInfo - * @return + * @param changeInfo change information. + * @return default compatibility */ @Override protected CompatibilityInfo defaultCompatibility(IfFeature left, IfFeature right, diff --git a/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/MandatoryComparator.java b/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/MandatoryComparator.java index 375d69b..6e5cb43 100644 --- a/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/MandatoryComparator.java +++ b/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/MandatoryComparator.java @@ -24,10 +24,10 @@ import org.yangcentral.yangkit.model.api.stmt.Mandatory; public class MandatoryComparator extends CommonYangStatementComparator { /** - * + * get the change information. * @param left left statement * @param right right statement - * @return + * @return list of change information */ @Override protected List getChangeInfo(Mandatory left, Mandatory right) { @@ -45,11 +45,11 @@ public class MandatoryComparator extends CommonYangStatementComparator { /** - * + * get the change information. * @param left left statement * @param right right statement - * @return + * @return list of change information */ @Override protected List getChangeInfo(MaxElements left, MaxElements right) { @@ -51,11 +51,11 @@ public class MaxElementsComparator extends CommonYangStatementComparator { - /** - * - * @param left left statement - * @param right right statement - * @return - */ + @Override protected List getChangeInfo(MinElements left, MinElements right) { List changeInfos = new ArrayList<>(); @@ -44,13 +39,7 @@ public class MinElementsComparator extends CommonYangStatementComparator { - /** - * - * @param left left statement - * @param right right statement - * @return - */ + @Override protected List getChangeInfo(Module left, Module right) { return super.getChangeInfo(left, right); } - /** - * - * @param left left statement - * @param right right statement - * @param changeInfo - * @return - */ + @Override protected CompatibilityInfo defaultCompatibility(Module left, Module right, CompatibilityRule.ChangeInfo changeInfo) { @@ -54,12 +43,7 @@ public class ModuleComparator extends CommonYangStatementComparator { return super.defaultCompatibility(left, right, changeInfo); } - /** - * - * @param left left statement - * @param right right statement - * @return - */ + @Override protected List compareChildren(Module left, Module right) { List results = new ArrayList<>(); diff --git a/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/NamespaceComparator.java b/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/NamespaceComparator.java index 8ea9953..565cf6d 100644 --- a/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/NamespaceComparator.java +++ b/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/NamespaceComparator.java @@ -21,13 +21,7 @@ import org.yangcentral.yangkit.model.api.stmt.Namespace; public class NamespaceComparator extends CommonYangStatementComparator { - /** - * - * @param left left statement - * @param right right statement - * @param changeInfo - * @return - */ + @Override protected CompatibilityInfo defaultCompatibility(Namespace left, Namespace right, CompatibilityRule.ChangeInfo changeInfo) { diff --git a/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/OperationComparator.java b/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/OperationComparator.java index 58cde02..6ae9aee 100644 --- a/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/OperationComparator.java +++ b/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/OperationComparator.java @@ -28,11 +28,6 @@ import org.yangcentral.yangkit.model.api.stmt.YangStatement; public class OperationComparator extends SchemaNodeComparator { - /** - * - * @param schemaNodeContainer - * @return - */ private boolean hasActiveSchemaChildren(SchemaNodeContainer schemaNodeContainer) { for (SchemaNode schemaNode : schemaNodeContainer.getSchemaNodeChildren()) { if (schemaNode.isActive()) { @@ -42,12 +37,7 @@ public class OperationComparator extends SchemaNodeComparator { return false; } - /** - * - * @param left left statement - * @param right right statement - * @return - */ + @Override protected List compareChildren(Operation left, Operation right) { List compareResults = new ArrayList<>(); diff --git a/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/PatternComparator.java b/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/PatternComparator.java index 83f3f9b..f373a09 100644 --- a/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/PatternComparator.java +++ b/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/PatternComparator.java @@ -21,13 +21,7 @@ import org.yangcentral.yangkit.model.api.stmt.type.Pattern; public class PatternComparator extends CommonYangStatementComparator { - /** - * - * @param left left statement - * @param right right statement - * @param changeInfo - * @return - */ + @Override protected CompatibilityInfo defaultCompatibility(Pattern left, Pattern right, CompatibilityRule.ChangeInfo changeInfo) { diff --git a/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/RangeLengthComparator.java b/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/RangeLengthComparator.java index 076b7bf..ea4ef6c 100644 --- a/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/RangeLengthComparator.java +++ b/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/RangeLengthComparator.java @@ -24,12 +24,7 @@ import org.yangcentral.yangkit.model.api.stmt.type.SectionExpression; public class RangeLengthComparator extends CommonYangStatementComparator { - /** - * - * @param left left statement - * @param right right statement - * @return - */ + @Override protected List getChangeInfo(SectionExpression left, SectionExpression right) { List changeInfos = new ArrayList<>(); @@ -48,13 +43,7 @@ public class RangeLengthComparator extends CommonYangStatementComparator
{ - /** - * - * @param left left statement - * @param right right statement - * @param changeInfo - * @return - */ @Override protected CompatibilityInfo defaultCompatibility(Reference left, Reference right, CompatibilityRule.ChangeInfo changeInfo) { diff --git a/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/SchemaNodeComparator.java b/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/SchemaNodeComparator.java index ff6de53..3439b7f 100644 --- a/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/SchemaNodeComparator.java +++ b/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/SchemaNodeComparator.java @@ -25,12 +25,7 @@ import org.yangcentral.yangkit.model.api.stmt.SchemaNodeContainer; public class SchemaNodeComparator extends CommonYangStatementComparator { - /** - * - * @param left left statement - * @param right right statement - * @return - */ + @Override protected List getChangeInfo(T left, T right) { List changeInfos = new ArrayList<>(); @@ -48,13 +43,6 @@ public class SchemaNodeComparator extends CommonYangStatem return changeInfos; } - /** - * - * @param left left statement - * @param right right statement - * @param changeInfo - * @return - */ @Override protected CompatibilityInfo defaultCompatibility(T left, T right, CompatibilityRule.ChangeInfo changeInfo) { @@ -66,12 +54,7 @@ public class SchemaNodeComparator extends CommonYangStatem } - /** - * - * @param left left statement - * @param right right statement - * @return - */ + @Override protected List compareChildren(T left, T right) { List results = new ArrayList<>(); @@ -92,12 +75,7 @@ public class SchemaNodeComparator extends CommonYangStatem return results; } - /** - * - * @param left left statement - * @param right right statement - * @return - */ + @Override public List compare(T left, T right) { List compareResults = new ArrayList<>(); diff --git a/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/StatusComparator.java b/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/StatusComparator.java index 8a6df4d..ff92321 100644 --- a/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/StatusComparator.java +++ b/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/StatusComparator.java @@ -26,12 +26,6 @@ import org.yangcentral.yangkit.model.api.stmt.StatusStmt; public class StatusComparator extends CommonYangStatementComparator { - /** - * - * @param left left statement - * @param right right statement - * @return - */ @Override protected List getChangeInfo(StatusStmt left, StatusStmt right) { List changeInfos = new ArrayList<>(); @@ -52,13 +46,7 @@ public class StatusComparator extends CommonYangStatementComparator } - /** - * - * @param left left statement - * @param right right statement - * @param changeInfo - * @return - */ + @Override protected CompatibilityInfo defaultCompatibility(StatusStmt left, StatusStmt right, CompatibilityRule.ChangeInfo changeInfo) { diff --git a/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/UniqueComparator.java b/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/UniqueComparator.java index 1611818..be53a75 100644 --- a/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/UniqueComparator.java +++ b/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/UniqueComparator.java @@ -25,12 +25,7 @@ import org.yangcentral.yangkit.model.api.stmt.YangStatement; public class UniqueComparator extends CommonYangStatementComparator { - /** - * - * @param left left statement - * @param right right statement - * @return - */ + @Override protected List getChangeInfo(Unique left, Unique right) { List changeInfos = new ArrayList<>(); @@ -85,13 +80,7 @@ public class UniqueComparator extends CommonYangStatementComparator { return changeInfos; } - /** - * - * @param left left statement - * @param right right statement - * @param changeInfo - * @return - */ + @Override protected CompatibilityInfo defaultCompatibility(Unique left, Unique right, CompatibilityRule.ChangeInfo changeInfo) { diff --git a/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/UnitsComparator.java b/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/UnitsComparator.java index f484af2..a7f7045 100644 --- a/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/UnitsComparator.java +++ b/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/UnitsComparator.java @@ -21,13 +21,7 @@ import org.yangcentral.yangkit.model.api.stmt.Units; public class UnitsComparator extends CommonYangStatementComparator { - /** - * - * @param left left statement - * @param right right statement - * @param changeInfo - * @return - */ + @Override protected CompatibilityInfo defaultCompatibility(Units left, Units right, CompatibilityRule.ChangeInfo changeInfo) { diff --git a/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/ValuePositionComparator.java b/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/ValuePositionComparator.java index c680dea..f27f5db 100644 --- a/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/ValuePositionComparator.java +++ b/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/ValuePositionComparator.java @@ -20,13 +20,7 @@ import org.yangcentral.yangkit.model.api.stmt.YangStatement; public class ValuePositionComparator extends CommonYangStatementComparator { - /** - * - * @param left left statement - * @param right right statement - * @param changeInfo - * @return - */ + @Override protected CompatibilityInfo defaultCompatibility(YangStatement left, YangStatement right, CompatibilityRule.ChangeInfo changeInfo) { diff --git a/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/WhenMustComparator.java b/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/WhenMustComparator.java index 3825a74..a933ccc 100644 --- a/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/WhenMustComparator.java +++ b/yang-comparator/src/main/java/org/onap/modeling/yangkit/comparator/WhenMustComparator.java @@ -20,13 +20,7 @@ import org.yangcentral.yangkit.model.api.stmt.YangStatement; public class WhenMustComparator extends CommonYangStatementComparator { - /** - * - * @param left left statement - * @param right right statement - * @param changeInfo - * @return - */ + @Override protected CompatibilityInfo defaultCompatibility(YangStatement left, YangStatement right, CompatibilityRule.ChangeInfo changeInfo) { 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 8b513cc..a46b97d 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 @@ -16,26 +16,28 @@ limitations under the License. package org.onap.modeling.yangkit.comparator.app; -import java.io.File; +import com.google.gson.JsonElement; + import java.io.IOException; -import java.util.Iterator; import java.util.List; -import java.util.Map; -import java.util.Properties; import org.dom4j.Document; import org.dom4j.DocumentException; import org.onap.modeling.yangkit.comparator.CompareType; import org.onap.modeling.yangkit.comparator.YangComparator; import org.onap.modeling.yangkit.comparator.YangCompareResult; +import org.onap.modeling.yangkit.compiler.BuildOption; +import org.onap.modeling.yangkit.compiler.Settings; +import org.onap.modeling.yangkit.compiler.Source; +import org.onap.modeling.yangkit.compiler.YangCompiler; +import org.onap.modeling.yangkit.compiler.YangCompilerException; +import org.onap.modeling.yangkit.compiler.plugin.YangCompilerPlugin; +import org.onap.modeling.yangkit.compiler.plugin.YangCompilerPluginParameter; +import org.onap.modeling.yangkit.compiler.util.YangCompilerUtil; import org.yangcentral.yangkit.common.api.validate.ValidatorResult; -import org.yangcentral.yangkit.compiler.Settings; -import org.yangcentral.yangkit.compiler.YangCompiler; -import org.yangcentral.yangkit.compiler.YangCompilerException; + import org.yangcentral.yangkit.model.api.schema.YangSchemaContext; -import org.yangcentral.yangkit.plugin.YangCompilerPlugin; -import org.yangcentral.yangkit.plugin.YangCompilerPluginParameter; import org.yangcentral.yangkit.utils.file.FileUtil; import org.yangcentral.yangkit.utils.xml.XmlWriter; @@ -45,65 +47,62 @@ import org.yangcentral.yangkit.utils.xml.XmlWriter; */ public class YangComparatorPlugin implements YangCompilerPlugin { @Override - public YangCompilerPluginParameter getParameter(Properties properties, String name, String value) + 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); } - YangCompilerPluginParameter yangCompilerPluginParameter = new YangCompilerPluginParameter() { - @Override - public String getName() { - return 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") || name.equals("settings") - || name.equals("rule") || name.equals("result")) { - Iterator> it = properties.entrySet().iterator(); - String formatStr = value; - while (it.hasNext()) { - Map.Entry entry = it.next(); - formatStr = formatStr.replaceAll("\\{" + entry.getKey() + "\\}", (String) entry.getValue()); + @Override + public Object getValue() throws YangCompilerException { + if (name.equals("old-yang")) { + return BuildOption.parseSources(value); } - return formatStr; - } - 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; + 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); } - throw new YangCompilerException("unrecognized value:" + value); + return null; } - return null; - } - }; - return yangCompilerPluginParameter; + }; + return yangCompilerPluginParameter; + } + return YangCompilerPlugin.super.getParameter(name, value); + } @Override public void run(YangSchemaContext yangSchemaContext, YangCompiler yangCompiler, List list) throws YangCompilerException { CompareType compareType = null; - String oldYangPath = null; + List sources = null; + Settings settings = yangCompiler.getSettings(); String rulePath = null; String resultPath = null; for (YangCompilerPluginParameter parameter : list) { //System.out.println("para name="+parameter.getName() + " para value="+parameter.getValue()); if (parameter.getName().equals("old-yang")) { - oldYangPath = (String) parameter.getValue(); - yangCompiler.setYang(new File(oldYangPath)); + sources = (List) parameter.getValue(); } else if (parameter.getName().equals("settings")) { String settingsPath = (String) parameter.getValue(); try { - yangCompiler.setSettings(Settings.parse(FileUtil.readFile2String(settingsPath))); + settings = Settings.parse(FileUtil.readFile2String(settingsPath)); } catch (IOException e) { throw new RuntimeException(e); } @@ -116,7 +115,7 @@ public class YangComparatorPlugin implements YangCompilerPlugin { } } - if (oldYangPath == null) { + if (sources == null) { throw new YangCompilerException("missing mandatory parameter:old-yang"); } if (compareType == null) { @@ -125,11 +124,10 @@ public class YangComparatorPlugin implements YangCompilerPlugin { if (resultPath == null) { throw new YangCompilerException("missing mandatory parameter:result"); } - YangSchemaContext oldSchemaContext = yangCompiler.buildSchemaContext(); + YangSchemaContext oldSchemaContext = YangCompilerUtil.buildSchemaContext(sources, settings); ValidatorResult oldResult = oldSchemaContext.validate(); if (!oldResult.isOk()) { - throw new YangCompilerException("fail to validate the schema context of " - + oldYangPath + throw new YangCompilerException("fail to validate the schema context" + ".\n" + oldResult); } diff --git a/yang-compiler/src/main/java/org/onap/modeling/yangkit/compiler/BuildOption.java b/yang-compiler/src/main/java/org/onap/modeling/yangkit/compiler/BuildOption.java index 328d2a4..0c95e45 100644 --- a/yang-compiler/src/main/java/org/onap/modeling/yangkit/compiler/BuildOption.java +++ b/yang-compiler/src/main/java/org/onap/modeling/yangkit/compiler/BuildOption.java @@ -94,6 +94,65 @@ public class BuildOption { this.settings = settings; } + /** + * parse the sources. + * @param yangElement yang element + * @return list of sources + */ + public static List parseSources(JsonElement yangElement) { + List sources = new ArrayList<>(); + JsonObject yang = yangElement.getAsJsonObject(); + JsonElement dirElement = yang.get("dir"); + if (dirElement != null) { + JsonArray dirArray = dirElement.getAsJsonArray(); + List dirElementList = dirArray.asList(); + List dirs = new ArrayList<>(); + for (JsonElement dirElementItem : dirElementList) { + String yangDir = dirElementItem.getAsString(); + dirs.add(yangDir); + } + DirectorySource directorySource = new DirectorySource(dirs); + sources.add(directorySource); + } + JsonElement filesElement = yang.get("file"); + if (filesElement != null) { + JsonArray fileArray = filesElement.getAsJsonArray(); + List fileElementList = fileArray.asList(); + List files = new ArrayList<>(); + for (JsonElement fileElementItem : fileElementList) { + String yangFile = fileElementItem.getAsString(); + files.add(yangFile); + } + FileSource fileSource = new FileSource(files); + sources.add(fileSource); + } + JsonElement modulesElement = yang.get("module"); + if (modulesElement != null) { + JsonArray moduleArray = modulesElement.getAsJsonArray(); + List moduleList = moduleArray.asList(); + List moduleInfos = new ArrayList<>(); + for (JsonElement moduleElement : moduleList) { + JsonObject moduleObject = moduleElement.getAsJsonObject(); + String name = moduleObject.get("name").getAsString(); + String revision = moduleObject.get("revision").getAsString(); + String organization = null; + if (moduleObject.get("organization") != null) { + organization = moduleObject.get("organization").getAsString(); + } + URI schema = null; + if (moduleObject.get("schema") != null) { + schema = URI.create(moduleObject.get("schema").getAsString()); + } + ModuleInfo moduleInfo = new ModuleInfo(name, revision, organization); + moduleInfo.setSchema(schema); + moduleInfos.add(moduleInfo); + } + ModuleSource moduleSource = new ModuleSource(moduleInfos); + sources.add(moduleSource); + } + return sources; + } + /** * parse the build.json. * @@ -106,55 +165,7 @@ public class BuildOption { JsonElement yangElement = jsonObject.get("yang"); if (yangElement != null) { - JsonObject yang = yangElement.getAsJsonObject(); - JsonElement dirElement = yang.get("dir"); - if (dirElement != null) { - JsonArray dirArray = dirElement.getAsJsonArray(); - List dirElementList = dirArray.asList(); - List dirs = new ArrayList<>(); - for (JsonElement dirElementItem : dirElementList) { - String yangDir = dirElementItem.getAsString(); - dirs.add(yangDir); - } - DirectorySource directorySource = new DirectorySource(dirs); - buildOption.addSource(directorySource); - } - JsonElement filesElement = yang.get("file"); - if (filesElement != null) { - JsonArray fileArray = filesElement.getAsJsonArray(); - List fileElementList = fileArray.asList(); - List files = new ArrayList<>(); - for (JsonElement fileElementItem : fileElementList) { - String yangFile = fileElementItem.getAsString(); - files.add(yangFile); - } - FileSource fileSource = new FileSource(files); - buildOption.addSource(fileSource); - } - JsonElement modulesElement = yang.get("module"); - if (modulesElement != null) { - JsonArray moduleArray = modulesElement.getAsJsonArray(); - List moduleList = moduleArray.asList(); - List moduleInfos = new ArrayList<>(); - for (JsonElement moduleElement : moduleList) { - JsonObject moduleObject = moduleElement.getAsJsonObject(); - String name = moduleObject.get("name").getAsString(); - String revision = moduleObject.get("revision").getAsString(); - String organization = null; - if (moduleObject.get("organization") != null) { - organization = moduleObject.get("organization").getAsString(); - } - URI schema = null; - if (moduleObject.get("schema") != null) { - schema = URI.create(moduleObject.get("schema").getAsString()); - } - ModuleInfo moduleInfo = new ModuleInfo(name, revision, organization); - moduleInfo.setSchema(schema); - moduleInfos.add(moduleInfo); - } - ModuleSource moduleSource = new ModuleSource(moduleInfos); - buildOption.addSource(moduleSource); - } + buildOption.sources = parseSources(yangElement); } JsonElement settingsElement = jsonObject.get("settings"); if (settingsElement != null) { 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 87a1c5e..ccbfcbc 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 @@ -126,10 +126,7 @@ public class YangCompiler { public YangSchemaContext buildSchemaContext() { YangSchemaContext schemaContext = null; try { - List sources = buildOption.getSources(); - for (Source source : sources) { - schemaContext = source.buildSource(settings, schemaContext, true); - } + schemaContext = YangCompilerUtil.buildSchemaContext(buildOption.getSources(),getSettings()); return schemaContext; } catch (YangCompilerException e) { diff --git a/yang-compiler/src/main/java/org/onap/modeling/yangkit/compiler/util/YangCompilerUtil.java b/yang-compiler/src/main/java/org/onap/modeling/yangkit/compiler/util/YangCompilerUtil.java index 19a63bd..0f9c99f 100644 --- a/yang-compiler/src/main/java/org/onap/modeling/yangkit/compiler/util/YangCompilerUtil.java +++ b/yang-compiler/src/main/java/org/onap/modeling/yangkit/compiler/util/YangCompilerUtil.java @@ -46,11 +46,14 @@ import javax.net.ssl.X509TrustManager; import org.onap.modeling.yangkit.catalog.ModuleInfo; import org.onap.modeling.yangkit.catalog.YangCatalog; import org.onap.modeling.yangkit.compiler.Settings; +import org.onap.modeling.yangkit.compiler.Source; +import org.onap.modeling.yangkit.compiler.YangCompilerException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.yangcentral.yangkit.base.YangBuiltinKeyword; +import org.yangcentral.yangkit.model.api.schema.YangSchemaContext; import org.yangcentral.yangkit.model.api.stmt.Module; import org.yangcentral.yangkit.model.api.stmt.SubModule; import org.yangcentral.yangkit.model.api.stmt.YangStatement; @@ -438,4 +441,22 @@ public class YangCompilerUtil { } return dependencies; } + + /** + * build schema context from sources and settings. + * @param sources yang sources + * @param settings settings + * @return yang schema context + * @throws YangCompilerException yang compiler exception + */ + public static YangSchemaContext buildSchemaContext(List sources, Settings settings) + throws YangCompilerException { + YangSchemaContext schemaContext = null; + + for (Source source : sources) { + schemaContext = source.buildSource(settings, schemaContext, true); + } + return schemaContext; + + } } -- cgit 1.2.3-korg