From c122eb762125c570fc2f2f67345a4d9131b9b453 Mon Sep 17 00:00:00 2001 From: DEMAREY Christophe Date: Fri, 1 Mar 2024 15:05:08 +0100 Subject: [PATCH] Add a command to update Template sources. Related to #652 --- .../PhLTemplateUpdateCliCommandTest.class.st | 24 ++++++++++++ .../PhLTemplateUpdateCliCommand.class.st | 37 +++++++++++++++++++ .../PharoLauncherCLIModel.class.st | 5 +++ .../PhLPharoTemplateSources.class.st | 2 +- .../PhLTemplateSources.class.st | 18 ++++++++- 5 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 src/PharoLauncher-CLI-Tests/PhLTemplateUpdateCliCommandTest.class.st create mode 100644 src/PharoLauncher-CLI/PhLTemplateUpdateCliCommand.class.st diff --git a/src/PharoLauncher-CLI-Tests/PhLTemplateUpdateCliCommandTest.class.st b/src/PharoLauncher-CLI-Tests/PhLTemplateUpdateCliCommandTest.class.st new file mode 100644 index 00000000..3350febe --- /dev/null +++ b/src/PharoLauncher-CLI-Tests/PhLTemplateUpdateCliCommandTest.class.st @@ -0,0 +1,24 @@ +Class { + #name : #PhLTemplateUpdateCliCommandTest, + #superclass : #PhLTemplatesCliCommandTest, + #category : #'PharoLauncher-CLI-Tests' +} + +{ #category : #tests } +PhLTemplateUpdateCliCommandTest >> testTemplateUpdateShouldSucceed [ + | command workingDir | + + workingDir := FileSystem memory root. + self launcherModel templateRepository: (PhLTemplateGroupRepository newFromGroups: #()). + + PhLTemplateSources useLauncherCoreDir: workingDir during: [ + PhLTemplateSources flush: #() in: workingDir / PhLTemplateSources sourcesFileName. + command := (context arguments: #('launcher' 'template' 'update')) command. + self assert: command pharoLauncherModel templateRepository roots size equals: 0. + + command execute ]. + + "self assertSuccess." + self assert:( workingDir / 'sources.list') exists. + self assert: command pharoLauncherModel templateRepository roots size equals: 8 +] diff --git a/src/PharoLauncher-CLI/PhLTemplateUpdateCliCommand.class.st b/src/PharoLauncher-CLI/PhLTemplateUpdateCliCommand.class.st new file mode 100644 index 00000000..fa55652b --- /dev/null +++ b/src/PharoLauncher-CLI/PhLTemplateUpdateCliCommand.class.st @@ -0,0 +1,37 @@ +" +I represent Pharo Template update sub-command invoked from cmd line of Pharo Launcher. +My responsibility is to update the list of templates from the official source. +" +Class { + #name : #PhLTemplateUpdateCliCommand, + #superclass : #PhLTemplateCliCommand, + #category : #'PharoLauncher-CLI-Commands' +} + +{ #category : #'command line - converting' } +PhLTemplateUpdateCliCommand class >> asCliCommand [ + ^ self newLauncherCommandSpec: #update +] + +{ #category : #'command execution' } +PhLTemplateUpdateCliCommand >> basicExecute [ + + self registerOnTemplateSourcesUpdate. + PhLPharoTemplateSources fromFile checkForUpdates. + self pharoLauncherModel resetTemplateRepository. +] + +{ #category : #updating } +PhLTemplateUpdateCliCommand >> registerOnTemplateSourcesUpdate [ + + PhLPharoTemplateSources announcer weak + when: PhLSourcesFileUpdateAvailable + send: #updateTemplateSources + to: self. +] + +{ #category : #updating } +PhLTemplateUpdateCliCommand >> updateTemplateSources [ + + PhLPharoTemplateSources fromFile updateSourcesFile +] diff --git a/src/PharoLauncher-CLI/PharoLauncherCLIModel.class.st b/src/PharoLauncher-CLI/PharoLauncherCLIModel.class.st index eb2e2475..aba9b59b 100644 --- a/src/PharoLauncher-CLI/PharoLauncherCLIModel.class.st +++ b/src/PharoLauncher-CLI/PharoLauncherCLIModel.class.st @@ -75,6 +75,11 @@ PharoLauncherCLIModel >> imageRepository: aPhLDirectoryBasedImageRepository [ imageRepository := aPhLDirectoryBasedImageRepository ] +{ #category : #initialization } +PharoLauncherCLIModel >> resetTemplateRepository [ + templateRepository := nil +] + { #category : #accessing } PharoLauncherCLIModel >> templateRepository [ ^ templateRepository diff --git a/src/PharoLauncher-Core/PhLPharoTemplateSources.class.st b/src/PharoLauncher-Core/PhLPharoTemplateSources.class.st index 5fcc02d9..f9d3553b 100644 --- a/src/PharoLauncher-Core/PhLPharoTemplateSources.class.st +++ b/src/PharoLauncher-Core/PhLPharoTemplateSources.class.st @@ -90,7 +90,7 @@ PhLPharoTemplateSources class >> settingsOn: aBuilder [ { #category : #accessing } PhLPharoTemplateSources class >> sourcesFile [ "File with the list of default templates sources for Pharo Launcher" - ^ self launcherCoreDir / 'sources.list' + ^ self launcherCoreDir / self sourcesFileName ] { #category : #accessing } diff --git a/src/PharoLauncher-Core/PhLTemplateSources.class.st b/src/PharoLauncher-Core/PhLTemplateSources.class.st index 1764dcf0..8ccf142b 100644 --- a/src/PharoLauncher-Core/PhLTemplateSources.class.st +++ b/src/PharoLauncher-Core/PhLTemplateSources.class.st @@ -101,6 +101,22 @@ PhLTemplateSources class >> settingsOn: aBuilder [ , 'NOTE: This path might need to escape some whitespace characters.' translated. ] +{ #category : #accessing } +PhLTemplateSources class >> sourcesFileName [ + "Name of the file with the list of default templates sources for Pharo Launcher" + ^ 'sources.list' +] + +{ #category : #accessing } +PhLTemplateSources class >> useLauncherCoreDir: aDirectory during: aBlock [ + + | oldLauncherCoreDir | + oldLauncherCoreDir := LauncherCoreDir. + [ LauncherCoreDir := aDirectory. + aBlock value ] + ensure: [ LauncherCoreDir := oldLauncherCoreDir ] +] + { #category : #'instance creation' } PhLTemplateSources class >> withFile: aSourcesFile [ ^ self new @@ -111,7 +127,7 @@ PhLTemplateSources class >> withFile: aSourcesFile [ { #category : #'instance creation' } PhLTemplateSources class >> withTemplateList: aListOfPhLTemplateSource [ | file | - file := FileSystem memory / 'sources.list'. + file := FileSystem memory / self sourcesFileName. self flush: aListOfPhLTemplateSource in: file. ^ self withFile: file ]