Skip to content

Commit

Permalink
Fixes #73
Browse files Browse the repository at this point in the history
  • Loading branch information
eMaringolo committed Mar 14, 2022
1 parent f1fcf5a commit 4720d61
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 28 deletions.
39 changes: 39 additions & 0 deletions docs/configmaps.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,42 @@ All applications of the Configuration Map read from disk are expected to be in t

**NOTE**: On its binary format (within the ENVY Library or when exported as `.dat` file) the configuration maps refer to appplications and prerequisites using their internal timestamp, and Tonel will use that first to lookup their prerequisites or an existing map with the same timestamp in the repository.

### Loading required maps

When loading required maps for maps defined in a Tonel repository, there are going to be two kinds of required maps: those that are defined in the repository (e.g. from Test to the core), and those that are external configuration maps, that are expected to be available in the ENVY Library. We call the later, "references" (represented by the class `TonelEmConfigurationMapReference`).

As in the UI of the Configuration Maps Browser, sometimes you want to load the map together with its required maps, and
in some other cases you just want to load the map without the required maps, because you already have them (or its Applications) in the image.

To mimic that UI behavior, the `TonelLoader` has a boolean property called `loadsRequiredMaps` which, as you might guess
will instruct the loader to load the map and the required maps. This property is set to `true` by default.


```smalltalk
loader := TonelLoader readFromPath: (CfsPath named: '...').
loader
loadsRequiredMaps: true;
loadAllConfigurationMaps.
"Or its equivalent version"
loader := TonelLoader readFromPath: (CfsPath named: '...').
loader loadAllMapsWithRequiredMaps.
```

Or the option to NOT LOAD the required maps:
```smalltalk
loader := TonelLoader readFromPath: (CfsPath named: '...').
loader
loadsRequiredMaps: false;
loadAllConfigurationMaps.
"Or its equivalent version"
loader := TonelLoader readFromPath: (CfsPath named: '...').
loader loadAllMapsWithoutRequiredMaps.
```

This setting will be honored only for those configuration maps that are "references", it is, those that are not defined within the Tonel Repository.

E.g. If you have `Config Map A` and `Config Map B` in the repository, and `Config Map B` has `Config Map A` and `Config Map C` as prerequisites, if you setup the loader to not load maps prerequisites, when loading `Config Map B` it still will load `Config Map A`, because it is defined in the same repository.


14 changes: 7 additions & 7 deletions source/.configmaps
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@
},
{
#name : 'TonelLoaderInteractiveApp',
#versionName : '',
#versionName : '1.4.9',
#ts : 3824381840
},
{
#name : 'TonelLoaderModel',
#versionName : '',
#versionName : '1.4.9',
#ts : 3824364126
},
{
#name : 'TonelReaderModel',
#versionName : '',
#versionName : '1.4.9',
#ts : 3824469084
},
{
#name : 'TonelTools',
#versionName : '',
#versionName : '1.4.9',
#ts : 3824386303
},
{
Expand All @@ -42,11 +42,11 @@
}
],
#name : 'ENVY/Image Tonel',
#versionName : ''
#versionName : '1.4.9'
},
{
#conditions : [ ],
#ts : 3813497912,
#ts : 3812608505,
#comment : '',
#formatVersion : '1.1',
#applications : OrderedCollection [
Expand All @@ -72,6 +72,6 @@
}
],
#name : 'Test ENVY/Image Tonel',
#versionName : ''
#versionName : 'V 11.0.0 [496]'
}
]
39 changes: 29 additions & 10 deletions source/TonelLoaderModel/TonelConfigurationMap.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,14 @@ TonelConfigurationMap >> isExpressionValid: anExpression [

]

{ #category : 'testing' }
TonelConfigurationMap >> isReference [
"Answer whether receiver represents a reference to an actual EmConfigurationMap.
Receiver is a Tonel config map, not a reference, so always return false."

^false
]

{ #category : 'loading' }
TonelConfigurationMap >> load [
| emApps |
Expand Down Expand Up @@ -330,11 +338,16 @@ TonelConfigurationMap >> loader: anObject [

{ #category : 'loading',
#vaVisibility : 'private' }
TonelConfigurationMap >> loadRequiredMaps [
self requiredMaps do:
[:each |
(self loader loadedConfigurationMaps includes: each)
ifFalse: [each loadWithRequiredMaps]]
TonelConfigurationMap >> loadRequiredMaps: aBoolean [
"Load the required maps of receiver if aBoolean is true, if it was not
loaded yet.
If the required map is another TonelConfigurationMap, load it
regardless of whether aBoolean is true."

self requiredMaps do: [:each |
((self loader loadedConfigurationMaps includes: each) not
and: [each isReference not or: [aBoolean & each isReference]])
ifTrue: [each loadWithRequiredMaps]]
]

{ #category : 'loading' }
Expand All @@ -347,10 +360,11 @@ TonelConfigurationMap >> loadWithRequiredMaps [

{ #category : 'loading' }
TonelConfigurationMap >> loadWithRequiredMaps: aBoolean [

"Load the receiver. And all its required maps first if aBoolean is true.
Loading a required map may in turn load other required maps."

self loadRequiredMaps.
self loadRequiredMaps: aBoolean.
self load
]

Expand All @@ -366,14 +380,19 @@ TonelConfigurationMap >> name: anObject [

{ #category : 'printing' }
TonelConfigurationMap >> printOn: aStream [
"Prints a textual representation of receiver on aStream."

super printOn: aStream.
aStream
nextPutAll: '(''';
nextPutAll: self name;
space;
nextPutAll: self versionName asString;
nextPutAll: ''')'
nextPutAll: self name.

self versionName notEmpty
ifTrue: [
aStream
space;
nextPutAll: self versionName asString].
aStream nextPutAll: ''')'
]

{ #category : 'accessing' }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ RESPONSIBILITY:
- Load the proper EmConfigurationMap from the ENVY Library
"
Class {
#name : 'TonelEmConfigurationMap',
#name : 'TonelEmConfigurationMapReference',
#superclass : 'TonelConfigurationMap',
#category : 'TonelLoaderModel'
}

{ #category : 'Not categorized' }
TonelEmConfigurationMap class >> name: aString ts: seconds versionName: versionString [
TonelEmConfigurationMapReference class >> name: aString ts: seconds versionName: versionString [

^(self new)
name: aString;
Expand All @@ -23,8 +23,16 @@ TonelEmConfigurationMap class >> name: aString ts: seconds versionName: versionS
yourself
]

{ #category : 'testing' }
TonelEmConfigurationMapReference >> isReference [
"Answer whether receiver represents a reference to an actual EmConfigurationMap.
Receiver is a representation of a reference, so always return true."

^true
]

{ #category : 'loading' }
TonelEmConfigurationMap >> loadWithRequiredMaps: aBoolean [
TonelEmConfigurationMapReference >> loadWithRequiredMaps: aBoolean [
"Load the receiver. And all its required maps first if aBoolean is true.
Loading a required map may in turn load other required maps."

Expand Down
28 changes: 20 additions & 8 deletions source/TonelLoaderModel/TonelLoader.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Class {
'loadedConfigurationMaps',
'createsHookMethods',
'autogenerateInstanceInitializers',
'loadRequiredMaps'
'loadsRequiredMaps'
],
#classVars : [
'DefaultAppNameSuffix',
Expand Down Expand Up @@ -202,7 +202,7 @@ TonelLoader >> configurationMapNamed: aString ts: anEmTimeStamp versionName: ver
ts: anEmTimeStamp
versionName: versionName
ifNone: [
(TonelEmConfigurationMap name: aString ts: anEmTimeStamp seconds versionName: versionName)
(TonelEmConfigurationMapReference name: aString ts: anEmTimeStamp seconds versionName: versionName)
loader: self;
yourself]
]
Expand Down Expand Up @@ -342,6 +342,18 @@ TonelLoader >> loadAllConfigurationMaps [

]

{ #category : 'loading' }
TonelLoader >> loadAllMapsWithoutRequiredMaps [
"Loads all the configuration maps read from the receiver reader's repository
together without the required maps of each of them that are not
in the list of required maps.
It means that if a Tonel configuration map requires another
Tonel configuration map, it will be loaded."

self loadConfigurationMaps: self configurationMaps
]

{ #category : 'loading' }
TonelLoader >> loadAllMapsWithRequiredMaps [
"Loads all the configuration maps read from the receiver reader's repository
Expand Down Expand Up @@ -427,7 +439,7 @@ TonelLoader >> loadConfigurationMap: aTonelConfigurationMap withPrereqs: aBoolea
{ #category : 'loading' }
TonelLoader >> loadConfigurationMapNamed: aString [

self loadConfigurationMapNamed: aString withPrereqs: self loadRequiredMaps
self loadConfigurationMapNamed: aString withPrereqs: self loadsRequiredMaps
]

{ #category : 'loading' }
Expand All @@ -444,7 +456,7 @@ TonelLoader >> loadConfigurationMapNamed: aString withPrereqs: aBoolean [
TonelLoader >> loadConfigurationMaps: aCollection [
"Loads aCollection of TonelConfigurationMaps."

aCollection do: [:each | each loadWithRequiredMaps ]
aCollection do: [:each | each loadWithRequiredMaps: self loadsRequiredMaps ]
]

{ #category : 'accessing' }
Expand All @@ -466,17 +478,17 @@ TonelLoader >> loadedConfigurationMaps [
]

{ #category : 'accessing' }
TonelLoader >> loadRequiredMaps [
TonelLoader >> loadsRequiredMaps [
"Answer whether receiver will load the required maps of each Configuration Map when loading them."

^loadRequiredMaps ifNil: [loadRequiredMaps := true]
^loadsRequiredMaps ifNil: [loadsRequiredMaps := true]
]

{ #category : 'accessing' }
TonelLoader >> loadRequiredMaps: aBoolean [
TonelLoader >> loadsRequiredMaps: aBoolean [
"Sets whether receiver will load the required maps of each Configuration Map when loading them."

loadRequiredMaps := aBoolean
loadsRequiredMaps := aBoolean
]

{ #category : 'logging' }
Expand Down

0 comments on commit 4720d61

Please sign in to comment.