initial checkin
authorClaus Gittinger <cg@exept.de>
Wed, 21 Dec 2011 19:42:42 +0100
changeset 2653 ae32c052f8a1
parent 2652 f1faa96b62ac
child 2654 6cb5bc656e8c
initial checkin
FileBasedSourceCodeManager.st
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/FileBasedSourceCodeManager.st	Wed Dec 21 19:42:42 2011 +0100
@@ -0,0 +1,347 @@
+"
+ COPYRIGHT (c) 2011 by Claus Gittinger
+              All Rights Reserved
+
+ This software is furnished under a license and may be used
+ only in accordance with the terms of that license and with the
+ inclusion of the above copyright notice.   This software may not
+ be provided or otherwise made available to, or used by, any
+ other person.  No title to or ownership of the software is
+ hereby transferred.
+"
+"{ Package: 'stx:libbasic3' }"
+
+AbstractSourceCodeManager subclass:#FileBasedSourceCodeManager
+	instanceVariableNames:''
+	classVariableNames:'Verbose RepositoryPath ModulePathes'
+	poolDictionaries:''
+	category:'System-SourceCodeManagement'
+!
+
+!FileBasedSourceCodeManager class methodsFor:'documentation'!
+
+copyright
+"
+ COPYRIGHT (c) 2011 by Claus Gittinger
+              All Rights Reserved
+
+ This software is furnished under a license and may be used
+ only in accordance with the terms of that license and with the
+ inclusion of the above copyright notice.   This software may not
+ be provided or otherwise made available to, or used by, any
+ other person.  No title to or ownership of the software is
+ hereby transferred.
+"
+!
+
+documentation
+"
+    Unfinished.
+
+    A simple file based sourceCodeManager, which saves versions in a local directory.
+    Versions will be stored as filename.st.vNr (i.e. Foo.st.1, Foo.st.2, etc.)
+    
+    [author:]
+        Claus Gittinger
+"
+! !
+
+!FileBasedSourceCodeManager class methodsFor:'accessing'!
+
+knownModules
+    "return the modules, we currently know"
+
+    ^ ModulePathes keys
+
+    "Modified: / 21-12-2011 / 14:54:53 / cg"
+!
+
+repositoryPath
+    "return the path of the default repository"
+
+    ^ RepositoryPath
+
+    "Created: / 21-12-2011 / 14:55:12 / cg"
+! !
+
+!FileBasedSourceCodeManager class methodsFor:'queries'!
+
+enabled
+    ^ true "/ false.
+
+    "Created: / 21-12-2011 / 17:53:34 / cg"
+!
+
+isContainerBased
+    "true, if the SCM uses some kind of source container (,v files).
+     False, if it is like a database or filesystem."
+
+    ^ false
+
+    "Created: / 21-12-2011 / 18:53:55 / cg"
+!
+
+isResponsibleForPackage:aString
+
+    | id |
+
+    "JV@2011-07-09: The real check is too slow. Cache needed here"
+    ^true.
+
+"/    id := aString asPackageId. 
+"/    ^self checkForExistingModule: id module directory: id directory.
+
+    "Created: / 09-07-2011 / 14:32:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+managerTypeName
+    ^ 'FileRepository'
+
+    "Created: / 16-08-2006 / 11:05:56 / cg"
+!
+
+nameOfVersionMethodForExtensions
+    ^ #'extensionsVersion_FileRepository'
+
+    "Modified: / 21-12-2011 / 13:02:45 / cg"
+!
+
+nameOfVersionMethodInClasses
+    ^ #'version_FileRepository'
+
+    "Modified: / 21-12-2011 / 13:02:52 / cg"
+!
+
+revisionInfoFromString:aString
+    "{ Pragma: +optSpace }"
+
+    ^ nil
+
+    "Created: / 21-12-2011 / 14:50:12 / cg"
+!
+
+settingsApplicationClass
+    "link to my settings application (needed for the settings dialog"
+
+    ^ FileBasedSourceCodeManagementSettingsAppl
+
+    "Created: / 19-04-2011 / 12:43:29 / cg"
+    "Modified: / 21-12-2011 / 13:02:58 / cg"
+!
+
+supportsCheckinLogMessages
+    "no, log-messages are not supported (I am too stupid)"
+
+    ^ false
+
+    "Created: / 21-12-2011 / 18:02:42 / cg"
+! !
+
+!FileBasedSourceCodeManager class methodsFor:'saving'!
+
+savePreferencesOn:aStream
+"/    aStream nextPutLine:'CVSSourceCodeManager notNil ifTrue:['.
+"/    self repositoryInfoPerModule notEmptyOrNil ifTrue:[
+"/        aStream nextPutLine:'    CVSSourceCodeManager repositoryInfoPerModule:' , self repositoryInfoPerModule storeString , '.'.
+"/    ].
+"/    CVSExecutable notNil ifTrue:[
+"/        aStream nextPutLine:'    CVSSourceCodeManager cvsExecutable:' , CVSExecutable storeString , '.'.
+"/    ].
+"/    (Smalltalk at:#SourceCodeManager) == self ifTrue:[
+"/        aStream nextPutLine:'    Smalltalk at:#SourceCodeManager put: CVSSourceCodeManager.'.
+"/        aStream nextPutLine:'    CVSSourceCodeManager initializeForRepository:' , self repositoryName storeString , '.'.
+"/    ].
+"/    aStream nextPutLine:'].'.
+
+    "Created: / 09-11-2006 / 15:09:25 / cg"
+    "Modified: / 21-12-2011 / 13:03:30 / cg"
+! !
+
+!FileBasedSourceCodeManager class methodsFor:'source code administration'!
+
+checkForExistingContainer:fileName inModule:moduleName directory:dirName
+    ^ self checkForExistingModule:moduleName directory:dirName
+
+    "Created: / 21-12-2011 / 17:56:23 / cg"
+!
+
+checkForExistingModule:moduleDir
+    "check for a package directory to be present"
+
+    |dir|
+
+    dir := self moduleDirectoryFor:moduleDir.
+    ^ dir exists
+
+    "Created: / 21-12-2011 / 18:37:28 / cg"
+!
+
+checkForExistingModule:moduleDir directory:packageDir
+    "check for a package directory to be present"
+
+    |dir|
+
+    dir := self packageDirectoryForModule:moduleDir package:packageDir.
+    ^ dir exists
+
+    "Created: / 21-12-2011 / 18:03:33 / cg"
+!
+
+checkinClass:aClass fileName:classFileName directory:packageDir module:moduleDir source:sourceFile logMessage:logMessage force:force
+    "Return true if ok, false if not."
+
+    |targetDir newestRevision newRevision newFile packageMode filter outStream|
+
+    targetDir := self packageDirectoryForModule:moduleDir package:packageDir.
+
+    (targetDir filesMatching:(classFileName,'_*')) do:[:eachVersionFile |
+        |versionString|
+
+        versionString := eachVersionFile copyFrom:(classFileName size + 2).
+        (newestRevision isNil 
+        or:[ self isRevision:versionString after:newestRevision ]) ifTrue:[
+            newestRevision := versionString
+        ].
+    ].
+
+    newestRevision isNil ifTrue:[
+        newRevision := '1'
+    ] ifFalse:[
+        newRevision := self revisionAfter:newestRevision
+    ].
+    newFile := (targetDir construct:classFileName,'_',newRevision printString).
+
+    self updateVersionMethodOf:aClass for:(self revisionStringFor:aClass inModule:moduleDir directory:packageDir container:classFileName revision:newRevision).
+
+    packageMode := self checkMethodPackagesOf:aClass.
+    packageMode == #base ifTrue:[
+        filter := [:mthd | mthd package = aClass package].
+    ].
+
+    [
+        outStream := newFile writeStream.
+    ] on:FileStream openErrorSignal do:[:ex|
+        self reportError:('fileout failed').
+        ^ false
+    ].
+
+    Method flushSourceStreamCache.
+    Class fileOutErrorSignal handle:[:ex |
+        outStream close.
+        newFile delete.
+        self reportError:('fileout failed (',ex description,')').
+        ^ false
+    ] do:[
+        self 
+            fileOutSourceCodeOf:aClass 
+            on:outStream 
+            withTimeStamp:false 
+            withInitialize:true 
+            withDefinition:true
+            methodFilter:filter.
+    ].
+    outStream close.
+
+    newFile exists ifFalse:[
+        self reportError:'fileout failed'.
+        ^ false.
+    ].
+
+    ^ true
+
+    "Created: / 21-12-2011 / 19:01:07 / cg"
+!
+
+createModule:moduleDir
+    "create a module directory"
+
+    |dir|
+
+    dir := self moduleDirectoryFor:moduleDir.
+    dir recursiveMakeDirectory.
+    ^ dir exists.
+
+    "Created: / 21-12-2011 / 18:38:22 / cg"
+!
+
+createModule:moduleDir directory:packageDir
+    "create a package directory"
+
+    |dir|
+
+    dir := self packageDirectoryForModule:moduleDir package:packageDir.
+    dir recursiveMakeDirectory.
+    ^ dir exists.
+
+    "Created: / 21-12-2011 / 18:44:20 / cg"
+!
+
+initialRevisionStringFor:aClass inModule:moduleDir directory:packageDir container:fileName
+    "return a string usable as initial revision string"
+
+    ^ self 
+        revisionStringFor:aClass 
+        inModule:moduleDir 
+        directory:packageDir 
+        container:fileName 
+        revision:'1'
+
+    "Created: / 21-12-2011 / 18:14:03 / cg"
+!
+
+moduleDirectoryFor:moduleDir
+    "a modules directory as filename"
+
+    |root|
+
+    ModulePathes notNil ifTrue:[
+        root := ModulePathes at:moduleDir ifAbsent:nil.
+    ].
+    root isNil ifTrue:[
+        root := RepositoryPath.
+    ].
+    root isNil ifTrue:[
+        RepositoryPath := root := './versions'.
+    ].
+
+    ^ (root asFilename construct:moduleDir)
+
+    "Created: / 21-12-2011 / 18:38:38 / cg"
+!
+
+packageDirectoryForModule:moduleDir package:package
+    "a packages directory as filename"
+
+    |dir|
+
+    dir := self moduleDirectoryFor:moduleDir.
+    ^ dir construct:package
+
+    "Created: / 21-12-2011 / 18:43:27 / cg"
+!
+
+revisionStringFor:aClass inModule:moduleDir directory:packageDir container:fileName revision:revisionString
+    "return a string usable as initial revision string"
+
+    ^ 'Path: %1/%2/%3, Version: %4'
+        bindWith:moduleDir
+        with:packageDir
+        with:fileName
+        with:revisionString
+
+    "Created: / 21-12-2011 / 19:33:33 / cg"
+! !
+
+!FileBasedSourceCodeManager class methodsFor:'documentation'!
+
+version
+    ^ '$Header: /cvs/stx/stx/libbasic3/FileBasedSourceCodeManager.st,v 1.1 2011-12-21 18:42:42 cg Exp $'
+!
+
+version_CVS
+    ^ '$Header: /cvs/stx/stx/libbasic3/FileBasedSourceCodeManager.st,v 1.1 2011-12-21 18:42:42 cg Exp $'
+!
+
+version_FileRepository
+    ^ '§Path: stx/libbasic3/FileBasedSourceCodeManager.st, Version: 6§'
+! !