[ONOS-5232] bits enum class generation modifications and code refactoring.
Change-Id: I67fb31c586802e9cf682aa6e707475ad8fdc096f
diff --git a/generator/src/main/java/org/onosproject/yangutils/utils/io/YangPluginConfig.java b/generator/src/main/java/org/onosproject/yangutils/utils/io/YangPluginConfig.java
index e212832..86e4500 100644
--- a/generator/src/main/java/org/onosproject/yangutils/utils/io/YangPluginConfig.java
+++ b/generator/src/main/java/org/onosproject/yangutils/utils/io/YangPluginConfig.java
@@ -16,6 +16,16 @@
package org.onosproject.yangutils.utils.io;
+import javax.tools.JavaCompiler;
+import javax.tools.StandardJavaFileManager;
+import javax.tools.ToolProvider;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.onosproject.yangutils.utils.io.impl.YangFileScanner.getJavaFiles;
+
/**
* Representation of plugin configurations required for YANG utils.
*/
@@ -96,4 +106,31 @@
return conflictResolver;
}
+ /**
+ * Compiles the generated code for unit tests.
+ *
+ * @param dir1 directory path
+ * @throws IOException when generated code has compilation errors.
+ */
+ @SuppressWarnings("unchecked")
+ public static void compileCode(String dir1) throws IOException {
+ String classpath = System.getProperty("java.class.path");
+ List<String> optionList = new ArrayList<>();
+ optionList.addAll(Arrays.asList("-classpath", classpath));
+
+ List<String> files = getJavaFiles(dir1);
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ StandardJavaFileManager manager = compiler.getStandardFileManager(null, null, null);
+ Iterable fileObjects = manager.getJavaFileObjectsFromStrings(files);
+ JavaCompiler.CompilationTask task = compiler.getTask(null, null,
+ null, optionList, null,
+ fileObjects);
+
+ boolean failOnError = !task.call();
+ manager.close();
+ if (failOnError) {
+ throw new IOException("Yang Error : compilation errors in " +
+ "generated code.");
+ }
+ }
}
diff --git a/generator/src/main/java/org/onosproject/yangutils/utils/io/impl/YangIoUtils.java b/generator/src/main/java/org/onosproject/yangutils/utils/io/impl/YangIoUtils.java
index 1e856bf..a03ebb4 100644
--- a/generator/src/main/java/org/onosproject/yangutils/utils/io/impl/YangIoUtils.java
+++ b/generator/src/main/java/org/onosproject/yangutils/utils/io/impl/YangIoUtils.java
@@ -34,6 +34,7 @@
import java.util.Stack;
import java.util.regex.Pattern;
+import static java.lang.Integer.parseInt;
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
import static org.onosproject.yangutils.utils.UtilConstants.COLON;
import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
@@ -881,4 +882,19 @@
}
return isDeleted;
}
+
+ /**
+ * Converts string to integer number for maven version.
+ *
+ * @param ver version
+ * @return int value of version
+ */
+ public static int getVersionValue(String ver) {
+ String[] array = ver.split(Pattern.quote(PERIOD));
+ StringBuilder builder = new StringBuilder();
+ for (String str : array) {
+ builder.append(str);
+ }
+ return parseInt(builder.toString());
+ }
}