'From Cuis 5.0 [latest update: #3892] on 29 September 2019 at 11:10:54 pm'!

!FeatureRequirement methodsFor: 'testing' stamp: 'KenD 9/29/2019 22:50:36'!
checkRequirement
	"Answer if satisfied by package at pathName"
	
	pathName asFileEntry readStreamDo: [ :stream | | fSpec |
		fSpec := ((CodePackageFile buildFileStream: stream) featureSpec).
		((fSpec isNil) or: [(fSpec provides satisfies: self) not])
		ifTrue: [
			FeatureRequirementUnsatisfied 
					signal: pathName,
							String newLineString,
							' could not satisfy ', self printString.
			^false
		]
		ifFalse: [ ^true ]
	]
							 
! !


!CodePackageFile methodsFor: 'accessing' stamp: 'KenD 9/29/2019 21:28:27'!
featureSpec

	^ featureSpec! !


!FeatureRequirement methodsFor: 'requires' stamp: 'KenD 9/29/2019 22:55:34'!
require
	"See if all the transitive closure of requirements can be met and answer the load order if so"

	| packagesToLoad |
	
	"Preflight before load"
	[packagesToLoad _ self requireUnlessIn: OrderedCollection new main: nil]
		on: FeatureRequirementUnsatisfied  
		do: [ :error | error defaultAction. 
			^self "exit"
		].
	"Transcript show: 'packagesToLoad: '; newLine.
	packagesToLoad do: [ :x |Transcript show: x; newLine ].
	Transcript newLine ."
	
	[packagesToLoad do: [ :fReq | fReq checkRequirement ]]
		on: FeatureRequirementUnsatisfied  
		do: [ :error | error defaultAction. 
			^self "exit"
		].

	packagesToLoad reverseDo: [ :requirement |
		requirement isAlreadySatisfied ifFalse: [
			requirement install ]].
	self isAlreadySatisfied ifFalse: [
		self install ]! !

!FeatureRequirement methodsFor: 'private' stamp: 'KenD 9/29/2019 22:56:49'!
addToLoad: toLoad withMyRequirements: requirements

	"Add self to OrderedCollection toLoad before any requirements I have"
	toLoad do: [ :featureReq | 
		(featureReq satisfies: self)
		ifTrue: [
			"Transcript show: ('adding ', self name asString, ' before: ', featureReq name asString); newLine."
			toLoad add: self before: featureReq.
			^ toLoad
		]
	].
	"Transcript show: ('adding ', self name asString); newLine."
	toLoad addLast: self.
	^ toLoad
		! !

