I am trying to learn how to write a plugin using the new model rules format, but I’m having some trouble mapping what I want to do, to how I must specify it.
In a nutshell, I want to enhance certain classes (using Ebean) before they are added to the classpath for compilation. Therefore, classes in a certain package (e.g. “models”) are compiled before all others, then the Ebean agent is executed on the resulting .class files, resulting in a new set of changed .class files. This final set of .class files should then be added to the compile classpath.
I managed to write a rule to mutate the Java source set in order to exclude the classes that will be compiled separately (based on their path). I managed to create a separate Java source set with only the separate classes. What’s missing is how to run the agent at the right time.
I figure I need to somehow model:
A) That there’s a dependency between the compile configuration and the resulting set of enhanced classes
B) That the resulting set of enhanced classes are generated by first compiling them normally as .java files then running the Ebean agent on them
I’m not sure how I should proceed to do A and B, because I think I’m thinking too much about how to do instead of what should be done. In my mind it should be something similar to chaining two LanguageTransforms. Can such thing be done?
The way it is set-up right now, the separate set of classes to be enhanced is automatically compiled and added to the classpath (i.e., it’s treated as a normal Java source set). I’m thinking maybe I need to isolate the SourceSet (in a separate configuration?). How would I do that?
One way I thought about doing it was to treat the source set as if it were of a separate language (EbeanJavaSourceSet, or something like that), and manually define how it transforms ‘.java’ to ‘.class’ and performs the enhancement. If so, is there a way to reuse the code for compiling ‘.java’ to ‘.class’? (i.e., maybe writing a transform task that somehow uses a Java transform task?)
Am I on the right direction? Is there an easier way to achieve the same result?