reports/Builder__ReportRunner.st
changeset 72 c23d29fe0ec6
child 77 90d1dd533087
equal deleted inserted replaced
71:1ed7c6cb2f68 72:c23d29fe0ec6
       
     1 "{ Package: 'stx:goodies/builder/reports' }"
       
     2 
       
     3 "{ NameSpace: Builder }"
       
     4 
       
     5 StandaloneStartup subclass:#ReportRunner
       
     6 	instanceVariableNames:''
       
     7 	classVariableNames:''
       
     8 	poolDictionaries:''
       
     9 	category:'Builder-Reports'
       
    10 !
       
    11 
       
    12 ReportRunner class instanceVariableNames:'parser report debugging'
       
    13 
       
    14 "
       
    15  The following class instance variables are inherited by this class:
       
    16 
       
    17 	StandaloneStartup - MutexHandle
       
    18 	Object - 
       
    19 "
       
    20 !
       
    21 
       
    22 
       
    23 !ReportRunner class methodsFor:'initialization'!
       
    24 
       
    25 initialize
       
    26 
       
    27     super initialize.
       
    28     debugging := Transcript notNil and:[Transcript isView].
       
    29 
       
    30     "Created: / 06-11-2011 / 22:07:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    31 ! !
       
    32 
       
    33 !ReportRunner class methodsFor:'command line options'!
       
    34 
       
    35 cmdlineOptionOutputDirectory
       
    36 
       
    37     ^CmdLineOption new
       
    38         short: $D;
       
    39         long: 'output-directory';
       
    40         description: 'Default report output directory';
       
    41         action:[:outputdir | 
       
    42             Report outputDir: outputdir.
       
    43             self  verboseInfo:'Report dir: ' , Report outputDir asString.
       
    44         ]
       
    45 
       
    46     "Created: / 06-11-2011 / 09:33:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    47 !
       
    48 
       
    49 cmdlineOptionReport
       
    50 
       
    51     ^CmdLineOption new
       
    52         short: $r;
       
    53         long: '--report';
       
    54         description: 'Report to run';
       
    55         action:[:option |
       
    56             report := Smalltalk at: option asSymbol.
       
    57             report isNil ifTrue:[
       
    58                 Stderr nextPutLine:('ERROR: Report class %1 does not exist (forgot to load package)' bindWith: option).        
       
    59                 "/Smalltalk exit: 1.        
       
    60             ].
       
    61             report := report new.
       
    62             parser options addAll: (CmdLineOption optionsFor: report)
       
    63         ]
       
    64 
       
    65     "Created: / 06-11-2011 / 09:45:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    66 ! !
       
    67 
       
    68 !ReportRunner class methodsFor:'defaults'!
       
    69 
       
    70 allowDebugOption
       
    71 
       
    72     ^true
       
    73 
       
    74     "Created: / 21-07-2011 / 09:48:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    75 ! !
       
    76 
       
    77 !ReportRunner class methodsFor:'multiple applications support'!
       
    78 
       
    79 applicationRegistryPath
       
    80     "the key under which this application stores its process ID in the registry
       
    81      as a collection of path-components.
       
    82      i.e. if #('foo' 'bar' 'baz') is returned here, the current applications ID will be stored
       
    83      in HKEY_CURRENT_USER\Software\foo\bar\baz\CurrentID.
       
    84      (would also be used as a relative path for a temporary lock file under unix).
       
    85      Used to detect if another instance of this application is already running."
       
    86 
       
    87     ^ #('exept' 'smalltallx' 'hdreportrunner')
       
    88 
       
    89     "Modified: / 21-07-2011 / 09:43:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    90 !
       
    91 
       
    92 applicationUUID
       
    93     "answer an application-specific unique uuid.
       
    94      This is used as the name of some exclusive OS-resource, which is used to find out,
       
    95      if another instance of this application is already running.
       
    96      Under win32, a mutex is used; under unix, an exclusive file in the tempDir could be used."
       
    97 
       
    98     ^ '99f65c80-b375-11e0-86ad-0013e89c0459' asUUID
       
    99 
       
   100     "Modified: / 21-07-2011 / 09:44:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   101 ! !
       
   102 
       
   103 !ReportRunner class methodsFor:'startup'!
       
   104 
       
   105 setupToolsForDebug
       
   106 
       
   107     super setupToolsForDebug.
       
   108     debugging := true.
       
   109 
       
   110     "Created: / 06-11-2011 / 22:06:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   111 ! !
       
   112 
       
   113 !ReportRunner class methodsFor:'startup-to be redefined'!
       
   114 
       
   115 main:argv 
       
   116 
       
   117     "Process command line arguments"
       
   118     parser := CmdLineParser new.
       
   119     [               
       
   120         parser parse: argv for: self.        
       
   121     ] on: Error do:[:ex|
       
   122         Stderr nextPutLine:'Error when processing options: ', ex description.
       
   123         debugging ifFalse:[
       
   124             Stderr nextPutLine:'Exiting'.
       
   125             Smalltalk exit:1.
       
   126         ] ifTrue:[
       
   127             ex pass
       
   128         ]        
       
   129     ].
       
   130 
       
   131     [
       
   132         report run.
       
   133         debugging ifFalse:[
       
   134             Smalltalk exit:0.
       
   135         ].
       
   136     ] on: Error do:[:ex|
       
   137         Stderr nextPutAll:'Error when running tests: '.
       
   138         Stderr nextPutAll:ex description; cr.
       
   139         ex suspendedContext printAllOn:Stderr.
       
   140         debugging ifFalse:[
       
   141             Smalltalk exit:1.
       
   142         ] ifTrue:[
       
   143             ex pass
       
   144         ]
       
   145     ]
       
   146 
       
   147     "Modified: / 07-11-2011 / 09:26:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   148 !
       
   149 
       
   150 old_main:argv 
       
   151     |argc reports outputDir i|
       
   152 
       
   153     argc := argv size.
       
   154     outputDir := Smalltalk commandLineArgumentNamed:'-o'.
       
   155     outputDir 
       
   156         ifNil:[outputDir := Smalltalk commandLineArgumentNamed:'--out-dir'.].
       
   157     outputDir 
       
   158         ifNotNil:[
       
   159             outputDir asFilename exists ifFalse:[
       
   160                 outputDir asFilename recursiveMakeDirectory
       
   161             ].
       
   162             Report outputDir:outputDir.
       
   163         ].
       
   164     self 
       
   165         verboseInfo:'Report dir: ' , (Smalltalk at:#'Builder::Report:OutputDir') asString.
       
   166     reports := OrderedCollection new.
       
   167     i := 1.
       
   168     [
       
   169         [
       
   170             i := argv indexOf:'-r' startingAt:i.
       
   171             i ~~ 0 and:[i < argc]
       
   172         ] whileTrue:[
       
   173             |reportName formatName report|
       
   174 
       
   175             reportName := argv at:i + 1.
       
   176             i := i + 2.
       
   177             (report := Smalltalk at:reportName asSymbol) 
       
   178                 ifNil:[
       
   179                     Stderr
       
   180                         nextPutLine:'No class for report named ' , reportName;
       
   181                         nextPutLine:'Ignoring'
       
   182                 ]
       
   183                 ifNotNil:[reports add:(report := report new)].
       
   184             "Check for format"
       
   185             i := argv indexOf:'-F' startingAt:i.
       
   186             i ~~ 0 ifTrue:[
       
   187                 formatName := argv at:i + 1.
       
   188                 i := i + 2.
       
   189                 report format: formatName asSymbol.
       
   190             ].
       
   191         ].
       
   192         i := 1.
       
   193         [
       
   194             i := argv indexOf:'-p' startingAt:i.
       
   195             i ~~ 0 and:[i < argc]
       
   196         ] whileTrue:[
       
   197             |pkg|
       
   198 
       
   199             pkg := argv at:i + 1.
       
   200             i := i + 2.
       
   201             reports do:[:report |
       
   202                                 self verboseInfo: 
       
   203                                         ('Running %1 for package %2' bindWith: report name with: pkg).
       
   204                 report runPackage:pkg
       
   205             ]
       
   206         ].
       
   207         Smalltalk isStandAloneApp ifTrue:[
       
   208             Smalltalk exit:0.
       
   209         ]
       
   210     ] on:Error
       
   211             do:[:ex | 
       
   212         Stderr nextPutAll:'Error when running tests: '.
       
   213         Stderr
       
   214             nextPutAll:ex description;
       
   215             cr.
       
   216         ex suspendedContext printAllOn:Stderr.
       
   217         Smalltalk isHeadless ifTrue:[
       
   218             Smalltalk exit:1.
       
   219         ] ifFalse:[
       
   220             ex pass
       
   221         ]
       
   222     ]
       
   223 
       
   224     "Modified: / 06-10-2011 / 23:33:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   225     "Created: / 06-11-2011 / 21:53:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   226 ! !
       
   227 
       
   228 !ReportRunner class methodsFor:'documentation'!
       
   229 
       
   230 version
       
   231     ^ '$Header$'
       
   232 !
       
   233 
       
   234 version_CVS
       
   235     ^ '$Header$'
       
   236 !
       
   237 
       
   238 version_SVN
       
   239     ^ '§Id: Builder__ReportRunner.st 289 2011-11-10 15:39:10Z vranyj1 §'
       
   240 ! !
       
   241 
       
   242 ReportRunner initialize!