What is the purpose of CompilationCustomizer.getPhase(); Can importCustomizer() add imports, after groovy file execution has started, based on the instructions in that groovy file?
ÐилÑн ÐÐ°Ð»Ð°Ñ Ð·Ð¾Ð² Via Dev <dev-GSC0n/0aZo1d/SJB6HiN2Ni2O/[email protected]>
| Newsgroups | gmane.comp.lang.groovy.devel |
|---|---|
| Message-ID | <[email protected]> |
Hello,
* what is the purpose of CompilationCustomizer.getPhase(), which is not described at https://docs.groovy-lang.org/4.0.0/html/api/org/codehaus/groovy/control/customizers/CompilationCustomizer.html#getPhase() ?
OpenHAB integrates Groovy 4.0.28 ala JSR223 by utilizing two files - https://github.com/openhab/openhab-addons/tree/main/bundles/org.openhab.automation.groovyscripting/src/main/java/org/openhab/automation/groovyscripting/internal .
When a .groovy input file is proceeded, first some default things are inserted into the scripting engine in GroovyScriptEngineFactory.scopeValues(). If the thing is a variable, then it is inserted with scriptEngine.put(variable-name, value). If the thing is a class, then the class is added to an ImportCustomizer, and the latter is at the end .addCompilationCustomizers(importCustomizer). This works!
After the script execution has started, in OpenHAB JSR223 one can execute `se.importPreset("RuleSupport")` - cf https://www.openhab.org/docs/configuration/jsr223.html - to add further things in the context. Currently GroovyScriptEngineFactory.scopeValues() does again for classes create a new ImportCustomizer, addImport, e.g. addImport("TriggerBuilder", org.openhab.core.automation.util.TriggerBuilder). This does not work, however, and the question is why: with the content of file t.groovy:n
se.importPreset("RuleSupport")
var k = TriggerBuilder.create()
produces an error:
javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: TriggerBuilder for class: t
* As far as I see ImportCustomizer has always phase=CONVERSION. Does this mean, that ImportCustomizer can only be adjusted before script execution has started?
* What should above `se.importPreset("RuleSupport")` do, so that the second line assumes that `import org.openhab.core.automation.util.TriggerBuilder;` is executed after the first line and before the second line?
Thanks // Дилян