reports/Builder__ReportExtensionsSourceInfo.st
changeset 204 5450b318385a
child 264 ff9647e01309
equal deleted inserted replaced
203:297a4be47446 204:5450b318385a
       
     1 "{ Package: 'stx:goodies/builder/reports' }"
       
     2 
       
     3 "{ NameSpace: Builder }"
       
     4 
       
     5 ReportSourceInfo subclass:#ReportExtensionsSourceInfo
       
     6 	instanceVariableNames:''
       
     7 	classVariableNames:''
       
     8 	poolDictionaries:''
       
     9 	category:'Builder-Reports-Utils'
       
    10 !
       
    11 
       
    12 
       
    13 !ReportExtensionsSourceInfo methodsFor:'initialization'!
       
    14 
       
    15 initializeWithPackage: pkg
       
    16     package := pkg.
       
    17     self setup.
       
    18 
       
    19     "Created: / 29-07-2013 / 18:38:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    20 ! !
       
    21 
       
    22 !ReportExtensionsSourceInfo methodsFor:'utilities'!
       
    23 
       
    24 fileOutOn: streamArg
       
    25     "This code is stupid as it is a copy-paste of several methods here and there that
       
    26      files out an extension.st. But the the original code is so rubbish so I had
       
    27      to do it this way. Sorry."
       
    28 
       
    29     | extensions wide stream s methodsSortedByName defClass scmManagerOrNil |
       
    30 
       
    31     extensions := ProjectDefinition searchForExtensionsWithProject: package.     
       
    32     wide := false.
       
    33     stream := streamArg.
       
    34     extensions do:[:method|
       
    35         wide := wide or:[method source isWideString].
       
    36     ].
       
    37     wide ifTrue:[
       
    38         stream := EncodedStream stream: stream encoder: (CharacterEncoder encoderForUTF8).      
       
    39         stream nextPutAll: '"{ Encoding: utf8 }"'; cr;cr.
       
    40     ].
       
    41 
       
    42     s := stream.
       
    43 
       
    44     s nextPutAll:'"{ Package: '''.
       
    45     s nextPutAll:package asString.
       
    46     s nextPutAll:''' }"'; nextPutChunkSeparator; cr; cr.
       
    47 
       
    48     "/ don't write a timestamp. Otherwise we would always generate a new version, even if nothing changed
       
    49     "/ s nextPutAll:(Smalltalk timeStamp).
       
    50     "/ s nextPutChunkSeparator. 
       
    51     "/ s cr; cr.
       
    52 
       
    53     "/ sort them by name (to avoid conflicts due to SCM merge)
       
    54     methodsSortedByName := extensions asOrderedCollection.
       
    55     methodsSortedByName sort:[:a :b |
       
    56                                 |clsA clsB|
       
    57 
       
    58                                 clsA := a mclass name.
       
    59                                 clsB := b mclass name.
       
    60                                 clsA < clsB ifTrue:[
       
    61                                     true
       
    62                                 ] ifFalse:[
       
    63                                     clsA > clsB ifTrue:[
       
    64                                         false
       
    65                                     ] ifFalse:[
       
    66                                         a selector < b selector
       
    67                                     ]
       
    68                                 ]
       
    69                               ].
       
    70     methodsSortedByName do:[:aMethod |
       
    71         |cat source privacy aStream|
       
    72 
       
    73         aStream := s.
       
    74 
       
    75     aStream nextPutChunkSeparator.
       
    76     aMethod mclass name printOn:aStream.
       
    77 "/        self printClassNameOn:aStream.
       
    78 
       
    79     (privacy := aMethod privacy) ~~ #public ifTrue:[
       
    80         aStream space; nextPutAll:privacy; nextPutAll:'MethodsFor:'.
       
    81     ] ifFalse:[
       
    82         aStream nextPutAll:' methodsFor:'.
       
    83     ].
       
    84 
       
    85     cat := aMethod category ? ''.
       
    86     aStream nextPutAll:cat asString storeString.
       
    87     aStream nextPutChunkSeparator; cr; cr.
       
    88 
       
    89     SmalltalkChunkFileSourceWriter new fileOutMethod:aMethod on:aStream.
       
    90 
       
    91     aStream space.
       
    92     aStream nextPutChunkSeparator.
       
    93             aStream cr.    
       
    94         s cr.
       
    95     ].
       
    96 
       
    97     scmManagerOrNil := AbstractSourceCodeManager managerForPackage: package.
       
    98     scmManagerOrNil notNil ifTrue:[
       
    99         defClass := ProjectDefinition definitionClassForPackage:package.
       
   100         defClass notNil ifTrue:[
       
   101             "/ make sure, an extensionVersion_XXX method is included...
       
   102             "/ (notice: no need to support a secondary backward compatible non-manager related version method here)
       
   103             (methodsSortedByName contains:[:aMethod | aMethod selector == scmManagerOrNil nameOfVersionMethodForExtensions]) ifFalse:[
       
   104                 s nextPutLine:('!!%1 class methodsFor:''documentation''!!' bindWith:defClass name).
       
   105                 s cr.
       
   106                 s nextChunkPut:
       
   107                     (scmManagerOrNil versionMethodTemplateForSmalltalkFor:(scmManagerOrNil nameOfVersionMethodForExtensions)).
       
   108                 s space; nextPutChunkSeparator; cr.
       
   109             ].
       
   110         ].
       
   111     ].
       
   112 
       
   113     "Modified (comment): / 29-07-2013 / 17:44:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   114 !
       
   115 
       
   116 validate
       
   117     | file |
       
   118 
       
   119     file := (Smalltalk getPackageDirectoryForPackage: package) / 'extensions.st'.                       
       
   120     ^ self validateAgainstReference: file.
       
   121 
       
   122     "Modified: / 29-07-2013 / 14:55:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   123 ! !
       
   124 
       
   125 !ReportExtensionsSourceInfo class methodsFor:'documentation'!
       
   126 
       
   127 version
       
   128     ^ '$Header$'
       
   129 !
       
   130 
       
   131 version_CVS
       
   132     ^ '$Header$'
       
   133 ! !
       
   134