bytedeco / javacpp

The missing bridge between Java and native C++
Other
4.51k stars 586 forks source link

Simplify and clean-up javacpp.Loader #514

Open HannesWell opened 3 years ago

HannesWell commented 3 years ago

While working on the current OSGi issue in javacpp I read a lot through the javacpp.Loader and I have to admit, that it is sometimes hard to read and to understand this class. Not only because the class is very large but also because the big important methods (like findResources(), cacheResources(), ...) itself are complex monoliths that also sometimes repetitive code. For example SonarLint indicates a cognitive complexity of 141 for loadLibrary() and three other methods are close to to or above 100 while at most 15 is recommended. The exact numbers may be arguable, but those number underline my subjective impression.

Therefore I want to suggest to simplify and clean-up the javacpp.Loader in the following ways:

If you are interested in such simplifications/clean-ups I would be happy to provide a corresponding PR.

saudet commented 3 years ago

There's a lot of stuff that should be refactored, sure, but refactoring even just the Loader isn't going to be as easy as it looks. In that case, we need to think about more than just the JDK, with Android being of particular importance, so we should make sure that any major effort there also takes into consideration at least Android bundles too, see https://github.com/bytedeco/javacv/issues/1117.

saudet commented 2 years ago

BTW, it looks like supporting Android App Bundles isn't going to be a problem. We can easily extract everything we need from JAR files at the beginning of the build with Gradle in a way that is 100% supported by Google, see https://github.com/bytedeco/javacv/issues/1117#issuecomment-982336622.