Class.st
changeset 2958 ccfef4e0bd4a
parent 2955 6411d359b747
child 3002 0425e540f008
equal deleted inserted replaced
2957:46015145c398 2958:ccfef4e0bd4a
  1999      sourceFile may not be rewritten."
  1999      sourceFile may not be rewritten."
  2000 
  2000 
  2001     |baseName dirName fileNameString|
  2001     |baseName dirName fileNameString|
  2002 
  2002 
  2003     baseName := (Smalltalk fileNameForClass:self name).
  2003     baseName := (Smalltalk fileNameForClass:self name).
  2004     fileNameString := baseName , '.st'.
  2004     fileNameString := baseName asFilename withSuffix:'st'.
  2005 
  2005 
  2006     "
  2006     "
  2007      this test allows a smalltalk to be built without Projects/ChangeSets
  2007      this test allows a smalltalk to be built without Projects/ChangeSets
  2008     "
  2008     "
  2009     Project notNil ifTrue:[
  2009     Project notNil ifTrue:[
  2010         dirName := Project currentProjectDirectory
  2010         dirName := Project currentProjectDirectory
  2011     ] ifFalse:[
  2011     ] ifFalse:[
  2012         dirName := ''
  2012         dirName := Filename currentDirectory
  2013     ].
  2013     ].
  2014     fileNameString := dirName , fileNameString.
  2014     fileNameString := (dirName asFilename construct:fileNameString) name.
  2015 
  2015 
  2016     self fileOutAs:fileNameString.
  2016     self fileOutAs:fileNameString.
  2017 
  2017 
  2018 "/    "
  2018 "/    "
  2019 "/     add a change record; that way, administration is much easier,
  2019 "/     add a change record; that way, administration is much easier,
  2085      directory. Care is taken, to not clobber any existing file in
  2085      directory. Care is taken, to not clobber any existing file in
  2086      case of errors (for example: disk full). 
  2086      case of errors (for example: disk full). 
  2087      Also, since the classes methods need a valid sourcefile, the current 
  2087      Also, since the classes methods need a valid sourcefile, the current 
  2088      sourceFile may not be rewritten."
  2088      sourceFile may not be rewritten."
  2089 
  2089 
  2090     |aStream baseName dirName fileName newFileName needRename
  2090     |aStream fileName newFileName savFilename needRename
  2091      mySourceFileName sameFile s mySourceFileID anySourceRef|
  2091      mySourceFileName sameFile s mySourceFileID anySourceRef|
  2092 
  2092 
  2093     baseName := fileNameString asFilename baseName.
       
  2094     dirName := fileNameString asFilename directoryName.
       
  2095     fileName := fileNameString asFilename.
  2093     fileName := fileNameString asFilename.
  2096 
  2094 
  2097     "
  2095     "
  2098      if file exists, copy the existing to a .sav-file,
  2096      if file exists, copy the existing to a .sav-file,
  2099      create the new file as XXX.new-file,
  2097      create the new file as XXX.new-file,
  2147             ^ FileOutErrorSignal 
  2145             ^ FileOutErrorSignal 
  2148                 raiseRequestWith:fileNameString
  2146                 raiseRequestWith:fileNameString
  2149                 errorString:('may not overwrite sourcefile:', fileNameString)
  2147                 errorString:('may not overwrite sourcefile:', fileNameString)
  2150         ].
  2148         ].
  2151 
  2149 
  2152         fileName copyTo:('/tmp/' , baseName , '.sav').
  2150 	savFilename := Filename newTemporary.
  2153         newFileName := dirName , baseName , '.new'.
  2151         fileName copyTo:savFilename.
       
  2152         newFileName := fileName withSuffix:'new'.
  2154         needRename := true
  2153         needRename := true
  2155     ] ifFalse:[
  2154     ] ifFalse:[
  2156         newFileName := fileNameString.
  2155         newFileName := fileName.
  2157         needRename := false
  2156         needRename := false
  2158     ].
  2157     ].
  2159 
  2158 
  2160     aStream := FileStream newFileNamed:newFileName.
  2159     aStream := newFileName writeStream.
  2161     aStream isNil ifTrue:[
  2160     aStream isNil ifTrue:[
       
  2161 	savFilename notNil ifTrue:[
       
  2162 	    savFilename delete
       
  2163 	].
  2162         ^ FileOutErrorSignal 
  2164         ^ FileOutErrorSignal 
  2163                 raiseRequestWith:newFileName
  2165                 raiseRequestWith:newFileName
  2164                 errorString:('cannot create file:', newFileName)
  2166                 errorString:('cannot create file:', newFileName name)
  2165     ].
  2167     ].
  2166     self fileOutOn:aStream.
  2168     self fileOutOn:aStream.
  2167     aStream close.
  2169     aStream close.
  2168 
  2170 
  2169     "
  2171     "
  2170      finally, replace the old-file
  2172      finally, replace the old-file
  2171      be careful, if the old one is a symbolic link; in this case,
  2173      be careful, if the old one is a symbolic link; in this case,
  2172      we have to do a copy ...
  2174      we have to do a copy ...
  2173     "
  2175     "
  2174     needRename ifTrue:[
  2176     needRename ifTrue:[
  2175         newFileName asFilename copyTo:fileNameString.
  2177         newFileName copyTo:fileName.
  2176         newFileName asFilename delete
  2178         newFileName delete
       
  2179     ].
       
  2180     savFilename notNil ifTrue:[
       
  2181 	savFilename delete
  2177     ].
  2182     ].
  2178 
  2183 
  2179     "
  2184     "
  2180      add a change record; that way, administration is much easier,
  2185      add a change record; that way, administration is much easier,
  2181      since we can see in that changeBrowser, which changes have 
  2186      since we can see in that changeBrowser, which changes have 
  3259     ].
  3264     ].
  3260 
  3265 
  3261     sourceInfo isNil ifTrue:[^ nil].
  3266     sourceInfo isNil ifTrue:[^ nil].
  3262     components := sourceInfo asCollectionOfSubstringsSeparatedBy:$:.
  3267     components := sourceInfo asCollectionOfSubstringsSeparatedBy:$:.
  3263     components size == 0 ifTrue:[
  3268     components size == 0 ifTrue:[
  3264         moduleString := 'stx'.
  3269 "/        moduleString := 'stx'.
  3265         directoryString := libraryString := ''.
  3270 "/        directoryString := libraryString := ''.
  3266         ^ nil
  3271         ^ nil
  3267     ].
  3272     ].
  3268     components size == 1 ifTrue:[
  3273     components size == 1 ifTrue:[
  3269         "/ a single name given - the module becomes 'stx' or
  3274         "/ a single name given - the module becomes 'stx' or
  3270         "/ the very first directory component (if such a module exists).
  3275         "/ the very first directory component (if such a module exists).
  3337      MemoryMonitor packageSourceCodeInfo  
  3342      MemoryMonitor packageSourceCodeInfo  
  3338      ClockView packageSourceCodeInfo  
  3343      ClockView packageSourceCodeInfo  
  3339     "
  3344     "
  3340 
  3345 
  3341     "Created: 4.11.1995 / 20:36:53 / cg"
  3346     "Created: 4.11.1995 / 20:36:53 / cg"
  3342     "Modified: 8.9.1997 / 00:21:45 / cg"
  3347     "Modified: 19.9.1997 / 10:42:25 / cg"
  3343 !
  3348 !
  3344 
  3349 
  3345 revision
  3350 revision
  3346     "return the revision-ID of the class which corresponds to the
  3351     "return the revision-ID of the class which corresponds to the
  3347      rcs-id of the source to which this class is equivalent.
  3352      rcs-id of the source to which this class is equivalent.
  3829 ! !
  3834 ! !
  3830 
  3835 
  3831 !Class class methodsFor:'documentation'!
  3836 !Class class methodsFor:'documentation'!
  3832 
  3837 
  3833 version
  3838 version
  3834     ^ '$Header: /cvs/stx/stx/libbasic/Class.st,v 1.293 1997-09-18 23:00:35 stefan Exp $'
  3839     ^ '$Header: /cvs/stx/stx/libbasic/Class.st,v 1.294 1997-09-20 21:13:50 cg Exp $'
  3835 ! !
  3840 ! !