简体   繁体   中英

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.

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).

The version control system currently used by Pharo (called Monticello) cannot deal with those kinds of artefacts. Monticello knows about classes, methods, traits and a couple of other things but it stores neither variable data (eg your bitmap in the class variable) nor additional resources.

That being said, you can use a Git repository as the backend (see FileTree for the Monticello repository and you are free to add resources to the Git repository as you want (as long as you don't modify the FileTree structure). You can then simply load those when necessary.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM