[groovy-dev] Changes to global AST transformation loading
Hi guys!
While working on GROOVY-5025, I noticed a potential problem with the
current global AST transformation mechanism : if two threads were to
load or compile groovy scripts in parallel, there were chances that the
global AST transformations classes were not loaded from the right class
loader.
The problem is that the ASTTransformationVisitor makes use of static
fields to store the list of previously encountered global AST
transformation classes, but also the current compilation unit. After
digging into the code, I found that this was made necessary by the way
the GrabAnnotationTransformation works : it requires access to the
compilation unit in order to add global AST transformations from grabbed
jars.
Moreover, it was not easy to make GROOVY-5025 possible without changing
code: in a "secure environment", some people want to disable usage of
<at> Grab as well as the AstBuilder which are always loaded. Seeing this, I
reworked the way those transformations are loaded and removed the static
fields from ASTTransformationVisitor. Instead of CompilationUnit having
a transformLoader, I wrapped the latter in a ASTTransformationsContext
class which holds the state information that was previously found in
static members, that is to say the list of global AST transformations.
This class also holds the transform classloader, as well as a reference
to the compilation unit.
The second change introduces an interface, CompilationUnitAware, which
can be implemented by AST transformations which require access to the
current compilation unit. This way, the GrabAnnotationTransformation is
(Continue reading)