Login  Register

[Tip] Image init scripts when working with PharoLauncher

Posted by Torsten Bergmann on Jul 25, 2014; 11:54am
URL: https://forum.world.st/Tip-Image-init-scripts-when-working-with-PharoLauncher-tp4770062.html

PharoLauncher [1] allows you to work with many Pharo images.

You can download fresh images, clone existing ones and with its access
to the Pharo CI it allows you to easily reproduce errors in specific Pharo
image versions. I REALLY like this tool when working with Pharo.

There is a customizable hardware key on my laptop that I can just press
to open PharoLauncher, manage and launch the images and dive into the
world of Pharo.


To optimize my Pharo "easy access workflows" further I wanted all the
images that I started with PharoLauncher:
 - to share a common metacello repository cache (where all the mcz
   are stored independent from image location) for faster loading
 - to have the possibility to preset the Squeaksource, SS3 and STHub password already
 - to set my authors name

All this is already explained in Marianos blog posts [2] and [3] and
the PharoEnterprise book [4].

Nonetheless I would like to share the script that I personally use.
Maybe (in an adopted version) it is usefull for other PharoLauncher
users as well:
 
=====================================================================
COMMON SETTINGS FOR ALL PHARO IMAGES WHEN STARTED USING PHAROLAUNCHER
=====================================================================
Open any Pharo 3.0/4.0 image and execute

   StartupPreferencesLoader preferencesGeneralFolder fullName

in a workspace to find out the common preferences folder on your
local machine.

You can put a Smalltalk script into this folder, for instance
"initAllImages.st" that is evaluated each time an image runs.


I've found the following script very useful:

-----------------------------------------------------------------
| sharedPackageCacheDirectory |
"Never apply to PharoLauncher itself"
(SmalltalkImage current imageName includesSubstring: 'Launcher') ifTrue: [ ^self ].

"ask if script should be applied"
(UIManager default confirm: 'Apply init script from ', StartupPreferencesLoader preferencesGeneralFolder fullName,' to image') ifFalse: [^self ].

"Use a shared package cache to store Monticello MCS files for all images"
sharedPackageCacheDirectory := 'C:\Pharo\commonpackage-cache' asFileReference
        ensureCreateDirectory;
        yourself.
MCCacheRepository default directory: sharedPackageCacheDirectory.

"Set password for Squeaksource"
(MCRepositoryGroup default  repositories
        select: [:each | (each isKindOf: MCHttpRepository)
                                                and: [((each locationWithTrailingSlash includesSubstring: 'www.squeaksource.com')
                                                or: [each locationWithTrailingSlash includesSubstring: 'http://ss3.gemstone.com/ss/'])]
                        ])
        do: [:each | each user: 'squeaksourceuser'; password: 'secretsqueaksourcepassword'].

"Set password for SmalltalkHub (hub and HTTP repos)"
(MCRepositoryGroup default  repositories
        select: [:each |
                (each isKindOf: MCSmalltalkhubRepository) and: [each locationWithTrailingSlash includesSubstring: 'smalltalkhub.com']
                ])
        do: [:each | each user: 'PharoUser'; password: 'sthubpassword'].

(MCRepositoryGroup default  repositories
        select: [:each |
                (each isKindOf: MCHttpRepository) and: [each locationWithTrailingSlash includesSubstring: 'smalltalkhub.com']
                ])
        do: [:each | each user: 'PharoUser'; password: 'sthubpassword'].
       
"Set author name"
Author fullName: 'PharoUser'.

UIManager default inform: 'Script applied'.

-----------------------------------------------------------------

Hope it is usefull for others too.

Bye
T.

[1] http://www.smalltalkhub.com/#!/~Pharo/PharoLauncher
[2] http://marianopeck.wordpress.com/2012/05/19/pharo-tips-and-tricks/
[3] http://marianopeck.wordpress.com/2012/05/12/startuploader-running-startup-scripts-in-pharo/
[4] https://ci.inria.fr/pharo-contribution/job/PharoForTheEnterprise/ws/StartupPreferences/