Xpath linking issue

Change-Id: Iac26185641cd423eceade2e8fecebf8efcc177d7
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 5352a8e..f31ef91 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
@@ -325,6 +325,10 @@
             if (tempPath.getNodeIdentifier().getPrefix() == null) {
                 tempAugment = resolveIntraFileAugment(tempPath, root);
             } else {
+                if (!tempPath.getNodeIdentifier().getPrefix().equals(curPrefix)) {
+                    curPrefix = tempPath.getNodeIdentifier().getPrefix();
+                    root = getImportedNode(rootNode, tempPath.getNodeIdentifier());
+                }
                 tempAugment = resolveInterFileAugment(tempPath, root, index);
             }
             if (tempAugment != null) {
@@ -534,13 +538,7 @@
      */
     private YangNode resolveInterFileAugment(YangAtomicPath tempPath,
                                              YangNode root, int size) {
-
-        YangNode tempAugment;
-        if (!tempPath.getNodeIdentifier().getPrefix().equals(curPrefix)) {
-            curPrefix = tempPath.getNodeIdentifier().getPrefix();
-            root = getImportedNode(rootNode, tempPath.getNodeIdentifier());
-        }
-        tempAugment = getAugment(tempPath.getNodeIdentifier(), root, absPaths);
+        YangNode tempAugment = getAugment(tempPath.getNodeIdentifier(), root, absPaths);
         if (tempAugment == null) {
             return resolveInterToInterFileAugment(root, size);
         }
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 225b0c5..b178dba 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
@@ -624,4 +624,28 @@
         YangPluginConfig.compileCode(COMP);
         deleteDirectory(DIR);
     }
+
+    @Test
+    public void processMultipleAugment() throws IOException,
+            ParserException, MojoExecutionException {
+
+        deleteDirectory(DIR);
+        String dir = "src/test/resources/multipleaugment";
+
+        Set<Path> paths = new HashSet<>();
+        for (String file : getYangFiles(dir)) {
+            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/multipleaugment/ietf-network-test@2018-02-26.yang b/compiler/plugin/maven/src/test/resources/multipleaugment/ietf-network-test@2018-02-26.yang
new file mode 100644
index 0000000..287e23a
--- /dev/null
+++ b/compiler/plugin/maven/src/test/resources/multipleaugment/ietf-network-test@2018-02-26.yang
@@ -0,0 +1,23 @@
+module ietf-network-test {
+  yang-version 1.1;
+  namespace "urn:ietf:params:xml:ns:yang:ietf-network-test";
+  prefix nw;
+
+  revision 2018-02-26 {
+  }
+
+  container networks {
+    list network {
+      key "network-id";
+      leaf network-id {
+        type string;
+      }
+      list node {
+        key "node-id";
+        leaf node-id {
+          type string;
+        }
+      }
+    }
+  }
+}
diff --git a/compiler/plugin/maven/src/test/resources/multipleaugment/ietf-otn-topology-test@2017-10-30.yang b/compiler/plugin/maven/src/test/resources/multipleaugment/ietf-otn-topology-test@2017-10-30.yang
new file mode 100644
index 0000000..092719e
--- /dev/null
+++ b/compiler/plugin/maven/src/test/resources/multipleaugment/ietf-otn-topology-test@2017-10-30.yang
@@ -0,0 +1,26 @@
+module ietf-otn-topology-test {

+  yang-version 1.1;

+

+  namespace "urn:ietf:params:xml:ns:yang:ietf-otn-topology-test";

+  prefix "otntopo";

+

+  import ietf-network-test {

+    prefix "nw";

+  }

+

+  import ietf-te-topology-test {

+    prefix "tet";

+  }

+

+  revision 2017-10-30 {

+  }

+

+  augment "/nw:networks/nw:network/nw:node/tet:te/"

+          + "tet:te-node-attributes/tet:connectivity-matrices/"

+          + "tet:connectivity-matrix/tet:path-constraints/"

+          + "tet:te-bandwidth/tet:technology" {

+    leaf sample {

+        type string;

+    }

+  }

+}

diff --git a/compiler/plugin/maven/src/test/resources/multipleaugment/ietf-te-topology-test@2018-02-21.yang b/compiler/plugin/maven/src/test/resources/multipleaugment/ietf-te-topology-test@2018-02-21.yang
new file mode 100644
index 0000000..55eab72
--- /dev/null
+++ b/compiler/plugin/maven/src/test/resources/multipleaugment/ietf-te-topology-test@2018-02-21.yang
@@ -0,0 +1,75 @@
+module ietf-te-topology-test {
+  yang-version 1.1;
+  namespace "urn:ietf:params:xml:ns:yang:ietf-te-topology-test";
+
+  prefix "tet";
+
+  import ietf-te-types-test {
+    prefix "te-types";
+  }
+
+  import ietf-network-test {
+    prefix "nw";
+  }
+
+
+  revision "2018-02-21" {
+  }
+
+  grouping connectivity-matrix-entry-path-attributes {
+    uses te-types:generic-path-constraints;
+  } // connectivity-matrix-entry-path-attributes
+
+
+  grouping te-node-augment {
+    uses te-node-config;
+  } // te-node-augment
+
+  grouping te-node-config {
+    uses te-node-config-attributes;
+  } // te-node-config
+
+  grouping te-node-config-attributes {
+    container te-node-attributes {
+      uses te-node-connectivity-matrices;
+    } // te-node-attributes
+  } // te-node-config-attributes
+
+  grouping te-node-connectivity-matrices {
+    container connectivity-matrices {
+      uses connectivity-matrix-entry-path-attributes;
+      list connectivity-matrix {
+        key "id";
+        leaf id {
+          type uint32;
+        }
+      } // connectivity-matrix
+    } // connectivity-matrices
+  } // te-node-connectivity-matrices
+
+  grouping te-node-connectivity-matrix-attributes {
+    uses connectivity-matrix-entry-path-attributes;
+  } // te-node-connectivity-matrix-attributes
+
+
+  /*
+   * Data nodes  */
+  augment "/nw:networks/nw:network/nw:node" {
+    leaf te-node-id {
+      type string;
+      description
+        "The identifier of a node in the TE topology.
+         A node is specific to a topology to which it belongs.";
+    }
+    container te {
+      uses te-node-augment;
+    } // te
+  }
+
+  augment
+    "/nw:networks/nw:network/nw:node/te/te-node-attributes/"
+    + "connectivity-matrices/connectivity-matrix" {
+    uses te-node-connectivity-matrix-attributes;
+  }
+
+}
diff --git a/compiler/plugin/maven/src/test/resources/multipleaugment/ietf-te-types-test@2018-03-05.yang b/compiler/plugin/maven/src/test/resources/multipleaugment/ietf-te-types-test@2018-03-05.yang
new file mode 100644
index 0000000..4f32ac2
--- /dev/null
+++ b/compiler/plugin/maven/src/test/resources/multipleaugment/ietf-te-types-test@2018-03-05.yang
@@ -0,0 +1,32 @@
+module ietf-te-types-test {
+
+  namespace "urn:ietf:params:xml:ns:yang:ietf-te-types-test";
+
+  /* Replace with IANA when assigned */
+  prefix "te-types";
+
+  revision "2018-03-05" {
+  }
+
+  grouping te-bandwidth {
+    container te-bandwidth {
+      choice technology {
+        case generic {
+          leaf generic {
+            type string;
+          }
+        }
+      }
+    }
+  }
+
+  grouping common-constraints_config {
+    uses te-types:te-bandwidth;
+  }
+
+  grouping generic-path-constraints {
+    container path-constraints {
+      uses common-constraints_config;
+    }
+  }
+}