Merge "[ONOS-5631] YANG tool independent of tool chain"
diff --git a/generator/src/main/java/org/onosproject/yangutils/utils/io/YangPluginConfig.java b/generator/src/main/java/org/onosproject/yangutils/utils/io/YangPluginConfig.java
index 86e4500..f02ed1a 100644
--- a/generator/src/main/java/org/onosproject/yangutils/utils/io/YangPluginConfig.java
+++ b/generator/src/main/java/org/onosproject/yangutils/utils/io/YangPluginConfig.java
@@ -47,6 +47,13 @@
     private String codeGenerateForSbi;
 
     /**
+     * Path to generate the resource files, which will be used by the  plugin
+     * to add it as part of the resource, implicitly by the path location, or
+     * some explicit way to add to bundle.
+     */
+    private String resourceGenDir;
+
+    /**
      * Creates an object for YANG plugin config.
      */
     public YangPluginConfig() {
@@ -106,7 +113,18 @@
         return conflictResolver;
     }
 
+
+    public String resourceGenDir() {
+        return resourceGenDir;
+    }
+
+    public void resourceGenDir(String resourceGenDir) {
+        this.resourceGenDir = resourceGenDir;
+    }
+
     /**
+     * TODO: delete me, it is not part of config, it needs to be updated for
+     * test scripts
      * Compiles the generated code for unit tests.
      *
      * @param dir1 directory path
diff --git a/plugin/maven/pom.xml b/plugin/maven/pom.xml
index 572b1d6..9ad8b88 100644
--- a/plugin/maven/pom.xml
+++ b/plugin/maven/pom.xml
@@ -89,6 +89,16 @@
             <version>4.12</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-yang-tool</artifactId>
+            <version>1.10-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-yang-utils-parser</artifactId>
+            <version>1.10-SNAPSHOT</version>
+        </dependency>
     </dependencies>
 
     <build>
diff --git a/plugin/maven/src/main/java/org/onosproject/yangutils/plugin/manager/YangPluginUtils.java b/plugin/maven/src/main/java/org/onosproject/yangutils/plugin/manager/YangPluginUtils.java
index 9f461b6..82b1901 100644
--- a/plugin/maven/src/main/java/org/onosproject/yangutils/plugin/manager/YangPluginUtils.java
+++ b/plugin/maven/src/main/java/org/onosproject/yangutils/plugin/manager/YangPluginUtils.java
@@ -18,33 +18,29 @@
 
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.model.Dependency;
+import org.apache.maven.model.Plugin;
 import org.apache.maven.model.Resource;
 import org.apache.maven.project.MavenProject;
 import org.onosproject.yangutils.datamodel.YangNode;
 import org.slf4j.Logger;
 import org.sonatype.plexus.build.incremental.BuildContext;
 
-import java.io.BufferedReader;
 import java.io.File;
-import java.io.FileOutputStream;
-import java.io.FileReader;
 import java.io.IOException;
-import java.io.ObjectOutputStream;
-import java.nio.file.Files;
-import java.nio.file.StandardCopyOption;
+import java.io.PrintWriter;
 import java.util.ArrayList;
-import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Set;
 
 import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.parseJarFile;
+import static org.onosproject.yangutils.tool.YangToolManager.DEFAULT_JAR_RES_PATH;
+import static org.onosproject.yangutils.utils.UtilConstants.COLON;
+import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
 import static org.onosproject.yangutils.utils.UtilConstants.HYPHEN;
 import static org.onosproject.yangutils.utils.UtilConstants.JAR;
 import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
 import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
 import static org.onosproject.yangutils.utils.UtilConstants.TEMP;
-import static org.onosproject.yangutils.utils.UtilConstants.YANG_RESOURCES;
 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPackageDirPathFromJavaJPackage;
 import static org.slf4j.LoggerFactory.getLogger;
 
@@ -54,10 +50,10 @@
 public final class YangPluginUtils {
 
     private static final Logger log = getLogger(YangPluginUtils.class);
-    private static final String TARGET_RESOURCE_PATH = SLASH + TEMP + SLASH +
-            YANG_RESOURCES + SLASH;
-    private static final String SERIALIZED_FILE_EXTENSION = ".ser";
-    private static final String YANG_META_DATA = "YangMetaData";
+
+    private static final String TEXT_FILE_EXTENSION = ".txt";
+    private static final String VERSION_META_DATA = "VersionMetaData";
+    private static final String PLUGIN_ARTIFACT = "onos-yang-maven-plugin";
 
     private YangPluginUtils() {
     }
@@ -69,8 +65,7 @@
      * @param project current maven project
      * @param context current build context
      */
-    static void addToCompilationRoot(String source, MavenProject project,
-                                     BuildContext context) {
+    static void addToCompilationRoot(String source, MavenProject project, BuildContext context) {
         project.addCompileSourceRoot(source);
         context.refresh(project.getBasedir());
         log.info("Source directory added to compilation root: " + source);
@@ -79,100 +74,96 @@
     /**
      * Copies YANG files to the current project's output directory.
      *
-     * @param yangFileInfo list of YANG files
-     * @param outputDir    project's output directory
-     * @param project      maven project
+     * @param outputDir project's output directory
+     * @param project   maven project
      * @throws IOException when fails to copy files to destination resource directory
      */
-    static void copyYangFilesToTarget(Set<YangFileInfo> yangFileInfo,
-                                      String outputDir, MavenProject project)
+    static void copyYangFilesToTarget(String outputDir, MavenProject project)
             throws IOException {
 
-        List<File> files = getListOfFile(yangFileInfo);
-        String path = outputDir + TARGET_RESOURCE_PATH;
-        File targetDir = new File(path);
-        targetDir.mkdirs();
-        for (File file : files) {
-            Files.copy(file.toPath(),
-                       new File(path + file.getName()).toPath(),
-                       StandardCopyOption.REPLACE_EXISTING);
-        }
         addToProjectResource(outputDir + SLASH + TEMP + SLASH, project);
     }
 
     /**
-     * Provides a list of files from list of strings.
-     *
-     * @param yangFileInfo set of yang file information
-     * @return list of files
-     */
-    private static List<File> getListOfFile(Set<YangFileInfo> yangFileInfo) {
-        List<File> files = new ArrayList<>();
-        Iterator<YangFileInfo> yangFileIterator = yangFileInfo.iterator();
-        while (yangFileIterator.hasNext()) {
-            YangFileInfo yangFile = yangFileIterator.next();
-            if (yangFile.isForTranslator()) {
-                files.add(new File(yangFile.getYangFileName()));
-            }
-        }
-        return files;
-    }
-
-    /**
      * Serializes data-model.
      *
-     * @param dir       base directory for serialized files
-     * @param fileSet   YANG file info set
+     * @param directory base directory for serialized files
      * @param project   maven project
      * @param operation true if need to add to resource
      * @throws IOException when fails to do IO operations
      */
-    public static void serializeDataModel(String dir, Set<YangFileInfo> fileSet,
-                                          MavenProject project, boolean operation)
+    public static void serializeDataModel(String directory,
+                                          MavenProject project,
+                                          boolean operation)
             throws IOException {
-        String serFileDirPath = dir + TARGET_RESOURCE_PATH;
-        File dir1 = new File(serFileDirPath);
-        dir1.mkdirs();
+
+        String serFileDirPath = directory + DEFAULT_JAR_RES_PATH;
+        File dir = new File(serFileDirPath);
+        dir.mkdirs();
+
         if (operation) {
-            addToProjectResource(dir + SLASH + TEMP + SLASH, project);
-        }
-        Set<YangNode> nodes = new HashSet<>();
-        for (YangFileInfo fileInfo : fileSet) {
-            nodes.add(fileInfo.getRootNode());
+            addToProjectResource(directory + SLASH + TEMP + SLASH, project);
         }
 
-        String serFileName = serFileDirPath + YANG_META_DATA +
-                SERIALIZED_FILE_EXTENSION;
-        FileOutputStream out = new FileOutputStream(serFileName);
-        ObjectOutputStream objectOutputStream = new ObjectOutputStream(out);
-        objectOutputStream.writeObject(nodes);
-        objectOutputStream.close();
+        if (operation) {
+            addVersionMetaDataFile(project, serFileDirPath);
+        }
+    }
+
+    /**
+     * Adds version meta data files for YSR to know version of YANG tools.
+     *
+     * @param project maven project
+     * @param dir     directory
+     * @throws IOException when fails to do IO operations
+     */
+    private static void addVersionMetaDataFile(MavenProject project, String dir)
+            throws IOException {
+        List<Plugin> plugins = project.getBuildPlugins();
+        Iterator<Plugin> it = plugins.iterator();
+        Plugin plugin = it.next();
+        String data = EMPTY_STRING;
+        while (it.hasNext()) {
+            if (plugin.getArtifactId().equals(PLUGIN_ARTIFACT)) {
+                data = plugin.getGroupId() + COLON + plugin.getArtifactId()
+                        + COLON + plugin.getVersion();
+            }
+            plugin = it.next();
+        }
+        if (data.equals(EMPTY_STRING)) {
+            throw new IOException("Invalid artifact for " + PLUGIN_ARTIFACT);
+        }
+        String verFileName = dir + VERSION_META_DATA + TEXT_FILE_EXTENSION;
+        PrintWriter out = new PrintWriter(verFileName);
+        out.print(data);
         out.close();
     }
 
     /**
      * Returns list of jar path.
      *
-     * @param project     maven project
-     * @param localRepo   local repository
-     * @param remoteRepos remote repository
+     * @param project         maven project
+     * @param localRepository local repository
+     * @param remoteRepos     remote repository
      * @return list of jar paths
      */
-    private static List<String> resolveDependencyJarPath(
-            MavenProject project, ArtifactRepository localRepo,
-            List<ArtifactRepository> remoteRepos) {
+    private static List<String> resolveDependencyJarPath(MavenProject project, ArtifactRepository localRepository,
+                                                         List<ArtifactRepository> remoteRepos) {
 
         StringBuilder path = new StringBuilder();
         List<String> jarPaths = new ArrayList<>();
         for (Object obj : project.getDependencies()) {
 
             Dependency dependency = (Dependency) obj;
-            path.append(localRepo.getBasedir()).append(SLASH)
-                    .append(getPackageDirPathFromJavaJPackage(dependency.getGroupId()))
-                    .append(SLASH).append(dependency.getArtifactId())
-                    .append(SLASH).append(dependency.getVersion()).append(SLASH)
-                    .append(dependency.getArtifactId()).append(HYPHEN)
-                    .append(dependency.getVersion()).append(PERIOD).append(JAR);
+            path.append(localRepository.getBasedir());
+            path.append(SLASH);
+            path.append(getPackageDirPathFromJavaJPackage(dependency.getGroupId()));
+            path.append(SLASH);
+            path.append(dependency.getArtifactId());
+            path.append(SLASH);
+            path.append(dependency.getVersion());
+            path.append(SLASH);
+            path.append(dependency.getArtifactId() + HYPHEN + dependency.getVersion() + PERIOD + JAR);
             File jarFile = new File(path.toString());
             if (jarFile.exists()) {
                 jarPaths.add(path.toString());
@@ -189,23 +180,21 @@
     /**
      * Resolves inter jar dependencies.
      *
-     * @param project     current maven project
-     * @param localRepo   local maven repository
-     * @param remoteRepos list of remote repository
-     * @param dir         directory for serialized files
+     * @param project         current maven project
+     * @param localRepository local maven repository
+     * @param remoteRepos     list of remote repository
+     * @param directory       directory for serialized files
      * @return list of resolved datamodel nodes
      * @throws IOException when fails to do IO operations
      */
-    static List<YangNode> resolveInterJarDependencies(
-            MavenProject project, ArtifactRepository localRepo,
-            List<ArtifactRepository> remoteRepos, String dir)
+    static List<YangNode> resolveInterJarDependencies(MavenProject project, ArtifactRepository localRepository,
+                                                      List<ArtifactRepository> remoteRepos, String directory)
             throws IOException {
 
-        List<String> dependenciesJarPaths =
-                resolveDependencyJarPath(project, localRepo, remoteRepos);
+        List<String> dependenciesJarPaths = resolveDependencyJarPath(project, localRepository, remoteRepos);
         List<YangNode> resolvedDataModelNodes = new ArrayList<>();
         for (String dependency : dependenciesJarPaths) {
-            resolvedDataModelNodes.addAll(parseJarFile(dependency, dir));
+            resolvedDataModelNodes.addAll(parseJarFile(dependency, directory));
         }
         return resolvedDataModelNodes;
     }
diff --git a/plugin/maven/src/main/java/org/onosproject/yangutils/plugin/manager/YangUtilManager.java b/plugin/maven/src/main/java/org/onosproject/yangutils/plugin/manager/YangUtilManager.java
index ba0f6fd..1e38d88 100644
--- a/plugin/maven/src/main/java/org/onosproject/yangutils/plugin/manager/YangUtilManager.java
+++ b/plugin/maven/src/main/java/org/onosproject/yangutils/plugin/manager/YangUtilManager.java
@@ -34,6 +34,10 @@
 import org.onosproject.yangutils.parser.YangUtilsParser;
 import org.onosproject.yangutils.parser.exceptions.ParserException;
 import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
+import org.onosproject.yangutils.tool.CallablePlugin;
+import org.onosproject.yangutils.tool.YangFileInfo;
+import org.onosproject.yangutils.tool.YangToolManager;
+import org.onosproject.yangutils.tool.exception.YangToolException;
 import org.onosproject.yangutils.utils.io.YangPluginConfig;
 import org.onosproject.yangutils.utils.io.YangToJavaNamingConflictUtil;
 import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
@@ -55,8 +59,8 @@
 import static org.onosproject.yangutils.plugin.manager.YangPluginUtils.copyYangFilesToTarget;
 import static org.onosproject.yangutils.plugin.manager.YangPluginUtils.resolveInterJarDependencies;
 import static org.onosproject.yangutils.plugin.manager.YangPluginUtils.serializeDataModel;
+import static org.onosproject.yangutils.tool.YangToolManager.DEFAULT_JAR_RES_PATH;
 import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode;
-import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.translatorErrorHandler;
 import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_BASE_PKG;
 import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
 import static org.onosproject.yangutils.utils.UtilConstants.IN;
@@ -78,7 +82,7 @@
  */
 @Mojo(name = "yang2java", defaultPhase = PROCESS_SOURCES,
         requiresDependencyResolution = COMPILE)
-public class YangUtilManager extends AbstractMojo {
+public class YangUtilManager extends AbstractMojo implements CallablePlugin {
 
     private static final String DEFAULT_PKG =
             getPackageDirPathFromJavaJPackage(DEFAULT_BASE_PKG);
@@ -211,52 +215,45 @@
             yangPlugin.setCodeGenDir(codeGenDir);
             yangPlugin.setConflictResolver(conflictResolver);
 
+            yangPlugin.resourceGenDir(outputDir + DEFAULT_JAR_RES_PATH);
             yangPlugin.setCodeGenerateForSbi(generateJavaFileForSbi.toLowerCase());
+
             /*
              * Obtain the YANG files at a path mentioned in plugin and creates
              * YANG file information set.
              */
             createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
 
-            // Check if there are any file to translate, if not return.
-            if (yangFileInfoSet == null || yangFileInfoSet.isEmpty()) {
-                // No files to translate
-                return;
-            }
-            // Resolve inter jar dependency.
-            resolveInterJarDependency();
+            YangToolManager toolManager = new YangToolManager();
+            List<YangNode> interJarResolvedNodes =
+                    resolveInterJarDependencies(project, localRepository,
+                                                remoteRepository, outputDir);
+            System.out.println("going to call tool manager");
+            toolManager.compileYangFiles(yangFileInfoSet,
+                                         interJarResolvedNodes, yangPlugin,
+                                         this);
+            System.out.println("called tool manager");
 
-            // Carry out the parsing for all the YANG files.
-            parseYangFileInfoSet();
 
-            // Resolve dependencies using linker.
-            resolveDependenciesUsingLinker();
-
-            // Perform translation to JAVA.
-            translateToJava(yangPlugin);
-
-            // Serialize data model.
-            serializeDataModel(outputDir, yangFileInfoSet, project, true);
-            addToCompilationRoot(codeGenDir, project, context);
-
-            copyYangFilesToTarget(yangFileInfoSet, outputDir, project);
-        } catch (IOException | ParserException e) {
+        } catch (YangToolException e) {
             String fileName = EMPTY_STRING;
-            if (curYangFileInfo != null) {
-                fileName = curYangFileInfo.getYangFileName();
+            if (e.getCurYangFile() != null) {
+                fileName = e.getCurYangFile().getYangFileName();
             }
             try {
-                translatorErrorHandler(rootNode, yangPlugin);
                 deleteDirectory(codeGenDir + DEFAULT_PKG);
             } catch (IOException ex) {
                 e.printStackTrace();
                 throw new MojoExecutionException(
                         "Error handler failed to delete files for data model node.");
             }
-            getLog().info(e);
+            getLog().info(e.getCause());
             throw new MojoExecutionException(
                     "Exception occurred due to " + e.getLocalizedMessage() +
                             IN + fileName + " YANG file.");
+        } catch (IOException e) {
+            throw new MojoExecutionException(
+                    "Failed to process files");
         }
     }
 
@@ -282,30 +279,7 @@
     }
 
     /**
-     * Resolved inter-jar dependencies.
-     *
-     * @throws IOException when fails to do IO operations
-     */
-    private void resolveInterJarDependency()
-            throws IOException {
-        try {
-            List<YangNode> interJarResolvedNodes =
-                    resolveInterJarDependencies(project, localRepository,
-                                                remoteRepository, outputDir);
-            for (YangNode node : interJarResolvedNodes) {
-                YangFileInfo dependentFileInfo = new YangFileInfo();
-                node.setToTranslate(false);
-                dependentFileInfo.setRootNode(node);
-                dependentFileInfo.setForTranslator(false);
-                dependentFileInfo.setYangFileName(node.getName());
-                yangFileInfoSet.add(dependentFileInfo);
-            }
-        } catch (IOException e) {
-            throw new IOException("failed to resolve in inter-jar scenario.");
-        }
-    }
-
-    /**
+     * TODO: Delete me and use the tool code for UT test cases
      * Links all the provided with the YANG file info set.
      *
      * @throws MojoExecutionException a violation in mojo execution
@@ -323,15 +297,17 @@
     }
 
     /**
+     * TODO: Delete me and use the tool code for UT test cases
      * Creates YANG nodes set.
      */
-    public void createYangNodeSet() {
+    protected void createYangNodeSet() {
         for (YangFileInfo yangFileInfo : yangFileInfoSet) {
             yangNodeSet.add(yangFileInfo.getRootNode());
         }
     }
 
     /**
+     * TODO: Delete me and use the tool code for UT test cases
      * Parses all the provided YANG files and generates YANG data model tree.
      *
      * @throws IOException a violation in IO
@@ -368,6 +344,7 @@
     }
 
     /**
+     * TODO: Delete me and use the tool code for UT test cases
      * Translates to java code corresponding to the YANG schema.
      *
      * @param yangPlugin YANG plugin config
@@ -399,6 +376,7 @@
     }
 
     /**
+     * TODO: Delete me and use the tool code for UT test cases
      * Returns the YANG file info set.
      *
      * @return the YANG file info set
@@ -408,6 +386,7 @@
     }
 
     /**
+     * TODO: Delete me and use the tool code for UT test cases
      * Sets the YANG file info set.
      *
      * @param yangFileInfoSet the YANG file info set
@@ -439,4 +418,19 @@
         getLog().info(logInfo);
     }
 
+    @Override
+    public void addGeneratedCodeToBundle() {
+        addToCompilationRoot(codeGenDir, project, context);
+    }
+
+
+    @Override
+    public void addCompiledSchemaToBundle() throws IOException {
+        serializeDataModel(outputDir, project, true);
+    }
+
+    @Override
+    public void addYangFilesToBundle() throws IOException {
+        copyYangFilesToTarget(outputDir, project);
+    }
 }
diff --git a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/InterJarLinkerTest.java b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/InterJarLinkerTest.java
index e80bf0b..e2e704c 100644
--- a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/InterJarLinkerTest.java
+++ b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/InterJarLinkerTest.java
@@ -18,23 +18,17 @@
 
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.project.MavenProject;
-import org.junit.Test;
-import org.onosproject.yangutils.datamodel.YangContainer;
-import org.onosproject.yangutils.datamodel.YangDerivedInfo;
-import org.onosproject.yangutils.datamodel.YangGrouping;
-import org.onosproject.yangutils.datamodel.YangLeaf;
 import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.utils.io.YangPluginConfig;
-import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
+import org.onosproject.yangutils.tool.YangFileInfo;
 
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
-import java.util.ListIterator;
 import java.util.Set;
 import java.util.jar.JarEntry;
 import java.util.jar.JarOutputStream;
@@ -42,15 +36,10 @@
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.core.Is.is;
 import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.parseJarFile;
-import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.RESOLVED;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DERIVED;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.STRING;
 import static org.onosproject.yangutils.plugin.manager.YangPluginUtils.serializeDataModel;
 import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
 import static org.onosproject.yangutils.utils.UtilConstants.TEMP;
 import static org.onosproject.yangutils.utils.UtilConstants.YANG_RESOURCES;
-import static org.onosproject.yangutils.utils.io.impl.YangFileScanner.getYangFiles;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
 
 /**
  * Unit test case for inter jar linker.
@@ -76,118 +65,119 @@
      * @throws IOException            when fails to do IO operations
      * @throws MojoExecutionException when fails to do mojo operations
      */
-    @Test
-    public void processSingleJarLinking()
-            throws IOException, MojoExecutionException {
-        utilManager.createYangFileInfoSet(getYangFiles(YANG_FILES_DIR));
-        Set<YangFileInfo> info = utilManager.getYangFileInfoSet();
-        int size1 = info.size();
-        utilManager.parseYangFileInfoSet();
-
-        mockJarFileProvider.provideTestJarFile(utilManager);
-        utilManager.setYangFileInfoSet(removeFileInfoFromSet(info));
-        utilManager.resolveDependenciesUsingLinker();
-
-        int size2 = info.size();
-        assertThat(true, is(size1 != size2));
-        assertThat(true, is(parseFileInfoSet(info.iterator())));
-
-        deleteDirectory(TARGET);
-        mockJarFileProvider.deleteTestSerFile(YANG_FILES_DIR);
-    }
-
-    /**
-     * Unit test case for a multiple jar dependency.
-     *
-     * @throws IOException            when fails to do IO operations
-     * @throws MojoExecutionException when fails to do mojo operations
-     */
-    @Test
-    public void processMultipleJarLinking()
-            throws IOException, MojoExecutionException {
-        utilManager.createYangFileInfoSet(getYangFiles(YANG_FILES_DIR));
-
-        Set<YangFileInfo> info = utilManager.getYangFileInfoSet();
-        int size1 = info.size();
-        utilManager.parseYangFileInfoSet();
-
-        mockJarFileProvider.provideTestJarFile(utilManager);
-        utilManager.setYangFileInfoSet(removeFileInfoFromSet(info));
-
-        utilManager.resolveDependenciesUsingLinker();
-        int size2 = info.size();
-        assertThat(true, is(size1 != size2));
-        assertThat(true, is(parseFileInfoSet(info.iterator())));
-        assertThat(true, is(parseFileInfoSet(info.iterator())));
-
-        /*
-         * grouping flow-classifier {
-         *      container flow-classifier {
-         *           leaf id {
-         *                type flow-classifier-id;
-         *           }
-         *
-         *           leaf tenant-id {
-         *                type port-pair:tenant-id;
-         *           }
-         *           .
-         *           .
-         *           .
-         *
-         */
-
-        Iterator<YangFileInfo> yangFileInfoIterator = info.iterator();
-
-        YangFileInfo yangFileInfo = yangFileInfoIterator.next();
-
-        while (yangFileInfoIterator.hasNext()) {
-            if (yangFileInfo.getRootNode().getName().equals("flow-classifier")) {
-                break;
-            }
-            yangFileInfo = yangFileInfoIterator.next();
-        }
-
-        YangNode node = yangFileInfo.getRootNode();
-        node = node.getChild();
-        while (node != null) {
-            if (node instanceof YangGrouping) {
-                break;
-            }
-            node = node.getNextSibling();
-        }
-
-        node = node.getChild();
-        ListIterator<YangLeaf> leafIterator = ((YangContainer) node).getListOfLeaf().listIterator();
-        YangLeaf leafInfo = leafIterator.next();
-
-        assertThat(leafInfo.getName(), is("id"));
-        assertThat(leafInfo.getDataType().getDataTypeName(), is("flow-classifier-id"));
-        assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
-
-        leafInfo = leafIterator.next();
-
-        assertThat(leafInfo.getName(), is("tenant-id"));
-        assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
-
-        assertThat(true, is(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef()
-                                    .getName().equals("tenant-id")));
-
-        assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED));
-
-        YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo();
-
-        // Check for the effective built-in type.
-        assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING));
-
-        YangPluginConfig yangPluginConfig = new YangPluginConfig();
-        yangPluginConfig.setCodeGenDir(TARGET);
-
-        utilManager.translateToJava(yangPluginConfig);
-        testIfFlowClassifierFilesExists();
-        testIfPortPairFileDoesNotExist();
-        deleteDirectory(TARGET);
-        mockJarFileProvider.deleteTestSerFile(YANG_FILES_DIR);
-    }
+//TODO: FIX the interJAR test case for using toolmanger instead of plugin mgr
+    //    @Test
+//    public void processSingleJarLinking()
+//            throws IOException, MojoExecutionException {
+//        utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(YANG_FILES_DIR));
+//        Set<YangFileInfo> info = utilManager.getYangFileInfoSet();
+//        int size1 = info.size();
+//        utilManager.parseYangFileInfoSet();
+//
+//        mockJarFileProvider.provideTestJarFile(utilManager);
+//        utilManager.setYangFileInfoSet(removeFileInfoFromSet(info));
+//        utilManager.resolveDependenciesUsingLinker();
+//
+//        int size2 = info.size();
+//        assertThat(true, is(size1 != size2));
+//        assertThat(true, is(parseFileInfoSet(info.iterator())));
+//
+//        deleteDirectory(TARGET);
+//        mockJarFileProvider.deleteTestSerFile(YANG_FILES_DIR);
+//    }
+//
+//    /**
+//     * Unit test case for a multiple jar dependency.
+//     *
+//     * @throws IOException            when fails to do IO operations
+//     * @throws MojoExecutionException when fails to do mojo operations
+//     */
+//    @Test
+//    public void processMultipleJarLinking()
+//            throws IOException, MojoExecutionException {
+//        utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(YANG_FILES_DIR));
+//
+//        Set<YangFileInfo> info = utilManager.getYangFileInfoSet();
+//        int size1 = info.size();
+//        utilManager.parseYangFileInfoSet();
+//
+//        mockJarFileProvider.provideTestJarFile(utilManager);
+//        utilManager.setYangFileInfoSet(removeFileInfoFromSet(info));
+//
+//        utilManager.resolveDependenciesUsingLinker();
+//        int size2 = info.size();
+//        assertThat(true, is(size1 != size2));
+//        assertThat(true, is(parseFileInfoSet(info.iterator())));
+//        assertThat(true, is(parseFileInfoSet(info.iterator())));
+//
+//        /*
+//         * grouping flow-classifier {
+//         *      container flow-classifier {
+//         *           leaf id {
+//         *                type flow-classifier-id;
+//         *           }
+//         *
+//         *           leaf tenant-id {
+//         *                type port-pair:tenant-id;
+//         *           }
+//         *           .
+//         *           .
+//         *           .
+//         *
+//         */
+//
+//        Iterator<YangFileInfo> yangFileInfoIterator = info.iterator();
+//
+//        YangFileInfo yangFileInfo = yangFileInfoIterator.next();
+//
+//        while (yangFileInfoIterator.hasNext()) {
+//            if (yangFileInfo.getRootNode().getName().equals("flow-classifier")) {
+//                break;
+//            }
+//            yangFileInfo = yangFileInfoIterator.next();
+//        }
+//
+//        YangNode node = yangFileInfo.getRootNode();
+//        node = node.getChild();
+//        while (node != null) {
+//            if (node instanceof YangGrouping) {
+//                break;
+//            }
+//            node = node.getNextSibling();
+//        }
+//
+//        node = node.getChild();
+//        ListIterator<YangLeaf> leafIterator = ((YangContainer) node).getListOfLeaf().listIterator();
+//        YangLeaf leafInfo = leafIterator.next();
+//
+//        assertThat(leafInfo.getName(), is("id"));
+//        assertThat(leafInfo.getDataType().getDataTypeName(), is("flow-classifier-id"));
+//        assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
+//
+//        leafInfo = leafIterator.next();
+//
+//        assertThat(leafInfo.getName(), is("tenant-id"));
+//        assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
+//
+//        assertThat(true, is(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef()
+//                                    .getName().equals("tenant-id")));
+//
+//        assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED));
+//
+//        YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo();
+//
+//        // Check for the effective built-in type.
+//        assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING));
+//
+//        YangPluginConfig yangPluginConfig = new YangPluginConfig();
+//        yangPluginConfig.setCodeGenDir(TARGET);
+//
+//        utilManager.translateToJava(yangPluginConfig);
+//        testIfFlowClassifierFilesExists();
+//        testIfPortPairFileDoesNotExist();
+//        deleteDirectory(TARGET);
+//        mockJarFileProvider.deleteTestSerFile(YANG_FILES_DIR);
+//    }
 
     /**
      * Test if flow classifier code is generated.
@@ -270,8 +260,14 @@
         void provideTestJarFile(YangUtilManager utilManager) throws IOException {
 
             Set<YangFileInfo> info = utilManager.getYangFileInfoSet();
+
+            Set<YangNode> compiledSchemas = new HashSet<>();
+            for (YangFileInfo fileInfo : info) {
+                compiledSchemas.add(fileInfo.getRootNode());
+            }
+
             MavenProject project = new MavenProject();
-            serializeDataModel(TARGET, info, project, false);
+            serializeDataModel(TARGET, project, false);
             createTestJar();
 
             for (String file : getListOfTestJar(TARGET)) {
diff --git a/plugin/pom.xml b/plugin/pom.xml
index fe8a014..d3526bd 100644
--- a/plugin/pom.xml
+++ b/plugin/pom.xml
@@ -33,6 +33,7 @@
     </properties>
 
     <modules>
+        <module>tool</module>
         <module>maven</module>
         <module>buck</module>
     </modules>
diff --git a/plugin/tool/pom.xml b/plugin/tool/pom.xml
new file mode 100644
index 0000000..b0209a2
--- /dev/null
+++ b/plugin/tool/pom.xml
@@ -0,0 +1,61 @@
+<!--
+  ~ Copyright 2016-present Open Networking Laboratory
+  ~
+  ~ Licensed under the Apache License, Version 2.0 (the "License");
+  ~ you may not use this file except in compliance with the License.
+  ~ You may obtain a copy of the License at
+  ~
+  ~     http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.onosproject</groupId>
+        <artifactId>onos-yang-plugins</artifactId>
+        <version>1.10-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>onos-yang-tool</artifactId>
+    <version>1.10-SNAPSHOT</version>
+    <packaging>jar</packaging>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+            <version>1.7.21</version>
+            <scope>provided</scope>
+        </dependency>
+    </dependencies>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-jar-plugin</artifactId>
+                <version>3.0.2</version>
+                <configuration>
+                    <skipIfEmpty>true</skipIfEmpty>
+                </configuration>
+                <executions>
+                    <execution>
+                        <id>default</id>
+                        <goals>
+                            <goal>test-jar</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+</project>
diff --git a/plugin/tool/src/main/java/org/onosproject/yangutils/tool/CallablePlugin.java b/plugin/tool/src/main/java/org/onosproject/yangutils/tool/CallablePlugin.java
new file mode 100644
index 0000000..3f44863
--- /dev/null
+++ b/plugin/tool/src/main/java/org/onosproject/yangutils/tool/CallablePlugin.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.tool;
+
+import java.io.IOException;
+
+/**
+ * Abstractions of the hooks that needs to be supported by plugins, which
+ * will be used in by tool to be plugin agnostic.
+ */
+public interface CallablePlugin {
+    /**
+     * Adds generated source directory to the compilation root.
+     */
+    void addGeneratedCodeToBundle();
+
+    /**
+     * serialize the compiled schema and place it in the appropriate location
+     * so that it will be part of the generated OSGi bundle.
+     *
+     */
+    void addCompiledSchemaToBundle()
+            throws IOException;
+
+
+    /**
+     * Add the YANG files in the bundle, to support YANG display in protocols
+     * like RESTCONF.
+     *
+     */
+    void addYangFilesToBundle() throws IOException;
+}
diff --git a/plugin/tool/src/main/java/org/onosproject/yangutils/tool/ToolConstants.java b/plugin/tool/src/main/java/org/onosproject/yangutils/tool/ToolConstants.java
new file mode 100644
index 0000000..1c04358
--- /dev/null
+++ b/plugin/tool/src/main/java/org/onosproject/yangutils/tool/ToolConstants.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.tool;
+
+/**
+ * Represents common constant utility for YANG tool.
+ */
+final class ToolConstants {
+    private ToolConstants() {
+
+    }
+
+    static final String E_MISSING_INPUT = "Missing extected input ";
+    static final String E_CODE_GEN_PATH = "Missing plugin code gen directory";
+}
diff --git a/plugin/maven/src/main/java/org/onosproject/yangutils/plugin/manager/YangFileInfo.java b/plugin/tool/src/main/java/org/onosproject/yangutils/tool/YangFileInfo.java
similarity index 97%
rename from plugin/maven/src/main/java/org/onosproject/yangutils/plugin/manager/YangFileInfo.java
rename to plugin/tool/src/main/java/org/onosproject/yangutils/tool/YangFileInfo.java
index a0f1b1d..0959c34 100644
--- a/plugin/maven/src/main/java/org/onosproject/yangutils/plugin/manager/YangFileInfo.java
+++ b/plugin/tool/src/main/java/org/onosproject/yangutils/tool/YangFileInfo.java
@@ -14,12 +14,12 @@
  * limitations under the License.
  */
 
-package org.onosproject.yangutils.plugin.manager;
-
-import java.util.Objects;
+package org.onosproject.yangutils.tool;
 
 import org.onosproject.yangutils.datamodel.YangNode;
 
+import java.util.Objects;
+
 /**
  * Represents YANG file information.
  */
diff --git a/plugin/tool/src/main/java/org/onosproject/yangutils/tool/YangToolManager.java b/plugin/tool/src/main/java/org/onosproject/yangutils/tool/YangToolManager.java
new file mode 100644
index 0000000..0853775
--- /dev/null
+++ b/plugin/tool/src/main/java/org/onosproject/yangutils/tool/YangToolManager.java
@@ -0,0 +1,316 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.tool;
+
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangReferenceResolver;
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.linker.YangLinker;
+import org.onosproject.yangutils.linker.exceptions.LinkerException;
+import org.onosproject.yangutils.linker.impl.YangLinkerManager;
+import org.onosproject.yangutils.parser.YangUtilsParser;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
+import org.onosproject.yangutils.tool.exception.YangToolException;
+import org.onosproject.yangutils.utils.io.YangPluginConfig;
+import org.slf4j.Logger;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+import java.nio.file.Files;
+import java.nio.file.StandardCopyOption;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+
+import static java.util.Collections.sort;
+import static org.onosproject.yangutils.datamodel.ResolvableType.YANG_DERIVED_DATA_TYPE;
+import static org.onosproject.yangutils.datamodel.ResolvableType.YANG_IDENTITYREF;
+import static org.onosproject.yangutils.linker.impl.YangLinkerUtils.resolveGroupingInDefinationScope;
+import static org.onosproject.yangutils.tool.ToolConstants.E_CODE_GEN_PATH;
+import static org.onosproject.yangutils.tool.ToolConstants.E_MISSING_INPUT;
+import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode;
+import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.translatorErrorHandler;
+import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
+import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
+import static org.onosproject.yangutils.utils.UtilConstants.TEMP;
+import static org.onosproject.yangutils.utils.UtilConstants.YANG_RESOURCES;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.createDirectories;
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Represents ONOS YANG tool manager.
+ */
+public class YangToolManager {
+
+    private static final Logger log = getLogger(YangToolManager.class);
+    public static final String DEFAULT_JAR_RES_PATH = SLASH + TEMP + SLASH +
+            YANG_RESOURCES + SLASH;
+    public static final String YANG_META_DATA = "YangMetaData";
+    public static final String SERIALIZED_FILE_EXTENSION = ".ser";
+
+    // YANG file information set.
+    private Set<YangFileInfo> yangFileInfoSet; //initialize in tool invocation;
+    private final YangUtilsParser yangUtilsParser = new YangUtilsParserManager();
+    private final YangLinker yangLinker = new YangLinkerManager();
+    private YangFileInfo curYangFileInfo = new YangFileInfo();
+    private final Set<YangNode> yangNodeSet = new HashSet<>();
+
+    /**
+     * Provides a list of files from list of strings.
+     *
+     * @param yangFileInfo set of yang file information
+     * @return list of files
+     */
+    private static List<File> getListOfFile(Set<YangFileInfo> yangFileInfo) {
+        List<File> files = new ArrayList<>();
+        Iterator<YangFileInfo> yangFileIterator = yangFileInfo.iterator();
+        while (yangFileIterator.hasNext()) {
+            YangFileInfo yangFile = yangFileIterator.next();
+            if (yangFile.isForTranslator()) {
+                files.add(new File(yangFile.getYangFileName()));
+            }
+        }
+        return files;
+    }
+
+    /**
+     * Compile te YANG files and generate the corresponding Java files.
+     * Update the generated bundle with the schema metadata.
+     *
+     * @param yangFiles Application YANG files
+     * @param config    tool configuration
+     * @param plugin    invoking plugin
+     */
+    public void compileYangFiles(Set<YangFileInfo> yangFiles,
+                                 List<YangNode> dependentSchema,
+                                 YangPluginConfig config,
+                                 CallablePlugin plugin) throws IOException {
+
+        try {
+
+            if (config == null || yangFiles == null) {
+                throw new YangToolException(E_MISSING_INPUT);
+            }
+            yangFileInfoSet = yangFiles;
+
+            if (config.getCodeGenDir() == null) {
+                throw new YangToolException(E_CODE_GEN_PATH);
+            }
+
+            // Check if there are any file to translate, if not return.
+            if (yangFileInfoSet == null || yangFileInfoSet.isEmpty()) {
+                // No files to translate
+                return;
+            }
+
+            createDirectories(config.resourceGenDir());
+
+            // Resolve inter jar dependency.
+            addSchemaToFileSet(dependentSchema);
+
+
+            // Carry out the parsing for all the YANG files.
+            parseYangFileInfoSet();
+
+            // Resolve dependencies using linker.
+            resolveDependenciesUsingLinker();
+
+            // Perform translation to JAVA.
+            translateToJava(config);
+
+            // Serialize data model.
+            Set<YangNode> compiledSchemas = new HashSet<>();
+            for (YangFileInfo fileInfo : yangFileInfoSet) {
+                compiledSchemas.add(fileInfo.getRootNode());
+            }
+
+            String serFileName = config.resourceGenDir() + YANG_META_DATA + SERIALIZED_FILE_EXTENSION;
+            FileOutputStream fileOutputStream = new FileOutputStream(serFileName);
+            ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
+            objectOutputStream.writeObject(compiledSchemas);
+            objectOutputStream.close();
+            fileOutputStream.close();
+
+
+            //add YANG files to JAR
+            List<File> files = getListOfFile(yangFileInfoSet);
+            String path = config.resourceGenDir();
+            File targetDir = new File(path);
+            targetDir.mkdirs();
+
+            for (File file : files) {
+                Files.copy(file.toPath(),
+                           new File(path + file.getName()).toPath(),
+                           StandardCopyOption.REPLACE_EXISTING);
+            }
+
+            if (plugin != null) {
+                plugin.addCompiledSchemaToBundle();
+                plugin.addGeneratedCodeToBundle();
+                plugin.addYangFilesToBundle();
+            }
+
+        } catch (IOException | ParserException e) {
+            YangToolException exception =
+                    new YangToolException(e.getMessage(), e);
+            exception.setCurYangFile(curYangFileInfo);
+
+            if (curYangFileInfo != null &&
+                    curYangFileInfo.getRootNode() != null) {
+                try {
+                    translatorErrorHandler(curYangFileInfo.getRootNode(),
+                                           config);
+                } catch (IOException ex) {
+                    e.printStackTrace();
+                    throw ex;
+                }
+            }
+
+            throw exception;
+        }
+    }
+
+    /**
+     * Resolved inter-jar dependencies.
+     *
+     * @param dependentSchema dependent schema list
+     * @throws IOException when fails to do IO operations
+     */
+    private void addSchemaToFileSet(List<YangNode> dependentSchema)
+            throws IOException {
+        if (dependentSchema == null || dependentSchema.isEmpty()) {
+            return;
+        }
+
+        for (YangNode node : dependentSchema) {
+            YangFileInfo dependentFileInfo = new YangFileInfo();
+            node.setToTranslate(false);
+            dependentFileInfo.setRootNode(node);
+            dependentFileInfo.setForTranslator(false);
+            dependentFileInfo.setYangFileName(node.getName());
+            yangFileInfoSet.add(dependentFileInfo);
+        }
+    }
+
+    /**
+     * Links all the provided schema in the YANG file info set.
+     *
+     * @throws YangToolException failed to link schema
+     */
+    public void resolveDependenciesUsingLinker() {
+        createYangNodeSet();
+        try {
+            yangLinker.resolveDependencies(yangNodeSet);
+        } catch (LinkerException e) {
+            printLog(e.getFileName(), e.getLineNumber(), e.getCharPositionInLine(),
+                     e.getMessage(), e.getLocalizedMessage());
+            throw new YangToolException(e.getMessage());
+        }
+    }
+
+    /**
+     * Creates YANG nodes set.
+     */
+    public void createYangNodeSet() {
+        for (YangFileInfo yangFileInfo : yangFileInfoSet) {
+            yangNodeSet.add(yangFileInfo.getRootNode());
+        }
+    }
+
+    /**
+     * Parses all the provided YANG files and generates YANG data model tree.
+     *
+     * @throws IOException a violation in IO
+     */
+    public void parseYangFileInfoSet()
+            throws IOException {
+        for (YangFileInfo yangFileInfo : yangFileInfoSet) {
+            curYangFileInfo = yangFileInfo;
+            if (yangFileInfo.isForTranslator()) {
+                try {
+                    YangNode yangNode = yangUtilsParser.getDataModel(
+                            yangFileInfo.getYangFileName());
+                    yangFileInfo.setRootNode(yangNode);
+                    resolveGroupingInDefinationScope((YangReferenceResolver) yangNode);
+                    try {
+                        ((YangReferenceResolver) yangNode)
+                                .resolveSelfFileLinking(YANG_DERIVED_DATA_TYPE);
+                        ((YangReferenceResolver) yangNode)
+                                .resolveSelfFileLinking(YANG_IDENTITYREF);
+                    } catch (DataModelException e) {
+                        printLog(e.getFileName(), e.getLineNumber(), e
+                                .getCharPositionInLine(), e.getMessage(), e
+                                         .getLocalizedMessage());
+                    }
+                } catch (ParserException e) {
+                    printLog(e.getFileName(), e.getLineNumber(), e
+                            .getCharPositionInLine(), e.getMessage(), e
+                                     .getLocalizedMessage());
+                    throw e;
+                }
+            }
+        }
+    }
+
+    /**
+     * Translates to java code corresponding to the YANG schema.
+     *
+     * @param pluginConfig YANG plugin config
+     * @throws IOException when fails to generate java code file the current node
+     */
+    public void translateToJava(YangPluginConfig pluginConfig)
+            throws IOException {
+        List<YangNode> yangNodeSortedList = new LinkedList<>();
+        yangNodeSortedList.addAll(yangNodeSet);
+        sort(yangNodeSortedList);
+        for (YangNode node : yangNodeSortedList) {
+            if (node.isToTranslate()) {
+                generateJavaCode(node, pluginConfig);
+            }
+        }
+    }
+
+    /**
+     * Adds log info for exception.
+     *
+     * @param fileName file name
+     * @param line     line number
+     * @param position character position
+     * @param msg      error message
+     * @param localMsg local message
+     */
+    private void printLog(String fileName, int line, int position, String
+            msg, String localMsg) {
+        String logInfo = "Error in file: " + fileName;
+        if (line != 0) {
+            logInfo = logInfo + " at line: " + line + " at position: "
+                    + position;
+
+        }
+        if (msg != null) {
+            logInfo = logInfo + NEW_LINE + localMsg;
+        }
+        log.info(logInfo);
+    }
+
+}
diff --git a/plugin/tool/src/main/java/org/onosproject/yangutils/tool/exception/YangToolException.java b/plugin/tool/src/main/java/org/onosproject/yangutils/tool/exception/YangToolException.java
new file mode 100644
index 0000000..b8925a0
--- /dev/null
+++ b/plugin/tool/src/main/java/org/onosproject/yangutils/tool/exception/YangToolException.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.tool.exception;
+
+import org.onosproject.yangutils.tool.YangFileInfo;
+
+/**
+ * Represents base class for exceptions in YANG tool operations.
+ */
+public class YangToolException extends RuntimeException {
+
+    private static final long serialVersionUID = 20161028L;
+
+    private YangFileInfo curYangFile;
+
+    /**
+     * Creates a new YANG tool exception with given message.
+     *
+     * @param message the detail of exception in string
+     */
+    public YangToolException(String message) {
+        super(message);
+    }
+
+    /**
+     * Creates a new tool exception from given message and cause.
+     *
+     * @param message the detail of exception in string
+     * @param cause   underlying cause of the error
+     */
+    public YangToolException(final String message, final Throwable cause) {
+        super(message, cause);
+    }
+
+    /**
+     * Creates a new tool exception from cause.
+     *
+     * @param cause underlying cause of the error
+     */
+    public YangToolException(final Throwable cause) {
+        super(cause);
+    }
+
+    /**
+     * Retrieves the current YANG files for which exception has occured.
+     *
+     * @return current YANG file
+     */
+    public YangFileInfo getCurYangFile() {
+        return curYangFile;
+    }
+
+
+    /**
+     * Update the YANG file which caused the exception.
+     *
+     * @param curYangFile YANG files being processed
+     */
+    public void setCurYangFile(YangFileInfo curYangFile) {
+        this.curYangFile = curYangFile;
+    }
+}