OSGi is gaining a lot of traction lately. But what if you have a very large application? Migration can be a lot of work.
I would like to point to a simple tool we use that might help out a bit here. It’s called Macker and
it’s meant to model the architectural ideals programmers always dream up for their projects, and then break — it helps keep code clean and consistent.
Macker is open source (GPL). It’s current version is 0.4 and has been for a long time. That doesn’t mean it’s immature or abandoned, however. It’s author had a lot more features planned, hence the 0.4. But what’s already available is enough to give it a serious look.
So, what does Macker do, exactly? It enforces rules about your architecture. For example, suppose you have a product with a public API. You could create a rule file with an
<access-rule> that the API must be self-contained:
<message>The API should be self-contained</message> <deny> <from pattern="api" /> </deny> <allow> <from pattern="api" /> <to pattern="api" /> </allow> <allow> <from pattern="api" /> <to pattern="jre" /> </allow>
These rules can be very explicit about what is and what isn’t allowed. There are several ways to specify them, but I’ve found it easiest to use patterns, like in the example above, since they can have symbolic names. Here’s an example:
<pattern name="api"> <include class="com.acme.api.**"/> </pattern>
** denotes every class in the
com.acme.api package, or any of its sub-packages. See the Macker user guide for more information about supported regular expressions.
Macker comes with an Ant task, so you can enforce your architecture from your build. Maybe not as good as OSGi, but it sure helps with keeping your code the way you intended it.