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