Skip to content

Commit

Permalink
Improved compatibility with older project files
Browse files Browse the repository at this point in the history
  • Loading branch information
JanBliznicenko committed Oct 17, 2024
1 parent d81f0de commit ab0eb38
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 6 deletions.
7 changes: 7 additions & 0 deletions repository/OpenPonk-Core/ManifestOpenPonkCore.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,10 @@ ManifestOpenPonkCore class >> ruleRTInvocationSequenceRuleV1FalsePositive [
ManifestOpenPonkCore class >> ruleReTestClassNotInPackageWithTestEndingNameV1FalsePositive [
^ #(#(#(#RGPackageDefinition #(#'OpenPonk-Core')) #'2020-05-27T10:56:37.652665+02:00') )
]

{ #category : 'code-critics' }
ManifestOpenPonkCore class >> ruleStringConcatenationRuleV1FalsePositive [

<ignoreForCoverage>
^ #(#(#(#RGMethodDefinition #(#OPMementoDirectorySerializer #loadModelFrom: #false)) #'2024-10-17T12:14:35.401+02:00') )
]
20 changes: 15 additions & 5 deletions repository/OpenPonk-Core/OPMementoDirectorySerializer.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ OPMementoDirectorySerializer >> loadDiagramsOf: aModel from: aFolder [
ifFound: [ :exportInfoFile |
OPSerializer forExportInfoFile: exportInfoFile ]
ifNone: [ OPJsonDiagramSerializer new ].
^ ((aFolder filesMatching: '*.' , materializer fileExtension)
reject: [ :any | any basename = OPExportInfo fileName ])
collect: [ :eachFile |
^ aFolder files
select: [ :any |
(materializer fileExtensions includes: any extension) and: [
any basename ~= OPExportInfo fileName ] ]
thenCollect: [ :eachFile |
self loadDiagramOf: aModel from: eachFile by: materializer ]
]

Expand Down Expand Up @@ -75,8 +77,16 @@ OPMementoDirectorySerializer >> loadModelFrom: aFolder [
plugin modelSerializerClass forExportInfoFile:
exportInfoFile ]
ifNone: [ plugin modelSerializerClass new ].
modelFile := aFolder / 'model' , materializer fileExtension.
modelFile exists ifFalse: [ ^ nil ].

modelFile := aFolder files
detect: [ :anyFile |
materializer fileExtensions anySatisfy: [
:anyExtension |
anyFile basename = ('model.' , anyExtension) ] ]
ifNone: [
self error:
'Failed to find model file in .opp'
, aFolder absolutePath pathString ].
^ modelFile readStreamDo: [ :stream |
materializer materializeModelFrom: stream ]
]
Expand Down
13 changes: 12 additions & 1 deletion repository/OpenPonk-Core/OPSerializer.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ OPSerializer class >> exportVersion [
{ #category : 'accessing' }
OPSerializer class >> fileExtension [

^ self formatName
^ self fileExtensions first
]

{ #category : 'accessing' }
OPSerializer class >> fileExtensions [

^ { self formatName }
]

{ #category : 'as yet unclassified' }
Expand Down Expand Up @@ -102,6 +108,11 @@ OPSerializer >> fileExtension [
^ self class fileExtension
]

{ #category : 'accessing' }
OPSerializer >> fileExtensions [
^ self class fileExtensions
]

{ #category : 'formatting' }
OPSerializer >> formatName [
^ self class formatName
Expand Down
14 changes: 14 additions & 0 deletions repository/OpenPonk-Spec/ManifestOpenPonkSpec.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,17 @@ Class {
ManifestOpenPonkSpec class >> ruleRBContainsRuleV1FalsePositive [
^ #(#(#(#RGMethodDefinition #(#OPModelTypeSelector #addModel #false)) #'2021-03-04T21:09:27.51689+01:00') )
]

{ #category : 'code-critics' }
ManifestOpenPonkSpec class >> ruleRefersToClassRuleV1FalsePositive [

<ignoreForCoverage>
^ #(#(#(#RGMethodDefinition #(#'OPLegacyProjectLoadTest class' #generateFromProjectFile: #true)) #'2024-10-17T11:08:54.945+02:00') )
]

{ #category : 'code-critics' }
ManifestOpenPonkSpec class >> ruleTempsReadBeforeWrittenRuleV1FalsePositive [

<ignoreForCoverage>
^ #(#(#(#RGMethodDefinition #(#'OPLegacyProjectLoadTest class' #generateFromProjectFile: #true)) #'2024-10-17T11:08:51.1+02:00') )
]
96 changes: 96 additions & 0 deletions repository/OpenPonk-Spec/OPLegacyProjectLoadTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
Class {
#name : 'OPLegacyProjectLoadTest',
#superclass : 'TestCase',
#instVars : [
'workbench'
],
#category : 'OpenPonk-Spec-Tests',
#package : 'OpenPonk-Spec',
#tag : 'Tests'
}

{ #category : 'generating' }
OPLegacyProjectLoadTest class >> generateFromDesktopProjects [

<script>
FileLocator desktop asFileReference files
select: [ :each | each extension = 'opp' ]
thenDo: [ :file | self generateFromProjectFile: file ]
]

{ #category : 'generating' }
OPLegacyProjectLoadTest class >> generateFromProjectFile: file [

| pluginName version modelName base64 className |
pluginName := (file basename copyUpToLast: $-) capitalized.
version := (file basename copyAfterLast: $-) reject: [ :each |
each = $. ].
modelName := pluginName , version.

file binaryReadStreamDo: [ :s | base64 := s upToEnd base64Encoded ].
base64 ifNil: [ self error ].

className := ('OP' , modelName , 'ProjectLoadTest') asSymbol.

(OPLegacyProjectLoadTest << className)
tag: 'Tests';
package: 'OpenPonk-Spec';
install.

(Smalltalk at: className) compile: 'base64ProjectZip
^''' , base64 , '''
'
]

{ #category : 'testing' }
OPLegacyProjectLoadTest class >> isAbstract [

^ self = OPLegacyProjectLoadTest
]

{ #category : 'files' }
OPLegacyProjectLoadTest >> base64ProjectZip [

^ self subclassResponsibility
]

{ #category : 'files' }
OPLegacyProjectLoadTest >> file [

^ FileSystem memory root / 'testLegacyProject.opp'
]

{ #category : 'files' }
OPLegacyProjectLoadTest >> projectZip [

| file |
file := self file.
file ensureDelete.
file binaryWriteStreamDo: [ :s |
s nextPutAll: self base64ProjectZip base64Decoded ].
file exists ifFalse: [
self error: 'Failed to save the base64 as file in memory' ].
file size isZero ifTrue: [
self error: 'File with base64 content is empty' ].
^ file
]

{ #category : 'running' }
OPLegacyProjectLoadTest >> tearDown [

self file ensureDelete.
workbench ifNotNil: [ workbench delete ].
super tearDown
]

{ #category : 'tests' }
OPLegacyProjectLoadTest >> testLoad [

| project |
project := OPProjectController fromFile: self projectZip.
workbench := project open.
self assert: workbench focusedEditor isNotNil.
self assert:
workbench focusedEditor canvasPresenter canvas shapes isNotEmpty
]

0 comments on commit ab0eb38

Please sign in to comment.