Class.st
changeset 1765 64e428dbb53d
parent 1759 5b7c001edc06
child 1766 5c07f58a54c9
equal deleted inserted replaced
1764:c11fdbab616c 1765:64e428dbb53d
   376 !
   376 !
   377 
   377 
   378 revisionStringFromSource:aMethodSourceString
   378 revisionStringFromSource:aMethodSourceString
   379     "extract a revision string from a methods source string"
   379     "extract a revision string from a methods source string"
   380 
   380 
   381     |lines|
   381     |lines line|
   382 
   382 
   383     lines := aMethodSourceString asCollectionOfLines.
   383     lines := aMethodSourceString asCollectionOfLines.
   384     lines do:[:l |
   384     lines do:[:l |
   385         |i|
   385         |i|
   386 
   386 
   387         i := l indexOfSubCollection:'$Header: '.
   387         i := l indexOfSubCollection:'$Header: '.
   388         i ~~ 0 ifTrue:[
   388         i ~~ 0 ifTrue:[
   389             ^ l copyFrom:i
   389             line := l copyFrom:i.
       
   390             i := line lastIndexOf:$$.
       
   391             i > 1 ifTrue:[
       
   392                 line := line copyTo:i.
       
   393             ].
       
   394             ^ line
   390         ]
   395         ]
   391     ].
   396     ].
   392     ^ nil
   397     ^ nil
   393 
   398 
   394     "Created: 15.10.1996 / 18:57:57 / cg"
   399     "Created: 15.10.1996 / 18:57:57 / cg"
       
   400     "Modified: 16.10.1996 / 16:54:40 / cg"
   395 ! !
   401 ! !
   396 
   402 
   397 !Class class methodsFor:'queries'!
   403 !Class class methodsFor:'queries'!
   398 
   404 
   399 isBuiltInClass
   405 isBuiltInClass
  3938         "/ if that one does not know about the source, look in
  3944         "/ if that one does not know about the source, look in
  3939         "/ standard places
  3945         "/ standard places
  3940 
  3946 
  3941         mgr notNil ifTrue:[
  3947         mgr notNil ifTrue:[
  3942             aStream := mgr getSourceStreamFor:self.
  3948             aStream := mgr getSourceStreamFor:self.
       
  3949 
       
  3950             (self validateSourceStream:aStream) ifFalse:[
       
  3951                 ('CLASS: mgr source for ' , name , ' corrupted - try local file') infoPrintCR.
       
  3952                 aStream close.
       
  3953                 aStream := nil
       
  3954             ].
       
  3955 
  3943             aStream isNil ifTrue:[
  3956             aStream isNil ifTrue:[
  3944                 fileName := Smalltalk getSourceFileName:source.
  3957                 fileName := Smalltalk getSourceFileName:source.
  3945                 fileName notNil ifTrue:[
  3958                 fileName notNil ifTrue:[
  3946                     aStream := fileName asFilename readStream.
  3959                     aStream := fileName asFilename readStream.
  3947                 ]
  3960                 ]
  3963      Clock sourceStream
  3976      Clock sourceStream
  3964      Autoload sourceStream
  3977      Autoload sourceStream
  3965     "
  3978     "
  3966 
  3979 
  3967     "Created: 10.11.1995 / 21:05:13 / cg"
  3980     "Created: 10.11.1995 / 21:05:13 / cg"
  3968     "Modified: 15.10.1996 / 18:59:53 / cg"
  3981     "Modified: 16.10.1996 / 16:56:06 / cg"
  3969 !
  3982 !
  3970 
  3983 
  3971 updateVersionMethodFor:newRevisionString
  3984 updateVersionMethodFor:newRevisionString
  3972     "helper for the checkin procedure.
  3985     "helper for the checkin procedure.
  3973      Update my #version method, to now return newRevisionString."
  3986      Update my #version method, to now return newRevisionString."
  3999 
  4012 
  4000     ^ true
  4013     ^ true
  4001 
  4014 
  4002     "Created: 7.12.1995 / 20:42:22 / cg"
  4015     "Created: 7.12.1995 / 20:42:22 / cg"
  4003     "Modified: 15.10.1996 / 18:59:58 / cg"
  4016     "Modified: 15.10.1996 / 18:59:58 / cg"
       
  4017 !
       
  4018 
       
  4019 validateSourceStream:aStream
       
  4020     "check if aStream really contains my source.
       
  4021      This is done by checking the version methods return value
       
  4022      against the version string as contained in the version method"
       
  4023 
       
  4024     |cls meta cannotCheck versionMethod info
       
  4025      versionFromCode versionFromSource oldPos pos src rev|
       
  4026 
       
  4027     self isMeta ifTrue:[
       
  4028         meta := self. cls := self soleInstance
       
  4029     ] ifFalse:[
       
  4030         cls := self. meta := self class
       
  4031     ].
       
  4032 
       
  4033     cannotCheck := false.
       
  4034 
       
  4035     versionMethod := meta compiledMethodAt:#version.
       
  4036     (versionMethod isNil 
       
  4037     or:[versionMethod isExecutable not]) ifTrue:[
       
  4038         versionMethod := cls compiledMethodAt:#version.
       
  4039         (versionMethod isNil
       
  4040         or:[versionMethod isExecutable not]) ifTrue:[
       
  4041 "/ 'no version method' printCR.
       
  4042             cannotCheck := true.
       
  4043         ]
       
  4044     ].
       
  4045 
       
  4046     "/
       
  4047     "/ if its a method returning the string,
       
  4048     "/ thats the returned value
       
  4049     "/
       
  4050     versionFromCode := cls version.
       
  4051     versionFromCode isString ifFalse:[
       
  4052 "/ 'version method does not return a string' printCR.
       
  4053         cannotCheck := true
       
  4054     ].
       
  4055 
       
  4056     "/
       
  4057     "/ if its a method consisting of a comment only
       
  4058     "/ extract it - this may lead to a recursive call
       
  4059     "/ to myself (thats what the #isRecursive is for)
       
  4060     "/ in case we need to access the source code manager
       
  4061     "/ for the source ...
       
  4062     "/
       
  4063     pos := versionMethod sourcePosition.
       
  4064     pos isInteger ifFalse:[
       
  4065 "/ 'no source position for version-method' printCR.
       
  4066         cannotCheck := true
       
  4067     ].
       
  4068 
       
  4069     cannotCheck ifTrue:[
       
  4070         'CLASS: cannot validate source; trusting source' infoPrintCR.
       
  4071         ^ true
       
  4072     ].
       
  4073 
       
  4074     oldPos := aStream position.
       
  4075     aStream position:pos.
       
  4076     src := aStream nextChunk.
       
  4077     aStream position:oldPos.
       
  4078 
       
  4079     (src isNil or:[src isEmpty]) ifTrue:[
       
  4080 "/ 'empty source for version-method' printCR.
       
  4081         ^ false
       
  4082     ].
       
  4083 
       
  4084     versionFromSource := Class revisionStringFromSource:src.
       
  4085     versionFromSource = versionFromCode ifTrue:[^ true].
       
  4086 
       
  4087     "/ mhmh - check my binary version ...
       
  4088 
       
  4089     info := Class revisionInfoFromString:versionFromSource.
       
  4090     info notNil ifTrue:[
       
  4091         rev := info at:#revision.
       
  4092         rev = self binaryRevision ifTrue:[^ true].
       
  4093     ].
       
  4094     ^ false
       
  4095 
       
  4096     "Modified: 16.10.1996 / 17:04:22 / cg"
  4004 ! !
  4097 ! !
  4005 
  4098 
  4006 !Class class methodsFor:'documentation'!
  4099 !Class class methodsFor:'documentation'!
  4007 
  4100 
  4008 version
  4101 version
  4009     ^ '$Header: /cvs/stx/stx/libbasic/Class.st,v 1.189 1996-10-15 20:21:04 cg Exp $'
  4102     ^ '$Header: /cvs/stx/stx/libbasic/Class.st,v 1.190 1996-10-16 16:06:17 cg Exp $'
  4010 ! !
  4103 ! !
  4011 Class initialize!
  4104 Class initialize!