augment linking prefix change defect fix and it's ut
Change-Id: I6cad4b47f374c78ef68414a7481b2b1197bfdd6e
diff --git a/compiler/base/linker/src/main/java/org/onosproject/yang/compiler/linker/impl/YangXpathLinker.java b/compiler/base/linker/src/main/java/org/onosproject/yang/compiler/linker/impl/YangXpathLinker.java
index 4a5a7c1..bfea8f0 100644
--- a/compiler/base/linker/src/main/java/org/onosproject/yang/compiler/linker/impl/YangXpathLinker.java
+++ b/compiler/base/linker/src/main/java/org/onosproject/yang/compiler/linker/impl/YangXpathLinker.java
@@ -308,7 +308,7 @@
if (tempPath.getNodeIdentifier().getPrefix() == null) {
tempAugment = resolveIntraFileAugment(tempPath, root);
} else {
- tempAugment = resolveInterFileAugment(tempPath, root);
+ tempAugment = resolveInterFileAugment(tempPath, root, index);
}
if (tempAugment != null) {
linkerStack.push(tempNode);
@@ -396,10 +396,12 @@
* Resolves inter file augment linking.
*
* @param tempPath temporary absolute path
- * @param root root node
+ * @param root root node
+ * @param size node size
* @return linked target node
*/
- private YangNode resolveInterFileAugment(YangAtomicPath tempPath, YangNode root) {
+ private YangNode resolveInterFileAugment(YangAtomicPath tempPath,
+ YangNode root, int size) {
YangNode tempAugment;
if (!tempPath.getNodeIdentifier().getPrefix().equals(curPrefix)) {
@@ -408,20 +410,21 @@
}
tempAugment = getAugment(tempPath.getNodeIdentifier(), root, absPaths);
if (tempAugment == null) {
- return resolveInterToInterFileAugment(root);
+ return resolveInterToInterFileAugment(root, size);
}
return tempAugment;
}
/**
* Resolves augment when prefix changed from inter file to inter file.
- * it may be possible that the prefix used in imported module is different the
- * given list of node identifiers.
+ * it may be possible that the prefix used in imported module is different
+ * the given list of node identifiers.
*
* @param root root node
+ * @param size node size
* @return target node
*/
- private YangNode resolveInterToInterFileAugment(YangNode root) {
+ private YangNode resolveInterToInterFileAugment(YangNode root, int size) {
List<YangAugment> augments = getListOfYangAugment(root);
int index;
List<YangAtomicPath> paths = new ArrayList<>();
@@ -430,14 +433,15 @@
for (YangAtomicPath path : augment.getTargetNode()) {
- if (!searchForAugmentInImportedNode(path.getNodeIdentifier(), index)) {
+ if (!searchForAugmentInImportedNode(path.getNodeIdentifier(),
+ index)) {
paths.clear();
break;
}
paths.add(path);
index++;
}
- if (!paths.isEmpty() && paths.size() == absPaths.size() - 1) {
+ if (!paths.isEmpty() && paths.size() == size) {
return augment;
} else {
paths.clear();
diff --git a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/AugmentTranslatorTest.java b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/AugmentTranslatorTest.java
index 83969a2..f80c5d9 100644
--- a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/AugmentTranslatorTest.java
+++ b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/AugmentTranslatorTest.java
@@ -152,4 +152,37 @@
utilManager.translateToJava(yangPluginConfig);
deleteDirectory(DIR);
}
+
+ /**
+ * Checks the augment statements linking with prefix change from inter to.
+ * inter
+ *
+ * @throws IOException if any error occurs during IO on files
+ * @throws ParserException if any error occurs during parsing
+ * @throws MojoExecutionException if any mojo operation fails
+ */
+ @Test
+ public void processActnAugmentInterTranslator() throws IOException,
+ ParserException,
+ MojoExecutionException {
+
+ deleteDirectory(DIR);
+ String searchDir = "src/test/resources/actnInterAugments";
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
+ utilManager.parseYangFileInfoSet();
+ utilManager.createYangNodeSet();
+ utilManager.resolveDependenciesUsingLinker();
+
+ YangPluginConfig yangPluginConfig = new YangPluginConfig();
+ yangPluginConfig.setCodeGenDir(DIR);
+ utilManager.translateToJava(yangPluginConfig);
+ YangPluginConfig.compileCode(COMP);
+ deleteDirectory(DIR);
+ }
}
diff --git a/compiler/plugin/maven/src/test/resources/actnInterAugments/ietf-network-topology@2017-03-01.yang b/compiler/plugin/maven/src/test/resources/actnInterAugments/ietf-network-topology@2017-03-01.yang
new file mode 100644
index 0000000..c29a9cd
--- /dev/null
+++ b/compiler/plugin/maven/src/test/resources/actnInterAugments/ietf-network-topology@2017-03-01.yang
@@ -0,0 +1,23 @@
+module ietf-network-topology {
+ yang-version 1;
+ namespace "urn:ietf:params:xml:ns:yang:ietf-network-topology";
+ prefix lnk;
+
+ import ietf-network {
+ prefix nd;
+ }
+
+ revision 2017-03-01 {
+ reference
+ "draft-ietf-i2rs-yang-network-topo-12";
+ }
+
+ augment "/nd:networks/nd:network" {
+ list link {
+ key "link-id";
+ leaf link-id {
+ type string;
+ }
+ }
+ }
+ }
diff --git a/compiler/plugin/maven/src/test/resources/actnInterAugments/ietf-network@2017-03-01.yang b/compiler/plugin/maven/src/test/resources/actnInterAugments/ietf-network@2017-03-01.yang
new file mode 100644
index 0000000..7f4fe71
--- /dev/null
+++ b/compiler/plugin/maven/src/test/resources/actnInterAugments/ietf-network@2017-03-01.yang
@@ -0,0 +1,17 @@
+module ietf-network {
+ yang-version 1;
+ namespace "urn:ietf:params:xml:ns:yang:ietf-network";
+ prefix nd;
+ revision 2017-03-01 {
+ reference
+ "draft-ietf-i2rs-yang-network-topo-12";
+ }
+ container networks {
+ list network {
+ key "network-id";
+ leaf network-id {
+ type string;
+ }
+ }
+ }
+}
diff --git a/compiler/plugin/maven/src/test/resources/actnInterAugments/ietf-otn-topology@2017-04-25.yang b/compiler/plugin/maven/src/test/resources/actnInterAugments/ietf-otn-topology@2017-04-25.yang
new file mode 100644
index 0000000..19d9841
--- /dev/null
+++ b/compiler/plugin/maven/src/test/resources/actnInterAugments/ietf-otn-topology@2017-04-25.yang
@@ -0,0 +1,61 @@
+module ietf-otn-topology {
+ yang-version 1;
+
+ namespace "urn:ietf:params:xml:ns:yang:ietf-otn-topology";
+ prefix "otntopo";
+
+ import ietf-network {
+ prefix "nd";
+ }
+
+ import ietf-network-topology {
+ prefix "lnk";
+ }
+
+ import ietf-te-topology {
+ prefix "tet";
+ }
+
+
+ revision 2017-04-25 {
+ description
+ "Revision 0.3";
+ reference
+ "draft-zhang-ccamp-l1-topo-yang-07.txt";
+ }
+
+
+ grouping otn-link-attributes {
+
+ list available-odu-info{
+ key "priority";
+ max-elements "8";
+
+ leaf priority {
+ type uint8 {
+ range "0..7";
+ }
+ }
+
+ list odulist {
+ key "odu-type";
+
+ leaf odu-type {
+ type string;
+ }
+
+ leaf number {
+ type uint16;
+ }
+ }
+ }
+
+ leaf distance {
+ type uint32;
+ }
+ }
+
+ augment "/nd:networks/nd:network/lnk:link/tet:te/tet:config" {
+ uses otn-link-attributes;
+ }
+ }
diff --git a/compiler/plugin/maven/src/test/resources/actnInterAugments/ietf-te-topology@2017-03-12.yang b/compiler/plugin/maven/src/test/resources/actnInterAugments/ietf-te-topology@2017-03-12.yang
new file mode 100644
index 0000000..98054f8
--- /dev/null
+++ b/compiler/plugin/maven/src/test/resources/actnInterAugments/ietf-te-topology@2017-03-12.yang
@@ -0,0 +1,26 @@
+module ietf-te-topology {
+ yang-version 1;
+ namespace "urn:ietf:params:xml:ns:yang:ietf-te-topology";
+
+ prefix "tet";
+
+ import ietf-network {
+ prefix "nw";
+ }
+
+ import ietf-network-topology {
+ prefix "nt";
+ }
+
+ revision "2017-03-12" {
+ description "Initial revision";
+ reference "TBD";
+ }
+
+ augment "/nw:networks/nw:network/nt:link" {
+ container te {
+ container config {
+ } // config
+ } // te
+ }
+}