Conditional loading for OB examples

6 views
Skip to first unread message

Dale

unread,
Jan 11, 2010, 7:39:36 PM1/11/10
to Metacello
The first thing that you do is add some project attributes that
indicate whether or not OB is already loaded:

projectAttributes := #().
projectAttributes := projectAttributes, ((Smalltalk at: #OBNode
ifAbsent: []) isNil
ifTrue: [ #( #'OBNotPresent' ) ]
ifFalse: [ #( #'OBPresent' ) ]).
project projectAttributes: projectAttributes.

Next you define your baseline (or version) using the attributes:

spec for: #common do: [
spec project: 'OB' with: ["project reference"].

spec package: 'Package-That-Needs-OB'.
spec group: 'default' with: #('Package-That-Needs-OB');

spec for: #OBNotPresent do: [
spec package: 'Package-That-Needs-OB' with: [
spec requires: #('OB') ]].
].

When the above is loaded, if OB is present, 'Package-That-Needs-OB' is
loaded and OB is not affected. If OB is not already loaded, then OB is
loaded (according to the version and other things defined along with
the OB project) before 'Package-That-Needs-OB' is loaded.

If you look closely you'll see that I'm using a nested #for:do:. I
didn't actually intend for that to work, but after running a number of
tests, it seems to do the logical thing. In this case #OBNotPresent is
nested inside #common and if for some reason #common wasn't included
in the attributes then the #OBNotPresent block will never be executed
- so by nesting you are getting an effective AND operation which makes
sense in this context.

You use #OBPresent for doing things like the following where I want to
load 'Package-That-Needs-OB' automatically if OB is present and when
OB is not present only load it when explicitly requested:

spec for: #common do: [
spec project: 'OB' with: ["project reference"].

spec package: 'Example-Package'.
spec group: 'default' with: #('Example-Package');

spec for: #OBNotPresent do: [
spec package: 'Package-That-Needs-OB' with: [
spec requires: #('OB') ]].
spec for: #OBPresent do: [
spec group: 'default' with: #('Package-That-Needs-OB') ].
].

I will try to put this up as a FAQ or include it in the tutorial.

ConfigurationOfGemTools and ConfigurationOfSeaside30 will include
working examples, but I am not quite ready to publish them in
MetacelloRepository.

Dale

Danie Roux

unread,
Jan 12, 2010, 2:31:35 AM1/12/10
to meta...@googlegroups.com
On Tue, Jan 12, 2010 at 2:39 AM, Dale <dale.h...@gemstone.com> wrote:
> The first thing that you do is add some project attributes that
> indicate whether or not OB is already loaded:

Excellent example, thanks :-)

--
Danie Roux *shuffle* Adore Unix - http://danieroux.com

Mariano Martinez Peck

unread,
Jan 12, 2010, 6:00:04 PM1/12/10
to meta...@googlegroups.com
This is cool Dale. I was trying to see it in the code, but I failed

You didn't commit that yet?  If you did, where is it ?

Thanks!

Mariano

Dale Henrichs

unread,
Jan 12, 2010, 6:23:25 PM1/12/10
to meta...@googlegroups.com
I've used this technique in both ConfigurationOfSeaside30 and ConfigurationOfGemTools both in the MetacelloRepository...

Dale

Mariano Martinez Peck

unread,
Feb 14, 2010, 10:19:01 AM2/14/10
to meta...@googlegroups.com

I will try to put this up as a FAQ or include it in the tutorial.

ConfigurationOfGemTools and ConfigurationOfSeaside30 will include
working examples, but I am not quite ready to publish them in
MetacelloRepository.


Dale: let me know when you write this in the tutorial so that I can add something similar to the PBE chapter :)

Thanks

Mariano 

Dale Henrichs

unread,
Feb 15, 2010, 12:18:25 PM2/15/10
to meta...@googlegroups.com
Mariano,

Sorry, they've been published ... GemTools is an example of conditionally loading OB if it is not present. Seaside30 has an example of loading extra packages if OB _is_ present.

Dale
----- "Mariano Martinez Peck" <maria...@gmail.com> wrote:

Mariano Martinez Peck

unread,
Aug 17, 2010, 1:38:26 PM8/17/10
to meta...@googlegroups.com
Dale...is this thing of "Conditional loading" documented somewhere? I did a quick search in website and tutorial but without success.

Thanks in advance,

Mariano

Dale Henrichs

unread,
Aug 23, 2010, 12:45:17 PM8/23/10
to meta...@googlegroups.com
Mariano,

No I guess I haven't put anything up on the website ... presumably we
coudl put up a FAQ:

Here's a recent sample of doing conditional loading (in this case based
upon a specific GemStone version):

project

^ project ifNil: [ | projectAttributes gsVersion |
"Bootstrap Metacello if it is not already loaded"
self class ensureMetacello.
"Construct Metacello project"
project := (Smalltalk at: #MetacelloMCProject) new.
projectAttributes := #().
((gsVersion := System stoneVersionAt: 'gsVersion')
beginsWith: '2.4')
ifTrue: [
"needed to isolate the fix for Issue 129. The fix is needed for
versions 2.4.4.1 and earlier"
((MetacelloVersionNumber fromString: gsVersion) <
(MetacelloVersionNumber fromString: '2.4.4.2'))
ifTrue: [ projectAttributes := #(#'gs2.4.4.1') ]].
project projectAttributes: projectAttributes.
(Smalltalk at: #MetacelloVersionConstructor)
on: self
project: project.
project]

Versions and baselines can then use the #'gs2.4.4.1' attribute for
conditionally loading code...

Dale

Mariano Martinez Peck wrote:
> Dale...is this thing of "Conditional loading" documented somewhere? I
> did a quick search in website and tutorial but without success.
>
> Thanks in advance,
>
> Mariano
>
> On Mon, Feb 15, 2010 at 7:18 PM, Dale Henrichs
> <dale.h...@gemstone.com <mailto:dale.h...@gemstone.com>> wrote:
>
> Mariano,
>
> Sorry, they've been published ... GemTools is an example of
> conditionally loading OB if it is not present. Seaside30 has an
> example of loading extra packages if OB _is_ present.
>
> Dale
> ----- "Mariano Martinez Peck" <maria...@gmail.com

Sean P. DeNigris

unread,
Dec 8, 2011, 6:49:16 PM12/8/11
to meta...@googlegroups.com

Dale Henrichs wrote

>
> Versions and baselines can then use the #'gs2.4.4.1' attribute for
> conditionally loading code...
>

I tried to adapt the above to the latest #project template, but my custom
attribute doesn't seem to get called.

My #project looks like:
^ project ifNil: [ | constructor |


"Bootstrap Metacello if it is not already loaded"

(self class baseConfigurationClassIfAbsent: []) ensureMetacello.
"Construct Metacello project"
constructor := (Smalltalk at: #MetacelloVersionConstructor) on: self.
project := constructor project.
isOmniBrowserLoaded := self class environment includesKey: #OBCodeBrowser.
isOmniBrowserLoaded ifTrue: [ project projectAttributes: #(#'OB') ].
project loadType: #linear. "change to #atomic if desired"
project ]

The projectAttributes are set to #(#OB).

And in my baseline, I have:
spec for: #'OB' do: [ self halt.spec group: 'default' with:
#('DeNigrisSetup-OB' ) ].

But "ConfigurationOfDeNigrisSetup project bleedingEdge record" shows:
(linear load :
linear load : 1.0-baseline [ConfigurationOfDeNigrisSetup]
load : DeNigrisSetup-Core
load : DeNigrisSetup-Pharo13)

Thanks.

--
View this message in context: http://forum.world.st/Re-Conditional-loading-for-OB-examples-tp1555203p4174833.html
Sent from the Metacello mailing list archive at Nabble.com.

Dale Henrichs

unread,
Dec 9, 2011, 1:30:30 PM12/9/11
to meta...@googlegroups.com
Sean,

Try this version of #project:

project
^ project ifNil: [ | constructor isOmniBrowserLoaded |
self class ensureMetacello.
project := MetacelloMCProject new.


isOmniBrowserLoaded := self class environment includesKey: #OBCodeBrowser.
isOmniBrowserLoaded ifTrue: [ project projectAttributes: #(#'OB') ].

MetacelloVersionConstructor on: self project: project.
project ]

The technicality (with the current API) is that when you define your own project attributes, you must _defer_ the creation of the project until you have defined the project attributes.

Dale

Mariano Martinez Peck

unread,
Dec 14, 2011, 3:52:51 PM12/14/11
to meta...@googlegroups.com
Sean, do you think the chapter deserves an update with this issue?
--
Mariano
http://marianopeck.wordpress.com

Sean DeNigris

unread,
Dec 22, 2011, 6:00:21 PM12/22/11
to Metacello
On Dec 14, 3:52 pm, Mariano Martinez Peck <marianop...@gmail.com>
wrote:
> Sean, do you think the chapter deserves an update with this issue?

It definitely would've helped me, but you guys would know better about
the common use cases. I seem to always end up in the dark corners,
lol.

Dale, would it be worth it to have the template create:
ConfigurationOfMyProject>>project

project ifNil: [ | constructor |
"Bootstrap Metacello if it is not already loaded"
(self class baseConfigurationClassIfAbsent: []) ensureMetacello.
"Construct Metacello project"
project := MetacelloMCProject new projectAttributes: self
customProjectAttributes ].
constructor := (Smalltalk at: #MetacelloVersionConstructor) on: self
project: project.
project loadType: #linear. "change to #atomic if desired"
project ]

ConfigurationOfMyProject>>customProjectAttributes
"Edit to return any custom attributes e.g. for conditional loading"

^ #().

Sean DeNigris

unread,
Dec 22, 2011, 6:09:08 PM12/22/11
to Metacello
> ConfigurationOfMyProject>>customProjectAttributes
>         "Edit to return any custom attributes e.g. for conditional loading"
>
>         ^ #().

And maybe make the comment something like:
"Edit to return a collection of any custom attributes e.g. for
conditional loading: Array with: #'Condition1' with: #'Condition2"

Dale Henrichs

unread,
Dec 23, 2011, 12:44:05 PM12/23/11
to meta...@googlegroups.com
Sean,

Excellent suggestion!

Dale

----- Original Message -----
| From: "Sean DeNigris" <sean.p....@gmail.com>
| To: "Metacello" <meta...@googlegroups.com>
| Sent: Thursday, December 22, 2011 3:00:21 PM
| Subject: [Metacello] Re: Conditional loading for OB examples
|

Reply all
Reply to author
Forward
0 new messages