--- a/Class.st Thu Jul 09 21:49:04 2020 +0100
+++ b/Class.st Thu Jul 09 22:41:21 2020 +0100
@@ -2,6 +2,7 @@
COPYRIGHT (c) 1989 by Claus Gittinger
COPYRIGHT (c) 2009-2010 Jan Vrany
COPYRIGHT (c) 2015-2016 Jan Vrany
+ COPYRIGHT (c) 2020 LabWare
All Rights Reserved
This software is furnished under a license and may be used
@@ -64,6 +65,7 @@
COPYRIGHT (c) 1989 by Claus Gittinger
COPYRIGHT (c) 2009-2010 Jan Vrany
COPYRIGHT (c) 2015-2016 Jan Vrany
+ COPYRIGHT (c) 2020 LabWare
All Rights Reserved
This software is furnished under a license and may be used
@@ -149,6 +151,7 @@
"
! !
+
!Class class methodsFor:'accessing-flags'!
tryLocalSourceFirst
@@ -501,6 +504,7 @@
+
!Class methodsFor:'Compatibility-Dolphin'!
defaultCategoryForDolphinClasses
@@ -5448,137 +5452,41 @@
sourceStreamFor:source
"return an open stream on a sourcefile, nil if that is not available"
- |owner sourceStream sourceCodeManager validated guessedFileName sep mod dir|
+ |owner localStream sourceStream sourceCodeManager |
(owner := self owningClass) notNil ifTrue:[^ owner sourceStreamFor:source].
- validated := false.
-
- "/
- "/ if there is no SourceCodeManager,
- "/ or TryLocalSourceFirst is true,
- "/ look in standard places first
- "/
- "JV@2011-12-08:
- (i) first check TryLocalSourceFirst, this avoids useless call to
- #sourceCodeManagerFromBinaryRevision when TryLocalSourceFirst is
- set (for whatever reason)
- (ii) do NOT ask source code manager during system startup - source code
- managers are not configured anyway!! Also, avoids hangups during
- startup when CVSROOT is set, but server is unreacheable.
- CAVEAT: When somebody modifies the code after compilation and methods
- are recompiled during startup (for whatever reason), a bad code may
- used, compilation may fail. However, it may happen anyway as SCM's
- are not yet configured so the system may use wrong one. Moreover,
- the source from which the class is compiled may not be the one in
- repository. I (JV) think this is a good, less confusing compromise.
- "
- (TryLocalSourceFirst == true
- or:[Smalltalk isInitialized not
- or: [(sourceCodeManager := self sourceCodeManagerFromBinaryRevision) isNil]])
- ifTrue:[
- sourceStream := self localSourceStreamFor:source.
- ].
-
- sourceStream isNil ifTrue:[
- "/ mhmh - still no source file.
- "/ If there is a SourceCodeManager, ask it to acquire the
- "/ source for my class and return an open stream on it.
- "/ If that one does not know about the source, look in
- "/ standard places.
-
- sourceCodeManager notNil ifTrue:[
- classFilename ~= source ifTrue:[
- package notNil ifTrue:[
- sep := package indexOfAny:'/\:'.
- sep ~~ 0 ifTrue:[
- | sourceFileName |
-
-
- mod := package copyTo:sep - 1.
- dir := package copyFrom:sep + 1.
- sourceFileName := (source includes: Filename separator) ifTrue:[ source asFilename baseName ] ifFalse:[ source ].
- sourceStream := sourceCodeManager streamForClass:nil fileName:sourceFileName revision:(self binaryRevision) directory:dir module:mod cache:true.
- ]
+
+ "/ First, try local source, this is much quicker to access as one does
+ "/ not have to go through SCM (which is slowish)
+ sourceStream := localStream := self localSourceStreamFor:source.
+ sourceStream notNil ifTrue: [
+ (self validateSourceStream:sourceStream) ifTrue: [
+ ^ sourceStream
+ ] ifFalse: [
+ sourceStream := nil.
+ ].
+ ].
+
+ "/ Hmm, no local source or it is invalid. Perhaps it was compiled
+ "/ changed later. Try to extract source from SCM.
+ (Smalltalk isInitialized and:[(sourceCodeManager := self sourceCodeManagerFromBinaryRevision) notNil]) ifTrue: [
+ sourceStream := sourceCodeManager getSourceStreamFor: self.
+ sourceStream notNil ifTrue: [
+ (self validateSourceStream:sourceStream) ifTrue: [
+ localStream notNil ifTrue:[
+ localStream close
].
- ].
- sourceStream isNil ifTrue:[
- classFilename isNil ifTrue:[
- guessedFileName := (Smalltalk fileNameForClass:self) , '.st'.
- ].
- source asFilename baseName = (classFilename ? guessedFileName) asFilename baseName ifTrue:[
- sourceStream := sourceCodeManager getSourceStreamFor:self.
- ]
- ].
- sourceStream notNil ifTrue:[
- (self validateSourceStream:sourceStream) ifFalse:[
- ('Class [info]: repositories source for "%1" is invalid.' bindWith:self theNonMetaclass name) errorPrintCR.
- sourceStream close.
- sourceStream := nil
- ] ifTrue:[
- validated := true.
- ].
- ].
- ]
- ].
-
- sourceStream isNil ifTrue:[
- "/
- "/ hard case - there is no source file for this class
- "/ (in the source-dir-path).
- "/
-
- "/
- "/ look if my binary is from a dynamically loaded module,
- "/ and, if so, look in the modules directory for the
- "/ source file.
- "/
- ObjectFileLoader notNil ifTrue:[
- ObjectFileLoader loadedObjectHandlesDo:[:h |
- |f classes|
-
- sourceStream isNil ifTrue:[
- (classes := h classes) notEmptyOrNil ifTrue:[
- (classes includes:self) ifTrue:[
- f := h pathName.
- f := f asFilename directory.
- f := f construct:source.
- f exists ifTrue:[
- sourceStream := f readStreamOrNil.
- ].
- ].
- ].
- ]
+ ^ sourceStream
+ ] ifFalse: [
+ sourceStream close.
+ sourceStream := nil.
].
].
].
- "/
- "/ try along sourcePath
- "/
- sourceStream isNil ifTrue:[
- sourceStream := self localSourceStreamFor:source.
- ].
-
- "/
- "/ final chance: try current directory
- "/
- sourceStream isNil ifTrue:[
- sourceStream := source asFilename readStreamOrNil.
- ].
-
- (sourceStream notNil and:[validated not]) ifTrue:[
- (self validateSourceStream:sourceStream) ifFalse:[
- ('Class [warning]: source for "%1" is invalid or stripped. Take care.' bindWith:self theNonMetaclass name) errorPrintCR.
- sourceStream close.
- sourceStream := nil
- ].
- ].
-"/ (sourceStream notNil and:[sourceStream isFileStream]) ifTrue:[
-"/ guessedFileName notNil ifTrue:[
-"/ self setClassFilename:(aStream pathName asFilename baseName).
-"/ ]
-"/ ].
- ^ sourceStream
+ "/ Oops, no valid source? Return local source if any and issue warning...
+ Logger warning: 'Source for "%1" is invalid or stripped. Take care!!' with:self theNonMetaclass name.
+ ^ localStream
"
Object sourceStream
@@ -5590,6 +5498,7 @@
"Modified: / 22-04-1998 / 19:20:50 / ca"
"Modified: / 05-11-2001 / 16:36:30 / cg"
"Modified: / 07-09-2016 / 09:01:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified (comment): / 09-07-2020 / 22:11:24 / Jan Vrany <jan.vrany@labware.com>"
!
updateVersionMethodFor:newRevisionString