We are building an engine that will allow us to add new jar files whenever, load those jar files and look for some specific functionality, and run the code that exposes that functionality. Current plan is to use the ServiceLoader to do so (just an extra detail; I'm not married to that idea). For the moment let's assume that we completely control which jar files are going to be loaded (big assumption--I'd guess I'm going to eventually post something about that too).
Given all that, I would like to restrict access in those extensions to certain classes. For a fake example, we want to ensure that instead of using java.io.PrintStream
, they use our.better.PrintStreamSolution
.
I really don't have a good idea of what I could do here. Since for the time being, we own the code that will go out as extensions, we could just do very thorough code reviews but I'd rather do either a static analysis at install time or actually throw errors at runtime. Any idea how one would would accomplish this?