diff --git a/src/PharoLauncher-Core/PhLImageVersionFileNotFound.class.st b/src/PharoLauncher-Core/PhLImageVersionFileNotFound.class.st index 35bebd9d..b6db705e 100644 --- a/src/PharoLauncher-Core/PhLImageVersionFileNotFound.class.st +++ b/src/PharoLauncher-Core/PhLImageVersionFileNotFound.class.st @@ -16,6 +16,12 @@ PhLImageVersionFileNotFound >> longDescription [ Please, contact us at http://pharo.org/community' ] +{ #category : #accessing } +PhLImageVersionFileNotFound >> messageText [ + + ^ self longDescription +] + { #category : #accessing } PhLImageVersionFileNotFound >> name [ ^ 'Image version file ', PhLImage versionFileName , ' not found!' diff --git a/src/PharoLauncher-Core/PhLLaunchConfiguration.class.st b/src/PharoLauncher-Core/PhLLaunchConfiguration.class.st index c637d20c..5c168eff 100644 --- a/src/PharoLauncher-Core/PhLLaunchConfiguration.class.st +++ b/src/PharoLauncher-Core/PhLLaunchConfiguration.class.st @@ -92,7 +92,7 @@ PhLLaunchConfiguration >> commandString [ { #category : #querying } PhLLaunchConfiguration >> defaultVm [ - self image pharoVersion. + self image ensurePharoVersion. ^ self image vmManager virtualMachine ] @@ -128,8 +128,7 @@ PhLLaunchConfiguration >> initializeWithImage: anImage [ image := anImage. name := 'new configuration...'. usePharoSettings := true. - imageArguments := anImage defaultArguments. - image ensurePharoVersion + imageArguments := anImage defaultArguments ] { #category : #testing } @@ -169,7 +168,7 @@ PhLLaunchConfiguration >> printOn: aStream [ { #category : #configuring } PhLLaunchConfiguration >> useSettings: aBoolean [ "Cannot skip Pharo settings before Pharo 3.0" - self image pharoVersion asInteger < 30 ifTrue: [ ^ self ]. + self image ensurePharoVersion asInteger < 30 ifTrue: [ ^ self ]. usePharoSettings := aBoolean. ] diff --git a/src/PharoLauncher-Core/PhLLaunchImageCommand.class.st b/src/PharoLauncher-Core/PhLLaunchImageCommand.class.st index a6f3c941..06110857 100644 --- a/src/PharoLauncher-Core/PhLLaunchImageCommand.class.st +++ b/src/PharoLauncher-Core/PhLLaunchImageCommand.class.st @@ -128,7 +128,8 @@ PhLLaunchImageCommand >> launchConfigurationOfImage: aPhLImage [ { #category : #executing } PhLLaunchImageCommand >> launchImage: aPhLImage [ | process launchConfig | - + + self imagesPresenter ensurePharoVersion. [ launchConfig := self launchConfigurationOfImage: aPhLImage. launchConfig useSettings: useSettings. process := aPhLImage launchWithConfiguration: launchConfig ] diff --git a/src/PharoLauncher-Spec2/PhLImagesPresenter.class.st b/src/PharoLauncher-Spec2/PhLImagesPresenter.class.st index 3e0d8582..59a4e642 100644 --- a/src/PharoLauncher-Spec2/PhLImagesPresenter.class.st +++ b/src/PharoLauncher-Spec2/PhLImagesPresenter.class.st @@ -233,6 +233,20 @@ PhLImagesPresenter >> ensure: aBoolean [ ifFalse: [ PhLCommandError signal ] ] +{ #category : #computing } +PhLImagesPresenter >> ensurePharoVersion [ + | image | + image := self singleImage. + [ image ensurePharoVersion ] + on: PhLImageVersionFileNotFound + do: [ :error | | presenter | + presenter := PhLPharoVersionChooserPresenter new. + presenter openModal. + presenter version ifNil: [ error pass ]. + image versionFile + writeStreamDo: [ :stream | stream nextPutAll: presenter version ] ] +] + { #category : #private } PhLImagesPresenter >> filter: regexMatcher [ diff --git a/src/PharoLauncher-Spec2/PhLPharoVersionChooserPresenter.class.st b/src/PharoLauncher-Spec2/PhLPharoVersionChooserPresenter.class.st new file mode 100644 index 00000000..b3a13503 --- /dev/null +++ b/src/PharoLauncher-Spec2/PhLPharoVersionChooserPresenter.class.st @@ -0,0 +1,63 @@ +" +I'm a simple presenter to fix the version of a Pharo image when no version file exists. +" +Class { + #name : #PhLPharoVersionChooserPresenter, + #superclass : #SpPresenterWithModel, + #traits : 'TPhLInteractionTrait', + #classTraits : 'TPhLInteractionTrait classTrait', + #instVars : [ + 'versionTable' + ], + #category : #'PharoLauncher-Spec2' +} + +{ #category : #examples } +PhLPharoVersionChooserPresenter class >> example [ + + ^ self new + openDialog; + yourself +] + +{ #category : #layout } +PhLPharoVersionChooserPresenter >> defaultLayout [ + ^ SpBoxLayout newHorizontal + add: versionTable; + yourself +] + +{ #category : #initialization } +PhLPharoVersionChooserPresenter >> initializePresenters [ + versionTable := self newTable + addColumn: ((SpStringTableColumn title: 'Pharo version' evaluated: #key) width: 100; yourself); + addColumn: ((SpStringTableColumn + title: 'version string' + evaluated: #value) width: 60; yourself); + showColumnHeaders; + items: self pharoVersions; + yourself +] + +{ #category : #initialization } +PhLPharoVersionChooserPresenter >> initializeWindow: aWindowPresenter [ + + aWindowPresenter + title: 'Choose the Pharo version of the image:'; + initialExtent: 300@300; + centered +] + +{ #category : #accessing } +PhLPharoVersionChooserPresenter >> pharoVersions [ + | maxPharoVersion versions | + maxPharoVersion := 12. + versions := (#(1.2 1.3 1.4) copyWithAll: (2 to: maxPharoVersion)) reversed. + + ^ versions collect: [ :v | 'Pharo ', v asString -> (v * 10) asInteger asString] +] + +{ #category : #versions } +PhLPharoVersionChooserPresenter >> version [ + ^ versionTable selectedItem value +] diff --git a/src/PharoLauncher-Tests-Commands/PhLLaunchImageCommandTest.class.st b/src/PharoLauncher-Tests-Commands/PhLLaunchImageCommandTest.class.st index 6ace889e..fc337f4a 100644 --- a/src/PharoLauncher-Tests-Commands/PhLLaunchImageCommandTest.class.st +++ b/src/PharoLauncher-Tests-Commands/PhLLaunchImageCommandTest.class.st @@ -128,6 +128,19 @@ PhLLaunchImageCommandTest >> testExecutingImageWithScriptShouldSetFlagToShouldNo self deny: image shouldRunInitializationScript. ] +{ #category : #tests } +PhLLaunchImageCommandTest >> testLaunchImageShouldRaiseExceptionWhenNoPharoVersionFile [ + + image versionFile ensureDelete. + presenter + unselectAll; + selection: { image }. + + self + should: [ image launch ] + raise: PhLImageVersionFileNotFound +] + { #category : #tests } PhLLaunchImageCommandTest >> testRecreateAnImageWithoutOpeningItShouldStillExecuteScript [ diff --git a/src/PharoLauncher-Tests-SpecUI/PhLImagesPresenterTest.class.st b/src/PharoLauncher-Tests-SpecUI/PhLImagesPresenterTest.class.st index 00f020eb..254e6f1f 100644 --- a/src/PharoLauncher-Tests-SpecUI/PhLImagesPresenterTest.class.st +++ b/src/PharoLauncher-Tests-SpecUI/PhLImagesPresenterTest.class.st @@ -9,7 +9,7 @@ Class { { #category : #running } PhLImagesPresenterTest >> tearDown [ - presenter window ifNotNil: #close. + presenter window ifNotNil: [ :window | window close]. super tearDown ]