[英]How can I access a file in my Grails plugin from a src file in the same plugin?
I'm working on a JavaScript testing plugin for Grails. 我正在为Grails开发一个JavaScript测试插件。 I wrote some Groovy classes to perform the testing that I've stored in my src/groovy folder.
我写了一些Groovy类来执行我存储在src / groovy文件夹中的测试。 I hook into the testing events in my plugin's _Events.groovy script and inject an instance of the test runner.
我在我的插件的_Events.groovy脚本中挂钩测试事件并注入测试运行器的实例。 From that instance of the test runner, I need to access the JavaScript files, which I've stored in src/js, to perform the testing.
从测试运行器的那个实例,我需要访问我存储在src / js中的JavaScript文件来执行测试。
The plugin documentation specifies a way to get the path from my Gant scripts, but that doesn't work elsewhere. 插件文档指定了从我的Gant脚本获取路径的方法,但这在其他地方不起作用。 I've also tried to get access to the
GrailsApplication
via grailsApplication
or ApplicationHolder
, but I get null
. 我也尝试通过
grailsApplication
或ApplicationHolder
访问GrailsApplication
,但是我得到了null
。 Finally, I've tried accessing BuildSettings
and ConfigurationHolder
, but those show me an empty configuration. 最后,我尝试访问
BuildSettings
和ConfigurationHolder
,但那些显示我是一个空配置。
To make my plugin work, I am currently copying the JavaScript files into the application's test/resources folder so it's in a known location relative to the working directory, which I'm assuming is the project folder. 为了使我的插件工作,我目前正在将JavaScript文件复制到应用程序的test / resources文件夹中,因此它位于相对于工作目录的已知位置,我假设它是项目文件夹。 This feels invasive and fragile to me, so I'd like to figure out a "right" way.
这给我带来了侵略性和脆弱性,所以我想找出一种“正确”的方式。
How can I get a path to my plugin from my test runner so I can find those files? 如何从测试运行器获取插件的路径,以便找到这些文件?
如果您有BuildSettings和pluginManager
bean(使用def pluginManager
或通过PluginManagerHolder进行依赖注入),那么您可以获取路径
new File(buildSettings.projectPluginsDir, pluginManager.getPluginPath('foo'))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.