У меня странная ошибка времени выполнения, когда пользовательский DSL, основанный на AbstractFactory, компилируется и прекрасно работает с groovy 3.0.x, но не работает во время выполнения ниже 2.5.x.
Вот код:
@Test
void sayTest() {
PerCLScript script = percl.script {
say language: 'en-US', loop: 1, conferenceId: 'confId', text: 'some text', enforcePCI: false
}
compare('[{"Say":{"language":"en-US","conferenceId":"confId","text":"some text","enforcePCI":false,"loop":1}}]', script.serializeToPerCL())
}
Ошибка времени выполнения:
groovy.lang.MissingMethodException: No signature of method: com.freeclimb.groovy.PerCLBuilderTest.say() is applicable for argument types: (LinkedHashMap) values: [[language:en-US, loop:1, conferenceId:confId, text:some text, ...]]
Possible solutions: sms(), any(), any(groovy.lang.Closure), tap(groovy.lang.Closure), wait(), wait(long)
Я строю с помощью GmavenPlus 1.8.1, но я попробовал компилятор eclipse- groovy с теми же результатами.
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.8.1</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>compileTests</goal>
</goals>
</execution>
</executions>
<configuration>
<invokeDynamic>true</invokeDynamic>
</configuration>
</plugin>
PerCLBuilder
class PerCLBuilder extends FactoryBuilderSupport {
private PerCLScript percl
public PerCLBuilder(boolean init = true) {
super(init)
}
def registerObjectFactories() {
registerFactory('script', new ScriptFactory())
registerFactory('say', new PerCLCommandFactory(Say.class))
...
}
class PerCLCommandFactory extends AbstractFactory {
Class clazz;
PerCLCommandFactory(Class clazz) {
this.clazz = clazz;
}
@SuppressWarnings("GrDeprecatedAPIUsage")
Object newInstance(FactoryBuilderSupport builder, Object name, Object value, Map attributes)
throws InstantiationException, IllegalAccessException {
clazz.newInstance()
}
...