Open daberni opened 7 years ago
Looking into source files is not needed at all. And it can even cause all kinds of problems when doing it without full-blown code parsing.
Reflection can do everything that's needed there. For enumerating all classes, there's a helper library: https://github.com/ronmamo/reflections
Passing classes directly does not work for me. I still get ClassNotFoundException.
Well I have another issue. Seems it is not possible to find any kotlin class at all, when I pass class directly, and everything ok during compile time but there is java.lang.NoClassDefFoundError
during runtime.
Yeah you are right, there seems to be a problem with the classloader too, will have to investigate a bit further as my first approach at least worked once...
As temporary solution I've added classpath for kotlin classes at runtime, maybe it can be useful for someone:
private static void addPath(String classPath) throws Exception {
File file = new File(classPath);
URL url = file.toURL();
URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
Class urlClass = URLClassLoader.class;
Method method = urlClass.getDeclaredMethod("addURL", new Class[]{URL.class});
method.setAccessible(true);
method.invoke(urlClassLoader, new Object[]{url});
}
And actual path for kotlin classes i.e.
File kotlinClasses = new File("../../build/tmp/kotlin-classes/{selectedBuildType}")
Has anyone managed to write a version of OrmLiteConfigUtil
that works with Kotlin classes?
currently OrmLiteConfigUtil scans the project directory only for
.java
files and ignores the rest.As kotlin is gaining more and more popularity it would make sense to support those files too (I am currently using kotlin, especially for all of my model classes).
There are at least 2 points which should get considered
.kt
files into search-filter.kt
file (although this isn't the standard from the guidelines. This would be possible in the case of.java
-files too)package name is already parsed from inside the file instead of the directory tree, so this should apply for the class name too.
Current workaround for people with the same issue: derive from OrmLiteConfigUtil overwrite
main()
and callwriteConfigFile
with all required classes directly.