简体   繁体   English

如何从同一个插件中的src文件访问我的Grails插件中的文件?

[英]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 . 我也尝试通过grailsApplicationApplicationHolder访问GrailsApplication ,但是我得到了null Finally, I've tried accessing BuildSettings and ConfigurationHolder , but those show me an empty configuration. 最后,我尝试访问BuildSettingsConfigurationHolder ,但那些显示我是一个空配置。

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.

相关问题 如何重用ckeditor grails插件的文件选择器? - How can I reuse the file chooser of ckeditor grails plugin? 如何访问Grails插件的application.properties中的值? - How can I access the values in application.properties of a Grails plugin? 使用Grails rest插件下载文件时,如何从HTTP标头获取文件名? - How do I get the file name from HTTP header while downloading a file with Grails rest plugin? grails:文件管理器插件 - grails: file manager plugin 如何使用Grails Asset-Pipeline插件从Javascript访问图像? - How can I access images from Javascript using Grails Asset-Pipeline plugin? Grails Tika插件-如何将文件从数据库发送到tika进行解析 - Grails Tika Plugin - How do I send a file from a database to tika to parse 如何从 Grails 3 插件中排除类 - How can I exclude classes from a Grails 3 plugin 创建和安装grails插件-我的插件如何在安装过程中/安装后从其依赖的插件访问资源? - Creating and installing a grails plugin - how does my plugin access resources from a plugin its dependent upon during/after install? 如何为Grails插件生成zip文件 - How to generate zip file for a grails plugin GRAILS:包括一个JavaScript文件,该文件包含来自插件内部的grails代码 - GRAILS : include javascript file that contains grails code from within a plugin
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM