Skip to content

Commit

Permalink
Merge pull request #1029 from rsvato/master
Browse files Browse the repository at this point in the history
[#1028][feature] - Reuse DSL code with macros
  • Loading branch information
rsvato committed Aug 23, 2013
2 parents f4e871a + 38ee512 commit 95b58d9
Show file tree
Hide file tree
Showing 8 changed files with 561 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.griddynamics.genesis.template.dsl.groovy.transformations;

import org.codehaus.groovy.transform.GroovyASTTransformationClass;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.SOURCE)
@Target({ElementType.TYPE, ElementType.METHOD})
@GroovyASTTransformationClass({"com.griddynamics.genesis.template.dsl.groovy.transformations.MacroASTTransformation"})
public @interface MacroExpand {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.griddynamics.genesis.template.dsl.groovy.transformations.exceptions;


public class DSLSyntaxException extends Exception {
public DSLSyntaxException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.griddynamics.genesis.template.dsl.groovy.transformations.exceptions;


public class MacroParametersException extends DSLSyntaxException {
public MacroParametersException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ import com.griddynamics.genesis.annotation.RemoteGateway
import org.codehaus.groovy.control.CompilerConfiguration
import org.codehaus.groovy.control.customizers.ASTTransformationCustomizer
import support.VariablesSupport
import com.griddynamics.genesis.template.dsl.groovy.transformations.{PhaseContainer, Context}
import com.griddynamics.genesis.template.dsl.groovy.transformations.{MacroExpand, PhaseContainer, Context}
import scala.tools.ant.sabbus.CompilationFailure

@RemoteGateway("groovy template service")
class GroovyTemplateService(val templateRepoService : TemplateRepoService,
Expand Down Expand Up @@ -147,13 +148,17 @@ class GroovyTemplateService(val templateRepoService : TemplateRepoService,

try {
val compilerConfiguration = new CompilerConfiguration()
compilerConfiguration.addCompilationCustomizers(new ASTTransformationCustomizer(classOf[Context]),
new ASTTransformationCustomizer(classOf[PhaseContainer]))
compilerConfiguration.addCompilationCustomizers(
new ASTTransformationCustomizer(classOf[MacroExpand]),
new ASTTransformationCustomizer(classOf[Context]),
new ASTTransformationCustomizer(classOf[PhaseContainer])
)
val groovyShell = new GroovyShell(binding, compilerConfiguration)
groovyShell.evaluate(body)
projectId.foreach (evaluateIncludes(_, templateDecl.includes, groovyShell))
} catch {
case e: GroovyRuntimeException => throw new IllegalStateException("can't process template", e)
case compilation: CompilationFailure => throw new IllegalStateException("Conpilation error: " + compilation.message, compilation)
case e: GroovyRuntimeException => throw new IllegalStateException("can't process template: " + e.getMessage, e)
}
templateDecl.bodies.headOption.map { body => DslDelegate(body).to(builder).newTemplate() }
}
Expand Down
Loading

0 comments on commit 95b58d9

Please sign in to comment.