Adde parent/child relationship to SCMAbstractPackageModel
authorJan Vrany <jan.vrany@fit.cvut.cz>
Mon, 03 Dec 2012 16:17:39 +0000
changeset 122 f72225c1f433
parent 121 f7cac3dae028
child 123 ee1cc926f489
Adde parent/child relationship to SCMAbstractPackageModel
common/SCMAbstractCommitTask.st
common/SCMAbstractFileoutLikeTask.st
common/SCMAbstractPackageModel.st
common/SCMAbstractPackageModelRegistry.st
common/common.rc
--- a/common/SCMAbstractCommitTask.st	Sat Dec 01 02:27:24 2012 +0000
+++ b/common/SCMAbstractCommitTask.st	Mon Dec 03 16:17:39 2012 +0000
@@ -161,23 +161,6 @@
     "Modified: / 17-11-2012 / 01:02:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
-doCommit: msg files: containers
-    "Actually commit the changes, To be overridden by subclasses"
-
-    self synchronized:[
-        self package workingCopy commit: msg files: containers.
-
-"/      "Update the working copy. We need svn info
-"/       to report commited revision"
-"/      (UpdateCommand new)
-"/          workingCopy:self workingCopy;
-"/          execute
-    ].
-
-    "Created: / 15-11-2012 / 09:39:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 15-11-2012 / 16:55:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
 doPrepareWorkingCopy
 
     self doPrepareWorkingCopy1.
@@ -209,6 +192,25 @@
     ].
 
     "Created: / 10-05-2012 / 17:08:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!SCMAbstractCommitTask methodsFor:'executing-private'!
+
+doCommit: msg files: containers
+    "Actually commit the changes, To be overridden by subclasses"
+
+    self synchronized:[
+        self package workingCopy commit: msg files: containers.
+
+"/      "Update the working copy. We need svn info
+"/       to report commited revision"
+"/      (UpdateCommand new)
+"/          workingCopy:self workingCopy;
+"/          execute
+    ].
+
+    "Created: / 15-11-2012 / 09:39:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 15-11-2012 / 16:55:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 doSanityChecks
--- a/common/SCMAbstractFileoutLikeTask.st	Sat Dec 01 02:27:24 2012 +0000
+++ b/common/SCMAbstractFileoutLikeTask.st	Mon Dec 03 16:17:39 2012 +0000
@@ -120,45 +120,6 @@
     suppressExtensions := aBoolean.
 ! !
 
-!SCMAbstractFileoutLikeTask methodsFor:'executing'!
-
-doFileOut
-    "Fileouts everything to the working copy"
-
-    self
-        doUpdateBuildSupportFiles;
-        doRenameContainers;
-        doFileOutPackageClasses;
-        doFileOutPackageExtensions;
-        doAddNewContainers;
-        doRemoveOldContainers.
-
-    "Created: / 10-05-2012 / 17:05:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 21-11-2012 / 00:43:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-doFileOutAll
-
-    self
-        doUpdateCode;
-        doFileOut.
-
-    "Created: / 17-08-2009 / 18:28:18 / Jan Vrany <vranyj1@fel.cvut.cz>"
-    "Modified: / 10-05-2012 / 17:06:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-doUpdateCode
-    "Updates project definitions and compiles version/copyright methods"
-
-    self
-        doInitStateVariables;
-        doCompileVersionMethods;
-        doCompileCopyrightMethods;
-        doUpdateProjectDefinition.
-
-    "Created: / 10-05-2012 / 17:04:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-! !
-
 !SCMAbstractFileoutLikeTask methodsFor:'executing - private'!
 
 doAddNewContainers
@@ -262,6 +223,31 @@
     "Modified: / 16-11-2012 / 23:17:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
+doFileOut
+    "Fileouts everything to the working copy"
+
+    self
+        doUpdateBuildSupportFiles;
+        doRenameContainers;
+        doFileOutPackageClasses;
+        doFileOutPackageExtensions;
+        doAddNewContainers;
+        doRemoveOldContainers.
+
+    "Created: / 10-05-2012 / 17:05:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 21-11-2012 / 00:43:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+doFileOutAll
+
+    self
+        doUpdateCode;
+        doFileOut.
+
+    "Created: / 17-08-2009 / 18:28:18 / Jan Vrany <vranyj1@fel.cvut.cz>"
+    "Modified: / 10-05-2012 / 17:06:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 doFileOutPackageClasses
     |klasses|
 
@@ -413,6 +399,18 @@
     "Modified: / 01-12-2012 / 00:24:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
+doUpdateCode
+    "Updates project definitions and compiles version/copyright methods"
+
+    self
+        doInitStateVariables;
+        doCompileVersionMethods;
+        doCompileCopyrightMethods;
+        doUpdateProjectDefinition.
+
+    "Created: / 10-05-2012 / 17:04:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 doUpdateProjectDefinition
     |prjClass|
 
--- a/common/SCMAbstractPackageModel.st	Sat Dec 01 02:27:24 2012 +0000
+++ b/common/SCMAbstractPackageModel.st	Mon Dec 03 16:17:39 2012 +0000
@@ -1,8 +1,8 @@
 "{ Package: 'stx:libscm/common' }"
 
 Object subclass:#SCMAbstractPackageModel
-	instanceVariableNames:'name repository repositoryRoot wc wcroot classesHasChanged
-		extensionsHasChanged'
+	instanceVariableNames:'name parent children repository repositoryRoot wc wcroot
+		classesHasChanged extensionsHasChanged'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'SCM-Common-StX'
@@ -14,7 +14,17 @@
 "
     A model of a Smalltalk/X package in repository. It knows how to
     map living classes to their respective file containers and can
-    fileout individual classes
+    fileout individual classes.
+
+    Package models forms a hiearchy that copies package hiearchy. The root
+    has no parent and represent a package which is located in the root
+    of the repository. Examples:
+
+    stx:libscm           ---> parent = nil,         repository = /home/.../build/stx/libscm, repositoryPath = '.'
+    stx:libscm/common    ---> parent = stx:libscm,  repository = /home/.../build/stx/libscm, repositoryPath = 'common'
+    stx:libscm/mercurial ---> parent = stx:libscm,  repository = /home/.../build/stx/libscm, repositoryPath = 'mercurial'
+
+    In this case, the HGRepository object is shared by all three package models.
 
     [author:]
         Jan Vrany <jan.vrany@fit.cvut.cz>
@@ -34,6 +44,12 @@
     self subclassResponsibility
 
     "Created: / 16-11-2012 / 19:52:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+new
+    "return an initialized instance"
+
+    ^ self basicNew initialize.
 ! !
 
 !SCMAbstractPackageModel methodsFor:'accessing'!
@@ -73,6 +89,25 @@
     "Modified: / 13-11-2012 / 23:22:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
+construct: aString
+    "Create a package model for subpackage named aString"
+
+    | normalizedName components package |
+
+    normalizedName := (aString includes: $:) ifTrue:[aString copyReplaceAll:$: with:$/] ifFalse:[aString].
+    ( normalizedName includes: $/) ifFalse:[
+        ^self childNamed: normalizedName.
+    ].
+
+    components := normalizedName tokensBasedOn: $/.
+    package := self.
+    components do:[:each|package := package childNamed: each].
+    ^package
+
+    "Created: / 16-11-2012 / 23:47:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 03-12-2012 / 14:04:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 definition
     ^LibraryDefinition definitionClassForPackage:self name createIfAbsent:true
 
@@ -104,6 +139,14 @@
     ^ name
 !
 
+parent
+    "Returns the parent model. See class documentation for details on parents"
+
+    ^parent
+
+    "Created: / 01-12-2012 / 17:56:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 repositoryRoot
     "Returns relative path within the repository root where the package
      content is located. Example: let's assume:
@@ -293,6 +336,28 @@
     "Modified: / 15-11-2012 / 00:47:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
+!SCMAbstractPackageModel methodsFor:'accessing-private'!
+
+childNamed: aString
+    "Returns a child name aString. If no such child
+     exist, create one"
+
+    | child nm|
+
+    children at: aString ifPresent:[:child|^child].
+    child := self class new.
+    nm := (name includes: $:) 
+        ifTrue: [name , '/' , aString]
+        ifFalse:[name , ':' , aString].
+    child setName: nm repository: repository.
+    child setParent: self.
+    children at: aString put: child.
+    ^child
+
+    "Created: / 01-12-2012 / 01:29:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 01-12-2012 / 18:11:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
 !SCMAbstractPackageModel methodsFor:'file out'!
 
 fileOutClass:cls
@@ -420,21 +485,70 @@
 
 !SCMAbstractPackageModel methodsFor:'initialization'!
 
-name: aSymbolOrPackageId repository: aRepository
+initialize
+    "Invoked when a new instance is created."
+
+    "/ please change as required (and remove this comment)
+    "/ name := nil.
+    "/ parent := nil.
+    children := Dictionary new.
+    "/ repository := nil.
+    "/ repositoryRoot := nil.
+    "/ wc := nil.
+    "/ wcroot := nil.
+    "/ classesHasChanged := nil.
+    "/ extensionsHasChanged := nil.
+
+    "/ super initialize.   -- commented since inherited method does nothing
+
+    "Modified: / 01-12-2012 / 18:02:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+setName: aSymbolOrPackageId repository: aRepository
     "Initializes the package. This method also MUST initialize 'repositoryRoot' instvar!!"
 
     ^self subclassResponsibility
 
-    "Created: / 14-11-2012 / 00:31:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified (comment): / 01-12-2012 / 02:04:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Created: / 01-12-2012 / 17:52:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
-wc: aSCMAbstractWorkingCopy 
+setNameComponents: aCollection repository: aRepository
+
+    | nm |
+    aCollection isEmpty ifTrue:[
+        self setName:'' repository: aRepository.
+        ^self.
+    ].
+    aCollection size == 1 ifTrue:[
+        self setName: aCollection first repository: aRepository.
+        ^self.
+    ].
+    nm := aCollection first , ':' , aCollection second.
+    aCollection size > 2 ifTrue:[
+        3 to: aCollection size do:[:i|
+            nm := nm , '/' , (aCollection at: i)
+        ].
+    ].
+    self setName: nm repository: aRepository.
+    ^self
+
+    "Created: / 03-12-2012 / 12:36:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+setParent: parentModel
+    "Sets the parent model. See class documentation for details on parents models"
+
+    ^parent := parentModel
+
+    "Created: / 01-12-2012 / 17:54:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 03-12-2012 / 14:05:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+setWorkingCopy: aSCMAbstractWorkingCopy 
     wc := aSCMAbstractWorkingCopy.
     wcroot := wc root / self repositoryRoot
 
-    "Created: / 14-11-2012 / 00:32:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 01-12-2012 / 02:04:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Created: / 01-12-2012 / 17:53:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !SCMAbstractPackageModel methodsFor:'private'!
--- a/common/SCMAbstractPackageModelRegistry.st	Sat Dec 01 02:27:24 2012 +0000
+++ b/common/SCMAbstractPackageModelRegistry.st	Mon Dec 03 16:17:39 2012 +0000
@@ -52,9 +52,10 @@
 !
 
 flush
-    self current flush
+    Current := nil.
 
     "Created: / 06-10-2012 / 21:52:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 03-12-2012 / 13:36:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 packageNamed: package
--- a/common/common.rc	Sat Dec 01 02:27:24 2012 +0000
+++ b/common/common.rc	Mon Dec 03 16:17:39 2012 +0000
@@ -25,7 +25,7 @@
       VALUE "LegalCopyright", "Copyright Jan Vrany 2012\0"
       VALUE "ProductName", "Smalltalk/X SCM Support Library\0"
       VALUE "ProductVersion", "6.2.3.0\0"
-      VALUE "ProductDate", "Sat, 01 Dec 2012 01:02:20 GMT\0"
+      VALUE "ProductDate", "Mon, 03 Dec 2012 16:13:03 GMT\0"
     END
 
   END