-
Notifications
You must be signed in to change notification settings - Fork 91
How to get the main golo file's location? #496
Comments
Do you have a use case? |
The use case here would be if one wants to distribute a free-form golo project that includes some resources like text files or images that need to be loaded at runtime. An example of a layout would be this :
There is no simple way to retrieve the full path of |
The only workaround I can think of is using a script to launch the golo file that retrieves the path and passes it as an argument to the golo program, though this is far from straightforward and requires reliance on third-party tools as well as an additional argument to the program, which requires modifications to the main method/function. |
One way to fix this would be to use, in the GoloClassLoader, the version of defineClass that supports the a custom ProtectionDomain that can thus encapsulate a correct CodeSource object that includes location information to the source of the golo file. Doing this would require creating a new method in GoloClassLoader that supports a URL instead of an InputStream or that has a URL as an additional argument. |
I have implemented the mentioned fix in this commit : https://github.com/utybo/golo-lang/commit/49a9d89335a3b13007e3649d457b8146e4e91984 Should I open a pull request for this? @yloiseau |
I also added support for golosh in https://github.com/utybo/golo-lang/commit/cc7f15b7a73a651748b80937ced577e53c8d24e8 So now both |
For your resources use case, the classical approach is to create a jar and use the usual java methods to get the resources. |
Well I guess I didn't express myself clearly for the third party stuff, which meant "something outside of Golo" in that case. I still do not think having to use a script is handy for this, but yes gradle could do that. I still think having the option to grab the location from inside the code is much easier and doesn't require setting up an entire gradle build or jar just for this reason. However, feel free to reject the PR and this suggestion if you do not feel like it is a worthy addition. EDIT : Woops, looks as if I failed some of the requirements for contributing to an Eclipse project on the PR, I'll fix that ASAP if you are ok with the PR. |
I still don't see the point of your use case. Except for single-file scripts, you should distribute a jar bundling your resources, and thus use However, since compiled class can give access to this information, why not... |
Well, seeing that compiled classes and JARs give access to this data, I think it should be added to Golo for the sake of completeness. (and yeah, my use case kind of sucks, I'll give you that, but I think giving the information inside Golo is as flexible as it gets... Oh well) |
How can I get where the golo file containing the "main" function is? In Java, you can find where the JAR file is using one of the solutions posted here : https://stackoverflow.com/questions/15359702/get-location-of-jar-file but none of them work in Golo using
golo golo ...
The text was updated successfully, but these errors were encountered: