CypressPackage.st
changeset 12 ec118792047a
parent 11 333528cd629a
child 13 f90704544ca0
--- a/CypressPackage.st	Mon Sep 10 23:52:10 2012 +0000
+++ b/CypressPackage.st	Tue Sep 11 10:56:07 2012 +0000
@@ -39,6 +39,18 @@
     "Created: / 10-09-2012 / 23:45:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
+extensions
+
+    extensions isNil ifTrue:[
+        extensions := definition extensions collect:[:mthd|
+            CypressMethod fromMethod: mthd
+        ]
+    ].
+    ^extensions
+
+    "Created: / 11-09-2012 / 11:03:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 package
     "Returns a CypressPackage which the receiver belongs to"
 
@@ -67,16 +79,111 @@
     ^ self shouldImplement
 !
 
-writeTo:filename notice:copyrightNotice
+writeTo: directory
+    | notice |
+
+    notice := definition legalCopyright.
+    (self properties includesKey:'licenseFile') ifTrue:[
+        notice := notice , ' (for license, see file ' , (self properties at:'licenseFile') , ')'.
+    ].
+    self writeTo: directory asFilename notice: notice.
+
+    "Created: / 11-09-2012 / 11:45:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+writeTo: directory notice:copyrightNotice
     "Writes the receiver into directory/file named 'filename'
      with given copyrightNotice"
 
-    self writePropertiesTo: filename notice: copyrightNotice.
-    self classes do:[:cypressCls|
-        self halt.
-    ]
+    | dir |
+
+    dir := directory asFilename.
+    dir exists ifFalse: [ dir recursiveMakeDirectory ].
+
+    self writePropertiesTo: dir notice: copyrightNotice.
+    self writeClassesTo:  dir notice: copyrightNotice.
+    self writeExtensionsTo: dir notice: copyrightNotice.
+
+    "Modified (format): / 11-09-2012 / 11:50:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!CypressPackage methodsFor:'reading & writing - private'!
+
+writeClassesTo: directory notice:copyrightNotice
+    "Writes my classes  into 'directory' with given copyrightNotice"
+
+    | obsolete |
+
+    " collect possibly obsolete .class directories "
+    obsolete := Set new.
+    directory directoryContentsAsFilenamesDo:[:each|
+        | suffix |
+
+        each suffix = 'class' ifTrue:[
+            obsolete add: each.
+        ]
+    ].
+
+    " write classes... "
+    self classes do:[:cpsCls|
+        | cpsClsDir |
+
+        cpsClsDir := directory / ((cpsCls name copyReplaceAll: $: with: $_) , '.class').
+        obsolete remove: cpsClsDir ifAbsent:[].
+        cpsCls writeTo: cpsClsDir notice:copyrightNotice
+    ].
+
+    " wipe out obsolete .class directories "
+    obsolete do:[:each|
+        each recursiveRemove.
+    ].
 
-    "Modified: / 11-09-2012 / 00:38:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Created: / 11-09-2012 / 11:10:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+writeExtensionsTo: directory notice:copyrightNotice
+    "Writes extensions into 'directory'/file with given copyrightNotice"
+
+    |  obsolete extensionsPerClass |
+
+    " group extensions by class... "
+    extensionsPerClass := Dictionary new.
+    self extensions do:[:cpsMthd |
+        (extensionsPerClass at: cpsMthd klass ifAbsentPut: [ Set new ])
+            add: cpsMthd.
+    ].
+
+    " collect possibly obsolete .extension directories "
+    obsolete := Set new.
+    directory directoryContentsAsFilenamesDo:[:each|
+        | suffix |
+
+        each suffix = 'extension' ifTrue:[
+            obsolete add: each.
+        ]
+    ].
+
+    " write individual extensions... "
+    extensionsPerClass keysAndValuesDo:[:name :cpsMthds |
+        | cpsClsDir cpsCls |
+
+        cpsClsDir := directory / ((name copyReplaceAll: $: with: $_) , '.extension').
+        obsolete remove: cpsClsDir ifAbsent:[].
+        cpsClsDir exists ifFalse: [ cpsClsDir makeDirectory ].
+
+        " Here we create fake CypressClass with only extension methods - this
+          way I can reuse logic allready coded in CypressClass. "
+        cpsCls := CypressClass new.
+        cpsCls new initializeWithMethods: cpsMthds.
+        cpsCls writeMethodsTo: cpsClsDir notice:copyrightNotice.
+    ].
+
+    " wipe out obsolete .class directories "
+    obsolete do:[:each|
+        each recursiveRemove.
+    ].
+
+    "Created: / 11-09-2012 / 11:12:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !CypressPackage class methodsFor:'documentation'!