MetacelloProjectRegistry.st
author jv
Mon, 03 Sep 2012 11:13:41 +0000
changeset 1 9e312de5f694
child 3 504152ada1fc
permissions -rw-r--r--
- Initial commit
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
9e312de5f694 - Initial commit
jv
parents:
diff changeset
     1
"{ Package: 'stx:goodies/metacello' }"
9e312de5f694 - Initial commit
jv
parents:
diff changeset
     2
9e312de5f694 - Initial commit
jv
parents:
diff changeset
     3
Object subclass:#MetacelloProjectRegistry
9e312de5f694 - Initial commit
jv
parents:
diff changeset
     4
	instanceVariableNames:'baselineRegistry configurationRegistry'
9e312de5f694 - Initial commit
jv
parents:
diff changeset
     5
	classVariableNames:''
9e312de5f694 - Initial commit
jv
parents:
diff changeset
     6
	poolDictionaries:''
9e312de5f694 - Initial commit
jv
parents:
diff changeset
     7
	category:'Metacello-Core-Scripts'
9e312de5f694 - Initial commit
jv
parents:
diff changeset
     8
!
9e312de5f694 - Initial commit
jv
parents:
diff changeset
     9
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    10
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    11
!MetacelloProjectRegistry methodsFor:'accessing'!
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    12
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    13
baselineProjectSpecs
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    14
    "MetacelloProjectRegistration baselineProjectSpecs"
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    15
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    16
    | projectSpecs |
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    17
    projectSpecs := OrderedCollection new.
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    18
    self baselineRegistry
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    19
        keysAndValuesDo: [ :className :registration | projectSpecs add: (self projectSpecForClassNamed: className ifAbsent: [ self error: 'not expected' ]) ].
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    20
    ^ projectSpecs asArray
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    21
!
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    22
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    23
baselineRegistry
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    24
    baselineRegistry ifNil: [ baselineRegistry := Dictionary new ].
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    25
    ^ baselineRegistry
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    26
!
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    27
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    28
configurationProjectSpecs
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    29
    "MetacelloProjectRegistration configurationProjectSpecs"
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    30
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    31
    | projectSpecs |
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    32
    projectSpecs := OrderedCollection new.
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    33
    self configurationRegistry
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    34
        keysAndValuesDo: [ :className :registration | projectSpecs add: (self projectSpecForClassNamed: className ifAbsent: [ self error: 'not expected' ]) ].
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    35
    ^ projectSpecs asArray
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    36
!
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    37
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    38
configurationRegistry
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    39
    configurationRegistry ifNil: [ configurationRegistry := Dictionary new ].
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    40
    ^ configurationRegistry
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    41
!
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    42
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    43
projectSpecs
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    44
    "MetacelloProjectRegistration projectSpecs"
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    45
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    46
    ^ self configurationProjectSpecs , self baselineProjectSpecs
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    47
! !
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    48
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    49
!MetacelloProjectRegistry methodsFor:'copying'!
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    50
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    51
postCopy
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    52
    super postCopy.
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    53
    baselineRegistry := self baselineRegistry copy.
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    54
    configurationRegistry := self configurationRegistry copy
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    55
! !
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    56
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    57
!MetacelloProjectRegistry methodsFor:'initialization'!
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    58
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    59
primeRegistryFromImage
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    60
    "MetacelloProjectRegistration primeRegistryFromImage"
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    61
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    62
    MetacelloProjectRegistration configurationClasses
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    63
        do: [ :cl | 
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    64
            (self configurationRegistry includesKey: cl name asString)
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    65
                ifFalse: [ 
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    66
                    "not registered"
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    67
                    cl project currentVersion
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    68
                        ifNotNil: [ :version | 
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    69
                            | projectSpec |
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    70
                            projectSpec := (version project projectSpec
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    71
                                name: (MetacelloScriptEngine baseNameOf: cl name asString);
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    72
                                className: cl name asString;
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    73
                                versionString: version versionString;
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    74
                                repositories: version project projectPackage repositories copy;
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    75
                                yourself) asConfigurationProjectSpec.
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    76
                            projectSpec asProjectRegistration
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    77
                                loadedInImage: true;
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    78
                                registerProject ] ] ].
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    79
    MetacelloProjectRegistration baselineClasses
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    80
        do: [ :cl | 
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    81
            (self baselineRegistry includesKey: cl name asString)
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    82
                ifFalse: [ 
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    83
                    "not registered"
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    84
                    cl project currentVersion
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    85
                        ifNotNil: [ :version | 
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    86
                            | projectSpec |
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    87
                            projectSpec := (version project projectSpec
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    88
                                name: (MetacelloScriptEngine baseNameOf: cl name asString);
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    89
                                repositories: version project projectPackage repositories copy;
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    90
                                yourself) asBaselineProjectSpec.
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    91
                            projectSpec asProjectRegistration
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    92
                                loadedInImage: true;
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    93
                                registerProject ] ] ]
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    94
! !
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    95
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    96
!MetacelloProjectRegistry methodsFor:'querying'!
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    97
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    98
projectSpecForClassNamed: aClassName ifAbsent: absentBlock
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    99
    ^ (self configurationRegistry
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   100
        at: aClassName
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   101
        ifAbsent: [ ^ (self baselineRegistry at: aClassName ifAbsent: [^absentBlock value]) baselineProjectSpec ])
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   102
        configurationProjectSpec
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   103
!
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   104
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   105
registrationForClassNamed: aClassName ifAbsent: absentBlock
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   106
    | baseName |
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   107
    baseName := MetacelloScriptEngine baseNameOf: aClassName.
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   108
    self configurationRegistry at: aClassName ifPresent: [ :registration | ^ registration ].
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   109
    self baselineRegistry at: aClassName ifPresent: [ :registration | ^ registration ].
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   110
    self configurationRegistry at: 'ConfigurationOf' , baseName ifPresent: [ :registration | ^ registration ].
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   111
    self baselineRegistry at: 'BaselineOf' , baseName ifPresent: [ :registration | ^ registration ].
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   112
    ^ absentBlock value
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   113
! !
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   114
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   115
!MetacelloProjectRegistry methodsFor:'registration'!
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   116
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   117
registerProjectRegistration: aMetacelloProjectRegistration
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   118
    "unconditionally register <newRegistration> ... use with care"
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   119
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   120
    aMetacelloProjectRegistration configurationProjectSpec
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   121
        ifNotNil: [ :spec | 
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   122
            self configurationRegistry
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   123
                at: spec className
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   124
                ifPresent: [ :existing | 
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   125
                    (existing configurationProjectSpec registrationsCompareEqual: spec)
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   126
                        ifFalse: [ 
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   127
                            Transcript
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   128
                                cr;
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   129
                                show:
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   130
                                        'REGISTRATION OF INCOMPATABLE PROJECTS: ' , existing printString , ' REPLACED BY '
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   131
                                                , aMetacelloProjectRegistration printString ] ].
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   132
            spec immutable.
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   133
            self configurationRegistry at: spec className put: aMetacelloProjectRegistration ].
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   134
    aMetacelloProjectRegistration baselineProjectSpec
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   135
        ifNotNil: [ :spec | 
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   136
            self baselineRegistry
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   137
                at: spec className
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   138
                ifPresent: [ :existing | 
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   139
                    (existing baselineProjectSpec registrationsCompareEqual: spec)
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   140
                        ifFalse: [ 
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   141
                            Transcript
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   142
                                cr;
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   143
                                show:
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   144
                                        'REGISTRATION OF INCOMPATABLE PROJECTS: ' , existing printString , ' REPLACED BY '
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   145
                                                , aMetacelloProjectRegistration printString ] ].
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   146
            spec immutable.
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   147
            self baselineRegistry at: spec className put: aMetacelloProjectRegistration ].
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   148
    aMetacelloProjectRegistration immutable
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   149
!
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   150
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   151
registrationFor: aMetacelloProjectRegistration ifPresent: presentBlock ifAbsent: absentBlock
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   152
    | baseName |
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   153
    baseName := aMetacelloProjectRegistration baseName.
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   154
    aMetacelloProjectRegistration configurationProjectSpec
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   155
        ifNotNil: [ :spec | self configurationRegistry at: spec className ifPresent: [ :existing | ^ presentBlock value: existing ] ].
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   156
    aMetacelloProjectRegistration baselineProjectSpec
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   157
        ifNotNil: [ :spec | self baselineRegistry at: spec className ifPresent: [ :existing | ^ presentBlock value: existing ] ].
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   158
    self configurationRegistry
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   159
        at: 'ConfigurationOf' , baseName
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   160
        ifPresent: [ :existing | ^ presentBlock value: existing ].
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   161
    self baselineRegistry at: 'BaselineOf' , baseName ifPresent: [ :existing | ^ presentBlock value: existing ].
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   162
    ^ absentBlock value
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   163
!
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   164
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   165
unregisterProjectRegistration: aMetacelloProjectRegistration
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   166
    aMetacelloProjectRegistration configurationProjectSpec
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   167
        ifNotNil: [ :spec | 
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   168
            self configurationRegistry
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   169
                removeKey: spec className
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   170
                ifAbsent: [ self error: 'unexpectedly missing project registration' ] ].
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   171
    aMetacelloProjectRegistration baselineProjectSpec
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   172
        ifNotNil: [ :spec | self baselineRegistry removeKey: spec className ifAbsent: [ self error: 'unexpectedly missing project registration' ] ]
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   173
! !
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   174
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   175
!MetacelloProjectRegistry class methodsFor:'documentation'!
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   176
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   177
version_SVN
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   178
    ^ '$Id::                                                                                                                        $'
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   179
! !