Class.st
branchjv
changeset 18084 ab5b38bd8f81
parent 18076 17106b5b6cee
parent 15610 cdec81bdc7a7
child 18092 4174aa84a870
equal deleted inserted replaced
18083:5558dc303721 18084:ab5b38bd8f81
   916 
   916 
   917     "the comment is either a string, or an integer specifying the
   917     "the comment is either a string, or an integer specifying the
   918      position within the classes sourcefile ...
   918      position within the classes sourcefile ...
   919     "
   919     "
   920     comment isNumber ifTrue:[
   920     comment isNumber ifTrue:[
   921 	classFilename notNil ifTrue:[
   921         classFilename notNil ifTrue:[
   922 	    stream := self sourceStream.
   922             stream := self sourceStream.
   923 	    stream notNil ifTrue:[
   923             stream notNil ifTrue:[
   924 		stream position1Based:comment.
   924                 stream position:comment-1.
   925 		string := String readFrom:stream onError:''.
   925                 string := String readFrom:stream onError:''.
   926 		stream close.
   926                 stream close.
   927 		^ string
   927                 ^ string
   928 	    ].
   928             ].
   929 	    ^ nil
   929             ^ nil
   930 	]
   930         ]
   931     ].
   931     ].
   932     ^ comment
   932     ^ comment
   933 
   933 
   934     "
   934     "
   935      Object comment
   935      Object comment
  3553     "the attribute is either a string, or an integer specifying the
  3553     "the attribute is either a string, or an integer specifying the
  3554      position within the classes sourcefile ..."
  3554      position within the classes sourcefile ..."
  3555 
  3555 
  3556     pos isNumber ifTrue:[
  3556     pos isNumber ifTrue:[
  3557 "/        classFilename notNil ifTrue:[
  3557 "/        classFilename notNil ifTrue:[
  3558 	    stream := self sourceStream.
  3558             stream := self sourceStream.
  3559 	    stream notNil ifTrue:[
  3559             stream notNil ifTrue:[
  3560 		stream position0Based:pos.
  3560                 stream position:pos.
  3561 		string := stream nextChunk.
  3561                 string := stream nextChunk.
  3562 		stream close.
  3562                 stream close.
  3563 		^ string
  3563                 ^ string
  3564 	    ].
  3564             ].
  3565 "/        ].
  3565 "/        ].
  3566 	^ nil
  3566         ^ nil
  3567     ].
  3567     ].
  3568 
  3568 
  3569     ^ pos
  3569     ^ pos
  3570 !
  3570 !
  3571 
  3571 
  5275 
  5275 
  5276     |cls meta cannotCheckReason versionMethod info
  5276     |cls meta cannotCheckReason versionMethod info
  5277      versionFromCode versionFromSource oldPos pos src rev|
  5277      versionFromCode versionFromSource oldPos pos src rev|
  5278 
  5278 
  5279     ValidateSourceOnlyOnce == true ifTrue:[
  5279     ValidateSourceOnlyOnce == true ifTrue:[
  5280 	ValidatedClasses notNil ifTrue:[
  5280         ValidatedClasses notNil ifTrue:[
  5281 	    (ValidatedClasses includes:self) ifTrue:[
  5281             (ValidatedClasses includes:self) ifTrue:[
  5282 		Transcript showCR:'trust validated'.
  5282                 Transcript showCR:'trust validated'.
  5283 		^ true
  5283                 ^ true
  5284 	    ].
  5284             ].
  5285 	] ifFalse:[
  5285         ] ifFalse:[
  5286 	    ValidatedClasses := WeakIdentitySet new.
  5286             ValidatedClasses := WeakIdentitySet new.
  5287 	].
  5287         ].
  5288     ].
  5288     ].
  5289 
  5289 
  5290     meta := self theMetaclass.
  5290     meta := self theMetaclass.
  5291     cls := self theNonMetaclass.
  5291     cls := self theNonMetaclass.
  5292 
  5292 
  5293     cannotCheckReason := nil.
  5293     cannotCheckReason := nil.
  5294 
  5294 
  5295     versionMethod := self findVersionMethod.
  5295     versionMethod := self findVersionMethod.
  5296     versionMethod isNil ifTrue:[
  5296     versionMethod isNil ifTrue:[
  5297 	cannotCheckReason := 'no valid version method'.
  5297         cannotCheckReason := 'no valid version method'.
  5298     ] ifFalse:[
  5298     ] ifFalse:[
  5299 	"/
  5299         "/
  5300 	"/ if its a method returning the string,
  5300         "/ if its a method returning the string,
  5301 	"/ thats the returned value
  5301         "/ thats the returned value
  5302 	"/
  5302         "/
  5303 	versionFromCode := versionMethod valueWithReceiver:cls arguments:#().
  5303         versionFromCode := versionMethod valueWithReceiver:cls arguments:#().
  5304 	versionFromCode isString ifFalse:[
  5304         versionFromCode isString ifFalse:[
  5305 	    cannotCheckReason := 'version method does not return a string'
  5305             cannotCheckReason := 'version method does not return a string'
  5306 	].
  5306         ].
  5307     ].
  5307     ].
  5308 
  5308 
  5309     versionMethod notNil ifTrue:[
  5309     versionMethod notNil ifTrue:[
  5310 	pos := versionMethod sourcePosition.
  5310         pos := versionMethod sourcePosition.
  5311 	pos isInteger ifFalse:[
  5311         pos isInteger ifFalse:[
  5312 	    "/ mhmh - either no version method,
  5312             "/ mhmh - either no version method,
  5313 	    "/ or updated due to a checkin.
  5313             "/ or updated due to a checkin.
  5314 	    "/ in any case, this should be a good source.
  5314             "/ in any case, this should be a good source.
  5315 
  5315 
  5316 	    ^ true.
  5316             ^ true.
  5317 	    "/ cannotCheckReason := 'no source position for version-method'
  5317             "/ cannotCheckReason := 'no source position for version-method'
  5318 	]
  5318         ]
  5319     ].
  5319     ].
  5320 
  5320 
  5321     cannotCheckReason notNil ifTrue:[
  5321     cannotCheckReason notNil ifTrue:[
  5322 	('Class [warning]: ' , cannotCheckReason , ' in ' , self name) infoPrintCR.
  5322         ('Class [warning]: ' , cannotCheckReason , ' in ' , self name) infoPrintCR.
  5323 	'Class [info]: cannot validate source; trusting source' infoPrintCR.
  5323         'Class [info]: cannot validate source; trusting source' infoPrintCR.
  5324 	^ true
  5324         ^ true
  5325     ].
  5325     ].
  5326 
  5326 
  5327     oldPos := aStream position.
  5327     oldPos := aStream position.
  5328     Stream positionErrorSignal handle:[:ex |
  5328     Stream positionErrorSignal handle:[:ex |
  5329 	'Class [info]: position error when accessing source' infoPrintCR.
  5329         'Class [info]: position error when accessing source' infoPrintCR.
  5330 	^ false
  5330         ^ false
  5331     ] do:[
  5331     ] do:[
  5332 	aStream position1Based:pos.
  5332         aStream position:pos-1.
  5333     ].
  5333     ].
  5334     src := aStream nextChunk.
  5334     src := aStream nextChunk.
  5335     aStream position:oldPos.
  5335     aStream position:oldPos.
  5336 
  5336 
  5337     (src isEmptyOrNil) ifTrue:[
  5337     (src isEmptyOrNil) ifTrue:[
  5338 	'Class [info]: empty source for version-method' infoPrintCR.
  5338         'Class [info]: empty source for version-method' infoPrintCR.
  5339 	^ false
  5339         ^ false
  5340     ].
  5340     ].
  5341     (src startsWith:'version') ifFalse:[
  5341     (src startsWith:'version') ifFalse:[
  5342 	'Class [info]: corrupted source (source does not correspond to binary)' infoPrintCR.
  5342         'Class [info]: corrupted source (source does not correspond to binary)' infoPrintCR.
  5343 	^ false
  5343         ^ false
  5344     ].
  5344     ].
  5345 
  5345 
  5346     versionFromSource := Class revisionStringFromSource:src.
  5346     versionFromSource := Class revisionStringFromSource:src.
  5347     versionFromSource = versionFromCode ifTrue:[
  5347     versionFromSource = versionFromCode ifTrue:[
  5348 	ValidatedClasses notNil ifTrue:[ ValidatedClasses add:self ].
  5348         ValidatedClasses notNil ifTrue:[ ValidatedClasses add:self ].
  5349 	^ true
  5349         ^ true
  5350     ].
  5350     ].
  5351 
  5351 
  5352     versionFromSource isNil ifTrue:[
  5352     versionFromSource isNil ifTrue:[
  5353 	'Class [info]: version-from source is nil' infoPrintCR.
  5353         'Class [info]: version-from source is nil' infoPrintCR.
  5354 	^ false
  5354         ^ false
  5355     ].
  5355     ].
  5356 
  5356 
  5357     "/ mhmh - check my binary version ...
  5357     "/ mhmh - check my binary version ...
  5358 
  5358 
  5359     info := Class revisionInfoFromString:versionFromSource.
  5359     info := Class revisionInfoFromString:versionFromSource.
  5360     info notNil ifTrue:[
  5360     info notNil ifTrue:[
  5361 	rev := info at:#revision.
  5361         rev := info at:#revision.
  5362 	rev = self binaryRevision ifTrue:[
  5362         rev = self binaryRevision ifTrue:[
  5363 	    ValidatedClasses notNil ifTrue:[ ValidatedClasses add:self ].
  5363             ValidatedClasses notNil ifTrue:[ ValidatedClasses add:self ].
  5364 	    ^ true
  5364             ^ true
  5365 	].
  5365         ].
  5366     ].
  5366     ].
  5367     'Class [info]: source-version is different from binaryRevision' infoPrintCR.
  5367     'Class [info]: source-version is different from binaryRevision' infoPrintCR.
  5368     ^ false
  5368     ^ false
  5369 
  5369 
  5370     "Modified: / 29-09-2011 / 14:29:55 / cg"
  5370     "Modified: / 29-09-2011 / 14:29:55 / cg"
  5644 ! !
  5644 ! !
  5645 
  5645 
  5646 !Class class methodsFor:'documentation'!
  5646 !Class class methodsFor:'documentation'!
  5647 
  5647 
  5648 version
  5648 version
  5649     ^ '$Header: /cvs/stx/stx/libbasic/Class.st,v 1.628 2013-07-12 13:56:43 cg Exp $'
  5649     ^ '$Header: /cvs/stx/stx/libbasic/Class.st,v 1.629 2013-08-10 11:14:10 stefan Exp $'
  5650 !
  5650 !
  5651 
  5651 
  5652 version_CVS
  5652 version_CVS
  5653     ^ '$Header: /cvs/stx/stx/libbasic/Class.st,v 1.628 2013-07-12 13:56:43 cg Exp $'
  5653     ^ '$Header: /cvs/stx/stx/libbasic/Class.st,v 1.629 2013-08-10 11:14:10 stefan Exp $'
  5654 !
  5654 !
  5655 
  5655 
  5656 version_HG
  5656 version_HG
  5657 
  5657 
  5658     ^ '$Changeset: <not expanded> $'
  5658     ^ '$Changeset: <not expanded> $'