Bharat saraswal
Committed by Patrick Liu

[ONOS-4839] update file priority for translator and OP param file impl defect fix

Change-Id: Ieaef43f915996ed0a34dfa17c338ab612716b2bc
Showing 44 changed files with 539 additions and 302 deletions
......@@ -32,6 +32,11 @@ public class YangAtomicPath implements Serializable {
private List<YangPathPredicate> pathPredicatesList;
/**
* Resolved node for the absolute path.
*/
private YangNode resolvedNode;
/**
* Returns the node identifier.
*
* @return the node identifier
......@@ -75,4 +80,23 @@ public class YangAtomicPath implements Serializable {
public void addLeavesPredicate(YangPathPredicate predicatesExp) {
getPathPredicatesList().add(predicatesExp);
}
/**
* Returns resolved node.
*
* @return resolved node
*/
public YangNode getResolvedNode() {
return resolvedNode;
}
/**
* Sets resolved node.
*
* @param resolvedNode resolved node
*/
public void setResolvedNode(YangNode resolvedNode) {
this.resolvedNode = resolvedNode;
}
}
......
......@@ -15,10 +15,8 @@
*/
package org.onosproject.yangutils.datamodel;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
......@@ -130,11 +128,6 @@ public class YangAugment
private YangNode augmentedNode;
/**
* All resolved nodes in given xPath.
*/
private Map<YangAtomicPath, YangNode> resolveNodeInPath;
/**
* Status of resolution. If completely resolved enum value is "RESOLVED", if not enum value is "UNRESOLVED", in case
* reference of grouping/typedef is added to uses/type but it's not resolved value of enum should be
* "INTRA_FILE_RESOLVED".
......@@ -156,7 +149,6 @@ public class YangAugment
*/
public YangAugment() {
super(YangNodeType.AUGMENT_NODE);
resolveNodeInPath = new HashMap<>();
resolvableStatus = ResolvableStatus.UNRESOLVED;
}
......@@ -447,21 +439,4 @@ public class YangAugment
return null;
}
/**
* Returns all resolved node in path.
*
* @return all resolved node in path
*/
public Map<YangAtomicPath, YangNode> getResolveNodeInPath() {
return resolveNodeInPath;
}
/**
* Sets all resolved node in path.
*
* @param resolveNodeInPath all resolved node in path
*/
public void setResolveNodeInPath(Map<YangAtomicPath, YangNode> resolveNodeInPath) {
this.resolveNodeInPath = resolveNodeInPath;
}
}
......
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.yangutils.datamodel;
/**
* Abstraction of an entity which represent operation parameter info for augmentable node.
*/
public interface YangAugmentedOpParamInfo extends YangAugmentedInfo {
/**
* Returns class object of base class.
*
* @return class object of base class
*/
Class<?> getBaseClass();
/**
* Returns if augmented info's contents matches.
*
* @param augmentedInfo augmented info
* @return true or false
*/
boolean isFilterContentMatch(Object augmentedInfo);
}
......@@ -79,7 +79,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol
*/
public class YangGrouping
extends YangNode
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector {
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangTranslatorOperatorNode {
private static final long serialVersionUID = 806201607L;
......
......@@ -64,6 +64,11 @@ public abstract class YangNode
private int priority;
/**
* Flag if the node is for translation.
*/
private boolean isToTranslate = true;
/**
* Returns the priority of the node.
*
* @return priority of the node
......@@ -268,6 +273,7 @@ public abstract class YangNode
/**
* Clones the current node contents and create a new node.
*
* @param yangUses YANG uses
* @return cloned node
* @throws CloneNotSupportedException clone is not supported by the referred
* node
......@@ -297,6 +303,7 @@ public abstract class YangNode
*
* @param srcRootNode source node for sub tree cloning
* @param dstRootNode destination node where the sub tree needs to be cloned
* @param yangUses YANG uses
* @throws DataModelException data model error
*/
public static void cloneSubTree(YangNode srcRootNode, YangNode dstRootNode, YangUses yangUses)
......@@ -411,6 +418,24 @@ public abstract class YangNode
}
/**
* /** Returns true if translation required.
*
* @return true if translation required
*/
public boolean isToTranslate() {
return isToTranslate;
}
/**
* Sest true if translation required.
*
* @param toTranslate true if translation required.
*/
public void setToTranslate(boolean toTranslate) {
isToTranslate = toTranslate;
}
/**
* Adds a new next sibling.
*
* @param newSibling new sibling to be added
......
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.yangutils.datamodel;
/**
* Abstraction of an entity which provides info about whether to translate module/submodule in manager and service
* classes.
*/
public interface YangTranslatorOperatorNode {
}
......@@ -57,7 +57,8 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol
/**
* Represents data model node to maintain information defined in YANG typedef.
*/
public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable, YangTypeHolder, CollisionDetector {
public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable, YangTypeHolder, CollisionDetector,
YangTranslatorOperatorNode {
private static final long serialVersionUID = 806201615L;
......
......@@ -370,6 +370,7 @@ public final class DataModelUtils {
*
* @param clonedLeaf cloned leaf in uses from grouping
* @param leafParentHolder holder of the leaf from uses
* @param yangUses YANG uses
* @return entity of leafref which has to be resolved
* @throws DataModelException data model error
*/
......
......@@ -19,7 +19,7 @@ package org.onosproject.yangutils.linker.impl;
/**
* Enum for prefix resolver type when augment has come in path.
*/
public enum PrefixResolverType {
enum PrefixResolverType {
/**
* When prefix changes from inter file to intra file.
......@@ -37,12 +37,12 @@ public enum PrefixResolverType {
INTER_TO_INTER,
/**
* When no prefix change occurres.
* When no prefix change occurs.
*/
NO_PREFIX_CHANGE_FOR_INTRA,
/**
* When no prefix change occurres.
* When no prefix change occurs.
*/
NO_PREFIX_CHANGE_FOR_INTER
}
......
......@@ -18,13 +18,11 @@ package org.onosproject.yangutils.linker.impl;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import org.onosproject.yangutils.datamodel.ResolvableType;
import org.onosproject.yangutils.datamodel.YangImport;
import org.onosproject.yangutils.datamodel.YangInclude;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangReferenceResolver;
import org.onosproject.yangutils.datamodel.YangSubModule;
......@@ -32,6 +30,7 @@ import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.linker.YangLinker;
import org.onosproject.yangutils.linker.exceptions.LinkerException;
import static org.onosproject.yangutils.linker.impl.YangLinkerUtils.updateFilePriority;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
/**
......@@ -191,52 +190,4 @@ public class YangLinkerManager
}
}
/**
* Updates the priority for all the input files.
*
* @param yangNodeSet set of YANG files info
*/
public void updateFilePriority(Set<YangNode> yangNodeSet) {
for (YangNode yangNode : yangNodeSet) {
updateFilePriorityOfNode(yangNode);
}
}
/**
* Updates priority of the node.
*
* @param yangNode YANG node information
*/
public void updateFilePriorityOfNode(YangNode yangNode) {
int curNodePriority = yangNode.getPriority();
if (yangNode instanceof YangReferenceResolver) {
List<YangImport> yangImportList = ((YangReferenceResolver) yangNode).getImportList();
if (yangImportList != null && !yangImportList.isEmpty()) {
Iterator<YangImport> importInfoIterator = yangImportList.iterator();
// Run through the imported list to update priority.
while (importInfoIterator.hasNext()) {
YangImport yangImport = importInfoIterator.next();
YangNode importedNode = yangImport.getImportedNode();
if (curNodePriority >= importedNode.getPriority()) {
importedNode.setPriority(curNodePriority + 1);
updateFilePriorityOfNode(importedNode);
}
}
}
List<YangInclude> yangIncludeList = ((YangReferenceResolver) yangNode).getIncludeList();
if (yangIncludeList != null && !yangIncludeList.isEmpty()) {
Iterator<YangInclude> includeInfoIterator = yangIncludeList.iterator();
// Run through the imported list to update priority.
while (includeInfoIterator.hasNext()) {
YangInclude yangInclude = includeInfoIterator.next();
YangNode includedNode = yangInclude.getIncludedNode();
if (curNodePriority >= includedNode.getPriority()) {
includedNode.setPriority(curNodePriority + 1);
updateFilePriorityOfNode(includedNode);
}
}
}
}
}
}
......
......@@ -16,24 +16,29 @@
package org.onosproject.yangutils.linker.impl;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.regex.Pattern;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangAugmentableNode;
import org.onosproject.yangutils.datamodel.YangAugmentedInfo;
import org.onosproject.yangutils.datamodel.YangCase;
import org.onosproject.yangutils.datamodel.YangChoice;
import org.onosproject.yangutils.datamodel.YangImport;
import org.onosproject.yangutils.datamodel.YangInclude;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafList;
import org.onosproject.yangutils.datamodel.YangLeafRef;
import org.onosproject.yangutils.datamodel.YangLeavesHolder;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
import org.onosproject.yangutils.datamodel.YangReferenceResolver;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
import org.onosproject.yangutils.linker.exceptions.LinkerException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
import static org.onosproject.yangutils.utils.UtilConstants.COLON;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH_FOR_STRING;
......@@ -43,13 +48,13 @@ import static org.onosproject.yangutils.utils.UtilConstants.SLASH_FOR_STRING;
*/
public final class YangLinkerUtils {
private YangLinkerUtils() {
}
private static final int IDENTIFIER_LENGTH = 64;
private static final Pattern IDENTIFIER_PATTERN = Pattern.compile("[a-zA-Z_][a-zA-Z0-9_.-]*");
private static final String XML = "xml";
private YangLinkerUtils() {
}
/**
* Detects collision between target nodes leaf/leaf-list or child node with augmented leaf/leaf-list or child node.
*
......@@ -59,17 +64,28 @@ public final class YangLinkerUtils {
private static void detectCollision(YangNode targetNode, YangAugment augment) {
YangNode targetNodesChild = targetNode.getChild();
YangNode augmentsChild = augment.getChild();
YangLeavesHolder augmentsLeavesHolder = augment;
if (targetNode instanceof YangChoice) {
if (augmentsLeavesHolder.getListOfLeaf() != null
|| augmentsLeavesHolder.getListOfLeafList() != null) {
throw new LinkerException("target node " + targetNode.getName()
+ "is a instance of choice. it can " +
"only be augmented with leaf using a case node.");
YangNode parent = targetNode;
if (targetNode instanceof YangAugment) {
parent = targetNode.getParent();
} else {
while (parent.getParent() != null) {
parent = parent.getParent();
}
}
if (targetNode instanceof YangChoice) {
// no need to check here.
} else {
YangLeavesHolder targetNodesLeavesHolder = (YangLeavesHolder) targetNode;
detectCollisionInLeaveHolders(targetNode, augment);
while (augmentsChild != null) {
detectCollisionInChildNodes(targetNodesChild, augmentsChild, targetNode.getName(), parent.getName());
augmentsChild = augmentsChild.getNextSibling();
}
}
}
/*Detects collision between leaves/leaflists*/
private static void detectCollisionInLeaveHolders(YangNode targetNode, YangAugment augment) {
YangLeavesHolder targetNodesLeavesHolder = (YangLeavesHolder) targetNode;
YangNode parent = targetNode;
if (targetNode instanceof YangAugment) {
parent = targetNode.getParent();
......@@ -78,9 +94,9 @@ public final class YangLinkerUtils {
parent = parent.getParent();
}
}
if (augmentsLeavesHolder.getListOfLeaf() != null && augmentsLeavesHolder.getListOfLeaf().size() != 0
if (augment.getListOfLeaf() != null && augment.getListOfLeaf().size() != 0
&& targetNodesLeavesHolder.getListOfLeaf() != null) {
for (YangLeaf leaf : augmentsLeavesHolder.getListOfLeaf()) {
for (YangLeaf leaf : augment.getListOfLeaf()) {
for (YangLeaf targetLeaf : targetNodesLeavesHolder.getListOfLeaf()) {
if (targetLeaf.getName().equals(leaf.getName())) {
throw new LinkerException("target node " + targetNode.getName()
......@@ -89,10 +105,10 @@ public final class YangLinkerUtils {
}
}
}
} else if (augmentsLeavesHolder.getListOfLeafList() != null
&& augmentsLeavesHolder.getListOfLeafList().size() != 0
&& targetNodesLeavesHolder.getListOfLeafList() != null) {
for (YangLeafList leafList : augmentsLeavesHolder.getListOfLeafList()) {
} else if (augment.getListOfLeafList() != null
&& augment.getListOfLeafList().size() != 0
&& augment.getListOfLeafList() != null) {
for (YangLeafList leafList : augment.getListOfLeafList()) {
for (YangLeafList targetLeafList : targetNodesLeavesHolder.getListOfLeafList()) {
if (targetLeafList.getName().equals(leafList.getName())) {
throw new LinkerException("target node " + targetNode.getName()
......@@ -101,21 +117,24 @@ public final class YangLinkerUtils {
}
}
}
} else {
}
}
/*Detects collision for child nodes.*/
private static void detectCollisionInChildNodes(YangNode targetNodesChild, YangNode augmentsChild, String
targetName, String parentName) {
while (augmentsChild != null) {
while (targetNodesChild != null) {
if (targetNodesChild.getName().equals(augmentsChild.getName())) {
throw new LinkerException("target node " + targetNode.getName()
throw new LinkerException("target node " + targetName
+ " contains augmented child node" + augmentsChild.getName() + " in module "
+ parent.getName());
+ parentName);
}
targetNodesChild = targetNodesChild.getNextSibling();
}
augmentsChild = augmentsChild.getNextSibling();
}
}
}
}
/**
* Detects collision between target nodes and its all leaf/leaf-list or child node with augmented leaf/leaf-list or
......@@ -124,7 +143,7 @@ public final class YangLinkerUtils {
* @param targetNode target node
* @param augment augment node
*/
public static void detectCollisionForAugmentedNode(YangNode targetNode, YangAugment augment) {
static void detectCollisionForAugmentedNode(YangNode targetNode, YangAugment augment) {
// Detect collision for target node and augment node.
detectCollision(targetNode, augment);
List<YangAugmentedInfo> yangAugmentedInfo = ((YangAugmentableNode) targetNode).getAugmentedInfoList();
......@@ -228,4 +247,49 @@ public final class YangLinkerUtils {
return identifier;
}
}
/**
* Updates the priority for all the input files.
*
* @param yangNodeSet set of YANG files info
*/
public static void updateFilePriority(Set<YangNode> yangNodeSet) {
for (YangNode yangNode : yangNodeSet) {
updateFilePriorityOfNode(yangNode);
}
}
/**
* Updates priority of the node.
*
* @param yangNode YANG node information
*/
public static void updateFilePriorityOfNode(YangNode yangNode) {
int curNodePriority = yangNode.getPriority();
if (yangNode instanceof YangReferenceResolver) {
List<YangImport> yangImportList = ((YangReferenceResolver) yangNode).getImportList();
Iterator<YangImport> importInfoIterator = yangImportList.iterator();
// Run through the imported list to update priority.
while (importInfoIterator.hasNext()) {
YangImport yangImport = importInfoIterator.next();
YangNode importedNode = yangImport.getImportedNode();
if (curNodePriority >= importedNode.getPriority()) {
importedNode.setPriority(curNodePriority + 1);
updateFilePriorityOfNode(importedNode);
}
}
List<YangInclude> yangIncludeList = ((YangReferenceResolver) yangNode).getIncludeList();
Iterator<YangInclude> includeInfoIterator = yangIncludeList.iterator();
// Run through the imported list to update priority.
while (includeInfoIterator.hasNext()) {
YangInclude yangInclude = includeInfoIterator.next();
YangNode includedNode = yangInclude.getIncludedNode();
if (curNodePriority >= includedNode.getPriority()) {
includedNode.setPriority(curNodePriority + 1);
updateFilePriorityOfNode(includedNode);
}
}
}
}
}
......
......@@ -1209,7 +1209,6 @@ public class YangResolutionInfoImpl<T>
detectCollisionForAugmentedNode(targetNode, augment);
((YangAugmentableNode) targetNode).addAugmentation(augment);
augment.setAugmentedNode(targetNode);
augment.setResolveNodeInPath(xPathLinker.getResolvedNodes());
Resolvable resolvable = (Resolvable) entityToResolve;
resolvable.setResolvableStatus(RESOLVED);
} else {
......
......@@ -16,6 +16,12 @@
package org.onosproject.yangutils.linker.impl;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Stack;
import org.onosproject.yangutils.datamodel.YangAtomicPath;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangCase;
......@@ -37,13 +43,6 @@ import org.onosproject.yangutils.datamodel.YangTypeDef;
import org.onosproject.yangutils.datamodel.YangUses;
import org.onosproject.yangutils.linker.exceptions.LinkerException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Stack;
import static org.onosproject.yangutils.linker.impl.PrefixResolverType.INTER_TO_INTER;
import static org.onosproject.yangutils.linker.impl.PrefixResolverType.INTER_TO_INTRA;
import static org.onosproject.yangutils.linker.impl.PrefixResolverType.INTRA_TO_INTER;
......@@ -63,14 +62,12 @@ public class YangXpathLinker<T> {
private YangNode rootNode;
private Map<YangAtomicPath, PrefixResolverType> prefixResolverTypes;
private String curPrefix;
private Map<YangAtomicPath, YangNode> resolvedNodes;
/**
* Creates an instance of x-path linker.
*/
public YangXpathLinker() {
absPaths = new ArrayList<>();
setResolvedNodes(new HashMap<>());
}
/**
......@@ -156,31 +153,13 @@ public class YangXpathLinker<T> {
}
/**
* Returns resolved nodes.
*
* @return resolved nodes
*/
public Map<YangAtomicPath, YangNode> getResolvedNodes() {
return resolvedNodes;
}
/**
* Sets resolved nodes.
*
* @param resolvedNodes resolved nodes
*/
private void setResolvedNodes(Map<YangAtomicPath, YangNode> resolvedNodes) {
this.resolvedNodes = resolvedNodes;
}
/**
* Adds node to resolved nodes.
*
* @param path absolute path
* @param node resolved node
*/
private void addToResolvedNodes(YangAtomicPath path, YangNode node) {
getResolvedNodes().put(path, node);
path.setResolvedNode(node);
}
/**
......@@ -211,7 +190,7 @@ public class YangXpathLinker<T> {
*/
public T processLeafRefXpathLinking(List<YangAtomicPath> atomicPaths, YangNode root, YangLeafRef leafref) {
YangNode targetNode = null;
YangNode targetNode;
setRootNode(root);
setPrefixResolverTypes(new HashMap<>());
parsePrefixResolverList(atomicPaths);
......@@ -260,11 +239,8 @@ public class YangXpathLinker<T> {
* @param leafref instance of YANG leafref
*/
private void validateInvalidNodesInThePath(YangLeafRef leafref) {
Map<YangAtomicPath, YangNode> nodes = getResolvedNodes();
Iterator<Map.Entry<YangAtomicPath, YangNode>> nodesIterator = nodes.entrySet().iterator();
while (nodesIterator.hasNext()) {
Map.Entry<YangAtomicPath, YangNode> nodeInList = nodesIterator.next();
YangNode nodeInPath = nodeInList.getValue();
for (YangAtomicPath absolutePath : (Iterable<YangAtomicPath>) leafref.getAtomicPath()) {
YangNode nodeInPath = absolutePath.getResolvedNode();
if (nodeInPath instanceof YangGrouping || nodeInPath instanceof YangUses
|| nodeInPath instanceof YangTypeDef || nodeInPath instanceof YangCase
......@@ -331,9 +307,7 @@ public class YangXpathLinker<T> {
YangLeavesHolder holder = (YangLeavesHolder) targetNode;
List<YangLeaf> leaves = holder.getListOfLeaf();
if (leaves != null && !leaves.isEmpty()) {
Iterator<YangLeaf> leafIterator = leaves.listIterator();
while (leafIterator.hasNext()) {
YangLeaf leaf = leafIterator.next();
for (YangLeaf leaf : leaves) {
if (leaf.getName().equals(leafName)) {
return leaf;
}
......@@ -357,9 +331,7 @@ public class YangXpathLinker<T> {
YangLeavesHolder holder = (YangLeavesHolder) targetNode;
List<YangLeafList> leavesList = holder.getListOfLeafList();
if (leavesList != null && !leavesList.isEmpty()) {
Iterator<YangLeafList> leafListIterator = leavesList.listIterator();
while (leafListIterator.hasNext()) {
YangLeafList leafList = leafListIterator.next();
for (YangLeafList leafList : leavesList) {
if (leafList.getName().equals(leafListName)) {
return leafList;
}
......
......@@ -18,7 +18,6 @@ package org.onosproject.yangutils.plugin.manager;
import java.io.IOException;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.apache.maven.artifact.repository.ArtifactRepository;
......@@ -43,6 +42,7 @@ import org.sonatype.plexus.build.incremental.BuildContext;
import static org.apache.maven.plugins.annotations.LifecyclePhase.GENERATE_SOURCES;
import static org.apache.maven.plugins.annotations.ResolutionScope.COMPILE;
import static org.onosproject.yangutils.linker.impl.YangLinkerUtils.updateFilePriority;
import static org.onosproject.yangutils.plugin.manager.YangPluginUtils.addToCompilationRoot;
import static org.onosproject.yangutils.plugin.manager.YangPluginUtils.copyYangFilesToTarget;
import static org.onosproject.yangutils.plugin.manager.YangPluginUtils.resolveInterJarDependencies;
......@@ -67,17 +67,14 @@ import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPackageDirP
public class YangUtilManager
extends AbstractMojo {
private static final String DEFAULT_PKG = SLASH + getPackageDirPathFromJavaJPackage(DEFAULT_BASE_PKG);
private YangNode rootNode;
// YANG file information set.
private Set<YangFileInfo> yangFileInfoSet = new HashSet<>();
private YangUtilsParser yangUtilsParser = new YangUtilsParserManager();
private YangLinker yangLinker = new YangLinkerManager();
private YangFileInfo curYangFileInfo = new YangFileInfo();
private Set<YangNode> yangNodeSet = new HashSet<>();
private static final String DEFAULT_PKG = SLASH + getPackageDirPathFromJavaJPackage(DEFAULT_BASE_PKG);
/**
* Source directory for YANG files.
*/
......@@ -144,9 +141,15 @@ public class YangUtilManager
@Component
private BuildContext context;
/**
* Local maven repository.
*/
@Parameter(readonly = true, defaultValue = "${localRepository}")
private ArtifactRepository localRepository;
/**
* Remote maven repositories.
*/
@Parameter(readonly = true, defaultValue = "${project.remoteArtifactRepositories}")
private List<ArtifactRepository> remoteRepository;
......@@ -196,7 +199,7 @@ public class YangUtilManager
return;
}
// Resolve inter jar dependency.
resolveInterJardependency();
resolveInterJarDependency();
// Carry out the parsing for all the YANG files.
parseYangFileInfoSet();
......@@ -205,7 +208,7 @@ public class YangUtilManager
resolveDependenciesUsingLinker();
// Perform translation to JAVA.
translateToJava(getYangFileInfoSet(), yangPlugin);
translateToJava(yangPlugin);
// Serialize data model.
serializeDataModel(getDirectory(baseDir, outputDirectory), getYangFileInfoSet(), project, true);
......@@ -237,7 +240,7 @@ public class YangUtilManager
*
* @return YANG node set
*/
public Set<YangNode> getYangNodeSet() {
Set<YangNode> getYangNodeSet() {
return yangNodeSet;
}
......@@ -246,12 +249,13 @@ public class YangUtilManager
*
* @throws IOException when fails to do IO operations
*/
public void resolveInterJardependency() throws IOException {
private void resolveInterJarDependency() throws IOException {
try {
List<YangNode> interJarResolvedNodes = resolveInterJarDependencies(project, localRepository,
remoteRepository, getDirectory(baseDir, outputDirectory));
for (YangNode node : interJarResolvedNodes) {
YangFileInfo dependentFileInfo = new YangFileInfo();
node.setToTranslate(false);
dependentFileInfo.setRootNode(node);
dependentFileInfo.setForTranslator(false);
dependentFileInfo.setYangFileName(node.getName());
......@@ -281,7 +285,7 @@ public class YangUtilManager
/**
* Creates YANG nodes set.
*/
public void createYangNodeSet() {
void createYangNodeSet() {
for (YangFileInfo yangFileInfo : getYangFileInfoSet()) {
getYangNodeSet().add(yangFileInfo.getRootNode());
}
......@@ -339,19 +343,15 @@ public class YangUtilManager
/**
* Translates to java code corresponding to the YANG schema.
*
* @param yangFileInfoSet YANG file information
* @param yangPlugin YANG plugin config
* @throws IOException when fails to generate java code file the current
* node
* @throws IOException when fails to generate java code file the current node
*/
public void translateToJava(Set<YangFileInfo> yangFileInfoSet, YangPluginConfig yangPlugin)
public void translateToJava(YangPluginConfig yangPlugin)
throws IOException {
Iterator<YangFileInfo> yangFileIterator = yangFileInfoSet.iterator();
while (yangFileIterator.hasNext()) {
YangFileInfo yangFileInfo = yangFileIterator.next();
setCurYangFileInfo(yangFileInfo);
if (yangFileInfo.isForTranslator()) {
generateJavaCode(yangFileInfo.getRootNode(), yangPlugin);
updateFilePriority(getYangNodeSet());
for (YangNode node : getYangNodeSet()) {
if (node.isToTranslate()) {
generateJavaCode(node, yangPlugin);
}
}
}
......@@ -383,7 +383,7 @@ public class YangUtilManager
*
* @param yangFileInfoSet the YANG file info set
*/
public void setYangFileInfoSet(Set<YangFileInfo> yangFileInfoSet) {
void setYangFileInfoSet(Set<YangFileInfo> yangFileInfoSet) {
this.yangFileInfoSet = yangFileInfoSet;
}
......@@ -392,7 +392,7 @@ public class YangUtilManager
*
* @return the yangFileInfo
*/
public YangFileInfo getCurYangFileInfo() {
private YangFileInfo getCurYangFileInfo() {
return curYangFileInfo;
}
......@@ -401,7 +401,7 @@ public class YangUtilManager
*
* @param yangFileInfo the yangFileInfo to set
*/
public void setCurYangFileInfo(YangFileInfo yangFileInfo) {
private void setCurYangFileInfo(YangFileInfo yangFileInfo) {
curYangFileInfo = yangFileInfo;
}
}
......
......@@ -88,6 +88,12 @@ public final class GeneratedJavaFileType {
public static final int GENERATE_EVENT_SUBJECT_CLASS = 1024;
/**
* Java classes for events.
*/
public static final int GENERATE_ALL_EVENT_CLASS_MASK = GENERATE_EVENT_CLASS | GENERATE_EVENT_LISTENER_INTERFACE
| GENERATE_EVENT_SUBJECT_CLASS;
/**
* Identity listener class.
*/
public static final int GENERATE_IDENTITY_CLASS = 2048;
......
......@@ -42,6 +42,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.ONOS_EVENT_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_OP_PARAM_INFO_CLASS;
import static java.util.Collections.sort;
/**
......@@ -289,4 +290,14 @@ public class JavaImportData {
public String getYangAugmentedInfoImport() {
return IMPORT + YANG_AUGMENTED_INFO_CLASS_IMPORT_PKG + PERIOD + YANG_AUGMENTED_INFO_CLASS_IMPORT_CLASS;
}
/**
* Returns import string for YangAugmentedOpParamInfo class.
*
* @return import string for YangAugmentedOpParamInfo class
*/
public String getYangAugmentedOpParamInfoImport() {
return IMPORT + YANG_AUGMENTED_INFO_CLASS_IMPORT_PKG + PERIOD +
YANG_AUGMENTED_OP_PARAM_INFO_CLASS;
}
}
......
......@@ -23,6 +23,7 @@ import org.onosproject.yangutils.datamodel.YangTypeHolder;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ALL_EVENT_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
......@@ -56,6 +57,11 @@ public class TempJavaCodeFragmentFiles {
private TempJavaEnumerationFragmentFiles enumerationTempFiles;
/**
* Has the temporary files required for enumeration generated classes.
*/
private TempJavaEventFragmentFiles tempJavaEventFragmentFiles;
/**
* Creates an instance of temporary java code fragment.
*
* @param javaFileInfo generated java file info
......@@ -80,6 +86,10 @@ public class TempJavaCodeFragmentFiles {
setServiceTempFiles(new TempJavaServiceFragmentFiles(javaFileInfo));
}
if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_ALL_EVENT_CLASS_MASK) != 0) {
setEventFragmentFiles(new TempJavaEventFragmentFiles(javaFileInfo));
}
}
/**
......@@ -156,6 +166,25 @@ public class TempJavaCodeFragmentFiles {
}
/**
* Retrieves the temp file handle for event file generation.
*
* @return temp file handle for enumeration file generation
*/
public TempJavaEventFragmentFiles getEventFragmentFiles() {
return tempJavaEventFragmentFiles;
}
/**
* Sets temp file handle for event file generation.
*
* @param tempJavaEventFragmentFiles temp file handle for event file generation
*/
public void setEventFragmentFiles(TempJavaEventFragmentFiles tempJavaEventFragmentFiles) {
this.tempJavaEventFragmentFiles = tempJavaEventFragmentFiles;
}
/**
* Constructs java code exit.
*
* @param fileType generated file type
......@@ -183,6 +212,13 @@ public class TempJavaCodeFragmentFiles {
getServiceTempFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, curNode);
}
/**
* Creates event, event listener and event subject files.
*/
if (fileType == GENERATE_ALL_EVENT_CLASS_MASK) {
getEventFragmentFiles().generateJavaFile(GENERATE_ALL_EVENT_CLASS_MASK, curNode);
}
/*
* Creats enumeration class file.
*/
......
......@@ -16,23 +16,17 @@
package org.onosproject.yangutils.translator.tojava.javamodel;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeOfAugmentableNode;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
/**
* Represents augment information extended to support java code generation.
......@@ -44,23 +38,12 @@ public class YangJavaAugment
private static final long serialVersionUID = 806201632L;
/**
* Prefix to be added to generated java file for augment node.
*/
private static final String AUGMENTED = "Augmented";
/**
* Contains the information of the java file being generated.
*/
private JavaFileInfo javaFileInfo;
/**
* TargetNodes java qualified info.
*/
private List<JavaQualifiedTypeInfo> extendedClassInfo;
/**
* File handle to maintain temporary java code fragments as per the code
* snippet types.
* File handle to maintain temporary java code fragments as per the code snippet types.
*/
private transient TempJavaCodeFragmentFiles tempFileHandle;
......@@ -70,7 +53,6 @@ public class YangJavaAugment
public YangJavaAugment() {
super();
setJavaFileInfo(new JavaFileInfo());
setExtendedClassInfo(new ArrayList<>());
getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER);
}
......@@ -119,8 +101,7 @@ public class YangJavaAugment
}
/**
* Prepare the information for java code generation corresponding to YANG
* augment info.
* Prepare the information for java code generation corresponding to YANG augment info.
*
* @param yangPlugin YANG plugin config
* @throws TranslatorException translator operation fail
......@@ -148,46 +129,4 @@ public class YangJavaAugment
}
}
/**
* Returns augment class name.
*
* @return augment class name
*/
public String getAugmentClassName() {
YangNodeIdentifier nodeId = getTargetNode().get(getTargetNode().size() - 1).getNodeIdentifier();
String name = getCapitalCase(getCamelCase(nodeId.getName(), null));
if (nodeId.getPrefix() != null) {
return AUGMENTED + getCapitalCase(nodeId.getPrefix()) + name;
} else {
return AUGMENTED + name;
}
}
/**
* Returns extended class info.
*
* @return extended class info
*/
public List<JavaQualifiedTypeInfo> getExtendedClassInfo() {
return extendedClassInfo;
}
/**
* Sets extended class info.
*
* @param augmentedInfo extended class info
*/
private void setExtendedClassInfo(List<JavaQualifiedTypeInfo> augmentedInfo) {
extendedClassInfo = augmentedInfo;
}
/**
* Adds to extended class info list.
*
* @param augmentedInfo extended class info
*/
public void addToExtendedClassInfo(JavaQualifiedTypeInfo augmentedInfo) {
getExtendedClassInfo().add(augmentedInfo);
}
}
......
......@@ -15,6 +15,10 @@
*/
package org.onosproject.yangutils.translator.tojava.javamodel;
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.onosproject.yangutils.datamodel.YangIdentity;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
......@@ -25,12 +29,8 @@ import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import java.io.File;
import java.io.IOException;
import java.util.List;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_IDENTITY_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.updatePackageInfo;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.initiateJavaFileGeneration;
......@@ -145,7 +145,7 @@ public class YangJavaIdentity extends YangIdentity
}
}
File file = getFileObject(path, className, JAVA_FILE_EXTENSION, getJavaFileInfo());
File file = getFileObject(path, className, JAVA_FILE_EXTENSION, getJavaFileInfo().getBaseCodeGenPath());
initiateJavaFileGeneration(file, GENERATE_IDENTITY_CLASS, imports, this, className);
closeFile(file, false);
......
......@@ -29,14 +29,12 @@ import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ALL_EVENT_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeOfRootNode;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isManagerCodeGenRequired;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isGenerationOfCodeReq;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isManagerCodeGenRequired;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.searchAndDeleteTempDir;
import static org.onosproject.yangutils.utils.UtilConstants.SBI;
......@@ -56,8 +54,7 @@ public class YangJavaModule
private JavaFileInfo javaFileInfo;
/**
* File handle to maintain temporary java code fragments as per the code
* snippet types.
* File handle to maintain temporary java code fragments as per the code snippet types.
*/
private transient TempJavaCodeFragmentFiles tempFileHandle;
......@@ -73,12 +70,7 @@ public class YangJavaModule
super();
setJavaFileInfo(new JavaFileInfo());
setNotificationNodes(new ArrayList<>());
int gentype = GENERATE_SERVICE_AND_MANAGER | GENERATE_INTERFACE_WITH_BUILDER;
if (isNotificationChildNodePresent(this)) {
gentype = GENERATE_SERVICE_AND_MANAGER | GENERATE_EVENT_SUBJECT_CLASS | GENERATE_EVENT_CLASS
| GENERATE_EVENT_LISTENER_INTERFACE;
}
getJavaFileInfo().setGeneratedFileTypes(gentype);
getJavaFileInfo().setGeneratedFileTypes(GENERATE_SERVICE_AND_MANAGER | GENERATE_INTERFACE_WITH_BUILDER);
}
......@@ -135,6 +127,11 @@ public class YangJavaModule
public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
String modulePkg = getRootPackage(getVersion(), getNameSpace().getUri(), getRevision().getRevDate(),
yangPlugin.getConflictResolver());
if (isNotificationChildNodePresent(this)) {
getJavaFileInfo().setGeneratedFileTypes(getJavaFileInfo().getGeneratedFileTypes()
| GENERATE_ALL_EVENT_CLASS_MASK);
}
try {
generateCodeOfRootNode(this, yangPlugin, modulePkg);
} catch (IOException e) {
......@@ -157,17 +154,22 @@ public class YangJavaModule
*
* The manager class needs to extend the "ListenerRegistry".
*/
try {
if (isManagerCodeGenRequired(this) && isGenerationOfCodeReq(getJavaFileInfo())) {
if ((getJavaFileInfo().getPluginConfig().getCodeGenerateForsbi() == null) ||
(!getJavaFileInfo().getPluginConfig().getCodeGenerateForsbi().equals(SBI))) {
if ((getJavaFileInfo().getGeneratedFileTypes() & GENERATE_ALL_EVENT_CLASS_MASK) != 0) {
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_ALL_EVENT_CLASS_MASK, this);
}
getTempJavaCodeFragmentFiles()
.generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
getTempJavaCodeFragmentFiles()
.generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
if (isManagerCodeGenRequired(this)) {
if (isGenerationOfCodeReq(getJavaFileInfo())) {
if ((getJavaFileInfo().getPluginConfig().getCodeGenerateForsbi() == null)
|| (!getJavaFileInfo().getPluginConfig().getCodeGenerateForsbi().equals(SBI))) {
getTempJavaCodeFragmentFiles().getServiceTempFiles().setManagerNeedToBeGenerated(true);
}
}
}
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
searchAndDeleteTempDir(getJavaFileInfo().getBaseCodeGenPath() +
getJavaFileInfo().getPackageFilePath());
searchAndDeleteTempDir(getJavaFileInfo().getPluginConfig().getCodeGenDir() +
......
......@@ -31,14 +31,12 @@ import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ALL_EVENT_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeOfRootNode;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isManagerCodeGenRequired;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isGenerationOfCodeReq;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isManagerCodeGenRequired;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
import static org.onosproject.yangutils.utils.UtilConstants.SBI;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.searchAndDeleteTempDir;
......@@ -58,8 +56,7 @@ public class YangJavaSubModule
private JavaFileInfo javaFileInfo;
/**
* File handle to maintain temporary java code fragments as per the code
* snippet types.
* File handle to maintain temporary java code fragments as per the code snippet types.
*/
private transient TempJavaCodeFragmentFiles tempFileHandle;
......@@ -76,8 +73,7 @@ public class YangJavaSubModule
setJavaFileInfo(new JavaFileInfo());
int gentype = GENERATE_SERVICE_AND_MANAGER | GENERATE_INTERFACE_WITH_BUILDER;
if (isNotificationChildNodePresent(this)) {
gentype = GENERATE_SERVICE_AND_MANAGER | GENERATE_EVENT_SUBJECT_CLASS | GENERATE_EVENT_CLASS
| GENERATE_EVENT_LISTENER_INTERFACE;
gentype = GENERATE_SERVICE_AND_MANAGER | GENERATE_ALL_EVENT_CLASS_MASK;
}
getJavaFileInfo().setGeneratedFileTypes(gentype);
}
......@@ -145,6 +141,11 @@ public class YangJavaSubModule
public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
String subModulePkg = getRootPackage(getVersion(), getNameSpaceFromModule(getBelongsTo()),
getRevision().getRevDate(), yangPlugin.getConflictResolver());
if (isNotificationChildNodePresent(this)) {
getJavaFileInfo().setGeneratedFileTypes(getJavaFileInfo().getGeneratedFileTypes()
| GENERATE_ALL_EVENT_CLASS_MASK);
}
try {
generateCodeOfRootNode(this, yangPlugin, subModulePkg);
} catch (IOException e) {
......@@ -169,13 +170,21 @@ public class YangJavaSubModule
* The manager class needs to extend the "ListenerRegistry".
*/
try {
if (isManagerCodeGenRequired(this) && isGenerationOfCodeReq(getJavaFileInfo())) {
if ((getJavaFileInfo().getPluginConfig().getCodeGenerateForsbi() == null) ||
(!getJavaFileInfo().getPluginConfig().getCodeGenerateForsbi().equals(SBI))) {
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
if ((getJavaFileInfo().getGeneratedFileTypes() & GENERATE_ALL_EVENT_CLASS_MASK) != 0) {
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_ALL_EVENT_CLASS_MASK, this);
}
getTempJavaCodeFragmentFiles()
.generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
if (isManagerCodeGenRequired(this)) {
if (isGenerationOfCodeReq(getJavaFileInfo())) {
if ((getJavaFileInfo().getPluginConfig().getCodeGenerateForsbi() == null)
|| (!getJavaFileInfo().getPluginConfig().getCodeGenerateForsbi().equals(SBI))) {
getTempJavaCodeFragmentFiles().getServiceTempFiles().setManagerNeedToBeGenerated(true);
}
}
}
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
searchAndDeleteTempDir(getJavaFileInfo().getBaseCodeGenPath() +
getJavaFileInfo().getPackageFilePath());
searchAndDeleteTempDir(getJavaFileInfo().getPluginConfig().getCodeGenDir() +
......@@ -185,6 +194,7 @@ public class YangJavaSubModule
}
}
/**
* Returns notifications node list.
*
......
......@@ -95,8 +95,7 @@ public final class JavaCodeSnippetGen {
* Returns the textual java code information corresponding to the import list.
*
* @param importInfo import info
* @return the textual java code information corresponding to the import
* list
* @return the textual java code information corresponding to the import list
*/
public static String getImportText(JavaQualifiedTypeInfo importInfo) {
return IMPORT + importInfo.getPkgInfo() + PERIOD + importInfo.getClassInfo() + SEMI_COLAN + NEW_LINE;
......@@ -147,8 +146,7 @@ public final class JavaCodeSnippetGen {
}
/**
* Returns based on the file type and the YANG name of the file, generate the class
* / interface definition close.
* Returns based on the file type and the YANG name of the file, generate the class / interface definition close.
*
* @return corresponding textual java code information
*/
......
......@@ -31,8 +31,8 @@ import org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
/**
* Represent the extends list for generated java classes. It holds the class details which needs
* to be extended by the generated java code.
* Represent the extends list for generated java classes. It holds the class details which needs to be extended by the
* generated java code.
*/
public class JavaExtendsListHolder {
......
......@@ -517,11 +517,6 @@ public final class UtilConstants {
public static final String IF = "if";
/**
* Static attribute for "for" syntax.
*/
public static final String FOR = "for";
/**
* Static attribute for of.
*/
public static final String OF = "of";
......@@ -1185,7 +1180,7 @@ public final class UtilConstants {
/**
* Static attribute for augmentation class.
*/
public static final String AUGMENTATION = "Augmentation";
public static final String AUGMENTED_INFO = "AugmentedInfo";
/**
* Static attribute for AugmentedInfo class.
......@@ -1383,6 +1378,43 @@ public final class UtilConstants {
public static final String JAR = "jar";
/**
* Static attribute for for.
*/
public static final String FOR = "for";
/**
* Static attribute for YangAugmentedOpParamInfo.
*/
public static final String YANG_AUGMENTED_OP_PARAM_INFO = "YangAugmentedOpParamInfo";
/**
* Static attribute for YangAugmentedOpParamInfo.
*/
public static final String YANG_AUGMENTED_OP_PARAM_INFO_CLASS = "YangAugmentedOpParamInfo;\n";
/**
* Static attribute for IllegalArgumentException.
*/
public static final String ILLEGAL_ARGUMENT_EXCEPTION = "IllegalArgumentException";
/**
* Static attribute for IllegalArgumentException.
*/
public static final String ILLEGAL_ARGUMENT_EXCEPTION_MSG = "\"provided augmented info is invalid for content " +
"match.\"";
/**
* Static attribute for throw.
*/
public static final String THROW = "throw";
/**
* Static attribute for baseClass().
*/
public static final String BASE_CLASS = "BaseClass()";
/**
* Creates an instance of util constants.
*/
private UtilConstants() {
......
......@@ -56,7 +56,7 @@ public class IetfYangFileTest {
yangPluginConfig.setCodeGenDir("target/ietfyang/l3vpnservice/");
yangPluginConfig.setManagerCodeGenDir("target/ietfyang/l3vpnservice/");
utilManager.translateToJava(utilManager.getYangFileInfoSet(), yangPluginConfig);
utilManager.translateToJava(yangPluginConfig);
deleteDirectory(userDir + "/target/ietfyang/");
}
......
......@@ -50,7 +50,7 @@ public class AugmentTranslatorTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/augmentTranslator/");
yangPluginConfig.setManagerCodeGenDir("target/augmentTranslator/");
utilManager.translateToJava(utilManager.getYangFileInfoSet(), yangPluginConfig);
utilManager.translateToJava(yangPluginConfig);
deleteDirectory("target/augmentTranslator/");
}
......
......@@ -638,7 +638,7 @@ public class InterFileLinkingTest {
yangPluginConfig.setCodeGenDir("target/interfilewithusesreferringtype/");
yangPluginConfig.setManagerCodeGenDir("target/interfilewithusesreferringtype/");
utilManager.translateToJava(utilManager.getYangFileInfoSet(), yangPluginConfig);
utilManager.translateToJava(yangPluginConfig);
deleteDirectory("target/interfilewithusesreferringtype/");
......@@ -660,7 +660,7 @@ public class InterFileLinkingTest {
yangPluginConfig.setCodeGenDir("target/file1UsesFile2TypeDefFile3Type/");
yangPluginConfig.setManagerCodeGenDir("target/file1UsesFile2TypeDefFile3Type/");
utilManager.translateToJava(utilManager.getYangFileInfoSet(), yangPluginConfig);
utilManager.translateToJava(yangPluginConfig);
deleteDirectory("target/file1UsesFile2TypeDefFile3Type/");
......@@ -682,7 +682,7 @@ public class InterFileLinkingTest {
yangPluginConfig.setCodeGenDir("target/interfileietf/");
yangPluginConfig.setManagerCodeGenDir("target/interfileietf/");
utilManager.translateToJava(utilManager.getYangFileInfoSet(), yangPluginConfig);
utilManager.translateToJava(yangPluginConfig);
deleteDirectory("target/interfileietf/");
......@@ -704,7 +704,7 @@ public class InterFileLinkingTest {
yangPluginConfig.setCodeGenDir("target/usesInContainer/");
yangPluginConfig.setManagerCodeGenDir("target/usesInContainer/");
utilManager.translateToJava(utilManager.getYangFileInfoSet(), yangPluginConfig);
utilManager.translateToJava(yangPluginConfig);
deleteDirectory("target/usesInContainer/");
......@@ -726,7 +726,7 @@ public class InterFileLinkingTest {
yangPluginConfig.setCodeGenDir("target/groupingNodeSameAsModule/");
yangPluginConfig.setManagerCodeGenDir("target/groupingNodeSameAsModule/");
utilManager.translateToJava(utilManager.getYangFileInfoSet(), yangPluginConfig);
utilManager.translateToJava(yangPluginConfig);
deleteDirectory("target/groupingNodeSameAsModule/");
......
......@@ -191,7 +191,7 @@ public class InterJarLinkerTest {
yangPluginConfig.setCodeGenDir(TARGET);
yangPluginConfig.setManagerCodeGenDir(TARGET);
utilManager.translateToJava(utilManager.getYangFileInfoSet(), yangPluginConfig);
utilManager.translateToJava(yangPluginConfig);
testIfFlowClassifierFilesExists();
testIfPortPairFileDoesNotExist();
......@@ -308,6 +308,7 @@ public class InterJarLinkerTest {
for (YangNode node : interJarResolvedNodes) {
YangFileInfo dependentFileInfo = new YangFileInfo();
node.setToTranslate(false);
dependentFileInfo.setRootNode(node);
dependentFileInfo.setForTranslator(false);
dependentFileInfo.setYangFileName(node.getName());
......
......@@ -44,7 +44,7 @@ public class ManagerCodeGeneratorTest {
@Test
public void processManagerTranslator() throws IOException, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/manager";
String searchDir = "src/test/resources/manager/singleChild";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
......@@ -54,7 +54,7 @@ public class ManagerCodeGeneratorTest {
yangPluginConfig.setCodeGenDir("target/manager/");
yangPluginConfig.setManagerCodeGenDir("target/manager/");
utilManager.translateToJava(utilManager.getYangFileInfoSet(), yangPluginConfig);
utilManager.translateToJava(yangPluginConfig);
String file1 = "target/manager/org/onosproject/yang/gen/v1/test5/test/rev20160704/Test5Manager.java";
String file2 = "target/manager/org/onosproject/yang/gen/v1/test5/test/rev20160704/Test6Manager.java";
String file3 = "target/manager/org/onosproject/yang/gen/v1/test5/test/rev20160704/Test7Manager.java";
......@@ -79,7 +79,7 @@ public class ManagerCodeGeneratorTest {
public void processManagerInDifferentPackageTranslator() throws IOException, ParserException,
MojoExecutionException {
String searchDir = "src/test/resources/manager";
String searchDir = "src/test/resources/manager/singleChild";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
......@@ -87,10 +87,10 @@ public class ManagerCodeGeneratorTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/manager/");
yangPluginConfig.setManagerCodeGenDir("target/manager1/");
yangPluginConfig.setManagerCodeGenDir("target/manager/");
utilManager.translateToJava(utilManager.getYangFileInfoSet(), yangPluginConfig);
String file3 = "target/manager1/org/onosproject/yang/gen/v1/test5/test/rev20160704/Test7Manager.java";
utilManager.translateToJava(yangPluginConfig);
String file3 = "target/manager/org/onosproject/yang/gen/v1/test5/test/rev20160704/Test7Manager.java";
File manager3 = new File(file3);
assertThat(true, is(manager3.exists()));
......@@ -98,4 +98,48 @@ public class ManagerCodeGeneratorTest {
deleteDirectory("target/manager/");
deleteDirectory("target/manager1/");
}
/**
* Checks manager translation in different package should not result in any exception.
*
* @throws MojoExecutionException
*/
@Test
public void processManagerforMultiChildTranslator() throws IOException, ParserException,
MojoExecutionException {
String searchDir = "src/test/resources/manager/MultiChild";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/manager/");
yangPluginConfig.setManagerCodeGenDir("target/manager/");
utilManager.translateToJava(yangPluginConfig);
String file1 = "target/manager/org/onosproject/yang/gen/v1/test5/test/rev20160704/Test5Manager.java";
File manager1 = new File(file1);
assertThat(false, is(manager1.exists()));
String file2 = "target/manager/org/onosproject/yang/gen/v1/test5/test/rev20160704/Test6Manager.java";
File manager2 = new File(file2);
assertThat(false, is(manager2.exists()));
String file3 = "target/manager/org/onosproject/yang/gen/v1/test5/test/rev20160704/Test7Manager.java";
File manager3 = new File(file3);
assertThat(false, is(manager3.exists()));
String file4 = "target/manager/org/onosproject/yang/gen/v1/test8/test/rev20160704/Test8Manager.java";
File manager4 = new File(file4);
assertThat(true, is(manager4.exists()));
deleteDirectory("target/manager/");
deleteDirectory("target/manager1/");
}
}
......
module test5 {
namespace "test5:test";
prefix test ;
revision "2016-07-04" {
description "Initial revision.";
}
typedef typedef1 {
type int32;
}
typedef typedef2 {
type int32;
}
typedef typedef3 {
type int32;
}
}
submodule test6 {
belongs-to "test5" {
prefix "test";
}
revision "2016-07-04" {
description "Initial revision.";
}
grouping grouping1 {
leaf leaf1 {
type int32;
}
}
grouping grouping2 {
leaf leaf1 {
type int32;
}
}
grouping grouping3 {
leaf leaf1 {
type int32;
}
}
}
module test7 {
namespace "test5:test";
prefix test ;
revision "2016-07-04" {
description "Initial revision.";
}
grouping grouping1 {
leaf leaf1 {
type int32;
}
}
typedef typedef3 {
type int32;
}
}
module test8 {
namespace "test8:test";
prefix test ;
revision "2016-07-04" {
description "Initial revision.";
}
grouping grouping1 {
leaf leaf1 {
type int32;
}
}
typedef typedef3 {
type int32;
}
container container2 {
}
}
......@@ -5,7 +5,7 @@ module test5 {
revision "2016-07-04" {
description "Initial revision.";
}
typedef abc {
typedef typedef1 {
type int32;
}
......
......@@ -7,7 +7,7 @@ submodule test6 {
revision "2016-07-04" {
description "Initial revision.";
}
grouping abc {
grouping grouping1 {
leaf leaf1 {
type int32;
}
......
......@@ -6,8 +6,7 @@ module test7 {
description "Initial revision.";
}
leaf abc {
type int32;
container cont1 {
}
}
......