Committed by
Gerrit Code Review
[ONOS-4144] ,[ONOS-4145] Bug fixes for YANG translator.
Change-Id: I6922c01269611b3aec61a9e46cda5166f8fe1ec0
Showing
11 changed files
with
80 additions
and
259 deletions
... | @@ -333,6 +333,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable { | ... | @@ -333,6 +333,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable { |
333 | throw new IOException("Failed to create the source files."); | 333 | throw new IOException("Failed to create the source files."); |
334 | } | 334 | } |
335 | setFileHandle(handle); | 335 | setFileHandle(handle); |
336 | + getDerivedType().getDataTypeExtendedInfo().getBaseType().setJavaPackage(getPackage()); | ||
336 | addAttributeInfo(); | 337 | addAttributeInfo(); |
337 | addAttributeInParent(); | 338 | addAttributeInParent(); |
338 | } | 339 | } | ... | ... |
... | @@ -17,7 +17,6 @@ | ... | @@ -17,7 +17,6 @@ |
17 | package org.onosproject.yangutils.plugin.manager; | 17 | package org.onosproject.yangutils.plugin.manager; |
18 | 18 | ||
19 | import java.io.File; | 19 | import java.io.File; |
20 | -import java.io.IOException; | ||
21 | import java.util.Iterator; | 20 | import java.util.Iterator; |
22 | import java.util.List; | 21 | import java.util.List; |
23 | 22 | ||
... | @@ -56,6 +55,12 @@ public class YangUtilManager extends AbstractMojo { | ... | @@ -56,6 +55,12 @@ public class YangUtilManager extends AbstractMojo { |
56 | private String yangFilesDir; | 55 | private String yangFilesDir; |
57 | 56 | ||
58 | /** | 57 | /** |
58 | + * Source directory for generated files. | ||
59 | + */ | ||
60 | + @Parameter(property = "genFilesDir", defaultValue = "src/main/java") | ||
61 | + private String genFilesDir; | ||
62 | + | ||
63 | + /** | ||
59 | * Base directory for project. | 64 | * Base directory for project. |
60 | */ | 65 | */ |
61 | @Parameter(property = "basedir", defaultValue = "${basedir}") | 66 | @Parameter(property = "basedir", defaultValue = "${basedir}") |
... | @@ -105,7 +110,7 @@ public class YangUtilManager extends AbstractMojo { | ... | @@ -105,7 +110,7 @@ public class YangUtilManager extends AbstractMojo { |
105 | YangIoUtils.clean(baseDir); | 110 | YangIoUtils.clean(baseDir); |
106 | 111 | ||
107 | searchDir = baseDir + File.separator + yangFilesDir; | 112 | searchDir = baseDir + File.separator + yangFilesDir; |
108 | - codeGenDir = baseDir + File.separator + UtilConstants.YANG_GEN_DIR; | 113 | + codeGenDir = baseDir + File.separator + genFilesDir + File.separator; |
109 | 114 | ||
110 | List<String> yangFiles = YangFileScanner.getYangFiles(searchDir); | 115 | List<String> yangFiles = YangFileScanner.getYangFiles(searchDir); |
111 | Iterator<String> yangFileIterator = yangFiles.iterator(); | 116 | Iterator<String> yangFileIterator = yangFiles.iterator(); |
... | @@ -129,8 +134,8 @@ public class YangUtilManager extends AbstractMojo { | ... | @@ -129,8 +134,8 @@ public class YangUtilManager extends AbstractMojo { |
129 | } | 134 | } |
130 | 135 | ||
131 | YangIoUtils.addToSource(baseDir + File.separator + UtilConstants.YANG_GEN_DIR, project, context); | 136 | YangIoUtils.addToSource(baseDir + File.separator + UtilConstants.YANG_GEN_DIR, project, context); |
132 | - } catch (final IOException e) { | 137 | + } catch (Exception e) { |
133 | - getLog().info("IOException occured"); | 138 | + getLog().info(e); |
134 | } | 139 | } |
135 | } | 140 | } |
136 | 141 | ... | ... |
... | @@ -305,8 +305,8 @@ public class CachedJavaFileHandle implements CachedFileHandle { | ... | @@ -305,8 +305,8 @@ public class CachedJavaFileHandle implements CachedFileHandle { |
305 | @Override | 305 | @Override |
306 | public void close() throws IOException { | 306 | public void close() throws IOException { |
307 | 307 | ||
308 | + List<AttributeInfo> attrList = getCachedAttributeList(); | ||
308 | flushCacheAttrToTempFile(); | 309 | flushCacheAttrToTempFile(); |
309 | - | ||
310 | String className = getYangName(); | 310 | String className = getYangName(); |
311 | className = JavaIdentifierSyntax.getCaptialCase(className); | 311 | className = JavaIdentifierSyntax.getCaptialCase(className); |
312 | String path = getRelativeFilePath(); | 312 | String path = getRelativeFilePath(); |
... | @@ -322,11 +322,14 @@ public class CachedJavaFileHandle implements CachedFileHandle { | ... | @@ -322,11 +322,14 @@ public class CachedJavaFileHandle implements CachedFileHandle { |
322 | 322 | ||
323 | for (ImportInfo importInfo : new ArrayList<ImportInfo>(getImportSet())) { | 323 | for (ImportInfo importInfo : new ArrayList<ImportInfo>(getImportSet())) { |
324 | importString = UtilConstants.IMPORT; | 324 | importString = UtilConstants.IMPORT; |
325 | - if (importInfo.getPkgInfo() != null) { | 325 | + if (importInfo.getPkgInfo() != "" && importInfo.getClassInfo() != null |
326 | + && importInfo.getPkgInfo() != UtilConstants.JAVA_LANG) { | ||
326 | importString = importString + importInfo.getPkgInfo() + "."; | 327 | importString = importString + importInfo.getPkgInfo() + "."; |
328 | + importString = importString + importInfo.getClassInfo() + UtilConstants.SEMI_COLAN | ||
329 | + + UtilConstants.NEW_LINE; | ||
330 | + | ||
331 | + imports.add(importString); | ||
327 | } | 332 | } |
328 | - importString = importString + importInfo.getClassInfo() + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE; | ||
329 | - imports.add(importString); | ||
330 | } | 333 | } |
331 | java.util.Collections.sort(imports); | 334 | java.util.Collections.sort(imports); |
332 | 335 | ||
... | @@ -342,7 +345,7 @@ public class CachedJavaFileHandle implements CachedFileHandle { | ... | @@ -342,7 +345,7 @@ public class CachedJavaFileHandle implements CachedFileHandle { |
342 | String interfaceFileName = className; | 345 | String interfaceFileName = className; |
343 | File interfaceFile = JavaFileGenerator.getFileObject(path, interfaceFileName, JAVA_FILE_EXTENSION, this); | 346 | File interfaceFile = JavaFileGenerator.getFileObject(path, interfaceFileName, JAVA_FILE_EXTENSION, this); |
344 | interfaceFile = JavaFileGenerator.generateInterfaceFile(interfaceFile, className, imports, | 347 | interfaceFile = JavaFileGenerator.generateInterfaceFile(interfaceFile, className, imports, |
345 | - getCachedAttributeList(), path.replace('/', '.'), this); | 348 | + attrList, path.replace('/', '.'), this); |
346 | /** | 349 | /** |
347 | * Create temp builder interface file. | 350 | * Create temp builder interface file. |
348 | */ | 351 | */ |
... | @@ -350,7 +353,7 @@ public class CachedJavaFileHandle implements CachedFileHandle { | ... | @@ -350,7 +353,7 @@ public class CachedJavaFileHandle implements CachedFileHandle { |
350 | File builderInterfaceFile = JavaFileGenerator.getFileObject(path, builderInterfaceFileName, | 353 | File builderInterfaceFile = JavaFileGenerator.getFileObject(path, builderInterfaceFileName, |
351 | TEMP_FILE_EXTENSION, this); | 354 | TEMP_FILE_EXTENSION, this); |
352 | builderInterfaceFile = JavaFileGenerator.generateBuilderInterfaceFile(builderInterfaceFile, className, | 355 | builderInterfaceFile = JavaFileGenerator.generateBuilderInterfaceFile(builderInterfaceFile, className, |
353 | - path.replace('/', '.'), getCachedAttributeList(), this); | 356 | + path.replace('/', '.'), attrList, this); |
354 | /** | 357 | /** |
355 | * Append builder interface file to interface file and close it. | 358 | * Append builder interface file to interface file and close it. |
356 | */ | 359 | */ |
... | @@ -369,9 +372,11 @@ public class CachedJavaFileHandle implements CachedFileHandle { | ... | @@ -369,9 +372,11 @@ public class CachedJavaFileHandle implements CachedFileHandle { |
369 | JavaFileGenerator.clean(builderInterfaceFile); | 372 | JavaFileGenerator.clean(builderInterfaceFile); |
370 | } | 373 | } |
371 | 374 | ||
372 | - imports.add(UtilConstants.MORE_OBJECT_IMPORT); | 375 | + if (!attrList.isEmpty()) { |
373 | - imports.add(UtilConstants.JAVA_UTIL_OBJECTS_IMPORT); | 376 | + imports.add(UtilConstants.MORE_OBJECT_IMPORT); |
374 | - java.util.Collections.sort(imports); | 377 | + imports.add(UtilConstants.JAVA_UTIL_OBJECTS_IMPORT); |
378 | + java.util.Collections.sort(imports); | ||
379 | + } | ||
375 | 380 | ||
376 | if ((fileType & GeneratedFileType.BUILDER_CLASS_MASK) != 0 | 381 | if ((fileType & GeneratedFileType.BUILDER_CLASS_MASK) != 0 |
377 | || fileType == GeneratedFileType.GENERATE_INTERFACE_WITH_BUILDER) { | 382 | || fileType == GeneratedFileType.GENERATE_INTERFACE_WITH_BUILDER) { |
... | @@ -382,7 +387,7 @@ public class CachedJavaFileHandle implements CachedFileHandle { | ... | @@ -382,7 +387,7 @@ public class CachedJavaFileHandle implements CachedFileHandle { |
382 | String builderFileName = className + UtilConstants.BUILDER; | 387 | String builderFileName = className + UtilConstants.BUILDER; |
383 | File builderFile = JavaFileGenerator.getFileObject(path, builderFileName, JAVA_FILE_EXTENSION, this); | 388 | File builderFile = JavaFileGenerator.getFileObject(path, builderFileName, JAVA_FILE_EXTENSION, this); |
384 | builderFile = JavaFileGenerator.generateBuilderClassFile(builderFile, className, imports, | 389 | builderFile = JavaFileGenerator.generateBuilderClassFile(builderFile, className, imports, |
385 | - path.replace('/', '.'), getCachedAttributeList(), this); | 390 | + path.replace('/', '.'), attrList, this); |
386 | /** | 391 | /** |
387 | * Create temp impl class file. | 392 | * Create temp impl class file. |
388 | */ | 393 | */ |
... | @@ -390,7 +395,7 @@ public class CachedJavaFileHandle implements CachedFileHandle { | ... | @@ -390,7 +395,7 @@ public class CachedJavaFileHandle implements CachedFileHandle { |
390 | String implFileName = className + UtilConstants.IMPL; | 395 | String implFileName = className + UtilConstants.IMPL; |
391 | File implTempFile = JavaFileGenerator.getFileObject(path, implFileName, TEMP_FILE_EXTENSION, this); | 396 | File implTempFile = JavaFileGenerator.getFileObject(path, implFileName, TEMP_FILE_EXTENSION, this); |
392 | implTempFile = JavaFileGenerator.generateImplClassFile(implTempFile, className, | 397 | implTempFile = JavaFileGenerator.generateImplClassFile(implTempFile, className, |
393 | - path.replace('/', '.'), getCachedAttributeList(), this); | 398 | + path.replace('/', '.'), attrList, this); |
394 | /** | 399 | /** |
395 | * Append impl class to builder class and close it. | 400 | * Append impl class to builder class and close it. |
396 | */ | 401 | */ |
... | @@ -418,7 +423,7 @@ public class CachedJavaFileHandle implements CachedFileHandle { | ... | @@ -418,7 +423,7 @@ public class CachedJavaFileHandle implements CachedFileHandle { |
418 | String typeDefFileName = className; | 423 | String typeDefFileName = className; |
419 | File typeDefFile = JavaFileGenerator.getFileObject(path, typeDefFileName, JAVA_FILE_EXTENSION, this); | 424 | File typeDefFile = JavaFileGenerator.getFileObject(path, typeDefFileName, JAVA_FILE_EXTENSION, this); |
420 | typeDefFile = JavaFileGenerator.generateTypeDefClassFile(typeDefFile, className, imports, | 425 | typeDefFile = JavaFileGenerator.generateTypeDefClassFile(typeDefFile, className, imports, |
421 | - path.replace('/', '.'), getCachedAttributeList(), this); | 426 | + path.replace('/', '.'), attrList, this); |
422 | JavaFileGenerator.insert(typeDefFile, | 427 | JavaFileGenerator.insert(typeDefFile, |
423 | JavaFileGenerator.closeFile(GeneratedFileType.GENERATE_TYPEDEF_CLASS, typeDefFileName)); | 428 | JavaFileGenerator.closeFile(GeneratedFileType.GENERATE_TYPEDEF_CLASS, typeDefFileName)); |
424 | 429 | ||
... | @@ -428,10 +433,17 @@ public class CachedJavaFileHandle implements CachedFileHandle { | ... | @@ -428,10 +433,17 @@ public class CachedJavaFileHandle implements CachedFileHandle { |
428 | JavaFileGenerator.closeFileHandles(typeDefFile); | 433 | JavaFileGenerator.closeFileHandles(typeDefFile); |
429 | } | 434 | } |
430 | 435 | ||
431 | - closeTempDataFileHandles(className, getCodeGenFilePath() + getRelativeFilePath()); | 436 | + if (!getCachedAttributeList().isEmpty()) { |
432 | - JavaFileGenerator | 437 | + closeTempDataFileHandles(className, getCodeGenFilePath() + getRelativeFilePath()); |
433 | - .cleanTempFiles(new File(getCodeGenFilePath() + getRelativeFilePath() + File.separator + className | 438 | + JavaFileGenerator |
434 | - + TEMP_FOLDER_NAME_SUFIX)); | 439 | + .cleanTempFiles(new File(getCodeGenFilePath() + getRelativeFilePath() + File.separator + className |
440 | + + TEMP_FOLDER_NAME_SUFIX)); | ||
441 | + } | ||
442 | + | ||
443 | + /* | ||
444 | + * clear the contents from the cached attribute list. | ||
445 | + */ | ||
446 | + getCachedAttributeList().clear(); | ||
435 | } | 447 | } |
436 | 448 | ||
437 | @Override | 449 | @Override |
... | @@ -512,7 +524,12 @@ public class CachedJavaFileHandle implements CachedFileHandle { | ... | @@ -512,7 +524,12 @@ public class CachedJavaFileHandle implements CachedFileHandle { |
512 | + File.separator + className + TEMP_FOLDER_NAME_SUFIX + File.separator; | 524 | + File.separator + className + TEMP_FOLDER_NAME_SUFIX + File.separator; |
513 | 525 | ||
514 | try { | 526 | try { |
515 | - return readFile(path + fileName + TEMP_FILE_EXTENSION); | 527 | + String file = path + fileName + TEMP_FILE_EXTENSION; |
528 | + if (new File(file).exists()) { | ||
529 | + return readFile(path + fileName + TEMP_FILE_EXTENSION); | ||
530 | + } else { | ||
531 | + return ""; | ||
532 | + } | ||
516 | 533 | ||
517 | } catch (FileNotFoundException e) { | 534 | } catch (FileNotFoundException e) { |
518 | throw new FileNotFoundException("No such file or directory."); | 535 | throw new FileNotFoundException("No such file or directory."); |
... | @@ -533,8 +550,14 @@ public class CachedJavaFileHandle implements CachedFileHandle { | ... | @@ -533,8 +550,14 @@ public class CachedJavaFileHandle implements CachedFileHandle { |
533 | String line = bufferReader.readLine(); | 550 | String line = bufferReader.readLine(); |
534 | 551 | ||
535 | while (line != null) { | 552 | while (line != null) { |
536 | - stringBuilder.append(line); | 553 | + if (line.equals(UtilConstants.FOUR_SPACE_INDENTATION) |
537 | - stringBuilder.append("\n"); | 554 | + || line.equals(UtilConstants.EIGHT_SPACE_INDENTATION) |
555 | + || line.equals(UtilConstants.SPACE) || line.equals("") || line.equals(UtilConstants.NEW_LINE)) { | ||
556 | + stringBuilder.append("\n"); | ||
557 | + } else { | ||
558 | + stringBuilder.append(line); | ||
559 | + stringBuilder.append("\n"); | ||
560 | + } | ||
538 | line = bufferReader.readLine(); | 561 | line = bufferReader.readLine(); |
539 | } | 562 | } |
540 | return stringBuilder.toString(); | 563 | return stringBuilder.toString(); | ... | ... |
... | @@ -84,7 +84,7 @@ public final class ClassDefinitionGenerator { | ... | @@ -84,7 +84,7 @@ public final class ClassDefinitionGenerator { |
84 | */ | 84 | */ |
85 | private static String getBuilderInterfaceDefinition(String yangName) { | 85 | private static String getBuilderInterfaceDefinition(String yangName) { |
86 | return UtilConstants.INTERFACE + UtilConstants.SPACE + yangName + UtilConstants.BUILDER + UtilConstants.SPACE | 86 | return UtilConstants.INTERFACE + UtilConstants.SPACE + yangName + UtilConstants.BUILDER + UtilConstants.SPACE |
87 | - + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE; | 87 | + + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE + UtilConstants.NEW_LINE; |
88 | } | 88 | } |
89 | 89 | ||
90 | /** | 90 | /** |
... | @@ -112,8 +112,7 @@ public final class ClassDefinitionGenerator { | ... | @@ -112,8 +112,7 @@ public final class ClassDefinitionGenerator { |
112 | return UtilConstants.PUBLIC + UtilConstants.SPACE + UtilConstants.FINAL + UtilConstants.SPACE | 112 | return UtilConstants.PUBLIC + UtilConstants.SPACE + UtilConstants.FINAL + UtilConstants.SPACE |
113 | + UtilConstants.CLASS + UtilConstants.SPACE + yangName + UtilConstants.IMPL + UtilConstants.SPACE | 113 | + UtilConstants.CLASS + UtilConstants.SPACE + yangName + UtilConstants.IMPL + UtilConstants.SPACE |
114 | + UtilConstants.IMPLEMENTS + UtilConstants.SPACE + yangName + UtilConstants.SPACE | 114 | + UtilConstants.IMPLEMENTS + UtilConstants.SPACE + yangName + UtilConstants.SPACE |
115 | - + UtilConstants.OPEN_CURLY_BRACKET | 115 | + + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE + UtilConstants.NEW_LINE; |
116 | - + UtilConstants.SPACE + UtilConstants.NEW_LINE; | ||
117 | } | 116 | } |
118 | 117 | ||
119 | /** | 118 | /** |
... | @@ -126,7 +125,7 @@ public final class ClassDefinitionGenerator { | ... | @@ -126,7 +125,7 @@ public final class ClassDefinitionGenerator { |
126 | 125 | ||
127 | return UtilConstants.PUBLIC + UtilConstants.SPACE + UtilConstants.FINAL + UtilConstants.SPACE | 126 | return UtilConstants.PUBLIC + UtilConstants.SPACE + UtilConstants.FINAL + UtilConstants.SPACE |
128 | + UtilConstants.CLASS + UtilConstants.SPACE + yangName + UtilConstants.SPACE | 127 | + UtilConstants.CLASS + UtilConstants.SPACE + yangName + UtilConstants.SPACE |
129 | - + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.SPACE + UtilConstants.NEW_LINE; | 128 | + + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE; |
130 | } | 129 | } |
131 | 130 | ||
132 | } | 131 | } | ... | ... |
This diff is collapsed. Click to expand it.
... | @@ -434,7 +434,7 @@ public final class MethodsGenerator { | ... | @@ -434,7 +434,7 @@ public final class MethodsGenerator { |
434 | String constructor = UtilConstants.EIGHT_SPACE_INDENTATION + UtilConstants.THIS | 434 | String constructor = UtilConstants.EIGHT_SPACE_INDENTATION + UtilConstants.THIS |
435 | + UtilConstants.PERIOD + JavaIdentifierSyntax.getCamelCase(attributeName) | 435 | + UtilConstants.PERIOD + JavaIdentifierSyntax.getCamelCase(attributeName) |
436 | + UtilConstants.SPACE + UtilConstants.EQUAL + UtilConstants.SPACE + builderAttribute | 436 | + UtilConstants.SPACE + UtilConstants.EQUAL + UtilConstants.SPACE + builderAttribute |
437 | - + UtilConstants.OBJECT + UtilConstants.PERIOD + UtilConstants.GET_METHOD_PREFIX | 437 | + + UtilConstants.BUILDER + UtilConstants.OBJECT + UtilConstants.PERIOD + UtilConstants.GET_METHOD_PREFIX |
438 | + JavaIdentifierSyntax.getCaptialCase(JavaIdentifierSyntax.getCamelCase(attributeName)) | 438 | + JavaIdentifierSyntax.getCaptialCase(JavaIdentifierSyntax.getCamelCase(attributeName)) |
439 | + UtilConstants.OPEN_PARENTHESIS + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SEMI_COLAN | 439 | + UtilConstants.OPEN_PARENTHESIS + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SEMI_COLAN |
440 | + UtilConstants.NEW_LINE; | 440 | + UtilConstants.NEW_LINE; |
... | @@ -539,7 +539,6 @@ public final class MethodsGenerator { | ... | @@ -539,7 +539,6 @@ public final class MethodsGenerator { |
539 | public static String getHashCodeMethodClose(String hashcodeString) { | 539 | public static String getHashCodeMethodClose(String hashcodeString) { |
540 | hashcodeString = YangIoUtils.trimAtLast(hashcodeString, UtilConstants.COMMA); | 540 | hashcodeString = YangIoUtils.trimAtLast(hashcodeString, UtilConstants.COMMA); |
541 | hashcodeString = YangIoUtils.trimAtLast(hashcodeString, UtilConstants.SPACE); | 541 | hashcodeString = YangIoUtils.trimAtLast(hashcodeString, UtilConstants.SPACE); |
542 | - hashcodeString = YangIoUtils.partString(hashcodeString); | ||
543 | return hashcodeString + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE | 542 | return hashcodeString + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE |
544 | + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.CLOSE_CURLY_BRACKET; | 543 | + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.CLOSE_CURLY_BRACKET; |
545 | } | 544 | } | ... | ... |
... | @@ -119,7 +119,7 @@ public final class UtilConstants { | ... | @@ -119,7 +119,7 @@ public final class UtilConstants { |
119 | /** | 119 | /** |
120 | * For directories. | 120 | * For directories. |
121 | */ | 121 | */ |
122 | - public static final String YANG_GEN_DIR = "src/main/yangmodel/"; | 122 | + public static final String YANG_GEN_DIR = "src/main/java/"; |
123 | public static final String DEFAULT_BASE_PKG = "org.onosproject.yang.gen"; | 123 | public static final String DEFAULT_BASE_PKG = "org.onosproject.yang.gen"; |
124 | public static final String REVISION_PREFIX = "rev"; | 124 | public static final String REVISION_PREFIX = "rev"; |
125 | public static final String VERSION_PREFIX = "v"; | 125 | public static final String VERSION_PREFIX = "v"; | ... | ... |
... | @@ -122,8 +122,14 @@ public final class FileSystemUtil { | ... | @@ -122,8 +122,14 @@ public final class FileSystemUtil { |
122 | String line = bufferReader.readLine(); | 122 | String line = bufferReader.readLine(); |
123 | 123 | ||
124 | while (line != null) { | 124 | while (line != null) { |
125 | - stringBuilder.append(UtilConstants.FOUR_SPACE_INDENTATION + line); | 125 | + if (line.equals(UtilConstants.FOUR_SPACE_INDENTATION) |
126 | - stringBuilder.append("\n"); | 126 | + || line.equals(UtilConstants.EIGHT_SPACE_INDENTATION) |
127 | + || line.equals(UtilConstants.SPACE) || line.equals("") || line.equals(UtilConstants.NEW_LINE)) { | ||
128 | + stringBuilder.append("\n"); | ||
129 | + } else { | ||
130 | + stringBuilder.append(UtilConstants.FOUR_SPACE_INDENTATION + line); | ||
131 | + stringBuilder.append("\n"); | ||
132 | + } | ||
127 | line = bufferReader.readLine(); | 133 | line = bufferReader.readLine(); |
128 | } | 134 | } |
129 | return stringBuilder.toString(); | 135 | return stringBuilder.toString(); | ... | ... |
... | @@ -245,8 +245,8 @@ public final class JavaDocGen { | ... | @@ -245,8 +245,8 @@ public final class JavaDocGen { |
245 | * @return javaDocs | 245 | * @return javaDocs |
246 | */ | 246 | */ |
247 | private static String generateForImplClass(String className) { | 247 | private static String generateForImplClass(String className) { |
248 | - return UtilConstants.JAVA_DOC_FIRST_LINE + UtilConstants.IMPL_CLASS_JAVA_DOC + className + UtilConstants.PERIOD | 248 | + return UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_FIRST_LINE + UtilConstants.IMPL_CLASS_JAVA_DOC |
249 | - + UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_END_LINE; | 249 | + + className + UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_END_LINE; |
250 | } | 250 | } |
251 | 251 | ||
252 | /** | 252 | /** |
... | @@ -310,13 +310,15 @@ public final class JavaDocGen { | ... | @@ -310,13 +310,15 @@ public final class JavaDocGen { |
310 | * @return javaDocs | 310 | * @return javaDocs |
311 | */ | 311 | */ |
312 | private static String generateForConstructors(String className) { | 312 | private static String generateForConstructors(String className) { |
313 | - return UtilConstants.JAVA_DOC_FIRST_LINE + UtilConstants.FOUR_SPACE_INDENTATION | 313 | + return UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_FIRST_LINE |
314 | - + UtilConstants.JAVA_DOC_CONSTRUCTOR + className + UtilConstants.IMPL + UtilConstants.PERIOD | 314 | + + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_CONSTRUCTOR + className |
315 | - + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.NEW_LINE_ESTRIC | 315 | + + UtilConstants.IMPL + UtilConstants.PERIOD + UtilConstants.NEW_LINE |
316 | + + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.NEW_LINE_ESTRIC | ||
316 | + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_PARAM | 317 | + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_PARAM |
317 | - + className.substring(0, 1).toLowerCase() + className.substring(1) + UtilConstants.OBJECT | 318 | + + className.substring(0, 1).toLowerCase() + className.substring(1) + UtilConstants.BUILDER |
318 | - + UtilConstants.SPACE + UtilConstants.BUILDER_OBJECT + UtilConstants.SPACE + className | 319 | + + UtilConstants.OBJECT + UtilConstants.SPACE + UtilConstants.BUILDER_OBJECT + UtilConstants.SPACE |
319 | - + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_END_LINE; | 320 | + + className + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION |
321 | + + UtilConstants.JAVA_DOC_END_LINE; | ||
320 | } | 322 | } |
321 | 323 | ||
322 | /** | 324 | /** | ... | ... |
utils/yangutils/src/main/java/org/onosproject/yangutils/utils/io/impl/TempDataStore.java
deleted
100644 → 0
1 | -/* | ||
2 | - * Copyright 2016 Open Networking Laboratory | ||
3 | - * | ||
4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | - * you may not use this file except in compliance with the License. | ||
6 | - * You may obtain a copy of the License at | ||
7 | - * | ||
8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | - * | ||
10 | - * Unless required by applicable law or agreed to in writing, software | ||
11 | - * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | - * See the License for the specific language governing permissions and | ||
14 | - * limitations under the License. | ||
15 | - */ | ||
16 | - | ||
17 | -package org.onosproject.yangutils.utils.io.impl; | ||
18 | - | ||
19 | -import java.io.BufferedInputStream; | ||
20 | -import java.io.BufferedOutputStream; | ||
21 | -import java.io.File; | ||
22 | -import java.io.FileInputStream; | ||
23 | -import java.io.FileNotFoundException; | ||
24 | -import java.io.FileOutputStream; | ||
25 | -import java.io.IOException; | ||
26 | -import java.io.InputStream; | ||
27 | -import java.io.ObjectInput; | ||
28 | -import java.io.ObjectInputStream; | ||
29 | -import java.io.ObjectOutput; | ||
30 | -import java.io.ObjectOutputStream; | ||
31 | -import java.io.OutputStream; | ||
32 | -import java.util.ArrayList; | ||
33 | -import java.util.List; | ||
34 | - | ||
35 | -/** | ||
36 | - * Provides storage for Temp data while traversing data model tree for code | ||
37 | - * generation. | ||
38 | - */ | ||
39 | -public final class TempDataStore { | ||
40 | - | ||
41 | - /** | ||
42 | - * Data Store types. | ||
43 | - */ | ||
44 | - public static enum TempDataStoreType { | ||
45 | - | ||
46 | - /** | ||
47 | - * Methods. | ||
48 | - */ | ||
49 | - GETTER_METHODS, | ||
50 | - | ||
51 | - /** | ||
52 | - * Methods. | ||
53 | - */ | ||
54 | - BUILDER_METHODS, | ||
55 | - | ||
56 | - /** | ||
57 | - * Methods. | ||
58 | - */ | ||
59 | - BUILDER_INTERFACE_METHODS, | ||
60 | - | ||
61 | - /** | ||
62 | - * Methods. | ||
63 | - */ | ||
64 | - IMPL_METHODS, | ||
65 | - | ||
66 | - /** | ||
67 | - * Attributes. | ||
68 | - */ | ||
69 | - ATTRIBUTE, | ||
70 | - | ||
71 | - /** | ||
72 | - * Imports. | ||
73 | - */ | ||
74 | - IMPORT | ||
75 | - } | ||
76 | - | ||
77 | - /** | ||
78 | - * File name string for Temp files of methods. | ||
79 | - */ | ||
80 | - private static final String GETTER_METHOD_FILE_NAME = "TempGetterMethodDataStore"; | ||
81 | - | ||
82 | - /** | ||
83 | - * File name string for Temp files of methods. | ||
84 | - */ | ||
85 | - private static final String BUILDER_METHOD_FILE_NAME = "TempBuilderMethodDataStore"; | ||
86 | - | ||
87 | - /** | ||
88 | - * File name string for Temp files of methods. | ||
89 | - */ | ||
90 | - private static final String BUILDER_INTERFACE_METHOD_FILE_NAME = "TempBuilderInterfaceMethodDataStore"; | ||
91 | - | ||
92 | - /** | ||
93 | - * File name string for Temp files of methods. | ||
94 | - */ | ||
95 | - private static final String IMPL_METHOD_FILE_NAME = "TempImplMethodDataStore"; | ||
96 | - | ||
97 | - /** | ||
98 | - * File name string for Temp files of attributes. | ||
99 | - */ | ||
100 | - private static final String ATTRIBUTE_FILE_NAME = "TempAttributeDataStore"; | ||
101 | - | ||
102 | - /** | ||
103 | - * File name string for Temp files of imports. | ||
104 | - */ | ||
105 | - private static final String IMPORT_FILE_NAME = "TempImportDataStore"; | ||
106 | - | ||
107 | - /** | ||
108 | - * File extension of Temp files. | ||
109 | - */ | ||
110 | - private static final String FILE_EXTENSION = ".tmp"; | ||
111 | - | ||
112 | - /** | ||
113 | - * Directory for generating Temp files. | ||
114 | - */ | ||
115 | - private static final String GEN_DIR = "target/"; | ||
116 | - | ||
117 | - /** | ||
118 | - * Buffer size. | ||
119 | - */ | ||
120 | - private static final int BUFFER_SIZE = 8 * 1024; | ||
121 | - | ||
122 | - /** | ||
123 | - * Default constructor. | ||
124 | - */ | ||
125 | - private TempDataStore() { | ||
126 | - } | ||
127 | - | ||
128 | - /** | ||
129 | - * Writes specific info to a Temp file. | ||
130 | - * | ||
131 | - * @param data data to be stored | ||
132 | - * @param type type of Temp data store | ||
133 | - * @param className class name | ||
134 | - * @throws IOException when fails to create a Temp data file | ||
135 | - */ | ||
136 | - public static void setTempData(String data, TempDataStoreType type, String className) throws IOException { | ||
137 | - | ||
138 | - String fileName = ""; | ||
139 | - if (type.equals(TempDataStoreType.ATTRIBUTE)) { | ||
140 | - fileName = ATTRIBUTE_FILE_NAME; | ||
141 | - } else if (type.equals(TempDataStoreType.GETTER_METHODS)) { | ||
142 | - fileName = GETTER_METHOD_FILE_NAME; | ||
143 | - } else if (type.equals(TempDataStoreType.BUILDER_INTERFACE_METHODS)) { | ||
144 | - fileName = BUILDER_INTERFACE_METHOD_FILE_NAME; | ||
145 | - } else if (type.equals(TempDataStoreType.BUILDER_METHODS)) { | ||
146 | - fileName = BUILDER_METHOD_FILE_NAME; | ||
147 | - } else if (type.equals(TempDataStoreType.IMPL_METHODS)) { | ||
148 | - fileName = IMPL_METHOD_FILE_NAME; | ||
149 | - } else { | ||
150 | - fileName = IMPORT_FILE_NAME; | ||
151 | - } | ||
152 | - | ||
153 | - File dir = new File(GEN_DIR + className + File.separator); | ||
154 | - dir.mkdirs(); | ||
155 | - try { | ||
156 | - OutputStream file = new FileOutputStream(GEN_DIR + className + File.separator + fileName + FILE_EXTENSION); | ||
157 | - OutputStream buffer = new BufferedOutputStream(file, BUFFER_SIZE); | ||
158 | - | ||
159 | - ObjectOutput output = new ObjectOutputStream(buffer); | ||
160 | - try { | ||
161 | - output.writeObject(data); | ||
162 | - } finally { | ||
163 | - output.close(); | ||
164 | - } | ||
165 | - } catch (IOException ex) { | ||
166 | - throw new IOException("failed to serialize data"); | ||
167 | - } | ||
168 | - } | ||
169 | - | ||
170 | - /** | ||
171 | - * Get the Temp data. | ||
172 | - * | ||
173 | - * @param type type of Temp data store | ||
174 | - * @param className name of the class | ||
175 | - * @return list of attribute info | ||
176 | - * @throws IOException when fails to read from the file | ||
177 | - * @throws ClassNotFoundException when class is missing | ||
178 | - * @throws FileNotFoundException when file is missing | ||
179 | - */ | ||
180 | - public static List<String> getTempData(TempDataStoreType type, String className) | ||
181 | - throws IOException, FileNotFoundException, ClassNotFoundException { | ||
182 | - | ||
183 | - String fileName = ""; | ||
184 | - if (type.equals(TempDataStoreType.ATTRIBUTE)) { | ||
185 | - fileName = ATTRIBUTE_FILE_NAME; | ||
186 | - } else if (type.equals(TempDataStoreType.GETTER_METHODS)) { | ||
187 | - fileName = GETTER_METHOD_FILE_NAME; | ||
188 | - } else if (type.equals(TempDataStoreType.BUILDER_INTERFACE_METHODS)) { | ||
189 | - fileName = BUILDER_INTERFACE_METHOD_FILE_NAME; | ||
190 | - } else if (type.equals(TempDataStoreType.BUILDER_METHODS)) { | ||
191 | - fileName = BUILDER_METHOD_FILE_NAME; | ||
192 | - } else if (type.equals(TempDataStoreType.IMPL_METHODS)) { | ||
193 | - fileName = IMPL_METHOD_FILE_NAME; | ||
194 | - } else { | ||
195 | - fileName = IMPORT_FILE_NAME; | ||
196 | - } | ||
197 | - try { | ||
198 | - InputStream file = new FileInputStream(GEN_DIR + className + File.separator + fileName + FILE_EXTENSION); | ||
199 | - InputStream buffer = new BufferedInputStream(file); | ||
200 | - ObjectInput input = new ObjectInputStream(buffer); | ||
201 | - try { | ||
202 | - String data = (String) input.readObject(); | ||
203 | - List<String> recoveredData = new ArrayList<>(); | ||
204 | - recoveredData.add(data); | ||
205 | - return recoveredData; | ||
206 | - } finally { | ||
207 | - input.close(); | ||
208 | - file.close(); | ||
209 | - } | ||
210 | - } catch (FileNotFoundException ex) { | ||
211 | - throw new FileNotFoundException("No such file or directory."); | ||
212 | - } catch (ClassNotFoundException ex) { | ||
213 | - throw new ClassNotFoundException("failed to fetch the Temp data file."); | ||
214 | - } | ||
215 | - } | ||
216 | -} |
... | @@ -94,7 +94,8 @@ public final class YangIoUtils { | ... | @@ -94,7 +94,8 @@ public final class YangIoUtils { |
94 | * @param baseDir generated directory in previous build | 94 | * @param baseDir generated directory in previous build |
95 | */ | 95 | */ |
96 | public static void clean(String baseDir) { | 96 | public static void clean(String baseDir) { |
97 | - File generatedDirectory = new File(baseDir + File.separator + UtilConstants.YANG_GEN_DIR); | 97 | + File generatedDirectory = new File(baseDir + File.separator + UtilConstants.YANG_GEN_DIR |
98 | + + UtilConstants.DEFAULT_BASE_PKG.replace(UtilConstants.PERIOD, UtilConstants.SLASH)); | ||
98 | if (generatedDirectory.exists()) { | 99 | if (generatedDirectory.exists()) { |
99 | List<String> javafiles; | 100 | List<String> javafiles; |
100 | try { | 101 | try { |
... | @@ -151,10 +152,11 @@ public final class YangIoUtils { | ... | @@ -151,10 +152,11 @@ public final class YangIoUtils { |
151 | String[] strArray = partString.split(UtilConstants.COMMA); | 152 | String[] strArray = partString.split(UtilConstants.COMMA); |
152 | String newString = ""; | 153 | String newString = ""; |
153 | for (int i = 0; i < strArray.length; i++) { | 154 | for (int i = 0; i < strArray.length; i++) { |
154 | - if (i % 4 != 0) { | 155 | + if (i % 4 != 0 || i == 0) { |
155 | newString = newString + strArray[i] + UtilConstants.COMMA; | 156 | newString = newString + strArray[i] + UtilConstants.COMMA; |
156 | } else { | 157 | } else { |
157 | - newString = newString + UtilConstants.NEW_LINE + UtilConstants.TWELVE_SPACE_INDENTATION + strArray[i] | 158 | + newString = newString + UtilConstants.NEW_LINE + UtilConstants.TWELVE_SPACE_INDENTATION |
159 | + + strArray[i] | ||
158 | + UtilConstants.COMMA; | 160 | + UtilConstants.COMMA; |
159 | } | 161 | } |
160 | } | 162 | } | ... | ... |
-
Please register or login to post a comment