Skip to content

Commit

Permalink
[playframework#1354] Revert experimental GroovyTempate.compile code t…
Browse files Browse the repository at this point in the history
…o fix template files saving to projects root
  • Loading branch information
Maximillian13 committed Dec 27, 2021
1 parent 0ecac3b commit a6fa6de
Showing 1 changed file with 7 additions and 23 deletions.
30 changes: 7 additions & 23 deletions framework/src/play/templates/GroovyTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,34 +139,18 @@ public void compile() {
CompilationUnit compilationUnit = new CompilationUnit(compilerConfiguration);
compilationUnit.addSource(
new SourceUnit(name, compiledSource, compilerConfiguration, tClassLoader, compilationUnit.getErrorCollector()));

// The following approach to adding the phase operation replaces the original
// reflection based approach commented out lower down. This appears to be the
// canonical approach and possibly has only been made available in the v3.x
// stream but it differs in two ways from the reflection based approach and it's
// not clear if and what the impact is:
// 1. It does NOT guarantee an empty list of OUTPUT phases operations to begin with.
// 2. The new phase operation is added to the start and not the end.
// See https://github.com/apache/groovy/blob/GROOVY_3_0_6/src/main/java/org/codehaus/groovy/control/CompilationUnit.java#L349
compilationUnit.addPhaseOperation(new IGroovyClassOperation() {

Field phasesF = compilationUnit.getClass().getDeclaredField("phaseOperations");
phasesF.setAccessible(true);
Collection[] phases = (Collection[]) phasesF.get(compilationUnit);
LinkedList<IGroovyClassOperation> output = new LinkedList<>();
phases[Phases.OUTPUT] = output;
output.add(new IGroovyClassOperation() {
@Override
public void call(GroovyClass gclass) {
groovyClassesForThisTemplate.add(gclass);
}
});

// TOOD: Remove once the above replacement logic has been confirmed.
// Field phasesF = compilationUnit.getClass().getDeclaredField("phaseOperations");
// phasesF.setAccessible(true);
// Collection[] phases = (Collection[]) phasesF.get(compilationUnit);
// LinkedList<IGroovyClassOperation> output = new LinkedList<>();
// phases[Phases.OUTPUT] = output;
// output.add(new IGroovyClassOperation() {
// @Override
// public void call(GroovyClass gclass) {
// groovyClassesForThisTemplate.add(gclass);
// }
// });

compilationUnit.compile();
// ouf
Expand Down

0 comments on commit a6fa6de

Please sign in to comment.