[ONOS-4627] Rpc empty folder structure issue fixed.
Change-Id: Icc383958b178bc5f5bcb1c7ddbac14c9b63272d8
Showing
4 changed files
with
44 additions
and
4 deletions
utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaRpc.java
| ... | @@ -28,6 +28,7 @@ import org.onosproject.yangutils.datamodel.YangNode; | ... | @@ -28,6 +28,7 @@ import org.onosproject.yangutils.datamodel.YangNode; |
| 28 | import org.onosproject.yangutils.datamodel.YangOutput; | 28 | import org.onosproject.yangutils.datamodel.YangOutput; |
| 29 | import org.onosproject.yangutils.datamodel.YangRpc; | 29 | import org.onosproject.yangutils.datamodel.YangRpc; |
| 30 | import org.onosproject.yangutils.datamodel.YangType; | 30 | import org.onosproject.yangutils.datamodel.YangType; |
| 31 | +import org.onosproject.yangutils.datamodel.YangUses; | ||
| 31 | import org.onosproject.yangutils.translator.exception.TranslatorException; | 32 | import org.onosproject.yangutils.translator.exception.TranslatorException; |
| 32 | import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo; | 33 | import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo; |
| 33 | import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; | 34 | import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; |
| ... | @@ -48,8 +49,10 @@ import static org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDa | ... | @@ -48,8 +49,10 @@ import static org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDa |
| 48 | import static org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType.getJavaImportPackage; | 49 | import static org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType.getJavaImportPackage; |
| 49 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; | 50 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; |
| 50 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase; | 51 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase; |
| 52 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; | ||
| 51 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getParentNodeInGenCode; | 53 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getParentNodeInGenCode; |
| 52 | import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.updatePackageInfo; | 54 | import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.updatePackageInfo; |
| 55 | +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory; | ||
| 53 | 56 | ||
| 54 | /** | 57 | /** |
| 55 | * Represents rpc information extended to support java code generation. | 58 | * Represents rpc information extended to support java code generation. |
| ... | @@ -189,11 +192,37 @@ public class YangJavaRpc | ... | @@ -189,11 +192,37 @@ public class YangJavaRpc |
| 189 | * Add the rpc information to the parent's service temp file. | 192 | * Add the rpc information to the parent's service temp file. |
| 190 | */ | 193 | */ |
| 191 | try { | 194 | try { |
| 195 | + String rpcsChildNodePkg = getPackageDirPathFromJavaJPackage(getJavaFileInfo().getBaseCodeGenPath() + | ||
| 196 | + (getJavaFileInfo().getPackage() + "." + getJavaFileInfo().getJavaName()).toLowerCase()); | ||
| 197 | + | ||
| 192 | ((TempJavaCodeFragmentFilesContainer) parent).getTempJavaCodeFragmentFiles().getServiceTempFiles() | 198 | ((TempJavaCodeFragmentFilesContainer) parent).getTempJavaCodeFragmentFiles().getServiceTempFiles() |
| 193 | .addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfoOfInput, javaAttributeInfoOfOutput, | 199 | .addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfoOfInput, javaAttributeInfoOfOutput, |
| 194 | ((JavaFileInfoContainer) parent).getJavaFileInfo().getPluginConfig(), | 200 | ((JavaFileInfoContainer) parent).getJavaFileInfo().getPluginConfig(), |
| 195 | ((YangNode) this).getName(), isInputLeafHolder(), isOutputLeafHolder(), | 201 | ((YangNode) this).getName(), isInputLeafHolder(), isOutputLeafHolder(), |
| 196 | isInputSingleChildHolder(), isOutputSingleChildHolder()); | 202 | isInputSingleChildHolder(), isOutputSingleChildHolder()); |
| 203 | + | ||
| 204 | + if (javaAttributeInfoOfInput != null && javaAttributeInfoOfOutput != null | ||
| 205 | + && isInputLeafHolder() && isOutputLeafHolder()) { | ||
| 206 | + deleteDirectoryWhenNoFileIsGeneratedForInputOutput(rpcsChildNodePkg); | ||
| 207 | + } else if (javaAttributeInfoOfInput != null && javaAttributeInfoOfOutput == null | ||
| 208 | + && isInputLeafHolder()) { | ||
| 209 | + deleteDirectoryWhenNoFileIsGeneratedForInputOutput(rpcsChildNodePkg); | ||
| 210 | + } else if (javaAttributeInfoOfInput == null && javaAttributeInfoOfOutput != null | ||
| 211 | + && isOutputLeafHolder()) { | ||
| 212 | + deleteDirectoryWhenNoFileIsGeneratedForInputOutput(rpcsChildNodePkg); | ||
| 213 | + } else { | ||
| 214 | + YangNode node = this.getChild(); | ||
| 215 | + while (node != null) { | ||
| 216 | + YangNode tempNode = node.getChild(); | ||
| 217 | + while (tempNode != null) { | ||
| 218 | + if (tempNode instanceof YangUses) { | ||
| 219 | + deleteDirectoryWhenNoFileIsGeneratedForInputOutput(rpcsChildNodePkg); | ||
| 220 | + } | ||
| 221 | + tempNode = tempNode.getNextSibling(); | ||
| 222 | + } | ||
| 223 | + node = node.getNextSibling(); | ||
| 224 | + } | ||
| 225 | + } | ||
| 197 | } catch (IOException e) { | 226 | } catch (IOException e) { |
| 198 | throw new TranslatorException("Failed to generate code for RPC node " + this.getName()); | 227 | throw new TranslatorException("Failed to generate code for RPC node " + this.getName()); |
| 199 | } | 228 | } |
| ... | @@ -201,6 +230,17 @@ public class YangJavaRpc | ... | @@ -201,6 +230,17 @@ public class YangJavaRpc |
| 201 | } | 230 | } |
| 202 | 231 | ||
| 203 | /** | 232 | /** |
| 233 | + * When there is no file generation for input output node we should delete the directory generated | ||
| 234 | + * for RPC. | ||
| 235 | + * | ||
| 236 | + * @param emptyPkg empty package | ||
| 237 | + * @throws IOException when fails to do IO operations | ||
| 238 | + */ | ||
| 239 | + private void deleteDirectoryWhenNoFileIsGeneratedForInputOutput(String emptyPkg) throws IOException { | ||
| 240 | + deleteDirectory(emptyPkg); | ||
| 241 | + } | ||
| 242 | + | ||
| 243 | + /** | ||
| 204 | * Creates an attribute info object corresponding to a data model node and | 244 | * Creates an attribute info object corresponding to a data model node and |
| 205 | * return it. | 245 | * return it. |
| 206 | * | 246 | * | ... | ... |
| ... | @@ -14,7 +14,7 @@ | ... | @@ -14,7 +14,7 @@ |
| 14 | * limitations under the License. | 14 | * limitations under the License. |
| 15 | */ | 15 | */ |
| 16 | 16 | ||
| 17 | -package org.onosproject.yangutils.translator.tojava; | 17 | +package org.onosproject.yangutils.utils; |
| 18 | 18 | ||
| 19 | import java.util.List; | 19 | import java.util.List; |
| 20 | 20 | ... | ... |
| ... | @@ -14,7 +14,7 @@ | ... | @@ -14,7 +14,7 @@ |
| 14 | * limitations under the License. | 14 | * limitations under the License. |
| 15 | */ | 15 | */ |
| 16 | 16 | ||
| 17 | -package org.onosproject.yangutils.translator.tojava; | 17 | +package org.onosproject.yangutils.utils; |
| 18 | 18 | ||
| 19 | /** | 19 | /** |
| 20 | * Abstraction of an entity which represents augmented info. | 20 | * Abstraction of an entity which represents augmented info. | ... | ... |
| ... | @@ -930,7 +930,7 @@ public final class UtilConstants { | ... | @@ -930,7 +930,7 @@ public final class UtilConstants { |
| 930 | * Static attribute for AugmentationHolder class import package. | 930 | * Static attribute for AugmentationHolder class import package. |
| 931 | */ | 931 | */ |
| 932 | public static final String PROVIDED_AUGMENTATION_CLASS_IMPORT_PKG = | 932 | public static final String PROVIDED_AUGMENTATION_CLASS_IMPORT_PKG = |
| 933 | - "org.onosproject.yangutils.translator.tojava"; | 933 | + "org.onosproject.yangutils.utils"; |
| 934 | 934 | ||
| 935 | /** | 935 | /** |
| 936 | * Static attribute for AugmentationHolder class import class. | 936 | * Static attribute for AugmentationHolder class import class. |
| ... | @@ -940,7 +940,7 @@ public final class UtilConstants { | ... | @@ -940,7 +940,7 @@ public final class UtilConstants { |
| 940 | /** | 940 | /** |
| 941 | * Static attribute for AugmentedInfo class import package. | 941 | * Static attribute for AugmentedInfo class import package. |
| 942 | */ | 942 | */ |
| 943 | - public static final String AUGMENTED_INFO_CLASS_IMPORT_PKG = "org.onosproject.yangutils.translator.tojava"; | 943 | + public static final String AUGMENTED_INFO_CLASS_IMPORT_PKG = "org.onosproject.yangutils.utils"; |
| 944 | 944 | ||
| 945 | /** | 945 | /** |
| 946 | * Static attribute for AugmentedInfo class import class. | 946 | * Static attribute for AugmentedInfo class import class. | ... | ... |
-
Please register or login to post a comment