神经漫游日志
Frustrating OSGi

Recently I’ve been working on implementing a static analyzer. Generally, I want to make it modular - there are a bunch of loosely-coupled and plugable analyses, and we build up a analysis process with these building blocks.

I already have a old system wirtten in Java and analyzing Java programs, but now I need to write a analyzer for C programs. Thus, I resort to Eclipse CDT for C parsing. Eclipse uses OSGi tech, so I learnt a lot about OSGi. And then the catastrophy starts: I tried to transform my analysis framework into OSGi-based. To make it worse, I don’t like eclipse, so I made everything in Intellij IDEA, with bnd-gradle-plugin. What a mess! There is not much support for OSGi or bnd in IDEA, neither for eclipse, of course. It is hard to find useful documents online, either. Most articles I can find is out-dated, or too meta-physical to understand. I read a lot of doc of OSGi compendium and eclipse, but I still do not known how to launch my system correctly - yes, I can build all of my code into bundles, but everything is running like a coincidence, I don’t know why it fails, and then I don’t know why it works. I cannot distinguish which dependency is missing and which is redundant.

After months of work and missing one of my important deadlines, I realize that what I’ve done is pointless:

  1. Yes my system is modular, but it don’t have much to do with OSGi. It is modular by MY design paradigm, and then it can suit OSGi, but not the OSGi made my system modular.
  2. OSGi made a strong assumption that every bundle is hot-plugable. But in my analysis framework, every analysis part is fixed as long as the analsis process is built. I just need a mechanism of class-loading, but handling the non-existing unpluging part adds a lot of trouble.
  3. OSGi is too old. I spent a lot of time to find useful documents, but the more I searched, the more likely I find that there are not many products that uses OSGi now in 2020s.
  4. The only need comes from eclipse (and CDT), but the analyzer only needs something to provide it with source files and compile options, so it is not necessarily bound to eclipse.
  5. The homegrown C/CPP AST of CDT is not quite good for use, compared to LLVM toolchain, and CDT itself is leaning to LLVM as well.

So I need to make a big step back, throwing away the burden of OSGi framework. The OSGi part should be minimized to eclipse plugins that send source code and options of C and other languages to the analyzer, and receive analysis reports to render them. Similarly, we can build plugins for IDEA, VSCode, e.t.c.

Then the remaining problem is, how to make the analysis framework modular and plugable? As is mentioned, we have had a old system and it’s in Java 1.5, and the true need is to modernize it. Do I need to use Spring Boot, or I just need to write a simple framework on my own needs? This is my following work and I will write about it in future articles.

Comments have been disabled for this content