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