Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pharo - How do I share static resources in version control?

Suppose I have an image used by some objects in Pharo Smalltalk, how do I version that in the VCS repository? How those kind of static resources are dealt with in Pharo?

I know I can load an image from the Operational System hierarchy tree and put in a class instance variable, for example, and the image persistence will hold it, but I tried to version the package of this class through Monticello, remove and load it back and the image bitmap was lost.

I found this page http://smallthoughts.tonyfleig.com/Blog/article/id/1144940, but since I didn't find the class described in the current Pharo 5 distribution nor in the Catalog I wasn't sure if that would be a good approach.

like image 807
VitorCruz Avatar asked Feb 19 '26 16:02

VitorCruz


1 Answers

You have three primary options

Store the assets in methods as code

This is the most common approach, and is was also used by Pharo 5 and prior for storing icons (and is still used by some parts of the system).

The approach is to store the data in some encoded format (typically base64, or byte array) as a string, and then in second method you have a way to decode that. With this approach the assets are just a regular code so you will version it as such. For example:

MyIcons>>icons
    ^ icons ifNil: [ icons := Dictionary new ]

MyIcons>>myIconContents
    ^ 'BASE64STRING'

MyIcons>>myIcon
    ^ icons
            at: #myIcon
            ifAbsentPut: [ Form fromBinaryStream: (Base64MimeConverter mimeDecodeToBytes: self myIconContents readStream) ].

Ideally you also make the MyIcons class a singleton, so it can cache it properly.

This can be a bit tedious to do manually, so I've written a tool for this some time ago https://github.com/peteruhnak/IconFactory (it's still very basic, but it mostly does its job).

Add the assets in CI / load it on demand from web

If you a producing a pre-built images for end-users with CI (Jenkins, Travis), you can load the assets there as part of the build script. This is, I believe, what Pharo 6 currently uses for icons. However the downside is that the users would have to always use the built image, or it would automatically (from class' initialize) download the assets somewhere from the web (which can be problem if you don't have internet access, or the site is down).

Use Git

Finally, if you are using git to store the code (GitFileTree or IceBerg), then installing the project will also require a copy of the repository (so either it automatically downloads one, or you point it to your local clone). Then you can reference the cloned repo to retrieve the data. This will most likely be a bit finicky, but it should be in principle possible.


Note also that there were some plans to properly manage Assets with Pharo 6 (the current dev version), but I am not sure the state of it, or whether it was dropped for this release (which would push the development for Pharo 7 most likely).

like image 156
Peter Uhnak Avatar answered Feb 27 '26 03:02

Peter Uhnak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!