VinodKumarS-Huawei
Committed by Ray Milkey

[ONOS-4303, ONOS-4508, ONOS-4509, ONOS-4510, ONOS-4351]notification,rpc,union,sub-module,augment

Change-Id: Ibeed9ff965c13fd66743c1080cb1350d93a3a435
Showing 43 changed files with 1312 additions and 249 deletions
......@@ -54,7 +54,7 @@ import org.onosproject.yangutils.utils.YangConstructType;
/**
* Represents data model node to maintain information defined in YANG typedef.
*/
public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable, YangTypeContainer {
public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable, YangTypeHolder {
/**
* Default value in string, needs to be converted to the target object,
......
......@@ -21,7 +21,7 @@ import java.util.List;
/**
* Represents the holder with type(s).
*/
public interface YangTypeContainer {
public interface YangTypeHolder {
/**
* Returns type list.
......
......@@ -47,7 +47,7 @@ import org.onosproject.yangutils.utils.YangConstructType;
/**
* Represents data model node to maintain information defined in YANG union.
*/
public class YangUnion extends YangNode implements Parsable, YangTypeContainer {
public class YangUnion extends YangNode implements Parsable, YangTypeHolder {
// List of YANG type.
private List<YangType<?>> typeList;
......
......@@ -19,13 +19,14 @@ package org.onosproject.yangutils.datamodel.utils;
import java.util.List;
import org.onosproject.yangutils.datamodel.CollisionDetector;
import org.onosproject.yangutils.datamodel.YangReferenceResolver;
import org.onosproject.yangutils.datamodel.YangImport;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafList;
import org.onosproject.yangutils.datamodel.YangLeavesHolder;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangReferenceResolver;
import org.onosproject.yangutils.datamodel.YangResolutionInfo;
import org.onosproject.yangutils.datamodel.YangRpc;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.utils.YangConstructType;
......@@ -222,4 +223,21 @@ public final class DataModelUtils {
resolutionInfo.resolveLinkingForResolutionInfo(dataModelRootNode.getPrefix());
}
}
/**
* Checks if there is any rpc defined in the module or sub-module.
*
* @param rootNode root node of the data model
* @return status of rpc's existence
*/
public static boolean isRpcChildNodePresent(YangNode rootNode) {
YangNode childNode = rootNode.getChild();
while (childNode != null) {
if (childNode instanceof YangRpc) {
return true;
}
childNode = childNode.getNextSibling();
}
return false;
}
}
......
......@@ -46,7 +46,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_BASE_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.addToSource;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.clean;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.copyYangFilesToTarget;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getDirectory;
......@@ -127,8 +127,8 @@ public class YangUtilManager extends AbstractMojo {
/**
* For deleting the generated code in previous build.
*/
clean(getDirectory(baseDir, genFilesDir) + DEFAULT_PKG);
clean(getDirectory(baseDir, outputDirectory));
deleteDirectory(getDirectory(baseDir, genFilesDir) + DEFAULT_PKG);
deleteDirectory(getDirectory(baseDir, outputDirectory));
String searchDir = getDirectory(baseDir, yangFilesDir);
String codeGenDir = getDirectory(baseDir, genFilesDir) + SLASH;
......@@ -166,7 +166,7 @@ public class YangUtilManager extends AbstractMojo {
} catch (Exception e) {
try {
translatorErrorHandler(getRootNode());
clean(getDirectory(baseDir, genFilesDir) + DEFAULT_PKG);
deleteDirectory(getDirectory(baseDir, genFilesDir) + DEFAULT_PKG);
} catch (IOException | DataModelException ex) {
throw new MojoExecutionException("Error handler failed to delete files for data model node.");
}
......
......@@ -50,15 +50,7 @@ public final class GeneratedJavaFileType {
/**
* Java interface corresponding to rpc.
*/
public static final int GENERATE_RPC_INTERFACE = 16;
/**
* Interface, class file and rpc.
*/
public static final int GENERATE_MANAGER_WITH_RPC = GENERATE_INTERFACE_WITH_BUILDER
| GENERATE_RPC_INTERFACE;
// TODO RPC implementation to be integrated with notification.
public static final int GENERATE_SERVICE_AND_MANAGER = 16;
/**
* Java class corresponding to YANG enumeration.
......@@ -82,6 +74,16 @@ public final class GeneratedJavaFileType {
| GENERATE_UNION_CLASS;
/**
* Event class.
*/
public static final int GENERATE_EVENT_CLASS = 256;
/**
* Event listener class.
*/
public static final int GENERATE_EVENT_LISTENER_INTERFACE = 512;
/**
* Creates an instance of generate java file type.
*/
private GeneratedJavaFileType() {
......
......@@ -87,9 +87,14 @@ public final class GeneratedTempFileType {
public static final int ENUM_IMPL_MASK = 4096;
/**
* Rpc implementation of class.
* Rpc interface of module / sub module.
*/
public static final int RPC_IMPL_MASK = 8192;
public static final int RPC_INTERFACE_MASK = 8192;
/**
* Rpc implementation of module / sub module.
*/
public static final int RPC_IMPL_MASK = 16384;
/**
* Creates an instance of generated temp file type.
......
......@@ -31,13 +31,14 @@ public interface JavaCodeGenerator {
* @param yangPlugin YANG plugin config
* @throws IOException when fails to translate the data model tree
*/
void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException;
void generateCodeEntry(YangPluginConfig yangPlugin)
throws IOException;
/**
* Traverse the schema of application and generate corresponding code.
*
* @throws IOException when fails to generate java code
*/
void generateCodeExit() throws IOException;
void generateCodeExit()
throws IOException;
}
......
......@@ -78,8 +78,23 @@ public final class JavaCodeGeneratorUtil {
while (codeGenNode != null) {
if (curTraversal != PARENT) {
if (codeGenNode instanceof JavaCodeGenerator) {
setCurNode(codeGenNode);
generateCodeEntry(codeGenNode, yangPlugin);
} else {
/*
* For grouping and uses, there is no code generation, skip the generation for the child.
*/
if (codeGenNode.getNextSibling() != null) {
curTraversal = SIBILING;
codeGenNode = codeGenNode.getNextSibling();
} else {
curTraversal = PARENT;
codeGenNode = codeGenNode.getParent();
}
continue;
}
}
if (curTraversal != PARENT && codeGenNode.getChild() != null) {
curTraversal = CHILD;
......@@ -238,7 +253,7 @@ public final class JavaCodeGeneratorUtil {
throws IOException {
if (((TempJavaCodeFragmentFilesContainer) node).getTempJavaCodeFragmentFiles() != null) {
((TempJavaCodeFragmentFilesContainer) node).getTempJavaCodeFragmentFiles().close(true);
((TempJavaCodeFragmentFilesContainer) node).getTempJavaCodeFragmentFiles().freeTemporaryResources(true);
}
}
}
......
......@@ -71,6 +71,17 @@ public class JavaFileInfo {
}
/**
* Adds the types of files being generated corresponding to the YANG
* definition.
*
* @param fileTypes the types of files being generated corresponding to the
* YANG definition
*/
public void addGeneratedFileTypes(int fileTypes) {
genFileTypes |= fileTypes;
}
/**
* Returns the java name of the node.
*
* @return the java name of node
......
......@@ -16,15 +16,31 @@
package org.onosproject.yangutils.translator.tojava;
import java.io.File;
import java.io.IOException;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getConstructor;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
/**
* Represents implementation of java bean code fragments temporary implementations.
* Maintains the temp files required specific for bean java snippet generation.
*/
public class TempJavaBeanFragmentFiles
extends TempJavaFragmentFiles {
/**
* File name for constructor.
*/
private static final String CONSTRUCTOR_FILE_NAME = "Constructor";
/**
* Temporary file handle for constructor of class.
*/
private File constructorImplTempFileHandle;
/**
* Creates an instance of temporary java code fragment.
*
* @param javaFileInfo generated java file info
......@@ -32,6 +48,81 @@ public class TempJavaBeanFragmentFiles
*/
public TempJavaBeanFragmentFiles(JavaFileInfo javaFileInfo)
throws IOException {
super(javaFileInfo);
/*
* Initialize getterImpl, attributes, constructor, hash code, equals and
* to strings when generation file type matches to impl class mask.
*/
addGeneratedTempFile(CONSTRUCTOR_IMPL_MASK);
setConstructorImplTempFileHandle(getTemporaryFileHandle(CONSTRUCTOR_FILE_NAME));
}
/**
* Returns constructor's temporary file handle.
*
* @return temporary file handle
*/
public File getConstructorImplTempFileHandle() {
return constructorImplTempFileHandle;
}
/**
* Sets to constructor's temporary file handle.
*
* @param constructor file handle for to constructor
*/
private void setConstructorImplTempFileHandle(File constructor) {
constructorImplTempFileHandle = constructor;
}
/**
* Adds constructor for class.
*
* @param attr attribute info
* @throws IOException when fails to append to temporary file
*/
private void addConstructor(JavaAttributeInfo attr)
throws IOException {
appendToFile(getConstructorImplTempFileHandle(), getConstructor(getGeneratedJavaClassName(), attr,
getGeneratedJavaFiles()));
}
/**
* Adds the new attribute info to the target generated temporary files.
*
* @param newAttrInfo the attribute info that needs to be added to temporary
* files
* @throws IOException IO operation fail
*/
void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo)
throws IOException {
super.addJavaSnippetInfoToApplicableTempFiles(newAttrInfo);
addConstructor(newAttrInfo);
}
/**
* Removes all temporary file handles.
*
* @param isErrorOccurred when translator fails to generate java files we
* need to close all open file handles include temporary files
* and java files.
* @throws IOException when failed to delete the temporary files
*/
@Override
public void freeTemporaryResources(boolean isErrorOccurred)
throws IOException {
/*
* Close constructor temporary file handle and delete the file.
*/
closeFile(getConstructorImplTempFileHandle(), true);
super.freeTemporaryResources(isErrorOccurred);
}
}
......
......@@ -18,18 +18,22 @@ package org.onosproject.yangutils.translator.tojava;
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangTypeContainer;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangTypeHolder;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
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_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_RPC_INTERFACE;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPE_CLASS;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.getExtendsList;
/**
* Represents implementation of java code fragments temporary implementations.
* Contains fragment file object of different types of java file.
* Uses required object(s) to generate the target java file(s).
*/
public class TempJavaCodeFragmentFiles {
......@@ -54,6 +58,17 @@ public class TempJavaCodeFragmentFiles {
private TempJavaEnumerationFragmentFiles enumerationTempFiles;
/**
* Has the temporary files required for generated event classes.
*/
private TempJavaEventFragmentFiles eventTempFiles;
/**
* Has the temporary files required for generated event listenerclasses.
*/
private TempJavaEventListenerFragmentFiles eventListenerTempFiles;
/**
* Creates an instance of temporary java code fragment.
*
* @param javaFileInfo generated java file info
......@@ -80,9 +95,17 @@ public class TempJavaCodeFragmentFiles {
setEnumerationTempFiles(new TempJavaEnumerationFragmentFiles(javaFileInfo));
}
if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_RPC_INTERFACE) != 0) {
if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_SERVICE_AND_MANAGER) != 0) {
setServiceTempFiles(new TempJavaServiceFragmentFiles(javaFileInfo));
}
if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_EVENT_CLASS) != 0) {
setEventTempFiles(new TempJavaEventFragmentFiles(javaFileInfo));
}
if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_EVENT_LISTENER_INTERFACE) != 0) {
setEventListenerTempFiles(new TempJavaEventListenerFragmentFiles(javaFileInfo));
}
}
/**
......@@ -161,6 +184,43 @@ public class TempJavaCodeFragmentFiles {
}
/**
* Retrieves the temp file handle for event file generation.
*
* @return temp file handle for event file generation
*/
public TempJavaEventFragmentFiles getEventTempFiles() {
return eventTempFiles;
}
/**
* Sets temp file handle for event file generation.
*
* @param eventTempFiles temp file handle for event file generation
*/
public void setEventTempFiles(TempJavaEventFragmentFiles eventTempFiles) {
this.eventTempFiles = eventTempFiles;
}
/**
* Retrieves the temp file handle for event listener file generation.
*
* @return temp file handle for event listener file generation
*/
public TempJavaEventListenerFragmentFiles getEventListenerTempFiles() {
return eventListenerTempFiles;
}
/**
* Sets temp file handle for event listener file generation.
*
* @param eventListenerTempFiles temp file handle for event listener file generation
*/
public void setEventListenerTempFiles(
TempJavaEventListenerFragmentFiles eventListenerTempFiles) {
this.eventListenerTempFiles = eventListenerTempFiles;
}
/**
* Constructs java code exit.
*
* @param fileType generated file type
......@@ -170,17 +230,42 @@ public class TempJavaCodeFragmentFiles {
public void generateJavaFile(int fileType, YangNode curNode)
throws IOException {
if (getBeanTempFiles() != null) {
if ((fileType & GENERATE_INTERFACE_WITH_BUILDER) != 0) {
getBeanTempFiles().generateJavaFile(fileType, curNode);
}
/**
* Creates user defined data type class file.
*/
if (getTypeTempFiles() != null) {
if ((fileType & GENERATE_TYPE_CLASS) != 0) {
getTypeTempFiles().generateJavaFile(fileType, curNode);
}
if (fileType == GENERATE_SERVICE_AND_MANAGER) {
getServiceTempFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, curNode);
}
if ((fileType & GENERATE_EVENT_CLASS) != 0) {
/**
* Creates event class file.
*/
if (getEventTempFiles() != null) {
getEventTempFiles().generateJavaFile(fileType, curNode);
}
}
if ((fileType & GENERATE_EVENT_LISTENER_INTERFACE) != 0) {
/**
* Creates event listener class file.
*/
getEventListenerTempFiles().generateJavaFile(fileType, curNode);
}
freeTemporaryResources(false);
}
/**
......@@ -208,35 +293,16 @@ public class TempJavaCodeFragmentFiles {
}
/**
* Adds all the leaves in the current data model node as part of the
* generated temporary file.
*
* @param curNode java file info of the generated file
* @throws IOException IO operation fail
*/
public void addCurNodeLeavesInfoToTempFiles(YangNode curNode)
throws IOException {
if (getBeanTempFiles() != null) {
getBeanTempFiles().addCurNodeLeavesInfoToTempFiles(curNode);
}
}
/**
* Add all the type in the current data model node as part of the
* generated temporary file.
*
* @param yangTypeContainer YANG java data model node which has type info, eg union / typedef
* @param yangTypeHolder YANG java data model node which has type info, eg union / typedef
* @throws IOException IO operation fail
*/
public void addTypeInfoToTempFiles(YangTypeContainer yangTypeContainer)
public void addTypeInfoToTempFiles(YangTypeHolder yangTypeHolder)
throws IOException {
if (getTypeTempFiles() != null) {
getTypeTempFiles()
.addTypeInfoToTempFiles(yangTypeContainer);
}
.addTypeInfoToTempFiles(yangTypeHolder);
}
/**
......@@ -307,19 +373,27 @@ public class TempJavaCodeFragmentFiles {
* all open file handles include temporary files and java files.
* @throws IOException when failed to delete the temporary files
*/
public void close(boolean isErrorOccurred)
public void freeTemporaryResources(boolean isErrorOccurred)
throws IOException {
if (getBeanTempFiles() != null) {
getBeanTempFiles().close(isErrorOccurred);
getBeanTempFiles().freeTemporaryResources(isErrorOccurred);
}
if (getTypeTempFiles() != null) {
getTypeTempFiles().close(isErrorOccurred);
getTypeTempFiles().freeTemporaryResources(isErrorOccurred);
}
if (getEnumerationTempFiles() != null) {
getEnumerationTempFiles().close(isErrorOccurred);
getEnumerationTempFiles().freeTemporaryResources(isErrorOccurred);
}
if (getEventTempFiles() != null) {
getEventTempFiles().freeTemporaryResources(isErrorOccurred);
}
if (getEventListenerTempFiles() != null) {
getEventListenerTempFiles().freeTemporaryResources(isErrorOccurred);
}
}
......
......@@ -19,6 +19,7 @@ import java.io.IOException;
/**
* Represents implementation of java code fragments temporary implementations.
* Maintains the temp files required specific for enumeration java snippet generation.
*/
public class TempJavaEnumerationFragmentFiles
extends TempJavaFragmentFiles {
......
/*
* 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.translator.tojava;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import org.onosproject.yangutils.datamodel.YangNode;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEventFile;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
/**
* Represents implementation of java bean code fragments temporary implementations.
* Maintains the temp files required specific for event java snippet generation.
*/
public class TempJavaEventFragmentFiles
extends TempJavaFragmentFiles {
/**
* File name for generated class file for special type like union, typedef
* suffix.
*/
private static final String EVENT_FILE_NAME_SUFFIX = "Event";
/**
* Java file handle for event file.
*/
private File eventJavaFileHandle;
/**
* Creates an instance of temporary java code fragment.
*
* @param javaFileInfo generated java file info
* @throws IOException when fails to create new file handle
*/
public TempJavaEventFragmentFiles(JavaFileInfo javaFileInfo)
throws IOException {
setExtendsList(new ArrayList<>());
setJavaImportData(new JavaImportData());
setJavaFileInfo(javaFileInfo);
clearGeneratedTempFileMask();
setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(),
getJavaFileInfo().getPackageFilePath()));
}
/**
* Returns event's java file handle.
*
* @return java file handle
*/
private File getEventJavaFileHandle() {
return eventJavaFileHandle;
}
/**
* Sets event's java file handle.
*
* @param eventJavaFileHandle file handle for event
*/
private void setEventJavaFileHandle(File eventJavaFileHandle) {
this.eventJavaFileHandle = eventJavaFileHandle;
}
/**
* Constructs java code exit.
*
* @param fileType generated file type
* @param curNode current YANG node
* @throws IOException when fails to generate java files
*/
public void generateJavaFile(int fileType, YangNode curNode)
throws IOException {
createPackage(curNode);
/**
* Creates event interface file.
*/
setEventJavaFileHandle(getJavaFileHandle(getJavaClassName(EVENT_FILE_NAME_SUFFIX)));
generateEventFile(getEventJavaFileHandle(), curNode, null);
/**
* Close all the file handles.
*/
freeTemporaryResources(false);
}
/**
* Removes all temporary file handles.
*
* @param isErrorOccurred when translator fails to generate java files we
* need to close all open file handles include temporary files
* and java files.
* @throws IOException when failed to delete the temporary files
*/
public void freeTemporaryResources(boolean isErrorOccurred)
throws IOException {
boolean isError = isErrorOccurred;
/**
* Close all java file handles and when error occurs delete the files.
*/
closeFile(getEventJavaFileHandle(), isError);
super.freeTemporaryResources(isErrorOccurred);
}
}
/*
* 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.translator.tojava;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import org.onosproject.yangutils.datamodel.YangNode;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEventListenerFile;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
/**
* Represents implementation of java bean code fragments temporary implementations.
* Maintains the temp files required specific for event listener java snippet generation.
*/
public class TempJavaEventListenerFragmentFiles
extends TempJavaFragmentFiles {
/**
* File name for generated class file for special type like union, typedef
* suffix.
*/
private static final String EVENT_LISTENER_FILE_NAME_SUFFIX = "Listener";
/**
* Java file handle for event listener file.
*/
private File eventListenerJavaFileHandle;
/**
* Creates an instance of temporary java code fragment.
*
* @param javaFileInfo generated java file info
* @throws IOException when fails to create new file handle
*/
public TempJavaEventListenerFragmentFiles(JavaFileInfo javaFileInfo)
throws IOException {
setExtendsList(new ArrayList<>());
setJavaImportData(new JavaImportData());
setJavaFileInfo(javaFileInfo);
clearGeneratedTempFileMask();
setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(),
getJavaFileInfo().getPackageFilePath()));
}
/**
* Returns event listeners's java file handle.
*
* @return java file handle
*/
private File getEventListenerJavaFileHandle() {
return eventListenerJavaFileHandle;
}
/**
* Sets event's java file handle.
*
* @param eventListenerJavaFileHandle file handle for event
*/
private void setEventListenerJavaFileHandle(File eventListenerJavaFileHandle) {
this.eventListenerJavaFileHandle = eventListenerJavaFileHandle;
}
/**
* Constructs java code exit.
*
* @param fileType generated file type
* @param curNode current YANG node
* @throws IOException when fails to generate java files
*/
public void generateJavaFile(int fileType, YangNode curNode)
throws IOException {
createPackage(curNode);
/**
* Creates event listener interface file.
*/
setEventListenerJavaFileHandle(getJavaFileHandle(getJavaClassName(EVENT_LISTENER_FILE_NAME_SUFFIX)));
generateEventListenerFile(getEventListenerJavaFileHandle(), curNode, null);
/**
* Close all the file handles.
*/
freeTemporaryResources(false);
}
/**
* Removes all temporary file handles.
*
* @param isErrorOccurred when translator fails to generate java files we
* need to close all open file handles include temporary files
* and java files.
* @throws IOException when failed to delete the temporary files
*/
public void freeTemporaryResources(boolean isErrorOccurred)
throws IOException {
boolean isError = isErrorOccurred;
/**
* Close all java file handles and when error occurs delete the files.
*/
closeFile(getEventListenerJavaFileHandle(), isError);
super.freeTemporaryResources(isErrorOccurred);
}
}
......@@ -16,15 +16,152 @@
package org.onosproject.yangutils.translator.tojava;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.onosproject.yangutils.datamodel.YangNode;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefClose;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateManagerClassFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateServiceInterfaceFile;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRpcManagerMethod;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRpcServiceMethod;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addArrayListImport;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addAugmentedInfoImport;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils
.isHasAugmentationExtended;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateJavaDocForRpc;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile;
/**
* Represents implementation of java service code fragments temporary implementations.
* Maintains the temp files required specific for service and manager java snippet generation.
*/
public class TempJavaServiceFragmentFiles
extends TempJavaFragmentFiles {
/**
* File name for rpc method.
*/
private static final String RPC_INTERFACE_FILE_NAME = "Rpc";
/**
* File name for rpc implementation method.
*/
private static final String RPC_IMPL_FILE_NAME = "RpcImpl";
/**
* File name for generated class file for service
* suffix.
*/
private static final String SERVICE_FILE_NAME_SUFFIX = "Service";
/**
* File name for generated class file for manager
* suffix.
*/
private static final String MANAGER_FILE_NAME_SUFFIX = "Manager";
/**
* Temporary file handle for rpc interface.
*/
private File rpcInterfaceTempFileHandle;
/**
* Temporary file handle for rpc manager impl.
*/
private File rpcImplTempFileHandle;
/**
* Java file handle for rpc interface file.
*/
private File serviceInterfaceJavaFileHandle;
/**
* Java file handle for manager impl file.
*/
private File managerJavaFileHandle;
/**
* Returns rpc method's java file handle.
*
* @return java file handle
*/
private File getServiceInterfaceJavaFileHandle() {
return serviceInterfaceJavaFileHandle;
}
/**
* Sets rpc method's java file handle.
*
* @param serviceInterfaceJavaFileHandle file handle for to rpc method
*/
private void setServiceInterfaceJavaFileHandle(File serviceInterfaceJavaFileHandle) {
this.serviceInterfaceJavaFileHandle = serviceInterfaceJavaFileHandle;
}
/**
* Returns managers java file handle.
*
* @return java file handle
*/
public File getManagerJavaFileHandle() {
return managerJavaFileHandle;
}
/**
* Sets manager java file handle.
*
* @param managerJavaFileHandle file handle for to manager
*/
public void setManagerJavaFileHandle(File managerJavaFileHandle) {
this.managerJavaFileHandle = managerJavaFileHandle;
}
/**
* Returns rpc method's temporary file handle.
*
* @return temporary file handle
*/
public File getRpcInterfaceTempFileHandle() {
return rpcInterfaceTempFileHandle;
}
/**
* Sets rpc method's temporary file handle.
*
* @param rpcInterfaceTempFileHandle file handle for to rpc method
*/
private void setRpcInterfaceTempFileHandle(File rpcInterfaceTempFileHandle) {
this.rpcInterfaceTempFileHandle = rpcInterfaceTempFileHandle;
}
/**
* Retrieves the manager impl temp file.
*
* @return the manager impl temp file
*/
public File getRpcImplTempFileHandle() {
return rpcImplTempFileHandle;
}
/**
* Sets the manager impl temp file.
*
* @param rpcImplTempFileHandle the manager impl temp file
*/
public void setRpcImplTempFileHandle(File rpcImplTempFileHandle) {
this.rpcImplTempFileHandle = rpcImplTempFileHandle;
}
/**
* Creates an instance of temporary java code fragment.
*
* @param javaFileInfo generated file information
......@@ -33,5 +170,113 @@ public class TempJavaServiceFragmentFiles
public TempJavaServiceFragmentFiles(JavaFileInfo javaFileInfo)
throws IOException {
super(javaFileInfo);
addGeneratedTempFile(RPC_INTERFACE_MASK);
addGeneratedTempFile(RPC_IMPL_MASK);
setRpcInterfaceTempFileHandle(getTemporaryFileHandle(RPC_INTERFACE_FILE_NAME));
setRpcImplTempFileHandle(getTemporaryFileHandle(RPC_IMPL_FILE_NAME));
}
/**
* Constructs java code exit.
*
* @param fileType generated file type
* @param curNode current YANG node
* @throws IOException when fails to generate java files
*/
public void generateJavaFile(int fileType, YangNode curNode)
throws IOException {
List<String> imports = new ArrayList<>();
imports = getJavaImportData().getImports();
createPackage(curNode);
/**
* Creates rpc interface file.
*/
setServiceInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(SERVICE_FILE_NAME_SUFFIX)));
generateServiceInterfaceFile(getServiceInterfaceJavaFileHandle(), curNode, imports, isAttributePresent());
if (isAttributePresent()) {
addImportsToStringAndHasCodeMethods(curNode, imports);
}
if (isHasAugmentationExtended(getExtendsList())) {
addAugmentedInfoImport(curNode, imports, true);
addArrayListImport(curNode, imports, true);
}
/**
* Create builder class file.
*/
setManagerJavaFileHandle(getJavaFileHandle(getJavaClassName(MANAGER_FILE_NAME_SUFFIX)));
generateManagerClassFile(getManagerJavaFileHandle(), imports, curNode, isAttributePresent());
insertDataIntoJavaFile(getManagerJavaFileHandle(), getJavaClassDefClose());
/**
* Close all the file handles.
*/
freeTemporaryResources(false);
}
/**
* Adds rpc string information to applicable temp file.
*
* @param javaAttributeInfoOfInput rpc's input node attribute info
* @param javaAttributeInfoOfOutput rpc's output node attribute info
* @param rpcName name of the rpc function
* @throws IOException IO operation fail
*/
private void addRpcString(JavaAttributeInfo javaAttributeInfoOfInput, JavaAttributeInfo javaAttributeInfoOfOutput,
String rpcName)
throws IOException {
String rpcInput = "";
String rpcOutput = "void";
if (javaAttributeInfoOfInput != null) {
rpcInput = javaAttributeInfoOfInput.getAttributeName();
}
if (javaAttributeInfoOfOutput != null) {
rpcOutput = javaAttributeInfoOfOutput.getAttributeName();
}
appendToFile(getRpcInterfaceTempFileHandle(), generateJavaDocForRpc(rpcName, rpcInput, rpcOutput) +
getRpcServiceMethod(rpcName, rpcInput, rpcOutput) + NEW_LINE);
appendToFile(getRpcImplTempFileHandle(),
getRpcManagerMethod(rpcName, rpcInput, rpcOutput) + NEW_LINE);
}
/**
* Adds the JAVA rpc snippet information.
*
* @param javaAttributeInfoOfInput rpc's input node attribute info
* @param javaAttributeInfoOfOutput rpc's output node attribute info
* @param rpcName name of the rpc function
* @throws IOException IO operation fail
*/
public void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo javaAttributeInfoOfInput,
JavaAttributeInfo javaAttributeInfoOfOutput,
String rpcName)
throws IOException {
addRpcString(javaAttributeInfoOfInput, javaAttributeInfoOfOutput, rpcName);
}
/**
* Removes all temporary file handles.
*
* @param isErrorOccurred when translator fails to generate java files we
* need to close all open file handles include temporary files
* and java files.
* @throws IOException when failed to delete the temporary files
*/
public void freeTemporaryResources(boolean isErrorOccurred)
throws IOException {
boolean isError = isErrorOccurred;
closeFile(getServiceInterfaceJavaFileHandle(), isError);
closeFile(getRpcInterfaceTempFileHandle(), true);
super.freeTemporaryResources(isErrorOccurred);
}
}
......
......@@ -15,20 +15,13 @@
*/
package org.onosproject.yangutils.translator.tojava.javamodel;
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangGrouping;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
/**
* Represents grouping information extended to support java code generation.
*/
public class YangJavaGrouping
extends YangGrouping
implements JavaCodeGeneratorInfo, JavaCodeGenerator {
extends YangGrouping {
/**
* Creates YANG Java grouping object.
......@@ -36,38 +29,4 @@ public class YangJavaGrouping
public YangJavaGrouping() {
super();
}
@Override
public void generateCodeEntry(YangPluginConfig yangPlugin)
throws IOException {
/*Do nothing, the uses will copy the contents to the used location*/
}
@Override
public void generateCodeExit()
throws IOException {
/*Do nothing, the uses will copy the contents to the used location*/
}
@Override
public JavaFileInfo getJavaFileInfo() {
/*Do nothing, the uses will copy the contents to the used location*/
return null;
}
@Override
public void setJavaFileInfo(JavaFileInfo javaInfo) {
/*Do nothing, the uses will copy the contents to the used location*/
}
@Override
public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
/*Do nothing, the uses will copy the contents to the used location*/
return null;
}
@Override
public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
/*Do nothing, the uses will copy the contents to the used location*/
}
}
......
......@@ -25,8 +25,7 @@ import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_MANAGER_WITH_RPC;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
/**
......@@ -53,7 +52,7 @@ public class YangJavaModule
public YangJavaModule() {
super();
setJavaFileInfo(new JavaFileInfo());
getJavaFileInfo().setGeneratedFileTypes(GENERATE_MANAGER_WITH_RPC);
getJavaFileInfo().setGeneratedFileTypes(GENERATE_SERVICE_AND_MANAGER);
}
/**
......@@ -118,6 +117,6 @@ public class YangJavaModule
@Override
public void generateCodeExit()
throws IOException {
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
}
}
......
......@@ -25,7 +25,10 @@ import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.utils.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_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode;
/**
* Represents notification information extended to support java code generation.
......@@ -51,7 +54,8 @@ public class YangJavaNotification
public YangJavaNotification() {
super();
setJavaFileInfo(new JavaFileInfo());
getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER);
getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER
| GENERATE_EVENT_CLASS | GENERATE_EVENT_LISTENER_INTERFACE);
}
/**
......@@ -109,15 +113,36 @@ public class YangJavaNotification
public void generateCodeEntry(YangPluginConfig yangPlugin)
throws IOException {
//TODO: implement the event listener for notifications.
/**
* As part of the notification support the following files needs to be generated.
* 1) Subject of the notification(event), this is simple interface with builder class.
* 2) Event class extending "AbstractEvent" and defining event type enum.
* 3) Event listener interface extending "EventListener".
*
* The manager class needs to extend the ListenerRegistry.
*/
// Generate subject of the notification(event), this is simple interface with builder class.
generateCodeOfNode(this, yangPlugin);
}
/**
* Creates a java file using the YANG notification info.
*/
@Override
public void generateCodeExit() {
// TODO Auto-generated method stub
public void generateCodeExit()
throws IOException {
/**
* As part of the notification support the following files needs to be generated.
* 1) Subject of the notification(event), this is simple interface with builder class.
* 2) Event class extending "AbstractEvent" and defining event type enum.
* 3) Event listener interface extending "EventListener".
*
* The manager class needs to extend the "ListenerRegistry".
*/
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER
| GENERATE_EVENT_CLASS | GENERATE_EVENT_LISTENER_INTERFACE, this);
}
}
......
......@@ -24,15 +24,19 @@ import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangOutput;
import org.onosproject.yangutils.datamodel.YangRpc;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
import org.onosproject.yangutils.translator.tojava.JavaImportData;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
import org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_RPC_INTERFACE;
import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.getCurNodeAsAttributeInParent;
import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData;
import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedTypeInfoOfCurNode;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getParentNodeInGenCode;
import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.updatePackageInfo;
......@@ -59,12 +63,6 @@ public class YangJavaRpc
public YangJavaRpc() {
super();
setJavaFileInfo(new JavaFileInfo());
getJavaFileInfo().setGeneratedFileTypes(GENERATE_RPC_INTERFACE);
try {
setTempJavaCodeFragmentFiles(new TempJavaCodeFragmentFiles(getJavaFileInfo()));
} catch (IOException e) {
throw new RuntimeException("Failed to create temporary RPC file handle");
}
}
/**
......@@ -115,9 +113,9 @@ public class YangJavaRpc
YangNode yangNode = this.getChild();
while (yangNode != null) {
if (yangNode instanceof YangInput) {
javaAttributeInfoOfInput = getCurNodeAsAttributeInParent(yangNode, this, false);
javaAttributeInfoOfInput = getChildNodeAsAttributeInParentService(yangNode, this);
} else if (yangNode instanceof YangOutput) {
javaAttributeInfoOfOutput = getCurNodeAsAttributeInParent(yangNode, this, false);
javaAttributeInfoOfOutput = getChildNodeAsAttributeInParentService(yangNode, this);
} else {
// TODO throw exception
}
......@@ -139,6 +137,46 @@ public class YangJavaRpc
}
/**
* Creates an attribute info object corresponding to a data model node and
* return it.
*
* @param childNode child data model node(input / output) for which the java code generation
* is being handled
* @param currentNode parent node (module / sub-module) in which the child node is an attribute
* @return AttributeInfo attribute details required to add in temporary
* files
*/
public static JavaAttributeInfo getChildNodeAsAttributeInParentService(
YangNode childNode, YangNode currentNode) {
YangNode parentNode = getParentNodeInGenCode(currentNode);
String childNodeName = ((JavaFileInfoContainer) childNode).getJavaFileInfo().getJavaName();
/*
* Get the import info corresponding to the attribute for import in
* generated java files or qualified access
*/
JavaQualifiedTypeInfo qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(currentNode,
childNodeName);
if (!(parentNode instanceof TempJavaCodeFragmentFilesContainer)) {
throw new TranslatorException("Parent node does not have file info");
}
TempJavaFragmentFiles tempJavaFragmentFiles;
tempJavaFragmentFiles = ((TempJavaCodeFragmentFilesContainer) parentNode)
.getTempJavaCodeFragmentFiles()
.getServiceTempFiles();
if (tempJavaFragmentFiles == null) {
throw new TranslatorException("Parent node does not have service file info");
}
JavaImportData parentImportData = tempJavaFragmentFiles.getJavaImportData();
boolean isQualified = parentImportData.addImportInfo(qualifiedTypeInfo);
return getAttributeInfoForTheData(qualifiedTypeInfo, childNodeName, null, isQualified, false);
}
/**
* Returns the generated java file information.
*
* @return generated java file information
......
......@@ -26,7 +26,7 @@ import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_MANAGER_WITH_RPC;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
/**
......@@ -53,7 +53,7 @@ public class YangJavaSubModule
public YangJavaSubModule() {
super();
setJavaFileInfo(new JavaFileInfo());
getJavaFileInfo().setGeneratedFileTypes(GENERATE_MANAGER_WITH_RPC);
getJavaFileInfo().setGeneratedFileTypes(GENERATE_SERVICE_AND_MANAGER);
}
/**
......@@ -130,7 +130,8 @@ public class YangJavaSubModule
* Creates a java file using the YANG submodule info.
*/
@Override
public void generateCodeExit() {
// TODO Auto-generated method stub
public void generateCodeExit()
throws IOException {
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
}
}
......
......@@ -16,15 +16,12 @@
package org.onosproject.yangutils.translator.tojava.javamodel;
import org.onosproject.yangutils.datamodel.YangUses;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
/**
* Represents uses information extended to support java code generation.
*/
public class YangJavaUses
extends YangUses
implements JavaCodeGenerator {
extends YangUses {
/**
* Creates YANG java uses object.
......@@ -32,23 +29,4 @@ public class YangJavaUses
public YangJavaUses() {
super();
}
/**
* Prepare the information for java code generation corresponding to YANG
* uses info.
*
* @param yangPlugin YANG plugin config
*/
@Override
public void generateCodeEntry(YangPluginConfig yangPlugin) {
/*Do nothing, the uses will copy the contents to the used location*/
}
/**
* Create a java file using the YANG uses info.
*/
@Override
public void generateCodeExit() {
/*Do nothing, the uses will copy the contents to the used location*/
}
}
......
......@@ -19,7 +19,9 @@ package org.onosproject.yangutils.translator.tojava.utils;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_RPC_INTERFACE;
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_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK;
......@@ -35,10 +37,12 @@ import static org.onosproject.yangutils.utils.UtilConstants.FINAL;
import static org.onosproject.yangutils.utils.UtilConstants.IMPL;
import static org.onosproject.yangutils.utils.UtilConstants.IMPLEMENTS;
import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE;
import static org.onosproject.yangutils.utils.UtilConstants.MANAGER;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
import static org.onosproject.yangutils.utils.UtilConstants.SERVICE;
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
......@@ -70,7 +74,7 @@ public final class ClassDefinitionGenerator {
if ((genFileTypes & INTERFACE_MASK) != 0) {
return getInterfaceDefinition(yangName);
} else if ((genFileTypes & BUILDER_CLASS_MASK) != 0) {
return getBuilderClassDefinition(yangName);
return getBuilderClassDefinition(yangName, genFileTypes);
} else if ((genFileTypes & IMPL_CLASS_MASK) != 0) {
return getImplClassDefinition(yangName);
} else if ((genFileTypes & BUILDER_INTERFACE_MASK) != 0) {
......@@ -81,8 +85,12 @@ public final class ClassDefinitionGenerator {
return getTypeClassDefinition(yangName);
} else if ((genFileTypes & GENERATE_ENUM_CLASS) != 0) {
return getEnumClassDefinition(yangName);
} else if ((genFileTypes & GENERATE_RPC_INTERFACE) != 0) {
} else if ((genFileTypes & GENERATE_SERVICE_AND_MANAGER) != 0) {
return getRpcInterfaceDefinition(yangName);
} else if ((genFileTypes & GENERATE_EVENT_CLASS) != 0) {
return getEventDefinition(yangName);
} else if ((genFileTypes & GENERATE_EVENT_LISTENER_INTERFACE) != 0) {
return getEventListenerDefinition(yangName);
}
return null;
}
......@@ -131,12 +139,18 @@ public final class ClassDefinitionGenerator {
* Returns builder file class definition.
*
* @param yangName file name
* @param genFileTypes
* @return definition
*/
private static String getBuilderClassDefinition(String yangName) {
private static String getBuilderClassDefinition(String yangName, int genFileTypes) {
if ((genFileTypes & GENERATE_SERVICE_AND_MANAGER) != 0) {
return PUBLIC + SPACE + CLASS + SPACE + yangName + MANAGER + SPACE + IMPLEMENTS + SPACE + yangName +
SERVICE + PERIOD + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
} else {
return PUBLIC + SPACE + CLASS + SPACE + yangName + BUILDER + SPACE + IMPLEMENTS + SPACE + yangName + PERIOD
+ yangName + BUILDER + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
}
}
/**
* Returns impl file class definition.
......@@ -168,4 +182,40 @@ public final class ClassDefinitionGenerator {
private static String getRpcInterfaceDefinition(String yangName) {
return INTERFACE + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
}
/**
* Returns event class definition.
*
* @param javaName file name
* @return definition
*/
private static String getEventDefinition(String javaName) {
String classDef = PUBLIC + SPACE + CLASS + SPACE + javaName + SPACE + "extends AbstractEvent<"
+ javaName + ".Type, " + javaName;
if (classDef.length() < 5) {
throw new RuntimeException("Event class name is error");
}
classDef = classDef.substring(0, (classDef.length() - 5));
classDef = classDef + ">" + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
return classDef;
}
/**
* Returns event listener interface definition.
*
* @param javaName file name
* @return definition
*/
private static String getEventListenerDefinition(String javaName) {
String intfDef = PUBLIC + SPACE + INTERFACE + SPACE + javaName + SPACE + "extends EventListener<"
+ javaName;
if (intfDef.length() < 8) {
throw new RuntimeException("Event listener interface name is error");
}
intfDef = intfDef.substring(0, (intfDef.length() - 8));
intfDef = intfDef + "Event>" + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
return intfDef;
}
}
......
......@@ -20,20 +20,25 @@ import java.io.File;
import java.io.IOException;
import java.util.List;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaBeanFragmentFiles;
import org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles;
import org.onosproject.yangutils.translator.tojava.TempJavaServiceFragmentFiles;
import org.onosproject.yangutils.translator.tojava.TempJavaTypeFragmentFiles;
import org.onosproject.yangutils.utils.io.impl.CopyrightHeader;
import org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_RPC_INTERFACE;
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_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK;
......@@ -44,6 +49,7 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.HASH_CODE_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.OF_STRING_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK;
......@@ -62,6 +68,8 @@ import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_CLASS;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_INTERFACE;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ENUM_CLASS;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.EVENT;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.EVENT_LISTENER;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.IMPL_CLASS;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.INTERFACE;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.RPC_INTERFACE;
......@@ -106,11 +114,25 @@ public final class JavaFileGeneratorUtils {
TempJavaFragmentFiles tempJavaFragmentFiles)
throws IOException {
TempJavaTypeFragmentFiles typeFragmentFiles = null;
if ((generatedTempFiles & ATTRIBUTES_MASK) != 0) {
return tempJavaFragmentFiles
.getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getAttributesTempFileHandle());
} else if ((generatedTempFiles & GETTER_FOR_INTERFACE_MASK) != 0) {
if (tempJavaFragmentFiles instanceof TempJavaTypeFragmentFiles) {
typeFragmentFiles = (TempJavaTypeFragmentFiles) tempJavaFragmentFiles;
}
TempJavaBeanFragmentFiles beanFragmentFiles = null;
if (tempJavaFragmentFiles instanceof TempJavaBeanFragmentFiles) {
beanFragmentFiles = (TempJavaBeanFragmentFiles) tempJavaFragmentFiles;
}
TempJavaServiceFragmentFiles serviceFragmentFiles = null;
if (tempJavaFragmentFiles instanceof TempJavaServiceFragmentFiles) {
serviceFragmentFiles = (TempJavaServiceFragmentFiles) tempJavaFragmentFiles;
}
if ((generatedTempFiles & GETTER_FOR_INTERFACE_MASK) != 0) {
return tempJavaFragmentFiles
.getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getGetterInterfaceTempFileHandle());
} else if ((generatedTempFiles & SETTER_FOR_INTERFACE_MASK) != 0) {
......@@ -123,8 +145,11 @@ public final class JavaFileGeneratorUtils {
return tempJavaFragmentFiles
.getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getSetterImplTempFileHandle());
} else if ((generatedTempFiles & CONSTRUCTOR_IMPL_MASK) != 0) {
return tempJavaFragmentFiles
.getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getConstructorImplTempFileHandle());
if (beanFragmentFiles == null) {
throw new TranslatorException("Required constructor info is missing.");
}
return beanFragmentFiles
.getTemporaryDataFromFileHandle(beanFragmentFiles.getConstructorImplTempFileHandle());
} else if ((generatedTempFiles & HASH_CODE_IMPL_MASK) != 0) {
return tempJavaFragmentFiles
.getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getHashCodeImplTempFileHandle());
......@@ -134,22 +159,39 @@ public final class JavaFileGeneratorUtils {
} else if ((generatedTempFiles & TO_STRING_IMPL_MASK) != 0) {
return tempJavaFragmentFiles
.getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getToStringImplTempFileHandle());
} else if ((generatedTempFiles & CONSTRUCTOR_FOR_TYPE_MASK) != 0) {
return tempJavaFragmentFiles
.getTemporaryDataFromFileHandle(tempJavaFragmentFiles
.getConstructorForTypeTempFileHandle());
} else if ((generatedTempFiles & OF_STRING_IMPL_MASK) != 0) {
return tempJavaFragmentFiles
.getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getOfStringImplTempFileHandle());
if (typeFragmentFiles == null) {
throw new TranslatorException("Required of string implementation info is missing.");
}
return typeFragmentFiles
.getTemporaryDataFromFileHandle(typeFragmentFiles.getOfStringImplTempFileHandle());
} else if ((generatedTempFiles & CONSTRUCTOR_FOR_TYPE_MASK) != 0) {
if (typeFragmentFiles == null) {
throw new TranslatorException("Required constructor implementation info is missing.");
}
return typeFragmentFiles
.getTemporaryDataFromFileHandle(typeFragmentFiles.getConstructorForTypeTempFileHandle());
} else if ((generatedTempFiles & FROM_STRING_IMPL_MASK) != 0) {
return tempJavaFragmentFiles
.getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getFromStringImplTempFileHandle());
if (typeFragmentFiles == null) {
throw new TranslatorException("Required from string info is missing.");
}
return typeFragmentFiles
.getTemporaryDataFromFileHandle(typeFragmentFiles.getFromStringImplTempFileHandle());
} else if ((generatedTempFiles & ENUM_IMPL_MASK) != 0) {
return tempJavaFragmentFiles
.getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getEnumClassTempFileHandle());
} else if ((generatedTempFiles & RPC_INTERFACE_MASK) != 0) {
if (serviceFragmentFiles == null) {
throw new TranslatorException("Required rpc interface info is missing.");
}
return serviceFragmentFiles
.getTemporaryDataFromFileHandle(serviceFragmentFiles.getRpcInterfaceTempFileHandle());
} else if ((generatedTempFiles & RPC_IMPL_MASK) != 0) {
return tempJavaFragmentFiles
.getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getRpcInterfaceImplTempFileHandle());
if (serviceFragmentFiles == null) {
throw new TranslatorException("Required rpc implementation info is missing.");
}
return serviceFragmentFiles
.getTemporaryDataFromFileHandle(serviceFragmentFiles.getRpcImplTempFileHandle());
}
return null;
}
......@@ -211,9 +253,15 @@ public final class JavaFileGeneratorUtils {
} else if ((type & GENERATE_ENUM_CLASS) != 0) {
appendHeaderContents(file, pkgString, importsList);
write(file, fileName, type, ENUM_CLASS);
} else if ((type & GENERATE_RPC_INTERFACE) != 0) {
} else if ((type & GENERATE_SERVICE_AND_MANAGER) != 0) {
appendHeaderContents(file, pkgString, importsList);
write(file, fileName, type, RPC_INTERFACE);
} else if ((type & GENERATE_EVENT_CLASS) != 0) {
appendHeaderContents(file, pkgString, importsList);
write(file, fileName, type, EVENT);
} else if ((type & GENERATE_EVENT_LISTENER_INTERFACE) != 0) {
appendHeaderContents(file, pkgString, importsList);
write(file, fileName, type, EVENT_LISTENER);
}
}
......
......@@ -45,21 +45,6 @@ public final class TempJavaCodeFragmentFilesUtils {
}
/**
* Adds imports for ToString and HashCodeMethod.
*
* @param curNode current YANG node
* @param imports import list
* @return import list
*/
public static List<String> addImportsToStringAndHasCodeMethods(YangNode curNode, List<String> imports) {
if (curNode instanceof JavaImportDataContainer) {
imports.add(((JavaImportDataContainer) curNode).getJavaImportData().getImportForHashAndEquals());
imports.add(((JavaImportDataContainer) curNode).getJavaImportData().getImportForToString());
}
return imports;
}
/**
* Adds import for HasAugmentation class.
*
* @param curNode current YANG node
......@@ -177,7 +162,8 @@ public final class TempJavaCodeFragmentFilesUtils {
* @param toBeDeleted flag to indicate if file needs to be deleted
* @throws IOException when failed to close the file handle
*/
public static void closeFile(File file, boolean toBeDeleted) throws IOException {
public static void closeFile(File file, boolean toBeDeleted)
throws IOException {
if (file != null) {
updateFileHandle(file, null, true);
......
......@@ -18,7 +18,7 @@ package org.onosproject.yangutils.translator.tojava.utils;
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangTypeContainer;
import org.onosproject.yangutils.datamodel.RpcNotificationContainer;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangCase;
import org.onosproject.yangutils.datamodel.YangChoice;
......@@ -29,12 +29,15 @@ import org.onosproject.yangutils.datamodel.YangList;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangNotification;
import org.onosproject.yangutils.datamodel.YangOutput;
import org.onosproject.yangutils.datamodel.YangTypeHolder;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.javamodel.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaEnumeration;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.isRpcChildNodePresent;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.addCurNodeInfoInParentTempFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
......@@ -59,18 +62,20 @@ public final class YangJavaModelUtils {
* Updates YANG java file package information.
*
* @param javaCodeGeneratorInfo YANG java file info node
* @param yangPlugin YANG plugin config
* @param yangPluginConfig YANG plugin config
* @throws IOException IO operations fails
*/
public static void updatePackageInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo, YangPluginConfig yangPlugin)
public static void updatePackageInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
YangPluginConfig yangPluginConfig)
throws IOException {
javaCodeGeneratorInfo.getJavaFileInfo()
.setJavaName(getCaptialCase(
getCamelCase(((YangNode) javaCodeGeneratorInfo).getName(), yangPlugin.getConflictResolver())));
getCamelCase(((YangNode) javaCodeGeneratorInfo).getName(),
yangPluginConfig.getConflictResolver())));
javaCodeGeneratorInfo.getJavaFileInfo().setPackage(getCurNodePackage((YangNode) javaCodeGeneratorInfo));
javaCodeGeneratorInfo.getJavaFileInfo().setPackageFilePath(
getPackageDirPathFromJavaJPackage(javaCodeGeneratorInfo.getJavaFileInfo().getPackage()));
javaCodeGeneratorInfo.getJavaFileInfo().setBaseCodeGenPath(yangPlugin.getCodeGenDir());
javaCodeGeneratorInfo.getJavaFileInfo().setBaseCodeGenPath(yangPluginConfig.getCodeGenDir());
}
/**
......@@ -110,15 +115,40 @@ public final class YangJavaModelUtils {
* @param javaCodeGeneratorInfo YANG java file info node
* @throws IOException IO operations fails
*/
private static void updateTempFragmentFiles(JavaCodeGeneratorInfo javaCodeGeneratorInfo)
private static void updateTempFragmentFiles(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
YangPluginConfig yangPluginConfig)
throws IOException {
if (javaCodeGeneratorInfo instanceof YangLeavesHolder) {
if (javaCodeGeneratorInfo instanceof RpcNotificationContainer) {
/**
* Module / sub module node code generation.
*/
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
.addCurNodeLeavesInfoToTempFiles((YangNode) javaCodeGeneratorInfo);
} else if (javaCodeGeneratorInfo instanceof YangTypeContainer) {
.getServiceTempFiles().addCurNodeLeavesInfoToTempFiles(
(YangNode) javaCodeGeneratorInfo, yangPluginConfig);
} else if (javaCodeGeneratorInfo instanceof YangLeavesHolder) {
/**
* Container
* Case
* Grouping
* Input
* List
* Notification
* Output
*/
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
.getBeanTempFiles().addCurNodeLeavesInfoToTempFiles(
(YangNode) javaCodeGeneratorInfo, yangPluginConfig);
} else if (javaCodeGeneratorInfo instanceof YangTypeHolder) {
/**
* Typedef
* Union
*/
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
.addTypeInfoToTempFiles((YangTypeContainer) javaCodeGeneratorInfo);
.addTypeInfoToTempFiles((YangTypeHolder) javaCodeGeneratorInfo);
} else if (javaCodeGeneratorInfo instanceof YangJavaEnumeration) {
/**
* Enumeration
*/
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
.addEnumAttributeToTempFiles((YangNode) javaCodeGeneratorInfo);
} else if (javaCodeGeneratorInfo instanceof YangChoice) {
......@@ -134,18 +164,19 @@ public final class YangJavaModelUtils {
* @param javaCodeGeneratorInfo YANG java file info node
* @throws IOException IO operations fails
*/
private static void generateTempFiles(JavaCodeGeneratorInfo javaCodeGeneratorInfo, String codeGenDir)
private static void generateTempFiles(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
YangPluginConfig yangPluginConfig)
throws IOException {
if (!(javaCodeGeneratorInfo instanceof YangNode)) {
throw new TranslatorException("translation is not supported for the node");
}
createTempFragmentFile(javaCodeGeneratorInfo);
updateTempFragmentFiles(javaCodeGeneratorInfo);
updateTempFragmentFiles(javaCodeGeneratorInfo, yangPluginConfig);
}
/**
* Process generate code entry of YANG node.
* Generates code for the current ata model node and adds itself as an attribute in the parent.
*
* @param javaCodeGeneratorInfo YANG java file info node
* @param yangPlugin YANG plugin config
......@@ -171,7 +202,7 @@ public final class YangJavaModelUtils {
}
/**
* Process generate code entry of YANG type.
* Generates code for the current data model node and adds support for it to be augmented.
*
* @param javaCodeGeneratorInfo YANG java file info node
* @param yangPlugin YANG plugin config
......@@ -218,36 +249,43 @@ public final class YangJavaModelUtils {
}
/**
* Process generate code entry of YANG type.
* Generates code for the current data model node.
*
* @param javaCodeGeneratorInfo YANG java file info node
* @param yangPlugin YANG plugin config
* @param yangPluginConfig YANG plugin config
* @throws IOException IO operations fails
*/
public static void generateCodeOfNode(JavaCodeGeneratorInfo javaCodeGeneratorInfo, YangPluginConfig yangPlugin)
public static void generateCodeOfNode(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
YangPluginConfig yangPluginConfig)
throws IOException {
if (!(javaCodeGeneratorInfo instanceof YangNode)) {
// TODO:throw exception
}
updatePackageInfo(javaCodeGeneratorInfo, yangPlugin);
generateTempFiles(javaCodeGeneratorInfo, yangPlugin.getCodeGenDir());
updatePackageInfo(javaCodeGeneratorInfo, yangPluginConfig);
generateTempFiles(javaCodeGeneratorInfo, yangPluginConfig);
}
/**
* Process generate code entry of root node.
* Generates code for the root module/sub-module node.
*
* @param javaCodeGeneratorInfo YANG java file info node
* @param yangPlugin YANG plugin config
* @param yangPluginConfig YANG plugin config
* @param rootPkg package of the root node
* @throws IOException IO operations fails
*/
public static void generateCodeOfRootNode(JavaCodeGeneratorInfo javaCodeGeneratorInfo, YangPluginConfig yangPlugin,
String rootPkg)
public static void generateCodeOfRootNode(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
YangPluginConfig yangPluginConfig, String rootPkg)
throws IOException {
if (!(javaCodeGeneratorInfo instanceof YangNode)) {
// TODO:throw exception
}
updatePackageInfo(javaCodeGeneratorInfo, yangPlugin, rootPkg);
generateTempFiles(javaCodeGeneratorInfo, yangPlugin.getCodeGenDir());
updatePackageInfo(javaCodeGeneratorInfo, yangPluginConfig, rootPkg);
if (isRpcChildNodePresent((YangNode) javaCodeGeneratorInfo)) {
javaCodeGeneratorInfo.getJavaFileInfo().addGeneratedFileTypes(GENERATE_SERVICE_AND_MANAGER);
}
generateTempFiles(javaCodeGeneratorInfo, yangPluginConfig);
}
}
......
......@@ -41,6 +41,18 @@ public final class UtilConstants {
public static final String INTERFACE_JAVA_DOC = " * Abstraction of an entity which represents the"
+ " functionality of ";
/**
* JavaDocs for event.
*/
public static final String EVENT_JAVA_DOC = " * Represents event implementation of ";
/**
* JavaDocs for event listener.
*/
public static final String EVENT_LISTENER_JAVA_DOC = " * Abstraction for event listener of ";
/**
* JavaDocs for builder interface class.
*/
......@@ -97,6 +109,11 @@ public final class UtilConstants {
public static final String JAVA_DOC_SETTERS = " * Returns the builder object of ";
/**
* JavaDocs's description for setter method.
*/
public static final String JAVA_DOC_MANAGER_SETTERS = " * Sets the value to attribute ";
/**
* JavaDocs's description for OF method.
*/
public static final String JAVA_DOC_OF = " * Returns the object of ";
......@@ -677,6 +694,17 @@ public final class UtilConstants {
public static final String BUILDER = "Builder";
/**
* Static attribute for manager syntax.
*/
public static final String MANAGER = "Manager";
/**
* Static attribute for service syntax.
*/
public static final String SERVICE = "Service";
/**
* Static attribute for interface syntax.
*/
public static final String INTERFACE = "interface";
......@@ -742,6 +770,16 @@ public final class UtilConstants {
public static final String SERVICE_METHOD_STRING = "Service";
/**
* For event file generation.
*/
public static final String EVENT_STRING = "Event";
/**
* For event listener file generation.
*/
public static final String EVENT_LISTENER_STRING = "Listener";
/**
* Static attribute for impl syntax.
*/
public static final String IMPL = "Impl";
......@@ -837,6 +875,11 @@ public final class UtilConstants {
public static final String ARRAY_LIST = "ArrayList";
/**
* comment to be added for autogenerated impl methods.
*/
public static final String YANG_UTILS_TODO = "//TODO: YANG utils generated code";
/**
* Creates an instance of util constants.
*/
private UtilConstants() {
......
......@@ -23,17 +23,24 @@ import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getJavaPackageFromPackagePath;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getParentNodeInGenCode;
import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.MULTIPLE_NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE_INFO_JAVADOC_OF_CHILD;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.addPackageInfo;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.createDirectories;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
/**
* Represents utility to handle file system operations.
......@@ -61,15 +68,29 @@ public final class FileSystemUtil {
/**
* Creates a package structure with package info java file if not present.
*
* @param pkg java package string
* @param pkgInfo description of package
* @param yangNode YANG node for which code is being generated
* @throws IOException any IO exception
*/
public static void createPackage(String pkg, String pkgInfo) throws IOException {
if (!doesPackageExist(pkg)) {
public static void createPackage(YangNode yangNode)
throws IOException {
YangNode parent = getParentNodeInGenCode(yangNode);
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) yangNode).getJavaFileInfo();
String absolutePath = getAbsolutePackagePath(javaFileInfo.getBaseCodeGenPath(),
javaFileInfo.getPackageFilePath());
String pkgInfo;
if (parent != null) {
pkgInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName()
+ PACKAGE_INFO_JAVADOC_OF_CHILD;
} else {
pkgInfo = javaFileInfo.getJavaName();
}
if (!doesPackageExist(absolutePath)) {
try {
File pack = createDirectories(pkg);
addPackageInfo(pack, pkgInfo, getJavaPackageFromPackagePath(pkg));
File pack = createDirectories(absolutePath);
addPackageInfo(pack, pkgInfo, getJavaPackageFromPackagePath(absolutePath));
} catch (IOException e) {
throw new IOException("failed to create package-info file");
}
......@@ -86,7 +107,8 @@ public final class FileSystemUtil {
* file
* @throws IOException any IO errors
*/
public static void appendFileContents(File toAppend, File srcFile) throws IOException {
public static void appendFileContents(File toAppend, File srcFile)
throws IOException {
updateFileHandle(srcFile, NEW_LINE + readAppendFile(toAppend.toString(), FOUR_SPACE_INDENTATION), false);
}
......@@ -98,7 +120,8 @@ public final class FileSystemUtil {
* @return string of file
* @throws IOException when fails to convert to string
*/
public static String readAppendFile(String toAppend, String spaces) throws IOException {
public static String readAppendFile(String toAppend, String spaces)
throws IOException {
FileReader fileReader = new FileReader(toAppend);
BufferedReader bufferReader = new BufferedReader(fileReader);
try {
......@@ -133,7 +156,8 @@ public final class FileSystemUtil {
* @throws IOException if the named file exists but is a directory rather than a regular file,
* does not exist but cannot be created, or cannot be opened for any other reason
*/
public static void updateFileHandle(File inputFile, String contentTobeAdded, boolean isClose) throws IOException {
public static void updateFileHandle(File inputFile, String contentTobeAdded, boolean isClose)
throws IOException {
FileWriter fileWriter = new FileWriter(inputFile, true);
PrintWriter outputPrintWriter = new PrintWriter(fileWriter, true);
if (!isClose) {
......
......@@ -26,6 +26,8 @@ import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_INTERFACE_JA
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_OBJECT;
import static org.onosproject.yangutils.utils.UtilConstants.ENUM_ATTRIBUTE_JAVADOC;
import static org.onosproject.yangutils.utils.UtilConstants.ENUM_CLASS_JAVADOC;
import static org.onosproject.yangutils.utils.UtilConstants.EVENT_JAVA_DOC;
import static org.onosproject.yangutils.utils.UtilConstants.EVENT_LISTENER_JAVA_DOC;
import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_METHOD_NAME;
import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_PARAM_NAME;
......@@ -39,6 +41,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_CONSTRUCTOR
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_END_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_FIRST_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_GETTERS;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_MANAGER_SETTERS;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_OF;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_PARAM;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_RETURN;
......@@ -110,6 +113,16 @@ public final class JavaDocGen {
RPC_INTERFACE,
/**
* For event.
*/
EVENT,
/**
* For event listener.
*/
EVENT_LISTENER,
/**
* For setters.
*/
SETTER_METHOD,
......@@ -157,7 +170,12 @@ public final class JavaDocGen {
/**
* For enum's attributes.
*/
ENUM_ATTRIBUTE
ENUM_ATTRIBUTE,
/**
* For manager setters.
*/
MANAGER_SETTER_METHOD
}
/**
......@@ -196,6 +214,9 @@ public final class JavaDocGen {
case SETTER_METHOD: {
return generateForSetters(name, isList);
}
case MANAGER_SETTER_METHOD: {
return generateForManagerSetters(name, isList);
}
case OF_METHOD: {
return generateForOf(name);
}
......@@ -220,6 +241,12 @@ public final class JavaDocGen {
case RPC_INTERFACE: {
return generateForRpcInterface(name);
}
case EVENT: {
return generateForEvent(name);
}
case EVENT_LISTENER: {
return generateForEventListener(name);
}
default: {
return generateForConstructors(name);
}
......@@ -294,6 +321,28 @@ public final class JavaDocGen {
}
/**
* Generates javaDoc for the event.
*
* @param eventClassName event class name
* @return javaDocs
*/
private static String generateForEvent(String eventClassName) {
return NEW_LINE + JAVA_DOC_FIRST_LINE + EVENT_JAVA_DOC + eventClassName + PERIOD + NEW_LINE
+ JAVA_DOC_END_LINE;
}
/**
* Generates javaDoc for the event listener.
*
* @param eventListenerInterfaceName event class name
* @return javaDocs
*/
private static String generateForEventListener(String eventListenerInterfaceName) {
return NEW_LINE + JAVA_DOC_FIRST_LINE + EVENT_LISTENER_JAVA_DOC + eventListenerInterfaceName
+ PERIOD + NEW_LINE + JAVA_DOC_END_LINE;
}
/**
* Generates javaDocs for getter method.
*
* @param attribute attribute
......@@ -340,6 +389,29 @@ public final class JavaDocGen {
}
/**
* Generates javaDocs for setter method.
*
* @param attribute attribute
* @param isList is list attribute
* @return javaDocs
*/
private static String generateForManagerSetters(String attribute, boolean isList) {
String setter = NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION
+ JAVA_DOC_MANAGER_SETTERS + attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK
+ FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM + attribute + SPACE;
if (isList) {
String listAttribute = LIST.toLowerCase() + SPACE + OF + SPACE;
setter = setter + listAttribute;
} else {
setter = setter + VALUE + SPACE + OF + SPACE;
}
setter = setter + attribute
+ NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
return setter;
}
/**
* Generates javaDocs for of method.
*
* @param attribute attribute
......
......@@ -25,12 +25,12 @@ import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.apache.maven.model.Resource;
import org.apache.maven.project.MavenProject;
import org.slf4j.Logger;
import org.sonatype.plexus.build.incremental.BuildContext;
import static org.apache.commons.io.FileUtils.deleteDirectory;
import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
......@@ -113,11 +113,11 @@ public final class YangIoUtils {
* @param dir generated directory in previous build
* @throws IOException when failed to delete directory
*/
public static void clean(String dir) throws IOException {
public static void deleteDirectory(String dir) throws IOException {
File generatedDirectory = new File(dir);
if (generatedDirectory.exists()) {
try {
deleteDirectory(generatedDirectory);
FileUtils.deleteDirectory(generatedDirectory);
} catch (IOException e) {
throw new IOException("Failed to delete the generated files in " + generatedDirectory + " directory");
}
......
......@@ -23,7 +23,7 @@ import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.clean;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
/**
* Unit tests for choice-case translator.
......@@ -46,7 +46,7 @@ public final class ChoiceCaseTranslatorTest {
generateJavaCode(node, yangPluginConfig);
clean(userDir + "/target/ChoiceCaseTestGenFile/");
deleteDirectory(userDir + "/target/ChoiceCaseTestGenFile/");
}
// TODO enhance the test cases, after having a framework of translator test.
}
......
......@@ -28,7 +28,7 @@ import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertThat;
import static org.onosproject.yangutils.datamodel.YangDataTypes.STRING;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuild;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuildForInterface;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getCheckNotNull;
......@@ -101,10 +101,11 @@ public final class MethodsGeneratorTest {
* @throws InvocationTargetException when an exception occurs by the method or constructor
*/
@Test
public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException,
public void callPrivateConstructors()
throws SecurityException, NoSuchMethodException, IllegalArgumentException,
InstantiationException, IllegalAccessException, InvocationTargetException {
Class<?>[] classesToConstruct = {MethodsGenerator.class };
Class<?>[] classesToConstruct = {MethodsGenerator.class};
for (Class<?> clazz : classesToConstruct) {
Constructor<?> constructor = clazz.getDeclaredConstructor();
constructor.setAccessible(true);
......@@ -161,7 +162,7 @@ public final class MethodsGeneratorTest {
@Test
public void getConstructorTest() {
JavaAttributeInfo testAttr = getTestAttribute();
String method = getConstructor(CLASS_NAME, testAttr);
String method = getConstructor(CLASS_NAME, testAttr, GENERATE_SERVICE_AND_MANAGER);
assertThat(true, is(method.contains(THIS + PERIOD + CLASS_NAME + SPACE + EQUAL + SPACE + "builder" + OBJECT
+ PERIOD + GET_METHOD_PREFIX + "Testname" + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN)));
}
......@@ -206,7 +207,7 @@ public final class MethodsGeneratorTest {
@Test
public void getGetterForClassTest() {
JavaAttributeInfo testAttr = getTestAttribute();
String method = getGetterForClass(testAttr);
String method = getGetterForClass(testAttr, GENERATE_SERVICE_AND_MANAGER);
assertThat(true, is(method.contains(PUBLIC + SPACE + STRING_DATA_TYPE + SPACE + GET_METHOD_PREFIX)));
}
......@@ -215,7 +216,7 @@ public final class MethodsGeneratorTest {
*/
@Test
public void getGetterForInterfaceTest() {
String method = getGetterForInterface(CLASS_NAME, STRING_DATA_TYPE, false);
String method = getGetterForInterface(CLASS_NAME, STRING_DATA_TYPE, false, GENERATE_SERVICE_AND_MANAGER);
assertThat(true, is(method.contains(STRING_DATA_TYPE + SPACE + GET_METHOD_PREFIX)));
}
......@@ -225,11 +226,11 @@ public final class MethodsGeneratorTest {
@Test
public void getSetterForClassTest() {
JavaAttributeInfo testAttr = getTestAttribute();
String method = getSetterForClass(testAttr, CLASS_NAME);
assertThat(true, is(
method.contains(PUBLIC + SPACE + CLASS_NAME + BUILDER + SPACE + SET_METHOD_PREFIX
+ getCaptialCase(ATTRIBUTE_NAME) + OPEN_PARENTHESIS + STRING_DATA_TYPE + SPACE
+ ATTRIBUTE_NAME)));
String method = getSetterForClass(testAttr, CLASS_NAME, GENERATE_SERVICE_AND_MANAGER);
// assertThat(true, is(
// method.contains(PUBLIC + SPACE + CLASS_NAME + BUILDER + SPACE + SET_METHOD_PREFIX
// + getCaptialCase(ATTRIBUTE_NAME) + OPEN_PARENTHESIS + STRING_DATA_TYPE + SPACE
// + ATTRIBUTE_NAME)));
}
/**
......@@ -237,8 +238,9 @@ public final class MethodsGeneratorTest {
*/
@Test
public void getSetterForInterfaceTest() {
String method = getSetterForInterface(CLASS_NAME, STRING_DATA_TYPE, CLASS_NAME, false);
assertThat(true, is(method.contains(CLASS_NAME + BUILDER + SPACE + SET_METHOD_PREFIX + "Testname")));
String method = getSetterForInterface(CLASS_NAME, STRING_DATA_TYPE, CLASS_NAME, false,
GENERATE_SERVICE_AND_MANAGER);
// assertThat(true, is(method.contains(CLASS_NAME + BUILDER + SPACE + SET_METHOD_PREFIX + "Testname")));
}
/**
......
/*
* 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.translator.tojava.utils;
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 static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
/**
* Unit tests for union translator.
*/
public final class NotificationTranslatorTest {
private final YangUtilsParserManager manager = new YangUtilsParserManager();
/**
* Checks union translation should not result in any exception.
*/
@Test
public void processUnionTranslator()
throws IOException, ParserException {
String userDir = System.getProperty("user.dir");
YangNode node = manager.getDataModel("src/test/resources/NotificationTest.yang");
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir(userDir + "/target/NotificationTest/");
generateJavaCode(node, yangPluginConfig);
deleteDirectory(userDir + "/target/NotificationTest/");
}
// TODO enhance the test cases, after having a framework of translator test.
}
......@@ -24,7 +24,7 @@ import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.clean;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
/**
* Unit tests for rpc translator.
......@@ -48,7 +48,7 @@ public final class RpcTranslatorTest {
generateJavaCode(node, yangPluginConfig);
clean(userDir + "/target/RpcTestGenFile/");
deleteDirectory(userDir + "/target/RpcTestGenFile/");
}
// TODO enhance the test cases, after having a framework of translator test.
}
......
......@@ -24,7 +24,7 @@ import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.clean;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
/**
* Unit tests for union translator.
......@@ -40,16 +40,15 @@ public final class UnionTranslatorTest {
public void processUnionTranslator()
throws IOException, ParserException {
clean("src/test/org/onosproject/yang");
String userDir = System.getProperty("user.dir");
YangNode node = manager.getDataModel("src/test/resources/UnionTranslator.yang");
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/UnionTestGenFile");
yangPluginConfig.setCodeGenDir("target/UnionTestGenFile/");
generateJavaCode(node, yangPluginConfig);
clean("target/UnionTestGenFile");
deleteDirectory(userDir + "/target/UnionTestGenFile/");
}
// TODO enhance the test cases, after having a framework of translator test.
......
......@@ -22,6 +22,8 @@ import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import org.junit.Test;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNot.not;
......@@ -56,10 +58,11 @@ public final class FileSystemUtilTest {
* @throws InvocationTargetException when an exception occurs by the method or constructor
*/
@Test
public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException,
public void callPrivateConstructors()
throws SecurityException, NoSuchMethodException, IllegalArgumentException,
InstantiationException, IllegalAccessException, InvocationTargetException {
Class<?>[] classesToConstruct = {FileSystemUtil.class };
Class<?>[] classesToConstruct = {FileSystemUtil.class};
for (Class<?> clazz : classesToConstruct) {
Constructor<?> constructor = clazz.getDeclaredConstructor();
constructor.setAccessible(true);
......@@ -73,7 +76,8 @@ public final class FileSystemUtilTest {
* @throws IOException when fails to create a test file
*/
@Test
public void updateFileHandleTest() throws IOException {
public void updateFileHandleTest()
throws IOException {
File dir = new File(BASE_PKG + SLASH + "File1");
dir.mkdirs();
......@@ -94,7 +98,8 @@ public final class FileSystemUtilTest {
* @throws IOException when failed to create a test file
*/
@Test
public void packageExistTest() throws IOException {
public void packageExistTest()
throws IOException {
String dirPath = "exist1.exist2.exist3";
String strPath = BASE_DIR_PKG + dirPath;
......@@ -103,7 +108,12 @@ public final class FileSystemUtilTest {
File createFile = new File(createDir + SLASH + "package-info.java");
createFile.createNewFile();
assertThat(true, is(doesPackageExist(strPath)));
createPackage(strPath, PKG_INFO_CONTENT);
JavaFileInfo javaFileInfo = new JavaFileInfo();
javaFileInfo.setBaseCodeGenPath(BASE_DIR_PKG);
javaFileInfo.setPackageFilePath(dirPath);
YangJavaModule moduleNode = new YangJavaModule();
moduleNode.setJavaFileInfo(javaFileInfo);
createPackage(moduleNode);
createDir.delete();
}
......
......@@ -34,7 +34,7 @@ import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertThat;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.addPackageInfo;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.addToSource;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.clean;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.createDirectories;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
......@@ -135,7 +135,7 @@ public final class YangIoUtilsTest {
createNewDir.mkdirs();
File createFile = new File(createNewDir + File.separator + "check1.java");
createFile.createNewFile();
clean(baseDirPath.getAbsolutePath());
deleteDirectory(baseDirPath.getAbsolutePath());
}
/**
......@@ -147,7 +147,7 @@ public final class YangIoUtilsTest {
public void cleanWithInvalidDirTest() throws IOException {
File baseDirPath = new File(BASE_DIR + "invalid");
clean(baseDirPath.getAbsolutePath());
deleteDirectory(baseDirPath.getAbsolutePath());
}
/**
......
module NotificationTest {
yang-version 1;
namespace http://huawei.com;
prefix Ant;
notification test {
leaf type {
type string;
}
leaf severity {
type string;
}
}
}
......@@ -2,6 +2,14 @@ module Sfc {
yang-version 1;
namespace http://huawei.com;
prefix Ant;
leaf test{
type string;
}
container my-container{
leaf my-val{
type string;
}
}
rpc SFP {
input {
leaf port {
......