From 034d567c38f61ebe4e6f6199a628f4d64183f2e0 Mon Sep 17 00:00:00 2001 From: CyrilFerlicot Date: Wed, 6 Sep 2023 15:19:31 +0200 Subject: [PATCH] Remove usage of categories in MCOrganizationDefinition Base the organization definition on packages and tags instead of categories. #ensureMCClassOrganisationHasCorrectStructure: has been simplified because now the organization knows the package and we do not need to do magic to ensure we have the right one IcePackageDefinition has been updated to use the package name and tag names instead of categories. This change includes https://github.com/pharo-vcs/iceberg/pull/1728 --- .../IceConvertFormatAction.class.st | 61 ++++----------- Iceberg/IceMCDefinitionImporter.class.st | 8 +- Iceberg/IcePackageDefinition.class.st | 77 +++++++++++-------- 3 files changed, 66 insertions(+), 80 deletions(-) diff --git a/Iceberg-Plugin-Migration/IceConvertFormatAction.class.st b/Iceberg-Plugin-Migration/IceConvertFormatAction.class.st index 554caf39f1..b7f0770e95 100644 --- a/Iceberg-Plugin-Migration/IceConvertFormatAction.class.st +++ b/Iceberg-Plugin-Migration/IceConvertFormatAction.class.st @@ -34,21 +34,9 @@ IceConvertFormatAction >> codeDirectoryWithDelim [ { #category : #private } IceConvertFormatAction >> ensureMCClassOrganisationHasCorrectStructure: mcVersion [ - | organisation | - organisation := mcVersion snapshot definitions - detect: [ :each | each isOrganizationDefinition ]. - - (organisation categories size = 1) ifFalse: [ | baseCategory | - baseCategory := self - obtainCommonCategory: organisation categories first - from: organisation categories. - baseCategory ifEmpty: [ - self error: 'I didn''t find a base category, something is wrong with the package definition' ]. - baseCategory = organisation categories first ifFalse: [ - organisation categories: (organisation categories copyWithFirst: baseCategory) ] ]. - - ^ mcVersion + (mcVersion snapshot definitions detect: [ :each | each isOrganizationDefinition ]) packageName ifNil: [ + self error: 'I have no package name in the organization definition' ] ] { #category : #private } @@ -57,16 +45,14 @@ IceConvertFormatAction >> ensureMCVersionWithClassOrganisation: mcVersion [ only for extensions, we need to ensure it has one, otherwise package creation will fail" - ^ mcVersion snapshot definitions - detect: [ :each | each isClassDefinition ] - ifFound: [ :each | mcVersion ] - ifNone: [ - MCVersion - package: mcVersion package - info: mcVersion info - snapshot: (MCSnapshot fromDefinitions: ( - { MCOrganizationDefinition categories: { mcVersion package name }}, - mcVersion snapshot definitions)) ] + ^ mcVersion snapshot definitions + detect: [ :each | each isClassDefinition ] + ifFound: [ :each | mcVersion ] + ifNone: [ + MCVersion + package: mcVersion package + info: mcVersion info + snapshot: (MCSnapshot fromDefinitions: { (MCOrganizationDefinition packageName: mcVersion package name) } , mcVersion snapshot definitions) ] ] { #category : #execution } @@ -103,22 +89,20 @@ IceConvertFormatAction >> mergeWithCurrentBranch: anObject [ { #category : #private } IceConvertFormatAction >> migratePackage: packageName commit: commit [ + | filetreePackage srcDir subDirWithDelim mcVersion | - srcDir := self codeDirectory. subDirWithDelim := self codeDirectoryWithDelim. - + mcVersion := (commit versionFor: packageName) mcVersion. mcVersion := self ensureMCVersionWithClassOrganisation: mcVersion. - mcVersion := self ensureMCClassOrganisationHasCorrectStructure: mcVersion. - self writerClass - forInternalStoreFileOut: mcVersion - on: repository. + self ensureMCClassOrganisationHasCorrectStructure: mcVersion. + self writerClass forInternalStoreFileOut: mcVersion on: repository. filetreePackage := commit writerClass directoryNameFor: packageName. (srcDir / filetreePackage) ensureDeleteAll. - self repository addFilesToIndex: { - subDirWithDelim, (IceLibgitTonelWriter directoryNameFor: packageName). - subDirWithDelim, (IceLibgitFiletreeWriter directoryNameFor: packageName) } + self repository addFilesToIndex: { + (subDirWithDelim , (IceLibgitTonelWriter directoryNameFor: packageName)). + (subDirWithDelim , (IceLibgitFiletreeWriter directoryNameFor: packageName)) } ] { #category : #private } @@ -152,17 +136,6 @@ IceConvertFormatAction >> migrateSources [ andParents: { commit }. ] -{ #category : #private } -IceConvertFormatAction >> obtainCommonCategory: aString from: aCollection [ - - ^ (aCollection allSatisfy: [ :each | each beginsWith: aString ]) - ifTrue: [ aString ] - ifFalse: [ - (aString includes: $-) - ifTrue: [ self obtainCommonCategory: (aString copyUpToLast: $-) from: aCollection ] - ifFalse: [ '' ] ] -] - { #category : #private } IceConvertFormatAction >> removeFiletreeRemnants [ "remove .filetree remaining" diff --git a/Iceberg/IceMCDefinitionImporter.class.st b/Iceberg/IceMCDefinitionImporter.class.st index d76421608b..1aea3ee983 100644 --- a/Iceberg/IceMCDefinitionImporter.class.st +++ b/Iceberg/IceMCDefinitionImporter.class.st @@ -123,9 +123,11 @@ IceMCDefinitionImporter >> visitMethodDefinition: aMCMethodDefinition [ ] { #category : #visiting } -IceMCDefinitionImporter >> visitOrganizationDefinition: aMCOrganizationDefinition [ - - packageNode value categories: aMCOrganizationDefinition categories +IceMCDefinitionImporter >> visitOrganizationDefinition: aMCOrganizationDefinition [ + + packageNode value + packageName: aMCOrganizationDefinition packageName; + tagNames: aMCOrganizationDefinition tagNames ] { #category : #visiting } diff --git a/Iceberg/IcePackageDefinition.class.st b/Iceberg/IcePackageDefinition.class.st index 771ac28641..a1392a0d5d 100644 --- a/Iceberg/IcePackageDefinition.class.st +++ b/Iceberg/IcePackageDefinition.class.st @@ -10,10 +10,11 @@ Class { #superclass : #IceDefinition, #instVars : [ 'package', - 'categories', - 'path' + 'path', + 'packageName', + 'tagNames' ], - #category : 'Iceberg-Changes' + #category : #'Iceberg-Changes' } { #category : #visiting } @@ -37,44 +38,30 @@ IcePackageDefinition >> addModification: anIceModification toPatcher: aMCPatcher { #category : #patching } IcePackageDefinition >> addToPatcher: aPatcher [ - - aPatcher addDefinition: (MCOrganizationDefinition categories: categories) -] - -{ #category : #accessing } -IcePackageDefinition >> asMCDefinition [ - - ^ MCOrganizationDefinition categories: categories -] -{ #category : #accessing } -IcePackageDefinition >> categories [ - ^ categories + aPatcher addDefinition: self asMCDefinition ] { #category : #accessing } -IcePackageDefinition >> categories: aCollection [ +IcePackageDefinition >> asMCDefinition [ - categories := aCollection + ^ MCOrganizationDefinition packageName: packageName tagNames: tagNames ] { #category : #accessing } IcePackageDefinition >> contents [ - - ^ String streamContents: [ :stream | - stream nextPutAll: 'Package tags: '. - categories do: [ :elem | - stream nextPutAll: String crlf; - nextPutAll: String tab; - nextPutAll: elem. - ]] -] -{ #category : #initialization } -IcePackageDefinition >> initialize [ - - super initialize. - categories := #() + ^ String streamContents: [ :stream | + stream + nextPutAll: 'Package: '; + nextPutAll: self packageName; + crlf; + nextPutAll: 'Tags: '. + self tagNames do: [ :tagName | + stream + nextPutAll: String crlf; + nextPutAll: String tab; + nextPutAll: tagName ] ] ] { #category : #testing } @@ -89,6 +76,18 @@ IcePackageDefinition >> package [ ^ package ] +{ #category : #accessing } +IcePackageDefinition >> packageName [ + + ^ packageName +] + +{ #category : #accessing } +IcePackageDefinition >> packageName: anObject [ + + packageName := anObject +] + { #category : #accessing } IcePackageDefinition >> path [ ^ path @@ -107,6 +106,18 @@ IcePackageDefinition >> removeFrom: aVisitor [ { #category : #patching } IcePackageDefinition >> removeFromPatcher: aPatcher [ - - aPatcher removeDefinition: (MCOrganizationDefinition categories: categories) + + aPatcher removeDefinition: self asMCDefinition +] + +{ #category : #accessing } +IcePackageDefinition >> tagNames [ + + ^ tagNames +] + +{ #category : #accessing } +IcePackageDefinition >> tagNames: anObject [ + + tagNames := anObject ]