[ONOS-6675] Augment namespace based conflict resolution.

Change-Id: Ie90445a90bbf102a7f10459b34433db99aae81bb
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/exceptions/ErrorMessages.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/exceptions/ErrorMessages.java
index 26f813e..f828d29 100644
--- a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/exceptions/ErrorMessages.java
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/exceptions/ErrorMessages.java
@@ -39,8 +39,8 @@
     public static final String INVALID_CASE_HOLDER
             = "\"Internal Data Model Tree Error: Invalid/Missing \"" +
             "                                   \"holder in case \"";
-    public static final String TARGET_NODE_LEAF_INFO = "target node leaf/leaf-list";
-    public static final String TARGET_NODE = "target node ";
+    public static final String TGT_LEAF = " target node leaf/leaf-list";
+    public static final String TARGET_NODE = " target node ";
     public static final String COLLISION_DETECTION = "YANG File Error: " +
             "Identifier collision detected in";
     public static final String FAILED_TO_ADD_CASE = "Failed to add child " +
diff --git a/compiler/base/linker/src/main/java/org/onosproject/yang/compiler/linker/impl/YangLinkerUtils.java b/compiler/base/linker/src/main/java/org/onosproject/yang/compiler/linker/impl/YangLinkerUtils.java
index 31957ee..7f4c64c 100644
--- a/compiler/base/linker/src/main/java/org/onosproject/yang/compiler/linker/impl/YangLinkerUtils.java
+++ b/compiler/base/linker/src/main/java/org/onosproject/yang/compiler/linker/impl/YangLinkerUtils.java
@@ -16,6 +16,7 @@
 
 package org.onosproject.yang.compiler.linker.impl;
 
+import org.onosproject.yang.compiler.datamodel.LocationInfo;
 import org.onosproject.yang.compiler.datamodel.TraversalType;
 import org.onosproject.yang.compiler.datamodel.YangAtomicPath;
 import org.onosproject.yang.compiler.datamodel.YangAugment;
@@ -33,6 +34,7 @@
 import org.onosproject.yang.compiler.datamodel.YangLeafRef;
 import org.onosproject.yang.compiler.datamodel.YangLeavesHolder;
 import org.onosproject.yang.compiler.datamodel.YangList;
+import org.onosproject.yang.compiler.datamodel.YangNamespace;
 import org.onosproject.yang.compiler.datamodel.YangNode;
 import org.onosproject.yang.compiler.datamodel.YangNodeIdentifier;
 import org.onosproject.yang.compiler.datamodel.YangPathPredicate;
@@ -61,7 +63,7 @@
 import static org.onosproject.yang.compiler.datamodel.exceptions.ErrorMessages.COLLISION_DETECTION;
 import static org.onosproject.yang.compiler.datamodel.exceptions.ErrorMessages.FAILED_TO_ADD_CASE;
 import static org.onosproject.yang.compiler.datamodel.exceptions.ErrorMessages.TARGET_NODE;
-import static org.onosproject.yang.compiler.datamodel.exceptions.ErrorMessages.TARGET_NODE_LEAF_INFO;
+import static org.onosproject.yang.compiler.datamodel.exceptions.ErrorMessages.TGT_LEAF;
 import static org.onosproject.yang.compiler.datamodel.exceptions.ErrorMessages.getErrorMsg;
 import static org.onosproject.yang.compiler.datamodel.exceptions.ErrorMessages.getErrorMsgCollision;
 import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.addResolutionInfo;
@@ -112,79 +114,175 @@
     }
 
     /**
-     * Detects collision between target nodes leaf/leaf-list or child node with
-     * augmented leaf/leaf-list or child node.
+     * Detects collision between target nodes' leaf/leaf-list or child node
+     * with augmented leaf/leaf-list or child node.
      *
-     * @param targetNode target node
-     * @param augment    augment node
+     * @param tgt     target node
+     * @param aug     YANG augment
+     * @param augRoot augment's root
      */
-    private static void detectCollision(YangNode targetNode, YangAugment augment) {
-        YangNode targetNodesChild = targetNode.getChild();
-        YangNode augmentsChild = augment.getChild();
-        if (targetNode instanceof YangChoice) {
-            addCaseNodeToChoiceTarget(augment);
-        } else {
-            detectCollisionInLeaveHolders(targetNode, augment);
-            while (augmentsChild != null) {
-                detectCollisionInChildNodes(targetNodesChild, augmentsChild);
-                augmentsChild = augmentsChild.getNextSibling();
+    private static void detectCollision(YangNode tgt, YangAugment aug,
+                                        YangNode augRoot) {
+        YangNode tgtRoot = getTgtRootNode(tgt);
+        String augNs = ((YangNamespace) augRoot).getModuleNamespace();
+        String tgtNs = ((YangNamespace) tgtRoot).getModuleNamespace();
+
+        if (tgt instanceof YangChoice) {
+            addCaseNodeToChoiceTarget(aug);
+        }
+        detectCollisionInTgt(tgt, aug, augNs, tgtNs);
+    }
+
+    /**
+     * Detects collision in the target node according to the namespace match
+     * of the nodes.
+     *
+     * @param tgt   target node
+     * @param aug   YANG augment
+     * @param augNs augment root namespace
+     * @param tgtNs target root namespace
+     */
+    private static void detectCollisionInTgt(YangNode tgt, YangAugment aug,
+                                             String augNs, String tgtNs) {
+        if (!(augNs.equals(tgtNs))) {
+            return;
+        }
+
+        YangNode aChild = aug.getChild();
+        YangNode tChild = tgt.getChild();
+        List<YangLeaf> aL = aug.getListOfLeaf();
+        List<YangLeafList> aLl = aug.getListOfLeafList();
+
+        List<YangLeaf> tL = null;
+        List<YangLeafList> tLl = null;
+
+        if (tgt instanceof YangLeavesHolder) {
+            tL = ((YangLeavesHolder) tgt).getListOfLeaf();
+            tLl = ((YangLeavesHolder) tgt).getListOfLeafList();
+        }
+
+        detectLeavesCollision(tL, tLl, aL, aLl);
+        while (aChild != null) {
+            detectNodeCollision(aChild, tChild, aL, aLl);
+            detectLeafCollision(aChild.getName(), aChild, tL);
+            detectLeafListCollision(aChild.getName(), aChild, tLl);
+            aChild = aChild.getNextSibling();
+        }
+    }
+
+    /**
+     * Detects collision between augment's leaves and leaf lists' identifier
+     * with target node leaves and leaf lists' identifier.
+     *
+     * @param tL  target leaves
+     * @param tLl target leaf lists
+     * @param aL  augment leaves
+     * @param aLl augment leaf lists
+     */
+    private static void detectLeavesCollision(List<YangLeaf> tL,
+                                              List<YangLeafList> tLl,
+                                              List<YangLeaf> aL,
+                                              List<YangLeafList> aLl) {
+        if (aL != null && !aL.isEmpty()) {
+            for (YangLeaf aLeaf : aL) {
+                detectLeafCollision(aLeaf.getName(), aLeaf, tL);
+                detectLeafListCollision(aLeaf.getName(), aLeaf, tLl);
+            }
+        }
+        if (aLl != null && !aLl.isEmpty()) {
+            for (YangLeafList aLeafList : aLl) {
+                detectLeafCollision(aLeafList.getName(), aLeafList, tL);
+                detectLeafListCollision(aLeafList.getName(), aLeafList, tLl);
             }
         }
     }
 
-    /*Detects collision between leaves/leaf-lists*/
-    private static void detectCollisionInLeaveHolders(YangNode targetNode, YangAugment augment) {
-        YangLeavesHolder targetNodesLeavesHolder = (YangLeavesHolder) targetNode;
-        if (augment.getListOfLeaf() != null && augment.getListOfLeaf().isEmpty() &&
-                targetNodesLeavesHolder.getListOfLeaf() != null) {
-            for (YangLeaf leaf : augment.getListOfLeaf()) {
-                for (YangLeaf targetLeaf : targetNodesLeavesHolder.getListOfLeaf()) {
-                    detectCollision(targetLeaf.getName(), leaf.getName(),
-                                    leaf.getLineNumber(),
-                                    leaf.getCharPosition(),
-                                    leaf.getFileName(), TARGET_NODE_LEAF_INFO);
-                }
-            }
-        }
-        if (augment.getListOfLeafList() != null &&
-                augment.getListOfLeafList().isEmpty() &&
-                targetNodesLeavesHolder.getListOfLeafList() != null) {
-            for (YangLeafList leafList : augment.getListOfLeafList()) {
-                for (YangLeafList targetLeafList : targetNodesLeavesHolder.getListOfLeafList()) {
-                    detectCollision(targetLeafList.getName(), leafList.getName(),
-                                    leafList.getLineNumber(),
-                                    leafList.getCharPosition(),
-                                    leafList.getFileName(), TARGET_NODE_LEAF_INFO);
-                }
+    /**
+     * Detects collision with list of leaf-list name and any comparable
+     * identifier.
+     *
+     * @param name       comparable identifier
+     * @param info       location info
+     * @param leavesList list of leaf-list
+     */
+    private static void detectLeafListCollision(String name, LocationInfo info,
+                                                List<YangLeafList> leavesList) {
+        if (leavesList != null && !leavesList.isEmpty()) {
+            for (YangLeafList ll : leavesList) {
+                detectCollision(ll.getName(), name, info, TGT_LEAF);
             }
         }
     }
 
+    /**
+     * Detects collision with list of leaf name and any comparable
+     * identifier.
+     *
+     * @param name   comparable identifier
+     * @param info   location info
+     * @param leaves list of leaf
+     */
+    private static void detectLeafCollision(String name, LocationInfo info,
+                                            List<YangLeaf> leaves) {
+        if (leaves != null && !leaves.isEmpty()) {
+            for (YangLeaf leaf : leaves) {
+                detectCollision(leaf.getName(), name, info, TGT_LEAF);
+            }
+        }
+    }
 
+    /**
+     * Detects node collision of augment children nodes, leaves and leaf-lists
+     * with target node's children nodes.
+     *
+     * @param aug YANG augment's child
+     * @param tgt target node's child
+     * @param aL  augment leaves
+     * @param aLl augment leaf lists
+     */
+    private static void detectNodeCollision(YangNode aug, YangNode tgt,
+                                            List<YangLeaf> aL,
+                                            List<YangLeafList> aLl) {
+        while (tgt != null) {
+            detectCollision(tgt.getName(), aug.getName(), aug, TARGET_NODE);
+            detectLeafCollision(tgt.getName(), tgt, aL);
+            detectLeafListCollision(tgt.getName(), tgt, aLl);
+            tgt = tgt.getNextSibling();
+        }
+    }
+
+    /**
+     * Returns module or sub-module node of any YANG node.
+     *
+     * @param node YANG node
+     * @return root node
+     */
+    private static YangNode getTgtRootNode(YangNode node) {
+        YangNode root = node;
+        while (!(root instanceof YangReferenceResolver)) {
+            root = root.getParent();
+            if (root == null) {
+                throw new LinkerException("Datamodel tree is not correct");
+            }
+        }
+        return root;
+    }
+
+    /**
+     * Detects collision for two strings and throws exception if collision
+     * occurs.
+     *
+     * @param first  first string
+     * @param second second string
+     * @param info   location info
+     * @param type   collision type
+     */
     private static void detectCollision(String first, String second,
-                                        int line, int position, String
-                                                fileName, String type) {
+                                        LocationInfo info, String type) {
         if (first.equals(second)) {
             throw new LinkerException(getErrorMsgCollision(
-                    COLLISION_DETECTION, second, line, position, type,
-                    fileName));
-        }
-    }
-
-    /*Detects collision for child nodes.*/
-    private static void detectCollisionInChildNodes(YangNode targetNodesChild,
-                                                    YangNode augmentsChild) {
-        while (augmentsChild != null) {
-            while (targetNodesChild != null) {
-                if (targetNodesChild.getName().equals(augmentsChild.getName())) {
-                    detectCollision(targetNodesChild.getName(), augmentsChild.getName(),
-                                    augmentsChild.getLineNumber(),
-                                    augmentsChild.getCharPosition(),
-                                    augmentsChild.getFileName(), TARGET_NODE);
-                }
-                targetNodesChild = targetNodesChild.getNextSibling();
-            }
-            augmentsChild = augmentsChild.getNextSibling();
+                    COLLISION_DETECTION, second, info.getLineNumber(),
+                    info.getCharPosition(), type, info.getFileName()));
         }
     }
 
@@ -358,19 +456,23 @@
     }
 
     /**
-     * Detects collision between target nodes and its all leaf/leaf-list or child
-     * node with augmented leaf/leaf-list or child node.
+     * Detects collision between augment nodes' children and target nodes'
+     * nodes children and also between augment nodes' children and other
+     * augmented nodes.
      *
-     * @param targetNode target node
-     * @param augment    augment node
+     * @param tgt     target node
+     * @param aug     YANG augment
+     * @param augRoot augment's root
      */
-    static void detectCollisionForAugmentedNode(YangNode targetNode, YangAugment augment) {
+    static void detectCollisionForAugment(YangNode tgt, YangAugment aug,
+                                          YangNode augRoot) {
         // Detect collision for target node and augment node.
-        detectCollision(targetNode, augment);
-        List<YangAugment> yangAugmentedInfo = ((YangAugmentableNode) targetNode).getAugmentedInfoList();
+        detectCollision(tgt, aug, augRoot);
+        List<YangAugment> infoList = ((YangAugmentableNode) tgt)
+                .getAugmentedInfoList();
         // Detect collision for target augment node and current augment node.
-        for (YangAugment info : yangAugmentedInfo) {
-            detectCollision(info, augment);
+        for (YangAugment info : infoList) {
+            detectCollision(info, aug, augRoot);
         }
     }
 
diff --git a/compiler/base/linker/src/main/java/org/onosproject/yang/compiler/linker/impl/YangResolutionInfoImpl.java b/compiler/base/linker/src/main/java/org/onosproject/yang/compiler/linker/impl/YangResolutionInfoImpl.java
index 016f2d4..0c223c6 100644
--- a/compiler/base/linker/src/main/java/org/onosproject/yang/compiler/linker/impl/YangResolutionInfoImpl.java
+++ b/compiler/base/linker/src/main/java/org/onosproject/yang/compiler/linker/impl/YangResolutionInfoImpl.java
@@ -96,7 +96,7 @@
 import static org.onosproject.yang.compiler.linker.impl.XpathLinkingTypes.AUGMENT_LINKING;
 import static org.onosproject.yang.compiler.linker.impl.XpathLinkingTypes.DEVIATION_LINKING;
 import static org.onosproject.yang.compiler.linker.impl.XpathLinkingTypes.LEAF_REF_LINKING;
-import static org.onosproject.yang.compiler.linker.impl.YangLinkerUtils.detectCollisionForAugmentedNode;
+import static org.onosproject.yang.compiler.linker.impl.YangLinkerUtils.detectCollisionForAugment;
 import static org.onosproject.yang.compiler.linker.impl.YangLinkerUtils.fillPathPredicates;
 import static org.onosproject.yang.compiler.linker.impl.YangLinkerUtils.getErrorInfoForLinker;
 import static org.onosproject.yang.compiler.linker.impl.YangLinkerUtils.getLeafRefErrorInfo;
@@ -1063,7 +1063,8 @@
                             root, AUGMENT_LINKING);
             if (targetNode != null) {
                 if (targetNode instanceof YangAugmentableNode) {
-                    detectCollisionForAugmentedNode(targetNode, augment);
+                    detectCollisionForAugment(targetNode, augment,
+                                              (YangNode) root);
                     ((YangAugmentableNode) targetNode).addAugmentation(augment);
                     augment.setAugmentedNode(targetNode);
                     setAugmentedFlagInAncestors(targetNode);
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 668bdca..4c6ac91 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
@@ -17,7 +17,10 @@
 package org.onosproject.yang.compiler.plugin.maven;
 
 import org.apache.maven.plugin.MojoExecutionException;
+import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.onosproject.yang.compiler.api.YangCompilerException;
 import org.onosproject.yang.compiler.parser.exceptions.ParserException;
 import org.onosproject.yang.compiler.tool.YangCompilerManager;
 import org.onosproject.yang.compiler.utils.io.YangPluginConfig;
@@ -37,10 +40,13 @@
  */
 public class AugmentTranslatorTest {
 
-    private final YangCompilerManager utilManager = new YangCompilerManager();
     private static final String DIR = "target/augmentTranslator/";
     private static final String COMP = System.getProperty("user.dir") + File
             .separator + DIR;
+    private final YangCompilerManager utilManager = new YangCompilerManager();
+
+    @Rule
+    public ExpectedException thrown = ExpectedException.none();
 
     /**
      * Checks augment translation should not result in any exception.
@@ -185,4 +191,248 @@
         YangPluginConfig.compileCode(COMP);
         deleteDirectory(DIR);
     }
+
+    /**
+     * Checks collision detection of an augment linked to a target having
+     * same node in the same level.
+     *
+     * @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 processSingleAugToTgt() throws IOException,
+            ParserException, MojoExecutionException {
+
+        deleteDirectory(DIR);
+        String dir = "src/test/resources/augmentcollision/singleaugtotgt";
+
+        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);
+    }
+
+    /**
+     * Checks collision detection of two augments from two different modules
+     * linked to a target having same node in the same level.
+     *
+     * @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 processTwoAugToTgt() throws IOException,
+            ParserException, MojoExecutionException {
+
+        deleteDirectory(DIR);
+        String dir = "src/test/resources/augmentcollision/twoaugtotgt";
+
+        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);
+    }
+
+    /**
+     * Checks collision detection of two augments from module and its
+     * sub-module linked to a target having same node in the same level.
+     *
+     * @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 processSingleSubModToTgt() throws IOException,
+            ParserException, MojoExecutionException {
+
+        thrown.expect(YangCompilerException.class);
+        thrown.expectMessage(
+                "YANG File Error: Identifier collision detected in target " +
+                        "node as \"val in 12 at 8");
+
+        deleteDirectory(DIR);
+        String dir = "src/test/resources/augmentcollision/singlesubmodtotgt";
+
+        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);
+    }
+
+    /**
+     * Checks collision detection of two augments from same namespace
+     * sub-modules linked to a target having same node in the same level.
+     *
+     * @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 processTwoSubModToTgt() throws IOException,
+            ParserException, MojoExecutionException {
+
+        thrown.expect(YangCompilerException.class);
+        thrown.expectMessage(
+                "YANG File Error: Identifier collision detected in target " +
+                        "node as \"val in 12 at 8");
+
+        deleteDirectory(DIR);
+        String dir = "src/test/resources/augmentcollision/twosubmodtotgt";
+
+        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);
+    }
+
+    /**
+     * Checks collision detection of an augment from the same module linked
+     * to a target having same node in the same level.
+     *
+     * @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 processSelfAug() throws IOException,
+            ParserException, MojoExecutionException {
+
+        thrown.expect(YangCompilerException.class);
+        thrown.expectMessage(
+                "YANG File Error: Identifier collision detected in target " +
+                        "node as \"val in 16 at 8");
+
+        deleteDirectory(DIR);
+        String dir = "src/test/resources/augmentcollision/selfaug";
+
+        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);
+    }
+
+    /**
+     * Checks collision detection of two augments from the same module linked
+     * to a target having same node in the same level.
+     *
+     * @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 processSelfAugWithAug() throws IOException,
+            ParserException, MojoExecutionException {
+
+        thrown.expect(YangCompilerException.class);
+        thrown.expectMessage(
+                "YANG File Error: Identifier collision detected in target " +
+                        "node as \"val in 24 at 8");
+
+        deleteDirectory(DIR);
+        String dir = "src/test/resources/augmentcollision/selfaugwithaug";
+
+        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);
+    }
+
+    /**
+     * Checks collision detection of augments which are inter connected in
+     * multiple files.
+     *
+     * @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 processAugToAug() throws IOException,
+            ParserException, MojoExecutionException {
+
+        deleteDirectory(DIR);
+        String dir = "src/test/resources/augmentcollision/augtoaug";
+
+        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/augmentcollision/augtoaug/module-a.yang b/compiler/plugin/maven/src/test/resources/augmentcollision/augtoaug/module-a.yang
new file mode 100644
index 0000000..21d819a
--- /dev/null
+++ b/compiler/plugin/maven/src/test/resources/augmentcollision/augtoaug/module-a.yang
@@ -0,0 +1,20 @@
+module module-a {
+
+    namespace "urn:ietf:params:xml:ns:aug:module:a";
+
+    prefix mod-a;
+
+    import module-c {
+        prefix mod-c;
+    }
+
+    import module-b {
+        prefix mod-b;
+    }
+
+    augment "/mod-b:cont/mod-c:val" {
+        leaf arg {
+            type string;
+        }
+    }
+}
diff --git a/compiler/plugin/maven/src/test/resources/augmentcollision/augtoaug/module-b.yang b/compiler/plugin/maven/src/test/resources/augmentcollision/augtoaug/module-b.yang
new file mode 100644
index 0000000..ea7ce47
--- /dev/null
+++ b/compiler/plugin/maven/src/test/resources/augmentcollision/augtoaug/module-b.yang
@@ -0,0 +1,14 @@
+module module-b {
+
+    namespace "urn:ietf:params:xml:ns:aug:module:b";
+
+    prefix mod-b;
+
+    container cont{
+        container val {
+            leaf-list create {
+                type string;
+            }
+        }
+    }
+}
diff --git a/compiler/plugin/maven/src/test/resources/augmentcollision/augtoaug/module-c.yang b/compiler/plugin/maven/src/test/resources/augmentcollision/augtoaug/module-c.yang
new file mode 100644
index 0000000..09fef2e
--- /dev/null
+++ b/compiler/plugin/maven/src/test/resources/augmentcollision/augtoaug/module-c.yang
@@ -0,0 +1,18 @@
+module module-c {
+
+    namespace "urn:ietf:params:xml:ns:aug:module:c";
+
+    prefix mod-c;
+
+    import module-b {
+        prefix mod-b;
+    }
+
+    augment "/mod-b:cont" {
+        container val {
+            leaf arg {
+                type string;
+            }
+        }
+    }
+}
diff --git a/compiler/plugin/maven/src/test/resources/augmentcollision/selfaug/module-a.yang b/compiler/plugin/maven/src/test/resources/augmentcollision/selfaug/module-a.yang
new file mode 100644
index 0000000..2b73dfd
--- /dev/null
+++ b/compiler/plugin/maven/src/test/resources/augmentcollision/selfaug/module-a.yang
@@ -0,0 +1,22 @@
+module module-a {
+
+    namespace "urn:ietf:params:xml:ns:yang:module:a";
+
+    prefix mod-a;
+
+    container cont{
+        container val {
+            leaf-list create {
+                type string;
+            }
+        }
+    }
+
+    augment "/cont" {
+        container val {
+            leaf arg {
+                type string;
+            }
+        }
+    }
+}
diff --git a/compiler/plugin/maven/src/test/resources/augmentcollision/selfaugwithaug/module-a.yang b/compiler/plugin/maven/src/test/resources/augmentcollision/selfaugwithaug/module-a.yang
new file mode 100644
index 0000000..5016f89
--- /dev/null
+++ b/compiler/plugin/maven/src/test/resources/augmentcollision/selfaugwithaug/module-a.yang
@@ -0,0 +1,30 @@
+module module-a {
+
+    namespace "urn:ietf:params:xml:ns:yang:module:a";
+
+    prefix mod-a;
+
+    container cont{
+        container valid {
+            leaf-list create {
+                type string;
+            }
+        }
+    }
+
+    augment "/cont" {
+        container val {
+            leaf arg {
+                type string;
+            }
+        }
+    }
+
+    augment "/mod-a:cont" {
+        container val {
+            leaf arg {
+                type string;
+            }
+        }
+    }
+}
diff --git a/compiler/plugin/maven/src/test/resources/augmentcollision/singleaugtotgt/module-a.yang b/compiler/plugin/maven/src/test/resources/augmentcollision/singleaugtotgt/module-a.yang
new file mode 100644
index 0000000..7bf9564
--- /dev/null
+++ b/compiler/plugin/maven/src/test/resources/augmentcollision/singleaugtotgt/module-a.yang
@@ -0,0 +1,18 @@
+module module-a {
+
+    namespace "urn:ietf:params:xml:ns:yang:module:a";
+
+    prefix mod-a;
+
+    import module-b {
+        prefix mod-b;
+    }
+
+    augment "/mod-b:cont" {
+        container val {
+            leaf arg {
+                type string;
+            }
+        }
+    }
+}
diff --git a/compiler/plugin/maven/src/test/resources/augmentcollision/singleaugtotgt/module-b.yang b/compiler/plugin/maven/src/test/resources/augmentcollision/singleaugtotgt/module-b.yang
new file mode 100644
index 0000000..6b377ac
--- /dev/null
+++ b/compiler/plugin/maven/src/test/resources/augmentcollision/singleaugtotgt/module-b.yang
@@ -0,0 +1,14 @@
+module module-b {
+
+    namespace "urn:ietf:params:xml:ns:yang:module:b";
+
+    prefix mod-b;
+
+    container cont{
+        container val {
+            leaf-list create {
+                type string;
+            }
+        }
+    }
+}
diff --git a/compiler/plugin/maven/src/test/resources/augmentcollision/singlesubmodtotgt/module-a.yang b/compiler/plugin/maven/src/test/resources/augmentcollision/singlesubmodtotgt/module-a.yang
new file mode 100644
index 0000000..7bf9564
--- /dev/null
+++ b/compiler/plugin/maven/src/test/resources/augmentcollision/singlesubmodtotgt/module-a.yang
@@ -0,0 +1,18 @@
+module module-a {
+
+    namespace "urn:ietf:params:xml:ns:yang:module:a";
+
+    prefix mod-a;
+
+    import module-b {
+        prefix mod-b;
+    }
+
+    augment "/mod-b:cont" {
+        container val {
+            leaf arg {
+                type string;
+            }
+        }
+    }
+}
diff --git a/compiler/plugin/maven/src/test/resources/augmentcollision/singlesubmodtotgt/module-b.yang b/compiler/plugin/maven/src/test/resources/augmentcollision/singlesubmodtotgt/module-b.yang
new file mode 100644
index 0000000..6b377ac
--- /dev/null
+++ b/compiler/plugin/maven/src/test/resources/augmentcollision/singlesubmodtotgt/module-b.yang
@@ -0,0 +1,14 @@
+module module-b {
+
+    namespace "urn:ietf:params:xml:ns:yang:module:b";
+
+    prefix mod-b;
+
+    container cont{
+        container val {
+            leaf-list create {
+                type string;
+            }
+        }
+    }
+}
diff --git a/compiler/plugin/maven/src/test/resources/augmentcollision/singlesubmodtotgt/submodule-a.yang b/compiler/plugin/maven/src/test/resources/augmentcollision/singlesubmodtotgt/submodule-a.yang
new file mode 100644
index 0000000..062f184
--- /dev/null
+++ b/compiler/plugin/maven/src/test/resources/augmentcollision/singlesubmodtotgt/submodule-a.yang
@@ -0,0 +1,18 @@
+submodule sub-module-a {
+
+    belongs-to "module-a" {
+        prefix "mod-a";
+    }
+
+    import module-b {
+        prefix mod-b;
+    }
+
+    augment "/mod-b:cont" {
+        container val {
+            leaf arg {
+                type string;
+            }
+        }
+    }
+}
diff --git a/compiler/plugin/maven/src/test/resources/augmentcollision/twoaugtotgt/module-a.yang b/compiler/plugin/maven/src/test/resources/augmentcollision/twoaugtotgt/module-a.yang
new file mode 100644
index 0000000..dd4c5b0
--- /dev/null
+++ b/compiler/plugin/maven/src/test/resources/augmentcollision/twoaugtotgt/module-a.yang
@@ -0,0 +1,18 @@
+module module-a {
+
+    namespace "urn:ietf:params:xml:ns:aug:module:a";
+
+    prefix mod-a;
+
+    import module-b {
+        prefix mod-b;
+    }
+
+    augment "/mod-b:cont" {
+        container val {
+            leaf arg {
+                type string;
+            }
+        }
+    }
+}
diff --git a/compiler/plugin/maven/src/test/resources/augmentcollision/twoaugtotgt/module-b.yang b/compiler/plugin/maven/src/test/resources/augmentcollision/twoaugtotgt/module-b.yang
new file mode 100644
index 0000000..ea7ce47
--- /dev/null
+++ b/compiler/plugin/maven/src/test/resources/augmentcollision/twoaugtotgt/module-b.yang
@@ -0,0 +1,14 @@
+module module-b {
+
+    namespace "urn:ietf:params:xml:ns:aug:module:b";
+
+    prefix mod-b;
+
+    container cont{
+        container val {
+            leaf-list create {
+                type string;
+            }
+        }
+    }
+}
diff --git a/compiler/plugin/maven/src/test/resources/augmentcollision/twoaugtotgt/module-c.yang b/compiler/plugin/maven/src/test/resources/augmentcollision/twoaugtotgt/module-c.yang
new file mode 100644
index 0000000..09fef2e
--- /dev/null
+++ b/compiler/plugin/maven/src/test/resources/augmentcollision/twoaugtotgt/module-c.yang
@@ -0,0 +1,18 @@
+module module-c {
+
+    namespace "urn:ietf:params:xml:ns:aug:module:c";
+
+    prefix mod-c;
+
+    import module-b {
+        prefix mod-b;
+    }
+
+    augment "/mod-b:cont" {
+        container val {
+            leaf arg {
+                type string;
+            }
+        }
+    }
+}
diff --git a/compiler/plugin/maven/src/test/resources/augmentcollision/twosubmodtotgt/module-a.yang b/compiler/plugin/maven/src/test/resources/augmentcollision/twosubmodtotgt/module-a.yang
new file mode 100644
index 0000000..1a4af5c
--- /dev/null
+++ b/compiler/plugin/maven/src/test/resources/augmentcollision/twosubmodtotgt/module-a.yang
@@ -0,0 +1,10 @@
+module module-a {
+
+    namespace "urn:ietf:params:xml:ns:yang:module:a";
+
+    prefix mod-a;
+
+    leaf a-leaf {
+        type uint8;
+    }
+}
diff --git a/compiler/plugin/maven/src/test/resources/augmentcollision/twosubmodtotgt/module-b.yang b/compiler/plugin/maven/src/test/resources/augmentcollision/twosubmodtotgt/module-b.yang
new file mode 100644
index 0000000..6b377ac
--- /dev/null
+++ b/compiler/plugin/maven/src/test/resources/augmentcollision/twosubmodtotgt/module-b.yang
@@ -0,0 +1,14 @@
+module module-b {
+
+    namespace "urn:ietf:params:xml:ns:yang:module:b";
+
+    prefix mod-b;
+
+    container cont{
+        container val {
+            leaf-list create {
+                type string;
+            }
+        }
+    }
+}
diff --git a/compiler/plugin/maven/src/test/resources/augmentcollision/twosubmodtotgt/submodule-a-2.yang b/compiler/plugin/maven/src/test/resources/augmentcollision/twosubmodtotgt/submodule-a-2.yang
new file mode 100644
index 0000000..e3c8b9a
--- /dev/null
+++ b/compiler/plugin/maven/src/test/resources/augmentcollision/twosubmodtotgt/submodule-a-2.yang
@@ -0,0 +1,18 @@
+submodule sub-module-a2 {
+
+    belongs-to "module-a" {
+        prefix "mod-a";
+    }
+
+    import module-b {
+        prefix mod-b;
+    }
+
+    augment "/mod-b:cont" {
+        container val {
+            leaf arg {
+                type string;
+            }
+        }
+    }
+}
diff --git a/compiler/plugin/maven/src/test/resources/augmentcollision/twosubmodtotgt/submodule-a.yang b/compiler/plugin/maven/src/test/resources/augmentcollision/twosubmodtotgt/submodule-a.yang
new file mode 100644
index 0000000..062f184
--- /dev/null
+++ b/compiler/plugin/maven/src/test/resources/augmentcollision/twosubmodtotgt/submodule-a.yang
@@ -0,0 +1,18 @@
+submodule sub-module-a {
+
+    belongs-to "module-a" {
+        prefix "mod-a";
+    }
+
+    import module-b {
+        prefix mod-b;
+    }
+
+    augment "/mod-b:cont" {
+        container val {
+            leaf arg {
+                type string;
+            }
+        }
+    }
+}
diff --git a/compiler/plugin/maven/src/test/resources/rpcAugment/intra/all.yang b/compiler/plugin/maven/src/test/resources/rpcAugment/intra/all.yang
index 6fc76ea..b377a7c 100644
--- a/compiler/plugin/maven/src/test/resources/rpcAugment/intra/all.yang
+++ b/compiler/plugin/maven/src/test/resources/rpcAugment/intra/all.yang
@@ -95,7 +95,7 @@
     }           
   
     augment /get-port/input {
-       leaf port {
+       leaf port-n {
            type int32;
         }
     }