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
Excellent example, thanks :-)
--
Danie Roux *shuffle* Adore Unix - http://danieroux.com
Dale
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.
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:
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
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.
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
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
|