Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

master #94

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
private testing
hasStatefulTraits
"Pharo has stateful traits starting on version 7"

^ SystemVersion current major >= 7
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
private factory
basicNewTraitDefinitionFrom: anArray
newStatefulTraitDefinitionFrom: anArray
| metadata |

metadata := anArray sixth.
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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.' ]
20 changes: 10 additions & 10 deletions MonticelloTonel-Core.package/TonelReader.class/README.md
Original file line number Diff line number Diff line change
@@ -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.
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.
Original file line number Diff line number Diff line change
@@ -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 ]
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"commentStamp" : "GuillermoPolito 7/11/2018 11:02",
"commentStamp" : "StephaneDucasse 1/30/2021 15:48",
"super" : "MCVersionReader",
"category" : "MonticelloTonel-Core",
"classinstvars" : [ ],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' ])
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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').

Expand Down

This file was deleted.

This file was deleted.