Vinod Kumar S | 212fcdd | 2016-02-05 16:15:09 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0f7908b | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Vinod Kumar S | 212fcdd | 2016-02-05 16:15:09 +0530 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package org.onosproject.yangutils.plugin.manager; |
| 18 | |
Bharat saraswal | 780eca3 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 19 | import java.io.IOException; |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 20 | import java.util.HashSet; |
Bharat saraswal | f790747 | 2016-02-11 22:00:49 +0530 | [diff] [blame] | 21 | import java.util.Iterator; |
| 22 | import java.util.List; |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 23 | import java.util.Set; |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 24 | |
Vinod Kumar S | 212fcdd | 2016-02-05 16:15:09 +0530 | [diff] [blame] | 25 | import org.apache.maven.plugin.AbstractMojo; |
| 26 | import org.apache.maven.plugin.MojoExecutionException; |
| 27 | import org.apache.maven.plugin.MojoFailureException; |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 28 | import org.apache.maven.plugins.annotations.Component; |
Vinod Kumar S | 212fcdd | 2016-02-05 16:15:09 +0530 | [diff] [blame] | 29 | import org.apache.maven.plugins.annotations.Mojo; |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 30 | import org.apache.maven.plugins.annotations.Parameter; |
Bharat saraswal | f790747 | 2016-02-11 22:00:49 +0530 | [diff] [blame] | 31 | import org.apache.maven.project.MavenProject; |
Bharat saraswal | f790747 | 2016-02-11 22:00:49 +0530 | [diff] [blame] | 32 | import org.onosproject.yangutils.datamodel.YangNode; |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 33 | import org.onosproject.yangutils.linker.YangLinker; |
| 34 | import org.onosproject.yangutils.linker.exceptions.LinkerException; |
| 35 | import org.onosproject.yangutils.linker.impl.YangLinkerManager; |
Bharat saraswal | f790747 | 2016-02-11 22:00:49 +0530 | [diff] [blame] | 36 | import org.onosproject.yangutils.parser.YangUtilsParser; |
| 37 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 38 | import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; |
janani b | 1c6acc4 | 2016-04-15 16:18:30 +0530 | [diff] [blame] | 39 | import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; |
| 40 | import org.onosproject.yangutils.translator.tojava.utils.YangToJavaNamingConflictUtil; |
Bharat saraswal | f790747 | 2016-02-11 22:00:49 +0530 | [diff] [blame] | 41 | import org.onosproject.yangutils.utils.io.impl.YangFileScanner; |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 42 | import org.sonatype.plexus.build.incremental.BuildContext; |
Vinod Kumar S | 212fcdd | 2016-02-05 16:15:09 +0530 | [diff] [blame] | 43 | |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 44 | import static org.apache.maven.plugins.annotations.LifecyclePhase.GENERATE_SOURCES; |
| 45 | import static org.apache.maven.plugins.annotations.ResolutionScope.COMPILE; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 46 | import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode; |
Bharat saraswal | 780eca3 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 47 | import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.translatorErrorHandler; |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 48 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 49 | import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_BASE_PKG; |
| 50 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; |
| 51 | import static org.onosproject.yangutils.utils.UtilConstants.SLASH; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 52 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.addToSource; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 53 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.copyYangFilesToTarget; |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 54 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 55 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getDirectory; |
| 56 | |
Vinod Kumar S | 212fcdd | 2016-02-05 16:15:09 +0530 | [diff] [blame] | 57 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 58 | * Represents ONOS YANG utility maven plugin. |
Bharat saraswal | 2f1077d | 2016-04-19 19:50:32 +0530 | [diff] [blame] | 59 | * Goal of plugin is yang2java. |
| 60 | * Execution phase is generate-sources. |
| 61 | * requiresDependencyResolution at compile time. |
Bharat saraswal | f790747 | 2016-02-11 22:00:49 +0530 | [diff] [blame] | 62 | */ |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 63 | @Mojo(name = "yang2java", defaultPhase = GENERATE_SOURCES, requiresDependencyResolution = COMPILE, |
| 64 | requiresProject = true) |
Vinod Kumar S | 212fcdd | 2016-02-05 16:15:09 +0530 | [diff] [blame] | 65 | public class YangUtilManager extends AbstractMojo { |
| 66 | |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 67 | private YangNode rootNode; |
| 68 | // YANG file information set. |
| 69 | private Set<YangFileInfo> yangFileInfoSet = new HashSet<>(); |
| 70 | private YangUtilsParser yangUtilsParser = new YangUtilsParserManager(); |
| 71 | private YangLinker yangLinker = new YangLinkerManager(); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 72 | private YangFileInfo curYangFileInfo = new YangFileInfo(); |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 73 | |
| 74 | private static final String DEFAULT_PKG = SLASH + getPackageDirPathFromJavaJPackage(DEFAULT_BASE_PKG); |
| 75 | |
Bharat saraswal | f790747 | 2016-02-11 22:00:49 +0530 | [diff] [blame] | 76 | /** |
| 77 | * Source directory for YANG files. |
| 78 | */ |
| 79 | @Parameter(property = "yangFilesDir", defaultValue = "src/main/yang") |
| 80 | private String yangFilesDir; |
| 81 | |
| 82 | /** |
Bharat saraswal | 5600f0f | 2016-03-09 18:34:56 +0530 | [diff] [blame] | 83 | * Source directory for generated files. |
| 84 | */ |
| 85 | @Parameter(property = "genFilesDir", defaultValue = "src/main/java") |
| 86 | private String genFilesDir; |
| 87 | |
| 88 | /** |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 89 | * Base directory for project. |
| 90 | */ |
| 91 | @Parameter(property = "basedir", defaultValue = "${basedir}") |
| 92 | private String baseDir; |
| 93 | |
| 94 | /** |
Bharat saraswal | f790747 | 2016-02-11 22:00:49 +0530 | [diff] [blame] | 95 | * Output directory. |
| 96 | */ |
| 97 | @Parameter(property = "project.build.outputDirectory", required = true, defaultValue = "target/classes") |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 98 | private String outputDirectory; |
Bharat saraswal | f790747 | 2016-02-11 22:00:49 +0530 | [diff] [blame] | 99 | |
| 100 | /** |
| 101 | * Current maven project. |
| 102 | */ |
| 103 | @Parameter(property = "project", required = true, readonly = true, defaultValue = "${project}") |
| 104 | private MavenProject project; |
| 105 | |
| 106 | /** |
janani b | 1c6acc4 | 2016-04-15 16:18:30 +0530 | [diff] [blame] | 107 | * Replacement required for period special character in the identifier. |
| 108 | */ |
| 109 | @Parameter(property = "replacementForPeriod") |
| 110 | private String replacementForPeriod; |
| 111 | |
| 112 | /** |
| 113 | * Replacement required for underscore special character in the identifier. |
| 114 | */ |
| 115 | @Parameter(property = "replacementForUnderscore") |
| 116 | private String replacementForUnderscore; |
| 117 | |
| 118 | /** |
| 119 | * Replacement required for hyphen special character in the identifier. |
| 120 | */ |
| 121 | @Parameter(property = "replacementForHyphen") |
| 122 | private String replacementForHyphen; |
| 123 | |
| 124 | /** |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 125 | * Prefix which is required for adding with the identifier. |
| 126 | */ |
| 127 | @Parameter(property = "prefixForIdentifier") |
| 128 | private String prefixForIdentifier; |
| 129 | |
| 130 | /** |
Bharat saraswal | f790747 | 2016-02-11 22:00:49 +0530 | [diff] [blame] | 131 | * Build context. |
| 132 | */ |
| 133 | @Component |
| 134 | private BuildContext context; |
| 135 | |
Vinod Kumar S | 212fcdd | 2016-02-05 16:15:09 +0530 | [diff] [blame] | 136 | @Override |
| 137 | public void execute() throws MojoExecutionException, MojoFailureException { |
Bharat saraswal | f790747 | 2016-02-11 22:00:49 +0530 | [diff] [blame] | 138 | |
| 139 | try { |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 140 | |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 141 | /* |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 142 | * For deleting the generated code in previous build. |
| 143 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 144 | deleteDirectory(getDirectory(baseDir, genFilesDir) + DEFAULT_PKG); |
| 145 | deleteDirectory(getDirectory(baseDir, outputDirectory)); |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 146 | |
Vidyashree Rama | 1396065 | 2016-04-26 15:06:06 +0530 | [diff] [blame] | 147 | String searchDir = getDirectory(baseDir, yangFilesDir); |
| 148 | String codeGenDir = getDirectory(baseDir, genFilesDir) + SLASH; |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 149 | |
| 150 | // Creates conflict resolver and set values to it. |
janani b | 1c6acc4 | 2016-04-15 16:18:30 +0530 | [diff] [blame] | 151 | YangToJavaNamingConflictUtil conflictResolver = new YangToJavaNamingConflictUtil(); |
| 152 | conflictResolver.setReplacementForPeriod(replacementForPeriod); |
| 153 | conflictResolver.setReplacementForHyphen(replacementForHyphen); |
Vidyashree Rama | 1396065 | 2016-04-26 15:06:06 +0530 | [diff] [blame] | 154 | conflictResolver.setReplacementForUnderscore(replacementForUnderscore); |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 155 | conflictResolver.setPrefixForIdentifier(prefixForIdentifier); |
janani b | 1c6acc4 | 2016-04-15 16:18:30 +0530 | [diff] [blame] | 156 | YangPluginConfig yangPlugin = new YangPluginConfig(); |
| 157 | yangPlugin.setCodeGenDir(codeGenDir); |
| 158 | yangPlugin.setConflictResolver(conflictResolver); |
Vidyashree Rama | b624817 | 2016-05-17 16:16:15 +0530 | [diff] [blame] | 159 | |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 160 | /* |
| 161 | * Obtain the YANG files at a path mentioned in plugin and creates |
| 162 | * YANG file information set. |
| 163 | */ |
| 164 | createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 165 | |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 166 | // Check if there are any file to translate, if not return. |
| 167 | if (getYangFileInfoSet() == null || getYangFileInfoSet().isEmpty()) { |
| 168 | // No files to translate |
| 169 | return; |
Bharat saraswal | f790747 | 2016-02-11 22:00:49 +0530 | [diff] [blame] | 170 | } |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 171 | |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 172 | // Carry out the parsing for all the YANG files. |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 173 | parseYangFileInfoSet(); |
Vidyashree Rama | b624817 | 2016-05-17 16:16:15 +0530 | [diff] [blame] | 174 | |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 175 | // Resolve dependencies using linker. |
| 176 | resolveDependenciesUsingLinker(); |
| 177 | |
| 178 | // Perform translation to JAVA. |
| 179 | translateToJava(getYangFileInfoSet(), yangPlugin); |
Vidyashree Rama | b624817 | 2016-05-17 16:16:15 +0530 | [diff] [blame] | 180 | |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 181 | addToSource(getDirectory(baseDir, genFilesDir), project, context); |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 182 | |
| 183 | copyYangFilesToTarget(getYangFileInfoSet(), getDirectory(baseDir, outputDirectory), project); |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 184 | } catch (IOException | ParserException e) { |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 185 | String fileName = ""; |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 186 | if (getCurYangFileInfo() != null) { |
| 187 | fileName = getCurYangFileInfo().getYangFileName(); |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 188 | } |
Bharat saraswal | 780eca3 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 189 | try { |
| 190 | translatorErrorHandler(getRootNode()); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 191 | deleteDirectory(getDirectory(baseDir, genFilesDir) + DEFAULT_PKG); |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 192 | } catch (IOException ex) { |
| 193 | throw new MojoExecutionException( |
| 194 | "Error handler failed to delete files for data model node."); |
Bharat saraswal | 780eca3 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 195 | } |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 196 | throw new MojoExecutionException( |
| 197 | "Exception occured due to " + e.getLocalizedMessage() + " in " + fileName |
| 198 | + " YANG file."); |
Bharat saraswal | f790747 | 2016-02-11 22:00:49 +0530 | [diff] [blame] | 199 | } |
Vinod Kumar S | 212fcdd | 2016-02-05 16:15:09 +0530 | [diff] [blame] | 200 | } |
Bharat saraswal | 780eca3 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 201 | |
| 202 | /** |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 203 | * Links all the provided with the YANG file info set. |
Bharat saraswal | 780eca3 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 204 | * |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 205 | * @throws MojoExecutionException a violation in mojo excecution |
Bharat saraswal | 780eca3 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 206 | */ |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 207 | public void resolveDependenciesUsingLinker() throws MojoExecutionException { |
| 208 | for (YangFileInfo yangFileInfo : getYangFileInfoSet()) { |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 209 | setCurYangFileInfo(yangFileInfo); |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 210 | try { |
| 211 | yangLinker.resolveDependencies(getYangFileInfoSet()); |
| 212 | } catch (LinkerException e) { |
| 213 | throw new MojoExecutionException(e.getMessage()); |
| 214 | } |
| 215 | } |
Bharat saraswal | 780eca3 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | /** |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 219 | * Parses all the provided YANG files and generates YANG data model tree. |
Bharat saraswal | 780eca3 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 220 | * |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 221 | * @throws IOException a violation in IO |
Bharat saraswal | 780eca3 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 222 | */ |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 223 | public void parseYangFileInfoSet() throws IOException { |
| 224 | for (YangFileInfo yangFileInfo : getYangFileInfoSet()) { |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 225 | setCurYangFileInfo(yangFileInfo); |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 226 | try { |
| 227 | YangNode yangNode = yangUtilsParser.getDataModel(yangFileInfo.getYangFileName()); |
| 228 | yangFileInfo.setRootNode(yangNode); |
| 229 | setRootNode(yangNode); |
| 230 | } catch (ParserException e) { |
| 231 | String logInfo = "Error in file: " + e.getFileName(); |
| 232 | if (e.getLineNumber() != 0) { |
| 233 | logInfo = logInfo + " at line: " + e.getLineNumber() + " at position: " |
| 234 | + e.getCharPositionInLine(); |
| 235 | |
| 236 | } |
| 237 | if (e.getMessage() != null) { |
| 238 | logInfo = logInfo + NEW_LINE + e.getMessage(); |
| 239 | } |
| 240 | getLog().info(logInfo); |
| 241 | throw e; |
| 242 | } |
| 243 | } |
Bharat saraswal | 780eca3 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | /** |
| 247 | * Returns current root YANG node of data-model tree. |
| 248 | * |
| 249 | * @return current root YANG node of data-model tree |
| 250 | */ |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 251 | private YangNode getRootNode() { |
Bharat saraswal | 780eca3 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 252 | return rootNode; |
| 253 | } |
| 254 | |
| 255 | /** |
| 256 | * Sets current root YANG node of data-model tree. |
| 257 | * |
| 258 | * @param rootNode current root YANG node of data-model tree |
| 259 | */ |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 260 | private void setRootNode(YangNode rootNode) { |
Bharat saraswal | 780eca3 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 261 | this.rootNode = rootNode; |
| 262 | } |
| 263 | |
Vidyashree Rama | b624817 | 2016-05-17 16:16:15 +0530 | [diff] [blame] | 264 | /** |
| 265 | * Translates to java code corresponding to the YANG schema. |
| 266 | * |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 267 | * @param yangFileInfoSet YANG file information |
| 268 | * @param yangPlugin YANG plugin config |
Vidyashree Rama | b624817 | 2016-05-17 16:16:15 +0530 | [diff] [blame] | 269 | * @throws IOException when fails to generate java code file the current |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 270 | * node |
Vidyashree Rama | b624817 | 2016-05-17 16:16:15 +0530 | [diff] [blame] | 271 | */ |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 272 | public void translateToJava(Set<YangFileInfo> yangFileInfoSet, YangPluginConfig yangPlugin) |
Vidyashree Rama | b624817 | 2016-05-17 16:16:15 +0530 | [diff] [blame] | 273 | throws IOException { |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 274 | Iterator<YangFileInfo> yangFileIterator = yangFileInfoSet.iterator(); |
Vidyashree Rama | b624817 | 2016-05-17 16:16:15 +0530 | [diff] [blame] | 275 | while (yangFileIterator.hasNext()) { |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 276 | YangFileInfo yangFileInfo = yangFileIterator.next(); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 277 | setCurYangFileInfo(yangFileInfo); |
| 278 | generateJavaCode(yangFileInfo.getRootNode(), yangPlugin); |
Vidyashree Rama | b624817 | 2016-05-17 16:16:15 +0530 | [diff] [blame] | 279 | } |
| 280 | } |
| 281 | |
| 282 | /** |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 283 | * Creates a YANG file info set. |
Vidyashree Rama | b624817 | 2016-05-17 16:16:15 +0530 | [diff] [blame] | 284 | * |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 285 | * @param yangFileList YANG files list |
Vidyashree Rama | b624817 | 2016-05-17 16:16:15 +0530 | [diff] [blame] | 286 | */ |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 287 | public void createYangFileInfoSet(List<String> yangFileList) { |
| 288 | for (String yangFile : yangFileList) { |
| 289 | YangFileInfo yangFileInfo = new YangFileInfo(); |
| 290 | yangFileInfo.setYangFileName(yangFile); |
| 291 | getYangFileInfoSet().add(yangFileInfo); |
Vidyashree Rama | b624817 | 2016-05-17 16:16:15 +0530 | [diff] [blame] | 292 | } |
| 293 | } |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 294 | |
| 295 | /** |
| 296 | * Returns the YANG file info set. |
| 297 | * |
| 298 | * @return the YANG file info set |
| 299 | */ |
| 300 | public Set<YangFileInfo> getYangFileInfoSet() { |
| 301 | return yangFileInfoSet; |
| 302 | } |
| 303 | |
| 304 | /** |
| 305 | * Sets the YANG file info set. |
| 306 | * |
| 307 | * @param yangFileInfoSet the YANG file info set |
| 308 | */ |
| 309 | public void setYangFileInfoSet(Set<YangFileInfo> yangFileInfoSet) { |
| 310 | this.yangFileInfoSet = yangFileInfoSet; |
| 311 | } |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 312 | |
| 313 | /** |
| 314 | * Returns current YANG file's info. |
| 315 | * |
| 316 | * @return the yangFileInfo |
| 317 | */ |
| 318 | public YangFileInfo getCurYangFileInfo() { |
| 319 | return curYangFileInfo; |
| 320 | } |
| 321 | |
| 322 | /** |
| 323 | * Sets current YANG file's info. |
| 324 | * |
| 325 | * @param yangFileInfo the yangFileInfo to set |
| 326 | */ |
| 327 | public void setCurYangFileInfo(YangFileInfo yangFileInfo) { |
| 328 | this.curYangFileInfo = yangFileInfo; |
| 329 | } |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 330 | } |