diff --git a/MonticelloTonel-Core.package/TonelParser.class/instance/hasStatefulTraits.st b/MonticelloTonel-Core.package/TonelParser.class/instance/hasStatefulTraits.st new file mode 100644 index 0000000..3e049f2 --- /dev/null +++ b/MonticelloTonel-Core.package/TonelParser.class/instance/hasStatefulTraits.st @@ -0,0 +1,5 @@ +private testing +hasStatefulTraits + "Pharo has stateful traits starting on version 7" + + ^ SystemVersion current major >= 7 \ No newline at end of file diff --git a/MonticelloTonel-Core.package/TonelParser.class/instance/basicNewTraitDefinitionFrom..st b/MonticelloTonel-Core.package/TonelParser.class/instance/newStatefulTraitDefinitionFrom..st similarity index 92% rename from MonticelloTonel-Core.package/TonelParser.class/instance/basicNewTraitDefinitionFrom..st rename to MonticelloTonel-Core.package/TonelParser.class/instance/newStatefulTraitDefinitionFrom..st index 2a54f31..9f957bc 100644 --- a/MonticelloTonel-Core.package/TonelParser.class/instance/basicNewTraitDefinitionFrom..st +++ b/MonticelloTonel-Core.package/TonelParser.class/instance/newStatefulTraitDefinitionFrom..st @@ -1,5 +1,5 @@ private factory -basicNewTraitDefinitionFrom: anArray +newStatefulTraitDefinitionFrom: anArray | metadata | metadata := anArray sixth. diff --git a/MonticelloTonel-Core.package/TonelParser.class/instance/newStatelessTraitDefinitionFrom..st b/MonticelloTonel-Core.package/TonelParser.class/instance/newStatelessTraitDefinitionFrom..st new file mode 100644 index 0000000..56204fa --- /dev/null +++ b/MonticelloTonel-Core.package/TonelParser.class/instance/newStatelessTraitDefinitionFrom..st @@ -0,0 +1,15 @@ +private factory +newStatelessTraitDefinitionFrom: anArray + | metadata | + + metadata := anArray sixth. + + self validateStatelessTraitIsBeingRead: metadata. + + ^ MCTraitDefinition + name: (metadata at: #name) + traitComposition: (metadata at: #traits ifAbsent: [ '{}' ]) + classTraitComposition: (metadata at: #classTraits ifAbsent: [ '{}' ]) + category: (metadata at: #category) + comment: (anArray second ifNil: [ '' ]) + commentStamp: nil \ No newline at end of file diff --git a/MonticelloTonel-Core.package/TonelParser.class/instance/newTraitDefinitionFrom..st b/MonticelloTonel-Core.package/TonelParser.class/instance/newTraitDefinitionFrom..st index ddc355c..157c6f8 100644 --- a/MonticelloTonel-Core.package/TonelParser.class/instance/newTraitDefinitionFrom..st +++ b/MonticelloTonel-Core.package/TonelParser.class/instance/newTraitDefinitionFrom..st @@ -3,12 +3,17 @@ newTraitDefinitionFrom: anArray | metadata traitDefs | metadata := anArray sixth. - traitDefs := { self basicNewTraitDefinitionFrom: anArray }. + traitDefs := { + self hasStatefulTraits + ifTrue: [ self newStatefulTraitDefinitionFrom: anArray ] + ifFalse: [ self newStatelessTraitDefinitionFrom: anArray ] }. - traitDefs first hasClassTraitComposition ifTrue: [ + metadata + at: #classTraits + ifPresent: [ :classTraits | traitDefs := traitDefs copyWith: (MCClassTraitDefinition baseTraitName: (metadata at: #name) - classTraitComposition: (metadata at: #classTraits) + classTraitComposition: classTraits category: (metadata at: #category)) ]. ^ traitDefs \ No newline at end of file diff --git a/MonticelloTonel-Core.package/TonelParser.class/instance/validateStatelessTraitIsBeingRead..st b/MonticelloTonel-Core.package/TonelParser.class/instance/validateStatelessTraitIsBeingRead..st new file mode 100644 index 0000000..8eac06f --- /dev/null +++ b/MonticelloTonel-Core.package/TonelParser.class/instance/validateStatelessTraitIsBeingRead..st @@ -0,0 +1,11 @@ +private +validateStatelessTraitIsBeingRead: metadata + | vars | + + vars := Set new. + vars + addAll: (metadata at: #instVars ifAbsent: [ #() ]); + addAll: (metadata at: #classInstVars ifAbsent: [ #() ]). + + vars ifNotEmpty: [ + self error: 'Trying to load a stateful trait in a stateless version.' ] \ No newline at end of file diff --git a/MonticelloTonel-Core.package/TonelReader.class/README.md b/MonticelloTonel-Core.package/TonelReader.class/README.md index a6f1d61..22e2502 100644 --- a/MonticelloTonel-Core.package/TonelReader.class/README.md +++ b/MonticelloTonel-Core.package/TonelReader.class/README.md @@ -1,19 +1,19 @@ I'm a monticello reader for tonel format repositories. I read - - a package per directory - - a class per file - - a set of extensions to a single class per file (for example, all extensions of a package to String will be in a single file) +- a package per directory +- a class per file +- a set of extensions to a single class per file (for example, all extensions of a package to String will be in a single file) I'm created on a file reference to a directory where the package will be read and the name of the package to read. -[[[ -TonelReader on: 'someDirectoryWithTonelPackages' asFileReference filename: 'MyPackageName' -]]] +``` +TonelReader on: 'someDirectoryWithTonelPackages' asFileReference fileName: 'MyPackageName' +``` My main method is -- ==#definitions== reads and parses the tonel file, returns a list of monticello definitions. -- ==#snapshot== returns a monticello snapshot with the read definitions. -- ==#version== returns a monticello version with the read snapshot. +- `#definitions` reads and parses the tonel file, returns a list of monticello definitions. +- `#snapshot` returns a monticello snapshot with the read definitions. +- `#version` returns a monticello version with the read snapshot. ! Implementation details -The monticello versions I return do have artificial information. Since I'm just meant to read versions from a directory, this directory has no information such as commit message, commit time, author, or ancestors. Check the method ==#loadVersionInfo== for more information. \ No newline at end of file +The monticello versions I return do have artificial information. Since I'm just meant to read versions from a directory, this directory has no information such as commit message, commit time, author, or ancestors. Check the method `#loadVersionInfo` for more information. \ No newline at end of file diff --git a/MonticelloTonel-Core.package/TonelReader.class/instance/categoriesFrom..st b/MonticelloTonel-Core.package/TonelReader.class/instance/categoriesFrom..st index ef5dbe8..1cb84de 100644 --- a/MonticelloTonel-Core.package/TonelReader.class/instance/categoriesFrom..st +++ b/MonticelloTonel-Core.package/TonelReader.class/instance/categoriesFrom..st @@ -1,6 +1,6 @@ private categoriesFrom: aCollection - ^ ((aCollection select: #isClassDefinition) - collect: #category + ^ ((aCollection select: [:each | each isClassDefinition]) + collect: [:each | each category] as: Set) sorted: [ :a :b | a < b ] \ No newline at end of file diff --git a/MonticelloTonel-Core.package/TonelReader.class/properties.json b/MonticelloTonel-Core.package/TonelReader.class/properties.json index 09da5e2..34ef44b 100644 --- a/MonticelloTonel-Core.package/TonelReader.class/properties.json +++ b/MonticelloTonel-Core.package/TonelReader.class/properties.json @@ -1,5 +1,5 @@ { - "commentStamp" : "GuillermoPolito 7/11/2018 11:02", + "commentStamp" : "StephaneDucasse 1/30/2021 15:48", "super" : "MCVersionReader", "category" : "MonticelloTonel-Core", "classinstvars" : [ ], diff --git a/MonticelloTonel-Core.package/TonelWriter.class/instance/createDefaultOrganizationFrom..st b/MonticelloTonel-Core.package/TonelWriter.class/instance/createDefaultOrganizationFrom..st index 2a6e0a3..2b4e163 100644 --- a/MonticelloTonel-Core.package/TonelWriter.class/instance/createDefaultOrganizationFrom..st +++ b/MonticelloTonel-Core.package/TonelWriter.class/instance/createDefaultOrganizationFrom..st @@ -4,9 +4,9 @@ createDefaultOrganizationFrom: aCollection "simplest case, I answer the clas definition" snapshot definitions - detect: #isClassDefinition - ifFound: [ :each | ^ MCOrganizationDefinition categories: { each categoryWithoutTag } ]. + detect: [ :each | each isClassDefinition ] + ifFound: [ :each | ^ MCOrganizationDefinition categories: { each category } ]. ^ self createDefaultOrganizationFromDefinition: (snapshot definitions - detect: #isMethodDefinition + detect: [ :each | each isMethodDefinition ] ifNone: [ self error: 'cannot determine package name from empty snapshot' ]) diff --git a/MonticelloTonel-Core.package/TonelWriter.class/instance/packageNameForMethodDefinition..st b/MonticelloTonel-Core.package/TonelWriter.class/instance/packageNameForMethodDefinition..st index 13c16e2..6f55b99 100644 --- a/MonticelloTonel-Core.package/TonelWriter.class/instance/packageNameForMethodDefinition..st +++ b/MonticelloTonel-Core.package/TonelWriter.class/instance/packageNameForMethodDefinition..st @@ -5,6 +5,6 @@ packageNameForMethodDefinition: aMethodDefinition self assert: aMethodDefinition category first = $*. category := aMethodDefinition category allButFirst. ^(MCWorkingCopy allManagers - detect: ((category allSatisfy: #isLowercase) + detect: ((category allSatisfy: [ :each | each isLowercase ]) ifTrue: [[: wc| category beginsWith: wc packageName asLowercase]] ifFalse: [[: wc| category beginsWith: wc packageName]])) packageName \ No newline at end of file diff --git a/MonticelloTonel-Core.package/TonelWriter.class/instance/writeSnapshot..st b/MonticelloTonel-Core.package/TonelWriter.class/instance/writeSnapshot..st index 7cb9e3b..7c9c370 100644 --- a/MonticelloTonel-Core.package/TonelWriter.class/instance/writeSnapshot..st +++ b/MonticelloTonel-Core.package/TonelWriter.class/instance/writeSnapshot..st @@ -5,11 +5,11 @@ writeSnapshot: aSnapshot "ensure package dirs exists. It has to be just one but well..." self writePackage: (snapshot definitions - detect: #isOrganizationDefinition + detect: [:each | each isOrganizationDefinition ] ifNone: [ self createDefaultOrganizationFrom: snapshot definitions ]). "now export classes" (snapshot definitions - select: #isClassDefinition) + select: [:each | each isClassDefinition]) do: [ :each | self writeClass: each ]. "... and method extensions" self writeMethodExtensions \ No newline at end of file diff --git a/MonticelloTonel-Tests.package/TonelWriterTest.class/instance/checkFilesStructureIn..st b/MonticelloTonel-Tests.package/TonelWriterTest.class/instance/checkFilesStructureIn..st index b410d99..709efd0 100644 --- a/MonticelloTonel-Tests.package/TonelWriterTest.class/instance/checkFilesStructureIn..st +++ b/MonticelloTonel-Tests.package/TonelWriterTest.class/instance/checkFilesStructureIn..st @@ -15,7 +15,7 @@ checkFilesStructureIn: aFileReference 'MCMockClassF.class.st' 'MCMockClassG.class.st' 'MCMockClassH.class.st' - 'MCMockClassI.class.st' + 'MCMockClassI.class.st' 'MCSnapshotTest.extension.st' 'package.st'). diff --git a/MonticelloTonel-Tests.package/TonelWriterTest.class/instance/testWriteSnapshotWithOrganizationAndOnlyOnceClassWithTag.st b/MonticelloTonel-Tests.package/TonelWriterTest.class/instance/testWriteSnapshotWithOrganizationAndOnlyOnceClassWithTag.st deleted file mode 100644 index 07efdeb..0000000 --- a/MonticelloTonel-Tests.package/TonelWriterTest.class/instance/testWriteSnapshotWithOrganizationAndOnlyOnceClassWithTag.st +++ /dev/null @@ -1,17 +0,0 @@ -tests -testWriteSnapshotWithOrganizationAndOnlyOnceClassWithTag - - | aSnapshot memoryFileReference writer | - " Taking a snapshot of the package MonticelloMocks " - aSnapshot := self mockSnapshot copy. - " Removing all elements from the snapshot except one class - which is classified in the Package's tag 'Tag' " - (aSnapshot definitions - select: [ :def | def className ~= #MCMockClassI and: [ def isOrganizationDefinition not ]]) - do: [ :each | aSnapshot definitions remove: each ]. - memoryFileReference := FileSystem memory root. - writer := self actualClass on: memoryFileReference. - writer writeSnapshot: aSnapshot. - - self deny: (memoryFileReference / 'MonticelloMocks-Tag') exists. - self assert: (memoryFileReference / 'MonticelloMocks') exists. \ No newline at end of file diff --git a/MonticelloTonel-Tests.package/TonelWriterTest.class/instance/testWriteSnapshotWithoutOrganizationAndOnlyOnceClassWithTag.st b/MonticelloTonel-Tests.package/TonelWriterTest.class/instance/testWriteSnapshotWithoutOrganizationAndOnlyOnceClassWithTag.st deleted file mode 100644 index 25a829b..0000000 --- a/MonticelloTonel-Tests.package/TonelWriterTest.class/instance/testWriteSnapshotWithoutOrganizationAndOnlyOnceClassWithTag.st +++ /dev/null @@ -1,17 +0,0 @@ -tests -testWriteSnapshotWithoutOrganizationAndOnlyOnceClassWithTag - - | aSnapshot memoryFileReference writer | - " Taking a snapshot of the package MonticelloMocks " - aSnapshot := self mockSnapshot copy. - " Removing all elements from the snapshot except one class - which is classified in the Package's tag 'Tag' " - (aSnapshot definitions - select: [ :def | def className ~= #MCMockClassI ]) - do: [ :each | aSnapshot definitions remove: each ]. - memoryFileReference := FileSystem memory root. - writer := self actualClass on: memoryFileReference. - writer writeSnapshot: aSnapshot. - - self deny: (memoryFileReference / 'MonticelloMocks-Tag') exists. - self assert: (memoryFileReference / 'MonticelloMocks') exists. \ No newline at end of file