[ONOS-5482][ONOS-5275] Yms Operation requirement Implementation in onos-yang-tools
Change-Id: I463ed105f85ca65a61ff251e5ca062903d465551
diff --git a/plugin/buck/pom.xml b/plugin/buck/pom.xml
index fc1628b..09dde6d 100644
--- a/plugin/buck/pom.xml
+++ b/plugin/buck/pom.xml
@@ -13,7 +13,8 @@
~ 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"
+<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>
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 28e77c5..00331b2 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
@@ -16,10 +16,20 @@
package org.onosproject.yangutils.plugin.manager;
+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.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
+import java.io.PrintWriter;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
@@ -28,15 +38,9 @@
import java.util.List;
import java.util.Set;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.model.Dependency;
-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 static org.onosproject.yangutils.datamodel.utils.DataModelUtils.parseJarFile;
+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;
@@ -56,7 +60,10 @@
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 TEXT_FILE_EXTENSION = ".txt";
private static final String YANG_META_DATA = "YangMetaData";
+ private static final String VERSION_META_DATA = "VersionMetaData";
+ private static final String PLUGIN_ARTIFACT = "onos-yang-maven-plugin";
private YangPluginUtils() {
}
@@ -93,8 +100,8 @@
for (File file : files) {
Files.copy(file.toPath(),
- new File(path + file.getName()).toPath(),
- StandardCopyOption.REPLACE_EXISTING);
+ new File(path + file.getName()).toPath(),
+ StandardCopyOption.REPLACE_EXISTING);
}
addToProjectResource(outputDir + SLASH + TEMP + SLASH, project);
}
@@ -148,6 +155,38 @@
objectOutputStream.writeObject(nodes);
objectOutputStream.close();
fileOutputStream.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();
}
/**
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 e661c32..c965e95 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
@@ -39,12 +39,12 @@
import org.sonatype.plexus.build.incremental.BuildContext;
import java.io.IOException;
-import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
+import static java.util.Collections.sort;
import static org.apache.maven.plugins.annotations.LifecyclePhase.PROCESS_SOURCES;
import static org.apache.maven.plugins.annotations.ResolutionScope.COMPILE;
import static org.onosproject.yangutils.datamodel.ResolvableType.YANG_DERIVED_DATA_TYPE;
@@ -57,6 +57,8 @@
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;
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;
@@ -71,11 +73,13 @@
* Execution phase is generate-sources.
* requiresDependencyResolution at compile time.
*/
-@Mojo(name = "yang2java", defaultPhase = PROCESS_SOURCES, requiresDependencyResolution = COMPILE)
+@Mojo(name = "yang2java", defaultPhase = PROCESS_SOURCES,
+ requiresDependencyResolution = COMPILE)
public class YangUtilManager
extends AbstractMojo {
- private static final String DEFAULT_PKG = SLASH + getPackageDirPathFromJavaJPackage(DEFAULT_BASE_PKG);
+ private static final String DEFAULT_PKG =
+ getPackageDirPathFromJavaJPackage(DEFAULT_BASE_PKG);
private YangPluginConfig yangPlugin = new YangPluginConfig();
private YangNode rootNode;
// YANG file information set.
@@ -106,13 +110,15 @@
/**
* Output directory.
*/
- @Parameter(property = "project.build.outputDirectory", required = true, defaultValue = "target/classes")
+ @Parameter(property = "project.build.outputDirectory", required = true,
+ defaultValue = "target/classes")
private String outputDirectory;
/**
* Current maven project.
*/
- @Parameter(property = "project", required = true, readonly = true, defaultValue = "${project}")
+ @Parameter(property = "project", required = true, readonly = true,
+ defaultValue = "${project}")
private MavenProject project;
/**
@@ -163,19 +169,22 @@
@Parameter(property = "generateJavaFileForSbi", defaultValue = "nbi")
private String generateJavaFileForSbi;
+ private String outputDir;
+ private String codeGenDir;
+
@Override
public void execute()
throws MojoExecutionException, MojoFailureException {
try {
-
/*
* For deleting the generated code in previous build.
*/
- deleteDirectory(getDirectory(baseDir, outputDirectory + SLASH + TEMP));
- deleteDirectory(getDirectory(baseDir, outputDirectory + SLASH + YANG_RESOURCES));
+ outputDir = getDirectory(baseDir, outputDirectory);
+ deleteDirectory(outputDir + SLASH + TEMP);
+ deleteDirectory(outputDir + SLASH + YANG_RESOURCES);
String searchDir = getDirectory(baseDir, yangFilesDir);
- String codeGenDir = getDirectory(baseDir, classFileDir) + SLASH;
+ codeGenDir = getDirectory(baseDir, classFileDir) + SLASH;
// Creates conflict resolver and set values to it.
YangToJavaNamingConflictUtil conflictResolver = new YangToJavaNamingConflictUtil();
@@ -194,7 +203,7 @@
createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
// Check if there are any file to translate, if not return.
- if (getYangFileInfoSet() == null || getYangFileInfoSet().isEmpty()) {
+ if (yangFileInfoSet == null || yangFileInfoSet.isEmpty()) {
// No files to translate
return;
}
@@ -211,19 +220,18 @@
translateToJava(yangPlugin);
// Serialize data model.
- serializeDataModel(getDirectory(baseDir, outputDirectory), getYangFileInfoSet(), project, true);
-
+ serializeDataModel(outputDir, yangFileInfoSet, project, true);
addToCompilationRoot(codeGenDir, project, context);
- copyYangFilesToTarget(getYangFileInfoSet(), getDirectory(baseDir, outputDirectory), project);
+ copyYangFilesToTarget(yangFileInfoSet, outputDir, project);
} catch (IOException | ParserException e) {
- String fileName = "";
- if (getCurYangFileInfo() != null) {
- fileName = getCurYangFileInfo().getYangFileName();
+ String fileName = EMPTY_STRING;
+ if (curYangFileInfo != null) {
+ fileName = curYangFileInfo.getYangFileName();
}
try {
- translatorErrorHandler(getRootNode(), yangPlugin);
- deleteDirectory(getDirectory(baseDir, classFileDir) + DEFAULT_PKG);
+ translatorErrorHandler(rootNode, yangPlugin);
+ deleteDirectory(codeGenDir + DEFAULT_PKG);
} catch (IOException ex) {
e.printStackTrace();
throw new MojoExecutionException(
@@ -231,8 +239,8 @@
}
getLog().info(e);
throw new MojoExecutionException(
- "Exception occurred due to " + e.getLocalizedMessage() + " in " + fileName
- + " YANG file.");
+ "Exception occurred due to " + e.getLocalizedMessage() +
+ IN + fileName + " YANG file.");
}
}
@@ -253,15 +261,16 @@
private void resolveInterJarDependency()
throws IOException {
try {
- List<YangNode> interJarResolvedNodes = resolveInterJarDependencies(project, localRepository,
- remoteRepository, getDirectory(baseDir, outputDirectory));
+ 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());
- getYangFileInfoSet().add(dependentFileInfo);
+ yangFileInfoSet.add(dependentFileInfo);
}
} catch (IOException e) {
throw new IOException("failed to resolve in inter-jar scenario.");
@@ -277,19 +286,20 @@
throws MojoExecutionException {
createYangNodeSet();
try {
- yangLinker.resolveDependencies(getYangNodeSet());
+ yangLinker.resolveDependencies(yangNodeSet);
} catch (LinkerException e) {
+ printLog(e.getFileName(), e.getLineNumber(), e.getCharPositionInLine(),
+ e.getMessage(), e.getLocalizedMessage());
throw new MojoExecutionException(e.getMessage());
}
-
}
/**
* Creates YANG nodes set.
*/
public void createYangNodeSet() {
- for (YangFileInfo yangFileInfo : getYangFileInfoSet()) {
- getYangNodeSet().add(yangFileInfo.getRootNode());
+ for (YangFileInfo yangFileInfo : yangFileInfoSet) {
+ yangNodeSet.add(yangFileInfo.getRootNode());
}
}
@@ -300,31 +310,29 @@
*/
public void parseYangFileInfoSet()
throws IOException {
- for (YangFileInfo yangFileInfo : getYangFileInfoSet()) {
- setCurYangFileInfo(yangFileInfo);
+ for (YangFileInfo yangFileInfo : yangFileInfoSet) {
+ curYangFileInfo = yangFileInfo;
if (yangFileInfo.isForTranslator()) {
try {
- YangNode yangNode = yangUtilsParser.getDataModel(yangFileInfo.getYangFileName());
+ YangNode yangNode = yangUtilsParser.getDataModel(
+ yangFileInfo.getYangFileName());
yangFileInfo.setRootNode(yangNode);
- setRootNode(yangNode);
+ rootNode = yangNode;
resolveGroupingInDefinationScope((YangReferenceResolver) yangNode);
try {
- ((YangReferenceResolver) yangNode).resolveSelfFileLinking(YANG_DERIVED_DATA_TYPE);
- ((YangReferenceResolver) yangNode).resolveSelfFileLinking(YANG_IDENTITYREF);
+ ((YangReferenceResolver) yangNode)
+ .resolveSelfFileLinking(YANG_DERIVED_DATA_TYPE);
+ ((YangReferenceResolver) yangNode)
+ .resolveSelfFileLinking(YANG_IDENTITYREF);
} catch (DataModelException e) {
- //TODO: throw exception : throw e;
+ printLog(e.getFileName(), e.getLineNumber(), e
+ .getCharPositionInLine(), e.getMessage(), e
+ .getLocalizedMessage());
}
} catch (ParserException e) {
- String logInfo = "Error in file: " + e.getFileName();
- if (e.getLineNumber() != 0) {
- logInfo = logInfo + " at line: " + e.getLineNumber() + " at position: "
- + e.getCharPositionInLine();
-
- }
- if (e.getMessage() != null) {
- logInfo = logInfo + NEW_LINE + e.getLocalizedMessage();
- }
- getLog().info(logInfo);
+ printLog(e.getFileName(), e.getLineNumber(), e
+ .getCharPositionInLine(), e.getMessage(), e
+ .getLocalizedMessage());
throw e;
}
}
@@ -332,24 +340,6 @@
}
/**
- * Returns current root YANG node of data-model tree.
- *
- * @return current root YANG node of data-model tree
- */
- private YangNode getRootNode() {
- return rootNode;
- }
-
- /**
- * Sets current root YANG node of data-model tree.
- *
- * @param rootNode current root YANG node of data-model tree
- */
- private void setRootNode(YangNode rootNode) {
- this.rootNode = rootNode;
- }
-
- /**
* Translates to java code corresponding to the YANG schema.
*
* @param yangPlugin YANG plugin config
@@ -358,8 +348,8 @@
public void translateToJava(YangPluginConfig yangPlugin)
throws IOException {
List<YangNode> yangNodeSortedList = new LinkedList<>();
- yangNodeSortedList.addAll(getYangNodeSet());
- Collections.sort(yangNodeSortedList);
+ yangNodeSortedList.addAll(yangNodeSet);
+ sort(yangNodeSortedList);
for (YangNode node : yangNodeSortedList) {
if (node.isToTranslate()) {
generateJavaCode(node, yangPlugin);
@@ -376,7 +366,7 @@
for (String yangFile : yangFileList) {
YangFileInfo yangFileInfo = new YangFileInfo();
yangFileInfo.setYangFileName(yangFile);
- getYangFileInfoSet().add(yangFileInfo);
+ yangFileInfoSet.add(yangFileInfo);
}
}
@@ -399,20 +389,25 @@
}
/**
- * Returns current YANG file's info.
+ * Adds log info for exception.
*
- * @return the yangFileInfo
+ * @param fileName file name
+ * @param line line number
+ * @param position character position
+ * @param msg error message
+ * @param localMsg local message
*/
- private YangFileInfo getCurYangFileInfo() {
- return curYangFileInfo;
- }
+ 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;
- /**
- * Sets current YANG file's info.
- *
- * @param yangFileInfo the yangFileInfo to set
- */
- private void setCurYangFileInfo(YangFileInfo yangFileInfo) {
- curYangFileInfo = yangFileInfo;
+ }
+ if (msg != null) {
+ logInfo = logInfo + NEW_LINE + localMsg;
+ }
+ getLog().info(logInfo);
}
}
diff --git a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/AugmentTranslatorTest.java b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/AugmentTranslatorTest.java
index 9cd07b2..9ac1ad8 100644
--- a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/AugmentTranslatorTest.java
+++ b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/AugmentTranslatorTest.java
@@ -41,6 +41,7 @@
@Test
public void processAugmentTranslator() throws IOException, ParserException, MojoExecutionException {
+ deleteDirectory("target/augmentTranslator/");
String searchDir = "src/test/resources/augmentTranslator";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
diff --git a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/ChoiceCaseTranslatorTest.java b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/ChoiceCaseTranslatorTest.java
index 6ee1c71..7a1a8f6 100644
--- a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/ChoiceCaseTranslatorTest.java
+++ b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/ChoiceCaseTranslatorTest.java
@@ -16,14 +16,14 @@
package org.onosproject.yangutils.plugin.manager;
-import java.io.IOException;
-
import org.junit.Test;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import org.onosproject.yangutils.utils.io.YangPluginConfig;
+import java.io.IOException;
+
import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
@@ -40,6 +40,7 @@
@Test
public void processChoiceCaseTranslator() throws IOException, ParserException {
+ deleteDirectory("target/ChoiceCaseTestGenFile/");
YangNode node = manager.getDataModel("src/test/resources/ChoiceCaseTranslator.yang");
YangPluginConfig yangPluginConfig = new YangPluginConfig();
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 fb0f805..89f7439 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
@@ -79,17 +79,17 @@
public void processSingleJarLinking()
throws IOException, MojoExecutionException {
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(YANG_FILES_DIR));
-
- int size1 = utilManager.getYangFileInfoSet().size();
+ Set<YangFileInfo> info = utilManager.getYangFileInfoSet();
+ int size1 = info.size();
utilManager.parseYangFileInfoSet();
mockJarFileProvider.provideTestJarFile(utilManager);
- utilManager.setYangFileInfoSet(removeFileInfoFromSet(utilManager.getYangFileInfoSet()));
+ utilManager.setYangFileInfoSet(removeFileInfoFromSet(info));
utilManager.resolveDependenciesUsingLinker();
- int size2 = utilManager.getYangFileInfoSet().size();
+ int size2 = info.size();
assertThat(true, is(size1 != size2));
- assertThat(true, is(parseFileInfoSet(utilManager.getYangFileInfoSet().iterator())));
+ assertThat(true, is(parseFileInfoSet(info.iterator())));
deleteDirectory(TARGET);
mockJarFileProvider.deleteTestSerFile(YANG_FILES_DIR);
@@ -106,17 +106,18 @@
throws IOException, MojoExecutionException {
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(YANG_FILES_DIR));
- int size1 = utilManager.getYangFileInfoSet().size();
+ Set<YangFileInfo> info = utilManager.getYangFileInfoSet();
+ int size1 = info.size();
utilManager.parseYangFileInfoSet();
mockJarFileProvider.provideTestJarFile(utilManager);
- utilManager.setYangFileInfoSet(removeFileInfoFromSet(utilManager.getYangFileInfoSet()));
+ utilManager.setYangFileInfoSet(removeFileInfoFromSet(info));
utilManager.resolveDependenciesUsingLinker();
- int size2 = utilManager.getYangFileInfoSet().size();
+ int size2 = info.size();
assertThat(true, is(size1 != size2));
- assertThat(true, is(parseFileInfoSet(utilManager.getYangFileInfoSet().iterator())));
- assertThat(true, is(parseFileInfoSet(utilManager.getYangFileInfoSet().iterator())));
+ assertThat(true, is(parseFileInfoSet(info.iterator())));
+ assertThat(true, is(parseFileInfoSet(info.iterator())));
/*
* grouping flow-classifier {
@@ -134,7 +135,7 @@
*
*/
- Iterator<YangFileInfo> yangFileInfoIterator = utilManager.getYangFileInfoSet().iterator();
+ Iterator<YangFileInfo> yangFileInfoIterator = info.iterator();
YangFileInfo yangFileInfo = yangFileInfoIterator.next();
@@ -268,12 +269,13 @@
*/
void provideTestJarFile(YangUtilManager utilManager) throws IOException {
+ Set<YangFileInfo> info = utilManager.getYangFileInfoSet();
MavenProject project = new MavenProject();
- serializeDataModel(TARGET, utilManager.getYangFileInfoSet(), project, false);
+ serializeDataModel(TARGET, info, project, false);
createTestJar();
for (String file : getListOfTestJar(TARGET)) {
- addInterJarRootNodes(file, utilManager);
+ addInterJarRootNodes(file, info);
}
}
@@ -281,7 +283,8 @@
* Deletes serialized file.
*/
void deleteTestSerFile(String yangFileDir) {
- File ser = new File(System.getProperty("user.dir") + SLASH + yangFileDir + SLASH + SER_FILE_NAME);
+ File ser = new File(System.getProperty("user.dir") + SLASH + yangFileDir +
+ SLASH + SER_FILE_NAME);
ser.delete();
}
@@ -309,11 +312,11 @@
/**
* Adds data model nodes of jar to file info set.
*
- * @param jarFile jar file name
- * @param utilManager
+ * @param jarFile jar file name
+ * @param info file info
* @throws IOException when fails to do IO operations
*/
- private void addInterJarRootNodes(String jarFile, YangUtilManager utilManager) throws IOException {
+ private void addInterJarRootNodes(String jarFile, Set<YangFileInfo> info) throws IOException {
try {
List<YangNode> interJarResolvedNodes = parseJarFile(jarFile, TARGET);
@@ -323,7 +326,7 @@
dependentFileInfo.setRootNode(node);
dependentFileInfo.setForTranslator(false);
dependentFileInfo.setYangFileName(node.getName());
- utilManager.getYangFileInfoSet().add(dependentFileInfo);
+ info.add(dependentFileInfo);
}
} catch (IOException e) {
throw new IOException("failed to resolve in interjar scenario.");
diff --git a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/RootClassGeneratorTest.java b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/RootClassGeneratorTest.java
index 472f083..80fd438 100644
--- a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/RootClassGeneratorTest.java
+++ b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/RootClassGeneratorTest.java
@@ -38,6 +38,7 @@
@Test
public void rootClassGenTest() throws IOException, ParserException, MojoExecutionException {
+ deleteDirectory("target/manager/");
String searchDir = "src/test/resources/manager/singleChild";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
@@ -49,36 +50,20 @@
utilManager.translateToJava(yangPluginConfig);
String path = System.getProperty("user.dir") + "/target/manager/" +
- "org/onosproject/yang/gen/v1/test5/test/rev20160704/Test5.java";
- assertThat(true, is(!(new File(path)).exists()));
+ "org/onosproject/yang/gen/v1/single/test5/test/rev20160704" +
+ "/Test5.java";
+ assertThat(true, is((new File(path)).exists()));
path = System.getProperty("user.dir") + "/target/manager/" +
- "org/onosproject/yang/gen/v1/test5/test/rev20160704/Test7.java";
+ "org/onosproject/yang/gen/v1/single/test5/test/rev20160704" +
+ "/Test7.java";
assertThat(true, is((new File(path)).exists()));
deleteDirectory("target/manager/");
}
@Test
- public void rootClassNoGenTest() throws IOException, ParserException, MojoExecutionException {
- String searchDir = "src/test/resources/manager/nogen";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
- utilManager.parseYangFileInfoSet();
- utilManager.createYangNodeSet();
- utilManager.resolveDependenciesUsingLinker();
-
- YangPluginConfig yangPluginConfig = new YangPluginConfig();
- yangPluginConfig.setCodeGenDir("target/manager/");
- utilManager.translateToJava(yangPluginConfig);
-
- String path = System.getProperty("user.dir") + "/target/manager/" +
- "org/onosproject/yang/gen/v1/test5/test/rev20160704/Test5.java";
-
- assertThat(true, is(!(new File(path)).exists()));
- deleteDirectory("target/manager/");
- }
-
- @Test
public void rootClassGenwithoutRevTest() throws IOException, ParserException, MojoExecutionException {
+ deleteDirectory("target/manager/");
String searchDir = "src/test/resources/manager/genwithoutrev";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
@@ -98,6 +83,7 @@
@Test
public void rootClassMethodGenTest() throws IOException, ParserException, MojoExecutionException {
+ deleteDirectory("target/manager/");
String searchDir = "src/test/resources/manager/MultiChild";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
@@ -109,15 +95,18 @@
utilManager.translateToJava(yangPluginConfig);
String path = System.getProperty("user.dir") + "/target/manager/" +
- "org/onosproject/yang/gen/v1/test5/test/rev20160704/Test5.java";
- assertThat(true, is(!(new File(path)).exists()));
+ "org/onosproject/yang/gen/v1/multi/test5/test/rev20160704" +
+ "/Test5.java";
+ assertThat(true, is((new File(path)).exists()));
path = System.getProperty("user.dir") + "/target/manager/" +
- "org/onosproject/yang/gen/v1/test5/test/rev20160704/Test7.java";
- assertThat(true, is(!(new File(path)).exists()));
+ "org/onosproject/yang/gen/v1/multi/test5/test/rev20160704" +
+ "/Test7.java";
+ assertThat(true, is((new File(path)).exists()));
path = System.getProperty("user.dir") + "/target/manager/" +
- "org/onosproject/yang/gen/v1/test8/test/rev20160704/Test8.java";
+ "org/onosproject/yang/gen/v1/multi/test8/test/rev20160704" +
+ "/Test8.java";
assertThat(true, is((new File(path)).exists()));
deleteDirectory("target/manager/");
diff --git a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/TypeDefTranslatorTest.java b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/TypeDefTranslatorTest.java
index 4ef664c..40e567d 100644
--- a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/TypeDefTranslatorTest.java
+++ b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/TypeDefTranslatorTest.java
@@ -16,14 +16,14 @@
package org.onosproject.yangutils.plugin.manager;
-import java.io.IOException;
-
import org.apache.maven.plugin.MojoExecutionException;
import org.junit.Test;
-import org.onosproject.yangutils.utils.io.YangPluginConfig;
import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.utils.io.YangPluginConfig;
import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
+import java.io.IOException;
+
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
/**
@@ -76,4 +76,28 @@
}
+ /**
+ * Checks typedef translation should not result in any exception.
+ *
+ * @throws MojoExecutionException
+ */
+ @Test
+ public void processTypeDefWithUnionAndBitsTranslator() throws IOException,
+ ParserException, MojoExecutionException {
+
+ deleteDirectory("target/typedefTranslator/");
+ String searchDir = "src/test/resources/typedefTranslator/union";
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ utilManager.parseYangFileInfoSet();
+ utilManager.createYangNodeSet();
+ utilManager.resolveDependenciesUsingLinker();
+
+ YangPluginConfig yangPluginConfig = new YangPluginConfig();
+ yangPluginConfig.setCodeGenDir("target/typedefTranslator/");
+ utilManager.translateToJava(yangPluginConfig);
+
+ //deleteDirectory("target/typedefTranslator/");
+
+ }
+
}
diff --git a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/YangPluginUtilsTest.java b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/YangPluginUtilsTest.java
index 891a280..b6769ce 100644
--- a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/YangPluginUtilsTest.java
+++ b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/YangPluginUtilsTest.java
@@ -16,14 +16,17 @@
package org.onosproject.yangutils.plugin.manager;
-import java.io.File;
-import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.apache.maven.project.MavenProject;
import org.junit.Test;
import org.sonatype.plexus.build.incremental.BuildContext;
import org.sonatype.plexus.build.incremental.DefaultBuildContext;
+import java.io.File;
+import java.io.IOException;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
import static org.onosproject.yangutils.plugin.manager.YangPluginUtils.addToCompilationRoot;
/**
@@ -41,9 +44,12 @@
MavenProject project = new MavenProject();
BuildContext context = new DefaultBuildContext();
- File sourceDir = new File(BASE_DIR + File.separator + "yang");
+ String dir = BASE_DIR + File.separator + "yang";
+ String path = System.getProperty("user.dir") + File.separator + dir;
+ File sourceDir = new File(dir);
sourceDir.mkdirs();
addToCompilationRoot(sourceDir.toString(), project, context);
+ assertThat(true, is(project.getCompileSourceRoots().contains(path)));
FileUtils.deleteDirectory(sourceDir);
}
}
diff --git a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/YangXpathLinkerTest.java b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/YangXpathLinkerTest.java
index cca5c3f..3d8ca0c 100644
--- a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/YangXpathLinkerTest.java
+++ b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/YangXpathLinkerTest.java
@@ -16,9 +16,6 @@
package org.onosproject.yangutils.plugin.manager;
-import java.io.IOException;
-import java.util.List;
-
import org.apache.maven.plugin.MojoExecutionException;
import org.junit.Test;
import org.onosproject.yangutils.datamodel.ResolvableType;
@@ -28,12 +25,16 @@
import org.onosproject.yangutils.datamodel.YangResolutionInfo;
import org.onosproject.yangutils.linker.impl.YangLinkerManager;
import org.onosproject.yangutils.linker.impl.YangXpathLinker;
-import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
import org.onosproject.yangutils.utils.io.YangPluginConfig;
+import java.io.IOException;
+import java.util.List;
+
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
+import static org.onosproject.yangutils.linker.impl.XpathLinkingTypes.AUGMENT_LINKING;
import static org.onosproject.yangutils.linker.impl.YangLinkerUtils.updateFilePriority;
+import static org.onosproject.yangutils.utils.io.impl.YangFileScanner.getYangFiles;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
/**
@@ -57,7 +58,7 @@
@Test
public void processIntraFileLinkingSingleLevel() throws IOException, MojoExecutionException {
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTRA_FILE_PATH + "IntraSingle/"));
+ utilManager.createYangFileInfoSet(getYangFiles(INTRA_FILE_PATH + "IntraSingle/"));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
@@ -88,7 +89,7 @@
@Test
public void processIntraFileLinkingMultipleLevel() throws IOException {
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTRA_FILE_PATH + "IntraMulti/"));
+ utilManager.createYangFileInfoSet(getYangFiles(INTRA_FILE_PATH + "IntraMulti/"));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
@@ -101,7 +102,7 @@
for (YangAugment augment : augments) {
targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier()
.getName();
- targetNode = linker.processAugmentXpathLinking(augment.getTargetNode(), node);
+ targetNode = linker.processXpathLinking(augment.getTargetNode(), node, AUGMENT_LINKING);
}
}
@@ -115,7 +116,7 @@
*/
@Test
public void processIntraFileLinkingInAugmentSingleLevel() throws IOException {
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTRA_FILE_PATH + "IntraSingleAugment/"));
+ utilManager.createYangFileInfoSet(getYangFiles(INTRA_FILE_PATH + "IntraSingleAugment/"));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
@@ -128,7 +129,7 @@
for (YangAugment augment : augments) {
targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier()
.getName();
- targetNode = linker.processAugmentXpathLinking(augment.getTargetNode(), node);
+ targetNode = linker.processXpathLinking(augment.getTargetNode(), node, AUGMENT_LINKING);
}
}
@@ -142,7 +143,7 @@
*/
@Test
public void processIntraFileLinkingInAugmentMultiLevel() throws IOException {
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTRA_FILE_PATH + "IntraMultiAugment/"));
+ utilManager.createYangFileInfoSet(getYangFiles(INTRA_FILE_PATH + "IntraMultiAugment/"));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
@@ -159,7 +160,7 @@
for (YangAugment augment : augments) {
targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier()
.getName();
- targetNode = linker.processAugmentXpathLinking(augment.getTargetNode(), node);
+ targetNode = linker.processXpathLinking(augment.getTargetNode(), node, AUGMENT_LINKING);
}
}
@@ -174,7 +175,7 @@
*/
@Test
public void processIntraFileLinkingInSubModuleSingleLevel() throws IOException {
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTRA_FILE_PATH + "IntraSingleSubModule/"));
+ utilManager.createYangFileInfoSet(getYangFiles(INTRA_FILE_PATH + "IntraSingleSubModule/"));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
@@ -190,7 +191,7 @@
for (YangAugment augment : augments) {
targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier()
.getName();
- targetNode = linker.processAugmentXpathLinking(augment.getTargetNode(), node);
+ targetNode = linker.processXpathLinking(augment.getTargetNode(), node, AUGMENT_LINKING);
}
}
@@ -205,7 +206,7 @@
@Test
public void processIntraFileLinkingInSubModuleMultiLevel() throws IOException {
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTRA_FILE_PATH + "IntraMultiSubModule/"));
+ utilManager.createYangFileInfoSet(getYangFiles(INTRA_FILE_PATH + "IntraMultiSubModule/"));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
@@ -221,7 +222,7 @@
for (YangAugment augment : augments) {
targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier()
.getName();
- targetNode = linker.processAugmentXpathLinking(augment.getTargetNode(), node);
+ targetNode = linker.processXpathLinking(augment.getTargetNode(), node, AUGMENT_LINKING);
}
}
@@ -236,7 +237,7 @@
@Test
public void processIntraFileLinkingInUsesSingleLevel() throws IOException {
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTRA_FILE_PATH + "IntraSingleUses/"));
+ utilManager.createYangFileInfoSet(getYangFiles(INTRA_FILE_PATH + "IntraSingleUses/"));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
@@ -252,7 +253,7 @@
for (YangAugment augment : augments) {
targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier()
.getName();
- targetNode = linker.processAugmentXpathLinking(augment.getTargetNode(), node);
+ targetNode = linker.processXpathLinking(augment.getTargetNode(), node, AUGMENT_LINKING);
}
}
@@ -267,7 +268,7 @@
@Test
public void processIntraFileLinkingInUsesMultiLevel() throws IOException {
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTRA_FILE_PATH + "IntraMultiUses/"));
+ utilManager.createYangFileInfoSet(getYangFiles(INTRA_FILE_PATH + "IntraMultiUses/"));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
@@ -283,7 +284,7 @@
for (YangAugment augment : augments) {
targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier()
.getName();
- targetNode = linker.processAugmentXpathLinking(augment.getTargetNode(), node);
+ targetNode = linker.processXpathLinking(augment.getTargetNode(), node, AUGMENT_LINKING);
}
}
@@ -298,7 +299,7 @@
@Test
public void processInterFileLinkingSingleLevel() throws IOException {
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterSingle/"));
+ utilManager.createYangFileInfoSet(getYangFiles(INTER_FILE_PATH + "InterSingle/"));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
@@ -313,7 +314,7 @@
for (YangAugment augment : augments) {
targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier()
.getName();
- targetNode = linker.processAugmentXpathLinking(augment.getTargetNode(), node);
+ targetNode = linker.processXpathLinking(augment.getTargetNode(), node, AUGMENT_LINKING);
}
}
@@ -328,7 +329,7 @@
@Test
public void processInterFileLinkingMultipleLevel() throws IOException {
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterMulti/"));
+ utilManager.createYangFileInfoSet(getYangFiles(INTER_FILE_PATH + "InterMulti/"));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
@@ -343,7 +344,7 @@
for (YangAugment augment : augments) {
targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier()
.getName();
- targetNode = linker.processAugmentXpathLinking(augment.getTargetNode(), node);
+ targetNode = linker.processXpathLinking(augment.getTargetNode(), node, AUGMENT_LINKING);
}
}
@@ -358,7 +359,7 @@
@Test
public void processInterFileLinkingInAugmentSingleLevel() throws IOException {
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterSingleAugment/"));
+ utilManager.createYangFileInfoSet(getYangFiles(INTER_FILE_PATH + "InterSingleAugment/"));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
@@ -373,7 +374,7 @@
for (YangAugment augment : augments) {
targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier()
.getName();
- targetNode = linker.processAugmentXpathLinking(augment.getTargetNode(), node);
+ targetNode = linker.processXpathLinking(augment.getTargetNode(), node, AUGMENT_LINKING);
}
}
@@ -388,7 +389,7 @@
@Test
public void processInterFileLinkingInAugmentMultiLevel() throws IOException {
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterMultiAugment/"));
+ utilManager.createYangFileInfoSet(getYangFiles(INTER_FILE_PATH + "InterMultiAugment/"));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
@@ -403,7 +404,7 @@
for (YangAugment augment : augments) {
targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier()
.getName();
- targetNode = linker.processAugmentXpathLinking(augment.getTargetNode(), node);
+ targetNode = linker.processXpathLinking(augment.getTargetNode(), node, AUGMENT_LINKING);
}
}
@@ -418,7 +419,7 @@
@Test
public void processMultiInterFileLinkingInAugmentSingleLevel() throws IOException {
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterMultiFileAugment/"));
+ utilManager.createYangFileInfoSet(getYangFiles(INTER_FILE_PATH + "InterMultiFileAugment/"));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
@@ -433,7 +434,7 @@
for (YangAugment augment : augments) {
targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier()
.getName();
- targetNode = linker.processAugmentXpathLinking(augment.getTargetNode(), node);
+ targetNode = linker.processXpathLinking(augment.getTargetNode(), node, AUGMENT_LINKING);
}
}
@@ -449,7 +450,7 @@
public void processMultiInterFileLinkingInAugmentMultiLevel() throws IOException {
utilManager
- .createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterMultiFileAugmentMulti/"));
+ .createYangFileInfoSet(getYangFiles(INTER_FILE_PATH + "InterMultiFileAugmentMulti/"));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
@@ -483,7 +484,7 @@
@Test
public void processInterFileLinkingInSubModuleSingleLevel() throws IOException {
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterSingleSubModule/"));
+ utilManager.createYangFileInfoSet(getYangFiles(INTER_FILE_PATH + "InterSingleSubModule/"));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
@@ -516,7 +517,7 @@
@Test
public void processInterFileLinkingInSubModuleMultiLevel() throws IOException {
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterMultiSubModule/"));
+ utilManager.createYangFileInfoSet(getYangFiles(INTER_FILE_PATH + "InterMultiSubModule/"));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
@@ -549,7 +550,7 @@
@Test
public void processInterFileLinkingInUsesInAugment() throws IOException {
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterSingleUses/"));
+ utilManager.createYangFileInfoSet(getYangFiles(INTER_FILE_PATH + "InterSingleUses/"));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
@@ -584,7 +585,7 @@
@Test
public void processInterFileLinkingInUsesMultiLevel() throws IOException {
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterMultiUses/"));
+ utilManager.createYangFileInfoSet(getYangFiles(INTER_FILE_PATH + "InterMultiUses/"));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
@@ -602,7 +603,7 @@
for (YangAugment augment : augments) {
targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier()
.getName();
- targetNode = linker.processAugmentXpathLinking(augment.getTargetNode(), node);
+ targetNode = linker.processXpathLinking(augment.getTargetNode(), node, AUGMENT_LINKING);
}
}
@@ -617,7 +618,7 @@
@Test
public void processInterFileLinkingInMultipleSubmodules() throws IOException {
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(CASE_FILE_PATH + "submodule/"));
+ utilManager.createYangFileInfoSet(getYangFiles(CASE_FILE_PATH + "submodule/"));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
@@ -653,7 +654,7 @@
@Test
public void processInterFileLinkingInMultipleUses() throws IOException {
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(CASE_FILE_PATH + "uses/"));
+ utilManager.createYangFileInfoSet(getYangFiles(CASE_FILE_PATH + "uses/"));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
diff --git a/plugin/maven/src/test/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGeneratorTest.java b/plugin/maven/src/test/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGeneratorTest.java
index 6b20103..4de9402 100644
--- a/plugin/maven/src/test/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGeneratorTest.java
+++ b/plugin/maven/src/test/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGeneratorTest.java
@@ -99,13 +99,10 @@
private static final String SET = "setValue.set(0);\n";
private static final String UNION = " @Override\n" +
" public String toString() {\n" +
- " MoreObjects.ToStringHelper helper =" +
- " MoreObjects.toStringHelper(getClass())\n" +
- " .omitNullValues();\n" +
" if (setValue.get(0)) {\n" +
- " helper.add(\"string\", string);\n" +
+ " return string;\n" +
" }\n" +
- " return helper.toString();\n" +
+ " return null;\n" +
" }";
/**
@@ -259,7 +256,7 @@
JavaAttributeInfo testAttr = getTestAttribute();
List<YangType<?>> types = new ArrayList<>();
types.add(testAttr.getAttributeType());
- String method = getUnionToStringMethod(types);
+ String method = getUnionToStringMethod(types, CLASS_NAME);
assertThat(true, is(method.contains(UNION)));
}
diff --git a/plugin/maven/src/test/java/org/onosproject/yangutils/utils/io/impl/JavaDocGenTest.java b/plugin/maven/src/test/java/org/onosproject/yangutils/utils/io/impl/JavaDocGenTest.java
index dcb4a34..14c5134 100644
--- a/plugin/maven/src/test/java/org/onosproject/yangutils/utils/io/impl/JavaDocGenTest.java
+++ b/plugin/maven/src/test/java/org/onosproject/yangutils/utils/io/impl/JavaDocGenTest.java
@@ -34,7 +34,7 @@
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.CONSTRUCTOR;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.DEFAULT_CONSTRUCTOR;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.IMPL_CLASS;
+import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.DEFAULT_CLASS;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.INTERFACE;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.PACKAGE_INFO;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.SETTER_METHOD;
@@ -141,7 +141,7 @@
*/
@Test
public void implClassGenerationTest() {
- String implClassJavaDoc = getJavaDoc(IMPL_CLASS, TEST_NAME, false, null);
+ String implClassJavaDoc = getJavaDoc(DEFAULT_CLASS, TEST_NAME, false, null);
assertThat(true,
is(implClassJavaDoc.contains("Represents the implementation of")
&& implClassJavaDoc.contains(END_STRING)));
diff --git a/plugin/maven/src/test/resources/ChoiceCaseTranslator.yang b/plugin/maven/src/test/resources/ChoiceCaseTranslator.yang
index e8127ea..35cbf19 100644
--- a/plugin/maven/src/test/resources/ChoiceCaseTranslator.yang
+++ b/plugin/maven/src/test/resources/ChoiceCaseTranslator.yang
@@ -2,7 +2,7 @@
yang-version 1;
namespace http://huawei.com;
prefix Ant;
- container food {
+ notification food {
choice snack {
case sports-arena {
leaf pretzel {
diff --git a/plugin/maven/src/test/resources/manager/MultiChild/module.yang b/plugin/maven/src/test/resources/manager/MultiChild/module.yang
index 1c4637c..845380b 100644
--- a/plugin/maven/src/test/resources/manager/MultiChild/module.yang
+++ b/plugin/maven/src/test/resources/manager/MultiChild/module.yang
@@ -1,5 +1,5 @@
module test5 {
- namespace "test5:test";
+ namespace "multi:test5:test";
prefix test ;
revision "2016-07-04" {
diff --git a/plugin/maven/src/test/resources/manager/MultiChild/test.yang b/plugin/maven/src/test/resources/manager/MultiChild/test.yang
index 036d78a..2665267 100644
--- a/plugin/maven/src/test/resources/manager/MultiChild/test.yang
+++ b/plugin/maven/src/test/resources/manager/MultiChild/test.yang
@@ -1,5 +1,5 @@
module test7 {
- namespace "test5:test";
+ namespace "multi:test5:test";
prefix test ;
revision "2016-07-04" {
diff --git a/plugin/maven/src/test/resources/manager/MultiChild/test2.yang b/plugin/maven/src/test/resources/manager/MultiChild/test2.yang
index b252c23..c87022d 100644
--- a/plugin/maven/src/test/resources/manager/MultiChild/test2.yang
+++ b/plugin/maven/src/test/resources/manager/MultiChild/test2.yang
@@ -1,5 +1,5 @@
module test8 {
- namespace "test8:test";
+ namespace "multi:test8:test";
prefix test ;
revision "2016-07-04" {
diff --git a/plugin/maven/src/test/resources/manager/singleChild/module.yang b/plugin/maven/src/test/resources/manager/singleChild/module.yang
index 5fb8a9b..67f4bc9 100644
--- a/plugin/maven/src/test/resources/manager/singleChild/module.yang
+++ b/plugin/maven/src/test/resources/manager/singleChild/module.yang
@@ -1,5 +1,5 @@
module test5 {
- namespace "test5:test";
+ namespace "single:test5:test";
prefix test ;
revision "2016-07-04" {
diff --git a/plugin/maven/src/test/resources/manager/singleChild/test.yang b/plugin/maven/src/test/resources/manager/singleChild/test.yang
index 483e00e..2d13b4c 100644
--- a/plugin/maven/src/test/resources/manager/singleChild/test.yang
+++ b/plugin/maven/src/test/resources/manager/singleChild/test.yang
@@ -1,5 +1,5 @@
module test7 {
- namespace "test5:test";
+ namespace "single:test5:test";
prefix test ;
revision "2016-07-04" {
diff --git a/plugin/maven/src/test/resources/typedefTranslator/union/typedefs.yang b/plugin/maven/src/test/resources/typedefTranslator/union/typedefs.yang
new file mode 100644
index 0000000..4a3d150
--- /dev/null
+++ b/plugin/maven/src/test/resources/typedefTranslator/union/typedefs.yang
@@ -0,0 +1,52 @@
+module types {
+
+ namespace "yang:types";
+ prefix "types";
+ yang-version 1;
+
+ revision 2016-10-08;
+ typedef ip-address {
+ type union {
+ type ipv4-address;
+ type ipv6-address;
+ type leaf;
+ }
+ }
+
+ typedef ipv4-address {
+ type int32;
+ }
+
+ typedef ipv6-address {
+ type int32;
+ }
+
+ typedef port-number {
+ type bits {
+ bit disable-nagle {
+ position 0;
+ }
+ bit auto-sense-speed {
+ position 1;
+ }
+ bit Mb-only {
+ position 2;
+ }
+ }
+
+}
+
+
+ container con1 {
+ leaf abc {
+ type int32;
+ }
+ }
+
+ typedef leaf {
+ type leafref {
+ path "/con1/abc";
+ }
+ }
+
+}
diff --git a/plugin/maven/src/test/resources/xPathLinker/Case/uses/test2.yang b/plugin/maven/src/test/resources/xPathLinker/Case/uses/test2.yang
index e42101e..8e4dccf 100644
--- a/plugin/maven/src/test/resources/xPathLinker/Case/uses/test2.yang
+++ b/plugin/maven/src/test/resources/xPathLinker/Case/uses/test2.yang
@@ -53,7 +53,7 @@
}
}
- augment /group1/cont3/cont4 {
+ augment /cont5/cont6/cont3/cont4 {
container cont8 {
leaf leaf8 {
type int32;
diff --git a/plugin/pom.xml b/plugin/pom.xml
index f35583d..882703f 100644
--- a/plugin/pom.xml
+++ b/plugin/pom.xml
@@ -13,7 +13,8 @@
~ 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"
+<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>