Wednesday, October 09, 2013

TigerTeam TRIMM - Model Driven Generator just went Open Source

TigerTeam TRIMM – Model Driven Generator is just Open Sourced in July 2013. I myself never heard of this product before and found this product by coincidence as I tried to find a JPA 2 standalone cartridge / generator available in Internet. I know that AndroMDA has some cartridges to persist Java objects but as far as I know AndroMDA only support persistence in the context of EJB 3 not as standalone JPA.

After I found this product I began to analyze the code at Bitbucket.org and found out that the idea with the Events and Listeners as Extensions is a very good idea. TRIMM also uses Maven completely and does not have any dependencies to Eclipse plugins, so you are Eclipse independent. Special to this framework is that it uses its own metamodel and does not use UML2 metamodel for the generators. TRIMM should work for MagicDraw and Enterprise Architect and it can read the files directly from those UML tools. It also uses its own Java code generator which is basically based on String outputs. A very good thing is that TRIMM offers some ready to use cartridges like Java, JPA 2 and Webservice.

It seems that TRIMM does not suffer the problems I mentioned in my older Java article at Java Lobby post and uses almost the same approach of KissMDA. Following are the differences I can see in a glance:

(1) TRIMM is using its own Java generator which is basically based on String outputs and this is not the best way to generate Java codes. Using Eclipse JDT is a lot more easier and you always get syntactically correct Java codes which can be easily unit tested like this KissMDA example.

(2) Interesting to compare the transformers for Java code generation. In TRIMM you have the class JavaGenerator.java. In KissMDA you use the class SimpleJavaTransformer.java. They both are the main entering point for the generation of Java codes. Both classes look quite similar from the way of doing the works they need to do. Using DI framework like Guice in KissMDA makes the code more readable and easier to understand.

(3) Unit tests are crucial in KissMDA. The simple Java cartridge has in the mean time about 35 test cases. This is possible because we use Mockito extensively. TRIMM Java cartridge has also some unit tests which are not many in comparison with the available implementation classes.

I really like the idea of using Events and Listeners to plug the extensions. In this context I will try to write the next KissMDA cartridge which will be a JPA 2 cartridge using Events, Event Bus and Listeners. As a foundation I will use this easy and simple Event Binder framework: GWT Event Binder. In the mean time I found some Open Source Event Bus implementations like Guava and MBassador. This is a good blog which compares those Event Bus frameworks: Java Event Bus Library Comparison. My choice is MBassador because it supports Weak References in Event Bus.

Congratulation to the team of TRIMM and I  think, it is a very good move to Open Source TRIMM. I wish all the best for the future of TRIMM!

3 comments:

Jeppe Cramon said...

Hi. Thanks for your coverage and feedback on TRIMM :)

The JavaGenerator uses a mixed model for java Code generation. Where possible and feasible we use a CodeModel (which is resembles the .NET CodeDOM). This means all main concepts such as Class, Interface, Enumeration, Constructor, Methods incl. arguments/return-value, Parameters, Fields all have a Java object model representation. For the Code inside methods/constructors we switch to CodeSnippets which uses String concatenation. Sometimes we skimp on using the CodeDom for certain extensions and use CodeSnippets exclusively. It's a tradeoff that we try to make very consciously.

The use of the CodeModel allows us to reuse 80% of the Code generation for Java when e.g. generating Groovy Code. The largest difference is the CodeSnippets and especially the CodeWriter and CodeVisitor that's used: GroovyCodeWriter which uses the GroovyCodeWritingCodeVisitor instead of the JavaCodeWritingVisitor.

This allows you to write Code in the following fashion:
Constructor constructor = new Constructor(CodeElement.AccessModifier.Public);
for (Property immuteableProperty : immuteableProperties) {
constructor.addParameters(new Parameter(immuteableProperty.getName(), immuteableProperty.getField().getType()));
if (!superClazzImmuteableProperties.contains(immuteableProperty)) {
constructor.addCode(new CodeSnippet("this.", immuteableProperty.getField().getName(), " = ", immuteableProperty.getName(), ";"));
}
}
event.getClazz().add(constructor);

Regarding the Unit testing then you're right, the amount of Unit tests are smaller compared to the amount of Code. We basically only Unit test the Core parts (parser, generator).
For most other parts, we rely heavily on vertical slice testing/integration testing. We have created several Example/test projects, which tests large parts of the Code generator and many of the extensions. We then rely on automatically generated unit/integration-tests (e.g. JpaUnittestCreator) to create integration tests for the Code we generate based on a model.
We have used TRIMM in production since 2008 and many large projects and this approach has so far proved sufficient.
Again, it has been a tradeoff of delivering quality on time and still trying to maintain the quality over time.

If you have more feedback, I would love to hear it :)

/Jeppe

Dr. Lofi Dewanto said...

Thanks for your fast feedback and explanation!

As I said in my blog, TRIMM is the *first* MDSD framework which matches my vision of how MDSD framework should look like. Very pragmatic, lightweight and completely independent of IDE like Eclipse. So, IMHO, TRIMM is very nice. Don't worry I'll take further look on TRIMM and will give you a lot more feedbacks ;)

It's a pitty that I never heard TRIMM before it became Open Source. In January this year I wrote an article about "MDSD state of the art" at German's online developer magazine called heise Developer: http://heise.de/-1776860 and at that moment I did not know the existence of TRIMM.

Let me know, if there are things we can work together between KissMDA and TRIMM.

Thanks,
Lofi.

Henrik Wivel said...

Just for your information, we have recently released a new snapshot of TRIMM with support for Spring Data Mongo.

You can read more here: http://trimm.tigerteam.dk/trimmmongo-1-0-1-snapshot-support-spring-data-mongo/

/Henrik