Skip to content

Commit

Permalink
Merge pull request #65 from ba-st/gs64-options
Browse files Browse the repository at this point in the history
Refactorings and more class instances as transient objects
  • Loading branch information
gcotelli authored Apr 15, 2024
2 parents 1342ff1 + 0d978df commit 40dae7c
Show file tree
Hide file tree
Showing 16 changed files with 182 additions and 154 deletions.
12 changes: 10 additions & 2 deletions source/BaselineOfLaunchpad/BaselineOfLaunchpad.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ Class {
BaselineOfLaunchpad >> addLaunchpadLogRecordAsGlobalAndConfigureTransientClasses [

Smalltalk at: #LaunchpadLogRecord put: LogRecord.
LaunchpadApplication makeInstancesDbTransient.
CurrentlyRunningLaunchpadApplication makeInstancesDbTransient
self configureAsTransientInstancesOfAll: {
ApplicationConfiguration.
CurrentlyRunningLaunchpadApplication.
LaunchpadApplication }
]

{ #category : 'baselines' }
Expand Down Expand Up @@ -47,6 +49,12 @@ BaselineOfLaunchpad >> closeWelcomeWindow [
Smalltalk garbageCollect
]

{ #category : 'post-load actions' }
BaselineOfLaunchpad >> configureAsTransientInstancesOfAll: aClassCollection [

aClassCollection do: #makeInstancesDbTransient
]

{ #category : 'accessing' }
BaselineOfLaunchpad >> projectClass [

Expand Down
65 changes: 36 additions & 29 deletions source/Launchpad-Configuration/ApplicationConfiguration.class.st
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
Class {
#name : #ApplicationConfiguration,
#superclass : #Object,
#name : 'ApplicationConfiguration',
#superclass : 'Object',
#instVars : [
'parameters',
'provider',
'values'
],
#category : #'Launchpad-Configuration'
#category : 'Launchpad-Configuration',
#package : 'Launchpad-Configuration',
#'gs_options' : [
'dbTransient'
]
}

{ #category : #'instance creation' }
{ #category : 'instance creation' }
ApplicationConfiguration class >> forAll: parameters providedBy: aConfigurationProvider [

^ self new initializeForAll: parameters providedBy: aConfigurationProvider
]

{ #category : #converting }
{ #category : 'converting' }
ApplicationConfiguration >> asCommandLineOn: stream [

( parameters sorted: #commandLineArgumentName ascending ) do: [ :parameter |
Expand All @@ -28,7 +32,7 @@ ApplicationConfiguration >> asCommandLineOn: stream [
]
]

{ #category : #converting }
{ #category : 'converting' }
ApplicationConfiguration >> asEnvironmentOn: stream [

( parameters sorted: #environmentVariableName ascending ) do: [ :parameter |
Expand All @@ -44,7 +48,7 @@ ApplicationConfiguration >> asEnvironmentOn: stream [
]
]

{ #category : #private }
{ #category : 'private' }
ApplicationConfiguration >> asIniFile: aParameterCollection on: stream [

( aParameterCollection sorted: #attributeName ascending ) do: [ :parameter |
Expand All @@ -62,7 +66,7 @@ ApplicationConfiguration >> asIniFile: aParameterCollection on: stream [
]
]

{ #category : #converting }
{ #category : 'converting' }
ApplicationConfiguration >> asIniFileOn: stream [

| settingsInSection |
Expand All @@ -82,13 +86,13 @@ ApplicationConfiguration >> asIniFileOn: stream [
]
]

{ #category : #converting }
{ #category : 'converting' }
ApplicationConfiguration >> asJson [

^ String streamContents: [ :stream | self asJsonOn: stream ]
]

{ #category : #converting }
{ #category : 'converting' }
ApplicationConfiguration >> asJsonOn: stream [

^ ( NeoJSONWriterSortingKeys on: stream )
Expand All @@ -97,7 +101,7 @@ ApplicationConfiguration >> asJsonOn: stream [
nextPut: values
]

{ #category : #private }
{ #category : 'private' }
ApplicationConfiguration >> assert: section isNotInConflictWithParameterNamed: name [

"Sections in the configuration are instances of NeoJSONObject, if we get
Expand All @@ -108,7 +112,7 @@ ApplicationConfiguration >> assert: section isNotInConflictWithParameterNamed: n
raising: ConflictingObjectFound
]

{ #category : #private }
{ #category : 'private' }
ApplicationConfiguration >> containingSectionFor: parameter startingAt: resolvedValues [

| currentSection |
Expand All @@ -122,21 +126,21 @@ ApplicationConfiguration >> containingSectionFor: parameter startingAt: resolved
^ currentSection
]

{ #category : #'reflective operations' }
{ #category : 'reflective operations' }
ApplicationConfiguration >> doesNotUnderstand: message [

^ values at: message selector ifAbsent: [ super doesNotUnderstand: message ]
]

{ #category : #initialization }
{ #category : 'initialization' }
ApplicationConfiguration >> initializeForAll: aParameterCollection providedBy: aConfigurationProvider [

parameters := aParameterCollection.
provider := aConfigurationProvider.
self resolveParameterValues
]

{ #category : #private }
{ #category : 'private' }
ApplicationConfiguration >> missingConfigurationFor: parameter [

LogRecord emitError:
Expand All @@ -145,54 +149,57 @@ ApplicationConfiguration >> missingConfigurationFor: parameter [
( '"<1s>" parameter not present.' expandMacrosWith: parameter name )
]

{ #category : #accessing }
{ #category : 'accessing' }
ApplicationConfiguration >> parameters [

^ parameters
]

{ #category : #actions }
{ #category : 'actions' }
ApplicationConfiguration >> reload [

provider reloadConfiguration.
self resolveParameterValues
]

{ #category : #initialization }
{ #category : 'initialization' }
ApplicationConfiguration >> resolveParameterValues [

| section resolvedValues |

resolvedValues := NeoJSONObject new.
parameters do: [ :parameter |
section := self containingSectionFor: parameter startingAt: resolvedValues.
section at: parameter attributeName asSymbol
parameters do: [ :parameter |
section := self
containingSectionFor: parameter
startingAt: resolvedValues.
section
at: parameter attributeName asSymbol
ifPresent: [ self signalAsConflictingParameter: parameter ]
ifAbsentPut: [
parameter resolveValueUsing: provider ifUnable: [ self missingConfigurationFor: parameter ] ]
].
ifAbsentPut: [
parameter
resolveValueUsing: provider
ifUnable: [ self missingConfigurationFor: parameter ] ] ].
self synchronizeValuesWith: resolvedValues
]

{ #category : #'reflective operations' }
{ #category : 'reflective operations' }
ApplicationConfiguration >> respondsTo: selector [

^ ( super respondsTo: selector ) or: [ values includesKey: selector ]
]

{ #category : #private }
{ #category : 'private' }
ApplicationConfiguration >> signalAsConflictingParameter: parameter [

ConflictingObjectFound signal: ( 'Conflicting parameter: "<1s>"' expandMacrosWith: parameter name )
]

{ #category : #private }
{ #category : 'private' }
ApplicationConfiguration >> synchronizeValuesWith: resolvedValues [

values := resolvedValues
]

{ #category : #accessing }
{ #category : 'accessing' }
ApplicationConfiguration >> valueFor: aParameter [

| section |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
Class {
#name : #ConfigurationFromCommandLineProvider,
#superclass : #ConfigurationProvider,
#name : 'ConfigurationFromCommandLineProvider',
#superclass : 'ConfigurationProvider',
#instVars : [
'commandLine',
'nextProvider'
],
#category : #'Launchpad-Configuration'
#category : 'Launchpad-Configuration',
#package : 'Launchpad-Configuration'
}

{ #category : #'instance creation' }
{ #category : 'instance creation' }
ConfigurationFromCommandLineProvider class >> over: aCommandLine [

^ self over: aCommandLine chainedWith: NullConfigurationProvider new
]

{ #category : #'instance creation' }
{ #category : 'instance creation' }
ConfigurationFromCommandLineProvider class >> over: aCommandLine chainedWith: aConfigurationProvider [

^ self new initializeOver: aCommandLine chainedWith: aConfigurationProvider
]

{ #category : #initialization }
{ #category : 'initialization' }
ConfigurationFromCommandLineProvider >> initializeOver: aCommandLine chainedWith: aConfigurationProvider [

commandLine := aCommandLine.
nextProvider := aConfigurationProvider
]

{ #category : #initialization }
{ #category : 'initialization' }
ConfigurationFromCommandLineProvider >> reloadConfiguration [

nextProvider reloadConfiguration
]

{ #category : #resolving }
{ #category : 'resolving' }
ConfigurationFromCommandLineProvider >> valueFor: aConfigurationParameter ifFound: aPresentBlock ifNone: aFailBlock [

^ commandLine optionAt: aConfigurationParameter commandLineArgumentName
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
Class {
#name : #ConfigurationFromEnvironmentProvider,
#superclass : #ConfigurationProvider,
#name : 'ConfigurationFromEnvironmentProvider',
#superclass : 'ConfigurationProvider',
#instVars : [
'nextProvider'
],
#category : #'Launchpad-Configuration'
#category : 'Launchpad-Configuration',
#package : 'Launchpad-Configuration'
}

{ #category : #'instance creation' }
{ #category : 'instance creation' }
ConfigurationFromEnvironmentProvider class >> chainedWith: aConfigurationProvider [

^ super new initializeChainedWith: aConfigurationProvider
]

{ #category : #'instance creation' }
{ #category : 'instance creation' }
ConfigurationFromEnvironmentProvider class >> new [

^ self chainedWith: NullConfigurationProvider new
]

{ #category : #initialization }
{ #category : 'initialization' }
ConfigurationFromEnvironmentProvider >> initializeChainedWith: aConfigurationProvider [

nextProvider := aConfigurationProvider
]

{ #category : #initialization }
{ #category : 'initialization' }
ConfigurationFromEnvironmentProvider >> reloadConfiguration [

^ nextProvider reloadConfiguration
]

{ #category : #resolving }
{ #category : 'resolving' }
ConfigurationFromEnvironmentProvider >> valueFor: aConfigurationParameter ifFound: aPresentBlock ifNone: aFailBlock [

^ LanguagePlatform current os
Expand Down
Original file line number Diff line number Diff line change
@@ -1,48 +1,49 @@
Class {
#name : #ConfigurationFromIniSettingsFileProvider,
#superclass : #ConfigurationFromSettingsFileProvider,
#name : 'ConfigurationFromIniSettingsFileProvider',
#superclass : 'ConfigurationFromSettingsFileProvider',
#instVars : [
'fileReference',
'iniData',
'nextProvider'
],
#category : #'Launchpad-Configuration'
#category : 'Launchpad-Configuration',
#package : 'Launchpad-Configuration'
}

{ #category : #testing }
{ #category : 'testing' }
ConfigurationFromIniSettingsFileProvider class >> canHandle: aFileReference [

^ aFileReference extension = 'ini'
]

{ #category : #'instance creation' }
{ #category : 'instance creation' }
ConfigurationFromIniSettingsFileProvider class >> loading: anIniFileReference chainedWith: aConfigurationProvider [

^ self new initializeLoading: anIniFileReference chainedWith: aConfigurationProvider
]

{ #category : #initialization }
{ #category : 'initialization' }
ConfigurationFromIniSettingsFileProvider >> initializeLoading: aFileReference chainedWith: aConfigurationProvider [

fileReference := aFileReference.
self loadConfiguration.
nextProvider := aConfigurationProvider
]

{ #category : #initialization }
{ #category : 'initialization' }
ConfigurationFromIniSettingsFileProvider >> loadConfiguration [

fileReference readStreamDo: [ :stream | iniData := ( IniReader on: stream ) parse ]
]

{ #category : #initialization }
{ #category : 'initialization' }
ConfigurationFromIniSettingsFileProvider >> reloadConfiguration [

self loadConfiguration.
nextProvider reloadConfiguration
]

{ #category : #resolving }
{ #category : 'resolving' }
ConfigurationFromIniSettingsFileProvider >> valueFor: aConfigurationParameter ifFound: aPresentBlock ifNone: aFailBlock [

^ iniData
Expand Down
Loading

0 comments on commit 40dae7c

Please sign in to comment.