Quantcast

Getting resources from Grails 3 plugin

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Getting resources from Grails 3 plugin

Owen Rubel
Am trying to test a plugin locally and can see the resources for the plugin are generating fine in the build under 'build/resources/main/public' ... but when I include the plugin in a project and try to access the files, it says they're not there. Obviously it is looking locally but the plugin is trying to access it's resources in the project.

How do we write in the plugin so it can access it's resources when it is loaded in a project? I have it written as the following:

if(grailsApplication.isWarDeployed()){

    ioPath = Holders.servletContext.getRealPath('/')

    if(Environment.current == Environment.DEVELOPMENT || Environment.current == Environment.TEST){

        ioPath += 'WEB-INF/classes/iostate'

    }else{

        // test in Environment.PRODUCTION

        ioPath += 'WEB-INF/classes/iostate'

    }

}else{

    ioPath = (String) grails.util.BuildSettings.RESOURCES_DIR?.path

    if(Environment.current == Environment.DEVELOPMENT || Environment.current == Environment.TEST){

        ioPath += '/public/iostate'

    }else{

        // test in Environment.PRODUCTION

        ioPath += '/public/iostate'

    }

}


--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/a5606b7a-52b5-4670-a8c8-4e1b5f1019ad%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Getting resources from Grails 3 plugin

zyro
using springs resource abstraction will save you a lot of hassle, i think.

given a plugin resource src/main/resources/foo/bar.txt, it could be used
in one of these ways (among others ofc):

https://gist.github.com/zyro23/f662d4eef32dcead859e

a few things worth mentioning there:

- @Component/@PostConstruct just used for the example. as long as you
are in a bean that is subject to autowiring, you are set

- when using @Value injection into a Resource, the placeholder key has
to be a config entry (i.e. a resolvable property source entry), in my
example (application.yml):
foobar: classpath:foo/bar.txt
supplying a string directly will not use the required converter.

- when accessing resources inside jar files always use
Resource.getInputStream(). getFile() will not work reliably (if at all)
(because the resource is _inside_ a jar file..)

- if its really not possible for you to extract the resource loading
into a bean, you should be able to statically use
Holders.grailsApplication.mainContext.getResource(...).

hth, zyro

-------- Original Message  --------
Subject: Getting resources from Grails 3 plugin
From: Owen Rubel <[hidden email]>
To: [hidden email]
Date: Mon, 15 Jun 2015 11:39:45 -0700 (pdt)

> Am trying to test a plugin locally and can see the resources for the
> plugin are generating fine in the build under
> 'build/resources/main/public' ... but when I include the plugin in a
> project and try to access the files, it says they're not there.
> Obviously it is looking locally but the plugin is trying to access it's
> resources in the project.
>
> How do we write in the plugin so it can access it's resources when it is
> loaded in a project? I have it written as the following:
>
> *if*(grailsApplication.isWarDeployed()){
>
>      ioPath=Holders.servletContext.getRealPath('/')
>
> *
> if*(Environment.current==Environment.DEVELOPMENT||Environment.current==Environment.TEST){
>
>          ioPath+='WEB-INF/classes/iostate'
>
>      }*else*{
>
>          // test in Environment.PRODUCTION
>
>          ioPath+='WEB-INF/classes/iostate'
>
>      }
>
> }*else*{
>
>      ioPath=(String)grails.util.BuildSettings.RESOURCES_DIR?.path
>
> *
> if*(Environment.current==Environment.DEVELOPMENT||Environment.current==Environment.TEST){
>
>          ioPath+='/public/iostate'
>
>      }*else*{
>
>          // test in Environment.PRODUCTION
>
>          ioPath+='/public/iostate'
>
>      }
>
> }
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Grails Dev Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to [hidden email]
> <mailto:[hidden email]>.
> To post to this group, send email to [hidden email]
> <mailto:[hidden email]>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/grails-dev-discuss/a5606b7a-52b5-4670-a8c8-4e1b5f1019ad%40googlegroups.com
> <https://groups.google.com/d/msgid/grails-dev-discuss/a5606b7a-52b5-4670-a8c8-4e1b5f1019ad%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/557F2508.4010100%40zyro.net.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Getting resources from Grails 3 plugin

Owen Rubel
Two issues:

1) its a JSON file
2) Annotations create a binding and I need everything to be abstracted for theory and practice

Thanks for advice though. I'll give holders a shot. 

On Monday, June 15, 2015 at 12:18:38 PM UTC-7, zyro wrote:
using springs resource abstraction will save you a lot of hassle, i think.

given a plugin resource src/main/resources/foo/bar.txt, it could be used
in one of these ways (among others ofc):

<a href="https://gist.github.com/zyro23/f662d4eef32dcead859e" target="_blank" rel="nofollow" onmousedown="this.href='https://www.google.com/url?q\75https%3A%2F%2Fgist.github.com%2Fzyro23%2Ff662d4eef32dcead859e\46sa\75D\46sntz\0751\46usg\75AFQjCNFSEVE6iS6wAxkw0pB3u31wTQkNVg';return true;" onclick="this.href='https://www.google.com/url?q\75https%3A%2F%2Fgist.github.com%2Fzyro23%2Ff662d4eef32dcead859e\46sa\75D\46sntz\0751\46usg\75AFQjCNFSEVE6iS6wAxkw0pB3u31wTQkNVg';return true;">https://gist.github.com/zyro23/f662d4eef32dcead859e

a few things worth mentioning there:

- @Component/@PostConstruct just used for the example. as long as you
are in a bean that is subject to autowiring, you are set

- when using @Value injection into a Resource, the placeholder key has
to be a config entry (i.e. a resolvable property source entry), in my
example (application.yml):
foobar: classpath:foo/bar.txt
supplying a string directly will not use the required converter.

- when accessing resources inside jar files always use
Resource.getInputStream(). getFile() will not work reliably (if at all)
(because the resource is _inside_ a jar file..)

- if its really not possible for you to extract the resource loading
into a bean, you should be able to statically use
Holders.grailsApplication.mainContext.getResource(...).

hth, zyro

-------- Original Message  --------
Subject: Getting resources from Grails 3 plugin
From: Owen Rubel <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="b0voMSmGhN0J" rel="nofollow" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">oru...@...>
To: <a href="javascript:" target="_blank" gdf-obfuscated-mailto="b0voMSmGhN0J" rel="nofollow" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">grails-de...@googlegroups.com
Date: Mon, 15 Jun 2015 11:39:45 -0700 (pdt)

> Am trying to test a plugin locally and can see the resources for the
> plugin are generating fine in the build under
> 'build/resources/main/public' ... but when I include the plugin in a
> project and try to access the files, it says they're not there.
> Obviously it is looking locally but the plugin is trying to access it's
> resources in the project.
>
> How do we write in the plugin so it can access it's resources when it is
> loaded in a project? I have it written as the following:
>
> *if*(grailsApplication.isWarDeployed()){
>
>      ioPath=Holders.servletContext.getRealPath('/')
>
> *
> if*(Environment.current==Environment.DEVELOPMENT||Environment.current==Environment.TEST){
>
>          ioPath+='WEB-INF/classes/iostate'
>
>      }*else*{
>
>          // test in Environment.PRODUCTION
>
>          ioPath+='WEB-INF/classes/iostate'
>
>      }
>
> }*else*{
>
>      ioPath=(String)grails.util.BuildSettings.RESOURCES_DIR?.path
>
> *
> if*(Environment.current==Environment.DEVELOPMENT||Environment.current==Environment.TEST){
>
>          ioPath+='/public/iostate'
>
>      }*else*{
>
>          // test in Environment.PRODUCTION
>
>          ioPath+='/public/iostate'
>
>      }
>
> }
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Grails Dev Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="b0voMSmGhN0J" rel="nofollow" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">grails-dev-discuss+unsubscribe@...
> <mailto:<a href="javascript:" target="_blank" gdf-obfuscated-mailto="b0voMSmGhN0J" rel="nofollow" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">grails-dev-discuss+unsubscribe@...>.
> To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="b0voMSmGhN0J" rel="nofollow" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">grails-de...@googlegroups.com
> <mailto:<a href="javascript:" target="_blank" gdf-obfuscated-mailto="b0voMSmGhN0J" rel="nofollow" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">grails-de...@googlegroups.com>.
> To view this discussion on the web visit
> <a href="https://groups.google.com/d/msgid/grails-dev-discuss/a5606b7a-52b5-4670-a8c8-4e1b5f1019ad%40googlegroups.com" target="_blank" rel="nofollow" onmousedown="this.href='https://groups.google.com/d/msgid/grails-dev-discuss/a5606b7a-52b5-4670-a8c8-4e1b5f1019ad%40googlegroups.com';return true;" onclick="this.href='https://groups.google.com/d/msgid/grails-dev-discuss/a5606b7a-52b5-4670-a8c8-4e1b5f1019ad%40googlegroups.com';return true;">https://groups.google.com/d/msgid/grails-dev-discuss/a5606b7a-52b5-4670-a8c8-4e1b5f1019ad%40googlegroups.com
> <<a href="https://groups.google.com/d/msgid/grails-dev-discuss/a5606b7a-52b5-4670-a8c8-4e1b5f1019ad%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href='https://groups.google.com/d/msgid/grails-dev-discuss/a5606b7a-52b5-4670-a8c8-4e1b5f1019ad%40googlegroups.com?utm_medium\75email\46utm_source\75footer';return true;" onclick="this.href='https://groups.google.com/d/msgid/grails-dev-discuss/a5606b7a-52b5-4670-a8c8-4e1b5f1019ad%40googlegroups.com?utm_medium\75email\46utm_source\75footer';return true;">https://groups.google.com/d/msgid/grails-dev-discuss/a5606b7a-52b5-4670-a8c8-4e1b5f1019ad%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href='https://groups.google.com/d/optout';return true;" onclick="this.href='https://groups.google.com/d/optout';return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/f588dff7-b597-45ad-93a9-7ff2809deccd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Getting resources from Grails 3 plugin

Owen Rubel
No thats not it. I was getting better results prior. First the method needs a directory path to the walk through the files contained within

But when I go to the plugins resource dir in 3.0, I am getting this error...

Caused by: java.io.FileNotFoundException: /home/owenrubel/workspace/api-framework-example/./build/resources/main/iostate
at org.codehaus.groovy.runtime.ResourceGroovyMethods.checkDir(ResourceGroovyMethods.java:1011)
at org.codehaus.groovy.runtime.ResourceGroovyMethods.eachFile(ResourceGroovyMethods.java:1030)
at org.codehaus.groovy.runtime.ResourceGroovyMethods.eachFile(ResourceGroovyMethods.java:1056)
at org.codehaus.groovy.runtime.dgm$936.invoke(Unknown Source)
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoMetaMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:271)
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:53)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:110)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:122)
at net.nosegrind.apiframework.ApiObjectService.parseFiles(ApiObjectService.groovy:94)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInte.java:1270)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:207)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:56)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:49)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:151)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:163)
at net.nosegrind.apiframework.ApiObjectService.initialize(ApiObjectService.groovy:74)

The file is being pulled in in the applications build and IS at that location. But am wondering if I should file a JIRA for this.



On Monday, June 15, 2015 at 12:49:22 PM UTC-7, Owen Rubel wrote:
Two issues:

1) its a JSON file
2) Annotations create a binding and I need everything to be abstracted for theory and practice

Thanks for advice though. I'll give holders a shot. 

On Monday, June 15, 2015 at 12:18:38 PM UTC-7, zyro wrote:
using springs resource abstraction will save you a lot of hassle, i think.

given a plugin resource src/main/resources/foo/bar.txt, it could be used
in one of these ways (among others ofc):

<a href="https://gist.github.com/zyro23/f662d4eef32dcead859e" rel="nofollow" target="_blank" onmousedown="this.href='https://www.google.com/url?q\75https%3A%2F%2Fgist.github.com%2Fzyro23%2Ff662d4eef32dcead859e\46sa\75D\46sntz\0751\46usg\75AFQjCNFSEVE6iS6wAxkw0pB3u31wTQkNVg';return true;" onclick="this.href='https://www.google.com/url?q\75https%3A%2F%2Fgist.github.com%2Fzyro23%2Ff662d4eef32dcead859e\46sa\75D\46sntz\0751\46usg\75AFQjCNFSEVE6iS6wAxkw0pB3u31wTQkNVg';return true;">https://gist.github.com/zyro23/f662d4eef32dcead859e

a few things worth mentioning there:

- @Component/@PostConstruct just used for the example. as long as you
are in a bean that is subject to autowiring, you are set

- when using @Value injection into a Resource, the placeholder key has
to be a config entry (i.e. a resolvable property source entry), in my
example (application.yml):
foobar: classpath:foo/bar.txt
supplying a string directly will not use the required converter.

- when accessing resources inside jar files always use
Resource.getInputStream(). getFile() will not work reliably (if at all)
(because the resource is _inside_ a jar file..)

- if its really not possible for you to extract the resource loading
into a bean, you should be able to statically use
Holders.grailsApplication.mainContext.getResource(...).

hth, zyro

-------- Original Message  --------
Subject: Getting resources from Grails 3 plugin
From: Owen Rubel <[hidden email]>
To: [hidden email]
Date: Mon, 15 Jun 2015 11:39:45 -0700 (pdt)

> Am trying to test a plugin locally and can see the resources for the
> plugin are generating fine in the build under
> 'build/resources/main/public' ... but when I include the plugin in a
> project and try to access the files, it says they're not there.
> Obviously it is looking locally but the plugin is trying to access it's
> resources in the project.
>
> How do we write in the plugin so it can access it's resources when it is
> loaded in a project? I have it written as the following:
>
> *if*(grailsApplication.isWarDeployed()){
>
>      ioPath=Holders.servletContext.getRealPath('/')
>
> *
> if*(Environment.current==Environment.DEVELOPMENT||Environment.current==Environment.TEST){
>
>          ioPath+='WEB-INF/classes/iostate'
>
>      }*else*{
>
>          // test in Environment.PRODUCTION
>
>          ioPath+='WEB-INF/classes/iostate'
>
>      }
>
> }*else*{
>
>      ioPath=(String)grails.util.BuildSettings.RESOURCES_DIR?.path
>
> *
> if*(Environment.current==Environment.DEVELOPMENT||Environment.current==Environment.TEST){
>
>          ioPath+='/public/iostate'
>
>      }*else*{
>
>          // test in Environment.PRODUCTION
>
>          ioPath+='/public/iostate'
>
>      }
>
> }
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Grails Dev Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to grails-dev-discuss+[hidden email]
> <mailto:grails-dev-discuss+[hidden email]>.
> To post to this group, send email to [hidden email]
> <mailto:grails-de...@googlegroups.com>.
> To view this discussion on the web visit
> <a href="https://groups.google.com/d/msgid/grails-dev-discuss/a5606b7a-52b5-4670-a8c8-4e1b5f1019ad%40googlegroups.com" rel="nofollow" target="_blank" onmousedown="this.href='https://groups.google.com/d/msgid/grails-dev-discuss/a5606b7a-52b5-4670-a8c8-4e1b5f1019ad%40googlegroups.com';return true;" onclick="this.href='https://groups.google.com/d/msgid/grails-dev-discuss/a5606b7a-52b5-4670-a8c8-4e1b5f1019ad%40googlegroups.com';return true;">https://groups.google.com/d/msgid/grails-dev-discuss/a5606b7a-52b5-4670-a8c8-4e1b5f1019ad%40googlegroups.com
> <<a href="https://groups.google.com/d/msgid/grails-dev-discuss/a5606b7a-52b5-4670-a8c8-4e1b5f1019ad%40googlegroups.com?utm_medium=email&amp;utm_source=footer" rel="nofollow" target="_blank" onmousedown="this.href='https://groups.google.com/d/msgid/grails-dev-discuss/a5606b7a-52b5-4670-a8c8-4e1b5f1019ad%40googlegroups.com?utm_medium\75email\46utm_source\75footer';return true;" onclick="this.href='https://groups.google.com/d/msgid/grails-dev-discuss/a5606b7a-52b5-4670-a8c8-4e1b5f1019ad%40googlegroups.com?utm_medium\75email\46utm_source\75footer';return true;">https://groups.google.com/d/msgid/grails-dev-discuss/a5606b7a-52b5-4670-a8c8-4e1b5f1019ad%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit <a href="https://groups.google.com/d/optout" rel="nofollow" target="_blank" onmousedown="this.href='https://groups.google.com/d/optout';return true;" onclick="this.href='https://groups.google.com/d/optout';return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/c33c2c67-f8aa-41a0-b160-48f09ebf5aaa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Getting resources from Grails 3 plugin

Owen Rubel
So the issue is that previously, the plugin resources (like files in a plugins 'conf' dir) were loaded under an application 'build' directory during run-app.

Hence:

ioPath = (String) BuildSettings.TARGET_DIR?.path


This would allow me to find the resource in the plugin project when running the including application.


Now it seems that in 3.0, the files are kept in a build dir in the plugin, so the question is how do we access them iwthin the plugin from a script within the plugin when the application runs? Because the previous way doesn't seem to work anymore.


On Tuesday, June 16, 2015 at 9:01:05 AM UTC-7, Owen Rubel wrote:
No thats not it. I was getting better results prior. First the method needs a directory path to the walk through the files contained within

But when I go to the plugins resource dir in 3.0, I am getting this error...

Caused by: java.io.FileNotFoundException: /home/owenrubel/workspace/api-framework-example/./build/resources/main/iostate
at org.codehaus.groovy.runtime.ResourceGroovyMethods.checkDir(ResourceGroovyMethods.java:1011)
at org.codehaus.groovy.runtime.ResourceGroovyMethods.eachFile(ResourceGroovyMethods.java:1030)
at org.codehaus.groovy.runtime.ResourceGroovyMethods.eachFile(ResourceGroovyMethods.java:1056)
at org.codehaus.groovy.runtime.dgm$936.invoke(Unknown Source)
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoMetaMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:271)
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:53)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:110)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:122)
at net.nosegrind.apiframework.ApiObjectService.parseFiles(ApiObjectService.groovy:94)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInte.java:1270)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:207)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:56)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:49)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:151)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:163)
at net.nosegrind.apiframework.ApiObjectService.initialize(ApiObjectService.groovy:74)

The file is being pulled in in the applications build and IS at that location. But am wondering if I should file a JIRA for this.



On Monday, June 15, 2015 at 12:49:22 PM UTC-7, Owen Rubel wrote:
Two issues:

1) its a JSON file
2) Annotations create a binding and I need everything to be abstracted for theory and practice

Thanks for advice though. I'll give holders a shot. 

On Monday, June 15, 2015 at 12:18:38 PM UTC-7, zyro wrote:
using springs resource abstraction will save you a lot of hassle, i think.

given a plugin resource src/main/resources/foo/bar.txt, it could be used
in one of these ways (among others ofc):

<a href="https://gist.github.com/zyro23/f662d4eef32dcead859e" rel="nofollow" target="_blank" onmousedown="this.href='https://www.google.com/url?q\75https%3A%2F%2Fgist.github.com%2Fzyro23%2Ff662d4eef32dcead859e\46sa\75D\46sntz\0751\46usg\75AFQjCNFSEVE6iS6wAxkw0pB3u31wTQkNVg';return true;" onclick="this.href='https://www.google.com/url?q\75https%3A%2F%2Fgist.github.com%2Fzyro23%2Ff662d4eef32dcead859e\46sa\75D\46sntz\0751\46usg\75AFQjCNFSEVE6iS6wAxkw0pB3u31wTQkNVg';return true;">https://gist.github.com/zyro23/f662d4eef32dcead859e

a few things worth mentioning there:

- @Component/@PostConstruct just used for the example. as long as you
are in a bean that is subject to autowiring, you are set

- when using @Value injection into a Resource, the placeholder key has
to be a config entry (i.e. a resolvable property source entry), in my
example (application.yml):
foobar: classpath:foo/bar.txt
supplying a string directly will not use the required converter.

- when accessing resources inside jar files always use
Resource.getInputStream(). getFile() will not work reliably (if at all)
(because the resource is _inside_ a jar file..)

- if its really not possible for you to extract the resource loading
into a bean, you should be able to statically use
Holders.grailsApplication.mainContext.getResource(...).

hth, zyro

-------- Original Message  --------
Subject: Getting resources from Grails 3 plugin
From: Owen Rubel <[hidden email]>
To: [hidden email]
Date: Mon, 15 Jun 2015 11:39:45 -0700 (pdt)

> Am trying to test a plugin locally and can see the resources for the
> plugin are generating fine in the build under
> 'build/resources/main/public' ... but when I include the plugin in a
> project and try to access the files, it says they're not there.
> Obviously it is looking locally but the plugin is trying to access it's
> resources in the project.
>
> How do we write in the plugin so it can access it's resources when it is
> loaded in a project? I have it written as the following:
>
> *if*(grailsApplication.isWarDeployed()){
>
>      ioPath=Holders.servletContext.getRealPath('/')
>
> *
> if*(Environment.current==Environment.DEVELOPMENT||Environment.current==Environment.TEST){
>
>          ioPath+='WEB-INF/classes/iostate'
>
>      }*else*{
>
>          // test in Environment.PRODUCTION
>
>          ioPath+='WEB-INF/classes/iostate'
>
>      }
>
> }*else*{
>
>      ioPath=(String)grails.util.BuildSettings.RESOURCES_DIR?.path
>
> *
> if*(Environment.current==Environment.DEVELOPMENT||Environment.current==Environment.TEST){
>
>          ioPath+='/public/iostate'
>
>      }*else*{
>
>          // test in Environment.PRODUCTION
>
>          ioPath+='/public/iostate'
>
>      }
>
> }
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Grails Dev Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to grails-dev-discuss+[hidden email]
> <mailto:grails-dev-discuss+[hidden email]>.
> To post to this group, send email to [hidden email]
> <mailto:grails-de...@googlegroups.com>.
> To view this discussion on the web visit
> <a href="https://groups.google.com/d/msgid/grails-dev-discuss/a5606b7a-52b5-4670-a8c8-4e1b5f1019ad%40googlegroups.com" rel="nofollow" target="_blank" onmousedown="this.href='https://groups.google.com/d/msgid/grails-dev-discuss/a5606b7a-52b5-4670-a8c8-4e1b5f1019ad%40googlegroups.com';return true;" onclick="this.href='https://groups.google.com/d/msgid/grails-dev-discuss/a5606b7a-52b5-4670-a8c8-4e1b5f1019ad%40googlegroups.com';return true;">https://groups.google.com/d/msgid/grails-dev-discuss/a5606b7a-52b5-4670-a8c8-4e1b5f1019ad%40googlegroups.com
> <<a href="https://groups.google.com/d/msgid/grails-dev-discuss/a5606b7a-52b5-4670-a8c8-4e1b5f1019ad%40googlegroups.com?utm_medium=email&amp;utm_source=footer" rel="nofollow" target="_blank" onmousedown="this.href='https://groups.google.com/d/msgid/grails-dev-discuss/a5606b7a-52b5-4670-a8c8-4e1b5f1019ad%40googlegroups.com?utm_medium\75email\46utm_source\75footer';return true;" onclick="this.href='https://groups.google.com/d/msgid/grails-dev-discuss/a5606b7a-52b5-4670-a8c8-4e1b5f1019ad%40googlegroups.com?utm_medium\75email\46utm_source\75footer';return true;">https://groups.google.com/d/msgid/grails-dev-discuss/a5606b7a-52b5-4670-a8c8-4e1b5f1019ad%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit <a href="https://groups.google.com/d/optout" rel="nofollow" target="_blank" onmousedown="this.href='https://groups.google.com/d/optout';return true;" onclick="this.href='https://groups.google.com/d/optout';return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/18ad549f-c32e-4ee6-adbe-bbde4ac67228%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Getting resources from Grails 3 plugin

Owen Rubel
GrailsPluginUtils is also under codehaus and is deprecated (and I can't find a replacement class for it).

Everywhere I look where I would be able to reference classes in the plugin build has been removed, deprecated, etc and the application doesn't bring over those files.

How is the plugin supposed to reference its own BUILD files in the application when the application doesn't contain them??


On Tuesday, June 16, 2015 at 10:28:10 AM UTC-7, Owen Rubel wrote:
So the issue is that previously, the plugin resources (like files in a plugins 'conf' dir) were loaded under an application 'build' directory during run-app.

Hence:

ioPath = (String) BuildSettings.TARGET_DIR?.path


This would allow me to find the resource in the plugin project when running the including application.


Now it seems that in 3.0, the files are kept in a build dir in the plugin, so the question is how do we access them iwthin the plugin from a script within the plugin when the application runs? Because the previous way doesn't seem to work anymore.


On Tuesday, June 16, 2015 at 9:01:05 AM UTC-7, Owen Rubel wrote:
No thats not it. I was getting better results prior. First the method needs a directory path to the walk through the files contained within

But when I go to the plugins resource dir in 3.0, I am getting this error...

Caused by: java.io.FileNotFoundException: /home/owenrubel/workspace/api-framework-example/./build/resources/main/iostate
at org.codehaus.groovy.runtime.ResourceGroovyMethods.checkDir(ResourceGroovyMethods.java:1011)
at org.codehaus.groovy.runtime.ResourceGroovyMethods.eachFile(ResourceGroovyMethods.java:1030)
at org.codehaus.groovy.runtime.ResourceGroovyMethods.eachFile(ResourceGroovyMethods.java:1056)
at org.codehaus.groovy.runtime.dgm$936.invoke(Unknown Source)
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoMetaMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:271)
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:53)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:110)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:122)
at net.nosegrind.apiframework.ApiObjectService.parseFiles(ApiObjectService.groovy:94)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInte.java:1270)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:207)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:56)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:49)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:151)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:163)
at net.nosegrind.apiframework.ApiObjectService.initialize(ApiObjectService.groovy:74)

The file is being pulled in in the applications build and IS at that location. But am wondering if I should file a JIRA for this.



On Monday, June 15, 2015 at 12:49:22 PM UTC-7, Owen Rubel wrote:
Two issues:

1) its a JSON file
2) Annotations create a binding and I need everything to be abstracted for theory and practice

Thanks for advice though. I'll give holders a shot. 

On Monday, June 15, 2015 at 12:18:38 PM UTC-7, zyro wrote:
using springs resource abstraction will save you a lot of hassle, i think.

given a plugin resource src/main/resources/foo/bar.txt, it could be used
in one of these ways (among others ofc):

<a href="https://gist.github.com/zyro23/f662d4eef32dcead859e" rel="nofollow" target="_blank" onmousedown="this.href='https://www.google.com/url?q\75https%3A%2F%2Fgist.github.com%2Fzyro23%2Ff662d4eef32dcead859e\46sa\75D\46sntz\0751\46usg\75AFQjCNFSEVE6iS6wAxkw0pB3u31wTQkNVg';return true;" onclick="this.href='https://www.google.com/url?q\75https%3A%2F%2Fgist.github.com%2Fzyro23%2Ff662d4eef32dcead859e\46sa\75D\46sntz\0751\46usg\75AFQjCNFSEVE6iS6wAxkw0pB3u31wTQkNVg';return true;">https://gist.github.com/zyro23/f662d4eef32dcead859e

a few things worth mentioning there:

- @Component/@PostConstruct just used for the example. as long as you
are in a bean that is subject to autowiring, you are set

- when using @Value injection into a Resource, the placeholder key has
to be a config entry (i.e. a resolvable property source entry), in my
example (application.yml):
foobar: classpath:foo/bar.txt
supplying a string directly will not use the required converter.

- when accessing resources inside jar files always use
Resource.getInputStream(). getFile() will not work reliably (if at all)
(because the resource is _inside_ a jar file..)

- if its really not possible for you to extract the resource loading
into a bean, you should be able to statically use
Holders.grailsApplication.mainContext.getResource(...).

hth, zyro

-------- Original Message  --------
Subject: Getting resources from Grails 3 plugin
From: Owen Rubel <[hidden email]>
To: [hidden email]
Date: Mon, 15 Jun 2015 11:39:45 -0700 (pdt)

> Am trying to test a plugin locally and can see the resources for the
> plugin are generating fine in the build under
> 'build/resources/main/public' ... but when I include the plugin in a
> project and try to access the files, it says they're not there.
> Obviously it is looking locally but the plugin is trying to access it's
> resources in the project.
>
> How do we write in the plugin so it can access it's resources when it is
> loaded in a project? I have it written as the following:
>
> *if*(grailsApplication.isWarDeployed()){
>
>      ioPath=Holders.servletContext.getRealPath('/')
>
> *
> if*(Environment.current==Environment.DEVELOPMENT||Environment.current==Environment.TEST){
>
>          ioPath+='WEB-INF/classes/iostate'
>
>      }*else*{
>
>          // test in Environment.PRODUCTION
>
>          ioPath+='WEB-INF/classes/iostate'
>
>      }
>
> }*else*{
>
>      ioPath=(String)grails.util.BuildSettings.RESOURCES_DIR?.path
>
> *
> if*(Environment.current==Environment.DEVELOPMENT||Environment.current==Environment.TEST){
>
>          ioPath+='/public/iostate'
>
>      }*else*{
>
>          // test in Environment.PRODUCTION
>
>          ioPath+='/public/iostate'
>
>      }
>
> }
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Grails Dev Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to grails-dev-discuss+[hidden email]
> <mailto:grails-dev-discuss+[hidden email]>.
> To post to this group, send email to [hidden email]
> <mailto:grails-de...@googlegroups.com>.
> To view this discussion on the web visit
> <a href="https://groups.google.com/d/msgid/grails-dev-discuss/a5606b7a-52b5-4670-a8c8-4e1b5f1019ad%40googlegroups.com" rel="nofollow" target="_blank" onmousedown="this.href='https://groups.google.com/d/msgid/grails-dev-discuss/a5606b7a-52b5-4670-a8c8-4e1b5f1019ad%40googlegroups.com';return true;" onclick="this.href='https://groups.google.com/d/msgid/grails-dev-discuss/a5606b7a-52b5-4670-a8c8-4e1b5f1019ad%40googlegroups.com';return true;">https://groups.google.com/d/msgid/grails-dev-discuss/a5606b7a-52b5-4670-a8c8-4e1b5f1019ad%40googlegroups.com
> <<a href="https://groups.google.com/d/msgid/grails-dev-discuss/a5606b7a-52b5-4670-a8c8-4e1b5f1019ad%40googlegroups.com?utm_medium=email&amp;utm_source=footer" rel="nofollow" target="_blank" onmousedown="this.href='https://groups.google.com/d/msgid/grails-dev-discuss/a5606b7a-52b5-4670-a8c8-4e1b5f1019ad%40googlegroups.com?utm_medium\75email\46utm_source\75footer';return true;" onclick="this.href='https://groups.google.com/d/msgid/grails-dev-discuss/a5606b7a-52b5-4670-a8c8-4e1b5f1019ad%40googlegroups.com?utm_medium\75email\46utm_source\75footer';return true;">https://groups.google.com/d/msgid/grails-dev-discuss/a5606b7a-52b5-4670-a8c8-4e1b5f1019ad%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit <a href="https://groups.google.com/d/optout" rel="nofollow" target="_blank" onmousedown="this.href='https://groups.google.com/d/optout';return true;" onclick="this.href='https://groups.google.com/d/optout';return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/45db5aa4-d54a-4a5d-abc6-30448595b99f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Getting resources from Grails 3 plugin

Tyler Rafferty
@Owen were you able to find a package that replaced 
org.codehaus.groovy.grails.plugins.GrailsPluginUtils


On Tuesday, June 16, 2015 at 11:20:20 AM UTC-7, Owen Rubel wrote:
GrailsPluginUtils is also under codehaus and is deprecated (and I can't find a replacement class for it).

Everywhere I look where I would be able to reference classes in the plugin build has been removed, deprecated, etc and the application doesn't bring over those files.

How is the plugin supposed to reference its own BUILD files in the application when the application doesn't contain them?
 

 

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/4bd8c943-742d-4d68-9df3-286b3853138a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...