简体   繁体   English

Pharo - 如何在版本控制中共享静态资源?

[英]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? 假设我有Pharo Smalltalk中某些对象使用的图像,我该如何在VCS存储库中对其进行版本化? How those kind of static resources are dealt with in Pharo? 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. 我知道我可以从操作系统层次结构树加载一个图像并放入一个类实例变量,例如,图像持久性将保留它,但我试图通过Monticello对该类的包进行版本化,删除并加载回来并且图像位图丢失了。

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. 我找到了这个页面http://smallthoughts.tonyfleig.com/Blog/article/id/1144940 ,但由于我没有找到当前Pharo 5发行版和目录中描述的类,我不确定是否会是个好方法。

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). 这是最常用的方法,并且Pharo 5和之前也用于存储图标(并且仍然被系统的某些部分使用)。

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. 方法是将数据以某种编码格式(通常是base64或字节数组)存储为字符串,然后在第二种方法中,您可以解码该数据。 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. 理想情况下,您还可以将MyIconsMyIcons单例,因此可以正确缓存它。

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). 手动做这可能有点乏味,所以我前段时间写了一个工具https://github.com/peteruhnak/IconFactory (它仍然非常基本,但它主要完成它的工作)。

Add the assets in CI / load it on demand from web 在CI中添加资产/根据需要从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. 如果您为具有CI(Jenkins,Travis)的最终用户生成预构建的映像,则可以将资源作为构建脚本的一部分加载到那里。 This is, I believe, what Pharo 6 currently uses for icons. 我相信,这是Pharo 6目前用于图标的内容。 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). 然而,缺点是用户必须始终使用构建的映像,否则它将自动(从类初始化)从Web上的某处下载资产(如果您没有Internet访问权限,则可能会出现问题,或者网站落了)。

Use Git 使用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). 最后,如果您使用git来存储代码(GitFileTree或IceBerg),那么安装项目还需要存储库的副本(因此要么自动下载一个,要么将其指向您的本地克隆)。 Then you can reference the cloned repo to retrieve the data. 然后,您可以引用克隆的repo来检索数据。 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). 另请注意,有一些计划正在使用Pharo 6(当前的开发版本)正确管理资产,但我不确定它的状态,或者是否因此版本而被删除(这将最有可能推动Pharo 7的开发) )。

The version control system currently used by Pharo (called Monticello) cannot deal with those kinds of artefacts. Pharo(名为Monticello)目前使用的版本控制系统无法处理这些类型的文物。 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. 话虽这么说,您可以使用Git存储库作为后端(请参阅MontTello存储库的FileTree ,您可以根据需要随意添加资源到Git存储库(只要您不修改FileTree结构)。您可以然后在必要时简单地加载它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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