reports/Builder__Report.st
author Claus Gittinger <cg@exept.de>
Thu, 28 Mar 2019 13:54:38 +0100
changeset 542 aa25a71be62a
parent 231 9551cb7cfe38
permissions -rw-r--r--
#DOCUMENTATION by cg
class: stx_goodies_builder_quickSelfTest
class definition

class: stx_goodies_builder_quickSelfTest class
added:18 methods
     1 "{ Package: 'stx:goodies/builder/reports' }"
     2 
     3 "{ NameSpace: Builder }"
     4 
     5 Object subclass:#Report
     6 	instanceVariableNames:'name ident packages format'
     7 	classVariableNames:'Verbose OutputDir'
     8 	poolDictionaries:''
     9 	category:'Builder-Reports'
    10 !
    11 
    12 
    13 !Report class methodsFor:'initialization'!
    14 
    15 initialize
    16 
    17     Verbose := false.
    18     OutputDir := Filename currentDirectory.
    19 
    20     "Created: / 14-03-2011 / 19:42:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    21 ! !
    22 
    23 !Report class methodsFor:'instance creation'!
    24 
    25 new
    26     "return an initialized instance"
    27 
    28     ^ self basicNew initialize.
    29 ! !
    30 
    31 !Report class methodsFor:'accessing'!
    32 
    33 available
    34     "Return all available reports ready to run. 
    35      Unfinished/Experimental reports are not returned"
    36 
    37     ^{ 
    38         Builder::TestReport .
    39         Builder::LintReport .
    40     }
    41 
    42     "Created: / 13-01-2012 / 12:01:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    43 !
    44 
    45 outputDir
    46 
    47     ^OutputDir ? '.'
    48 
    49     "
    50         Report outputDir: '/tmp/reports' 
    51     "
    52 
    53     "Created: / 07-10-2011 / 09:12:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    54 !
    55 
    56 outputDir: aStringOrFilename
    57 
    58     OutputDir := aStringOrFilename asFilename.
    59 
    60     "
    61         Report outputDir: '/tmp/reports' 
    62     "
    63 
    64     "Created: / 14-03-2011 / 19:40:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    65 ! !
    66 
    67 !Report class methodsFor:'private'!
    68 
    69 convert: aString
    70 	^ (aString asString 
    71 		copyReplaceAll: (String with: Character cr with: Character lf) with: (String with: Character lf))
    72 		copyReplaceAll: (String with: Character cr) with: (String with: Character lf)
    73 !
    74 
    75 encode: aString
    76 
    77     | in out c |
    78 
    79     (aString includesAny: #($< $> $& $")) ifFalse:[^aString].
    80     in := aString readStream.
    81     out := String new writeStream.  
    82     [in atEnd ] whileFalse:[
    83         c := in next.
    84         c == $< ifTrue:[out nextPutAll:'&lt;'] ifFalse:[
    85         c == $> ifTrue:[out nextPutAll:'&gt;'] ifFalse:[
    86         c == $& ifTrue:[out nextPutAll:'&amp;'] ifFalse:[
    87         c == $" ifTrue:[out nextPutAll:'&quot;'] ifFalse:[
    88         out nextPut: c]]]]].
    89     ^out contents.
    90 
    91     "
    92         HDReport basicNew encode: 'abx' 
    93         HDReport basicNew encode: ''  
    94         HDReport basicNew encode: 'sss <clint>()'       
    95     "
    96 
    97     "Modified: / 11-03-2011 / 17:12:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    98 !
    99 
   100 encodeFilename: aString
   101 
   102     ^(aString copyReplaceAll: $: with:$_) copyReplaceAll: $/ with:$_
   103 
   104     "Created: / 14-03-2011 / 14:14:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   105     "Modified: / 14-03-2011 / 23:45:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   106 ! !
   107 
   108 !Report class methodsFor:'queries'!
   109 
   110 isAbstract
   111     "Return if this class is an abstract class.
   112      True is returned here for myself only; false for subclasses.
   113      Abstract subclasses must redefine again."
   114 
   115     ^ self == Builder::Report.
   116 ! !
   117 
   118 !Report class methodsFor:'running'!
   119 
   120 runClasses: aCollectionOfClasses
   121 
   122     ^self runClasses: aCollectionOfClasses named: 'Some classes'
   123 
   124     "Created: / 04-08-2011 / 12:25:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   125 !
   126 
   127 runClasses: aCollectionOfClasses named: aString
   128 
   129     ^self new runClasses: aCollectionOfClasses named: aString
   130 
   131     "Modified: / 04-08-2011 / 12:23:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   132 !
   133 
   134 runPackage: aString
   135 
   136     "Run a report for given package (package id)"
   137 
   138     ^self runPackages: (Array with: aString)
   139 
   140     "Modified (comment): / 04-08-2011 / 12:24:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   141 !
   142 
   143 runPackages: packages
   144 
   145     "Run a report for given list of packages
   146      (package IDs)"
   147 
   148     ^self new runPackages: packages
   149 
   150     "Modified (comment): / 04-08-2011 / 12:24:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   151 !
   152 
   153 verbose
   154 
   155     ^ Verbose
   156 
   157     "Created: / 21-07-2011 / 11:48:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   158 !
   159 
   160 verbose: aBoolean
   161 
   162     Verbose := aBoolean.
   163 
   164     "Created: / 21-07-2011 / 11:48:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   165 ! !
   166 
   167 !Report methodsFor:'accessing'!
   168 
   169 format
   170     ^ format
   171 !
   172 
   173 format: aFormatOrString
   174 
   175     aFormatOrString isString ifTrue:[
   176         format := ReportFormat named: aFormatOrString 
   177     ] ifFalse:[
   178         format := aFormatOrString 
   179     ]
   180 
   181     "Created: / 04-08-2011 / 11:55:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   182 !
   183 
   184 ident
   185     ^ ident
   186 !
   187 
   188 ident:aString
   189     ident := aString.
   190 !
   191 
   192 name
   193 
   194     ^name isNil ifTrue:[
   195         self defaultName
   196     ] ifFalse:[
   197         name
   198     ]
   199 
   200     "Modified: / 07-11-2011 / 09:47:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   201 !
   202 
   203 name:aString
   204     name := aString.
   205 !
   206 
   207 outputDirectory
   208 
   209     ^self class outputDir asFilename
   210 
   211     "Created: / 07-10-2011 / 09:12:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   212 ! !
   213 
   214 !Report methodsFor:'accessing-command line options'!
   215 
   216 cmdlineOptionFormat
   217 
   218     ^CmdLineOption new
   219         short: $F;
   220         long: 'format';
   221         description: 'Report format to use';
   222         action:[:option | self format: option ]
   223 
   224     "Created: / 06-11-2011 / 21:49:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   225     "Modified: / 25-06-2013 / 16:02:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   226 !
   227 
   228 cmdlineOptionPackage
   229 
   230     ^CmdLineOption new
   231         short: $p;
   232         long: 'package';
   233         description: 'Package in which to run the report';
   234         action:[:option | 
   235             packages isNil ifTrue:[ packages := Set new ].
   236             packages add: option.
   237         ]
   238 
   239     "Created: / 06-11-2011 / 21:49:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   240     "Modified: / 25-06-2013 / 16:02:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   241 ! !
   242 
   243 !Report methodsFor:'accessing-defaults'!
   244 
   245 defaultFileSuffix
   246 
   247     "Return a default filename suffix. Note that format suffix will be 
   248      appended too if not file is explicitely specified"
   249 
   250     ^self subclassResponsibility
   251 
   252     "Created: / 04-08-2011 / 12:47:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   253 !
   254 
   255 defaultFormat
   256     "raise an error: must be redefined in concrete subclass(es)"
   257 
   258     ^ self subclassResponsibility
   259 !
   260 
   261 defaultName
   262 
   263     ^self class name
   264 
   265     "Created: / 07-11-2011 / 09:47:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   266 ! !
   267 
   268 !Report methodsFor:'initialization'!
   269 
   270 setupForClasses: classes
   271     "raise an error: must be redefined in concrete subclass(es)"
   272 
   273     ^ self subclassResponsibility
   274 
   275     "Created: / 04-08-2011 / 14:34:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   276 !
   277 
   278 setupForPackages:pkgs
   279     "raise an error: must be redefined in concrete subclass(es)"
   280 
   281     ^ self subclassResponsibility
   282 ! !
   283 
   284 !Report methodsFor:'private'!
   285 
   286 convert:arg
   287     ^ self class convert:arg
   288 !
   289 
   290 encode:arg
   291     ^ self class encode:arg
   292 !
   293 
   294 encodeFilename:arg
   295     ^ self class encodeFilename:arg
   296 !
   297 
   298 loadPackageIfNotAlready: pkg
   299     "Loads a package, if it is not loaded already. 
   300      Raises an error if package cannot be loaded"
   301 
   302     | def |
   303     def := ProjectDefinition definitionClassForPackage:pkg.
   304     def isNil ifTrue:[ 
   305         (Smalltalk loadPackage:pkg) ifFalse:[
   306             self error:'Cannot load package: ', pkg.
   307         ].
   308         def := ProjectDefinition definitionClassForPackage:pkg. 
   309     ].
   310     def isNil ifTrue:[
   311         self error:'Package loaded but project definition not found: ', pkg.
   312     ].
   313 
   314     "Created: / 13-01-2012 / 12:56:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   315 ! !
   316 
   317 !Report methodsFor:'running'!
   318 
   319 run
   320 
   321     self setUp.
   322     format writeHeader.
   323     [ self runReport ] ensure:[
   324         format writeFooter.
   325         self tearDown.
   326     ]
   327 
   328     "Modified: / 04-08-2011 / 12:42:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   329 !
   330 
   331 runClasses:classes named:aString 
   332     name := aString.
   333     self setupForClasses:classes.
   334     self run
   335 
   336     "Modified: / 04-08-2011 / 14:34:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   337 !
   338 
   339 runPackage: package
   340 
   341     ^self runPackages: (Array with: package)
   342 
   343     "Created: / 04-08-2011 / 12:53:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   344 !
   345 
   346 runPackages:pkgs 
   347     pkgs size == 1 
   348         ifTrue:[ name := pkgs anyOne. ]
   349         ifFalse:[ name := ('%1 packages' bindWith:pkgs size). ].
   350     packages := pkgs.
   351     ^ self run
   352 
   353     "
   354         HDTestReport runPackage:'stx:goodies/monticello'
   355         HDTestReport runPackage:'stx:libjava'"
   356 
   357     "Created: / 04-08-2011 / 12:35:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   358     "Modified: / 25-06-2013 / 01:03:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   359 !
   360 
   361 runReport
   362     "Actually run the report. What to do (what classes/packages to check)
   363      must be stored instance variables"
   364 
   365     ^ self subclassResponsibility
   366 
   367     "Created: / 04-08-2011 / 12:39:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   368 !
   369 
   370 setUp
   371 
   372     | filename stream | 
   373 
   374     packages notNil ifTrue:[
   375         packages do:[:pkg| self loadPackageIfNotAlready: pkg].
   376         self setupForPackages: packages.
   377         packages := nil.
   378     ].
   379     format isNil ifTrue:[format := self defaultFormat].
   380     filename :=  '%1-%4%2.%3' bindWith: self name 
   381                                   with: self defaultFileSuffix 
   382                                   with: format defaultFileSuffix
   383                                   with: (ident isNil ifTrue:[''] ifFalse:[ident , '-']).
   384     stream := (OutputDir / (self encodeFilename:filename)) writeStream.
   385     format report: self stream: stream
   386 
   387     "Created: / 04-08-2011 / 12:43:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   388     "Modified: / 22-01-2014 / 10:06:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   389 !
   390 
   391 tearDown
   392 
   393     format streamFlush; streamClose.
   394 
   395     "Created: / 04-08-2011 / 12:43:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   396 ! !
   397 
   398 !Report class methodsFor:'documentation'!
   399 
   400 version
   401     ^ '$Header$'
   402 !
   403 
   404 version_CVS
   405     ^ '$Header$'
   406 !
   407 
   408 version_SVN
   409     ^ '$Id$'
   410 ! !
   411 
   412 
   413 Report initialize!