简体   繁体   English

Groovy脚本运行器体系结构

[英]Groovy script runner architecture

Initial info: I have a groovy app (let's call it Runner ) which is capable of running anything implementing certain interface (let's call it Runnable ). 初始信息:我有一个时髦的应用程序(我们称它为Runner ),它能够运行实现某些接口的任何东西(我们称其为Runnable )。 And I have a pool of Runnables (groovy scripts) which should be visible to this app at the init stage and which app will call (through the interface and passing an object as a param). 而且我有一个Runnables (常规脚本)池,该池在初始化阶段对此应用程序可见,并且将调用该应用程序(通过接口并将对象作为参数传递)。

Task: What I need is a way to load and call all the Runnables from the Runner . 任务:我需要的是一种从Runner加载并调用所有Runnable的方法。

Requirements: It's tricky, as scripts may not follow certain package structure and can be placed on the same machine as Runner but virtually in any place. 要求:这很棘手,因为脚本可能不遵循某些程序包结构,并且可以与Runner放置在同一台计算机上,但实际上可以放置在任何地方。 They can also be named differently (open discussion for mandatory java alike naming: class name == file name) and can be skipped for now (though if there's gonna be advice on that it's cool!). 它们的名称也可以不同(关于强制性Java的类似命名的公开讨论:类名==文件名),现在可以跳过(尽管如果有建议,那就太酷了!)。

NOTES: I imagine it possible through having a config file in which scripts are configured (absolute path is provided) and to load them using this stuff and either cast Object to Runnable interface and trigger what I need or to invokeMethod(...) . 注意:我想通过在其中配置脚本(提供绝对路径)的配置文件并使用此东西加载它们,然后将Object 强制转换Runnable接口并触发我需要的方法或invokeMethod(...),就可以实现 But have no idea if it can be done easier (there should be a way, cause it looks all too clumsy). 但是不知道是否可以更轻松地完成(应该有一种方法,因为它看起来太笨拙)。 I also cant think of a way to handle file naming issue and multiple classes in one file issue. 我也想不出一种方法来处理文件命名问题和一个文件问题中的多个类。

PS: Such long description might cause misunderstanding so please comment on vague parts. PS:这么长的描述可能会引起误解,因此请对模糊的部分进行评论。

I think you need to know all classes implementing an interface. 我认为您需要了解实现接口的所有类。 Find Java classes implementing an interface may be of interest to you. 查找实现接口的Java类可能会让您感兴趣。

The option to have a config file in which script's absolute paths are written is good and proved to be a working solution. 具有在其中写入脚本的绝对路径的配置文件的选项很好,并且被证明是可行的解决方案。 You'll have to deal with class loading of whatever is not visible in the app class loader. 您必须处理应用程序类加载器中不可见的任何类的类加载。 In particular you'll have to deal with annotation based POJO serialization problems. 特别是,您必须处理基于注释的POJO序列化问题。 Singleton of Runnable loader is a good practice. Singlenable Runnable加载程序是一个好习惯。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 脚本运行器中的Jira Groovy脚本 - Jira Groovy script in script runner Adaptavist Script Runner(Groovy)-单击创建子任务 - Adaptavist Script Runner (Groovy) - Create subtask on click 如何使用脚本运行程序 groovy 脚本获取数组项 - How to get an Array item using Script runner groovy script 使用 groovy/script runner [JIRA] 设置后提交 DueDate 时出现问题 - Trouble commiting DueDate after setting it with groovy/script runner [JIRA] 如何在JIRA脚本运行器Groovy中运行shell命令 - How to run shell command in JIRA script runner groovy Groovy 用于 Script Runner 的 Rest/HTTP 请求本机 - Groovy Rest/HTTP Request Native for use with Script Runner 尝试使用groovy脚本运行程序在JIRA中删除时出现NullPointerException - NullPointerException while trying to delete in JIRA using groovy script runner Groovy(Script Runner / Jira)从父问题到SubTask获取WorkLog - Groovy (Script Runner/Jira) Get WorkLog from Parent Issue to SubTask 收集Groovy中的自定义数字字段,并计算返回结果(JIRA脚本运行器) - Gathering custom number fields in Groovy, and calculating return result (JIRA script runner) 使用“启动测试运行器”从常规脚本保存全局属性时,未添加全局属性 - Global property is not getting added when saving it from groovy script using “launch test runner”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM