Announcement: Compilation-less Commons-Attributes
I like metadata for some tasks. Luckily for all of us, Commons-Attributes implements metadata for pre-Tiger JDKs. Unluckily, it requires an extra compilation step (with Ant, no less). But no more. I’ve created an extension that does it all in memory.
The class uses both xjavadoc and commons-attributes. Here is an example of usage:
CommonsMemoryAttributes attributes = new CommonsMemoryAttributes("src");
Class testClass = AttributeTestClass.class;
public void testClassAttribute() throws SecurityException {
Collection result = attributes.getAttributes(testClass, AttributeClass.class);
assertEquals(result.toString(), 1, result.size());
assertEquals(new AttributeClass("test", 123), result.iterator().next());
result = attributes.getAttributes(testClass);
assertEquals(result.toString(), 2, result.size());
}
The CommonsMemoryAttributes constructor takes the path to the source code. Using xjavadoc, I am able to parse and deal with the class very quickly.
There are still a few wrinkles to be ironed out, but I think it is a good start
The code is available here. All dependencies are handled through Maven, for your conveinience.