mercurial/HGRepositoriesResource.st
author Claus Gittinger <cg@exept.de>
Tue, 03 Jul 2018 09:41:04 +0200
branchcvs_MAIN
changeset 842 b5eb85f53c37
parent 511 ad2f56473052
child 515 d460ef249979
permissions -rw-r--r--
initial checkin

"
stx:libscm - a new source code management library for Smalltalk/X
Copyright (C) 2012-2015 Jan Vrany

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License. 

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
"
"{ Package: 'stx:libscm/mercurial' }"

TestResource subclass:#HGRepositoriesResource
	instanceVariableNames:'repositoryDirectory'
	classVariableNames:'HGRepositoriesArchiveDir'
	poolDictionaries:''
	category:'SCM-Mercurial-Tests'
!

!HGRepositoriesResource class methodsFor:'documentation'!

copyright
"
stx:libscm - a new source code management library for Smalltalk/X
Copyright (C) 2012-2015 Jan Vrany

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License. 

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
"
!

documentation
"
    This resouce provides some pre-created respositories to run tests
    against. 

    == test_repo_01 ========================================

            @  changeset:   4:6f88e1f44d9e
            |  tag:         tip
            |  user:        Jan Vrany <jan.vrany@fit.cvut.cz>
            |  date:        Wed Oct 17 13:20:53 2012 +0200
            |  summary:     Commit 4
            |
            o  changeset:   3:912a64597e4f
            |  user:        Jan Vrany <jan.vrany@fit.cvut.cz>
            |  date:        Wed Oct 17 13:20:38 2012 +0200
            |  summary:     Commit 3
            |
            o  changeset:   2:db43a5baa9ac
            |  user:        Jan Vrany <jan.vrany@fit.cvut.cz>
            |  date:        Wed Oct 17 13:20:18 2012 +0200
            |  summary:     Commit 2
            |
            o  changeset:   1:98087d77fbaa
            |  user:        Jan Vrany <jan.vrany@fit.cvut.cz>
            |  date:        Wed Oct 17 13:19:14 2012 +0200
            |  summary:     Commit 1
            |
            o  changeset:   0:98b9033d3bac
               user:        Jan Vrany <jan.vrany@fit.cvut.cz>
               date:        Wed Oct 17 13:18:37 2012 +0200
               summary:     Commit 0

    == test_repo_02 ========================================

            @    changeset:   5:f22945219f9b
            |\   tag:         tip
            | |  parent:      0:c81883a66d71
            | |  parent:      4:5bd21fb5eea8
            | |  user:        Jan Vrany <jan.vrany@fit.cvut.cz>
            | |  date:        Tue Nov 27 18:16:25 2012 +0000
            | |  summary:     Commit 5 (merged branch1)
            | |
            | o  changeset:   4:5bd21fb5eea8
            | |  branch:      branch1
            | |  parent:      1:60544c149e47
            | |  user:        Jan Vrany <jan.vrany@fit.cvut.cz>
            | |  date:        Tue Nov 27 18:15:31 2012 +0000
            | |  summary:     Commit 4
            | |
            | | o  changeset:   3:32d32dee719f
            | | |  branch:      branch2
            | | |  user:        Jan Vrany <jan.vrany@fit.cvut.cz>
            | | |  date:        Tue Nov 27 18:12:40 2012 +0000
            | | |  summary:     Commit 3 (branch2 is dead-end)
            | | |
            +---o  changeset:   2:d67d1ec9e26d
            | |    branch:      branch2
            | |    parent:      0:c81883a66d71
            | |    user:        Jan Vrany <jan.vrany@fit.cvut.cz>
            | |    date:        Tue Nov 27 18:12:03 2012 +0000
            | |    summary:     Commit 2 (create branch2 & modified file)
            | |
            | o  changeset:   1:60544c149e47
            |/   branch:      branch1
            |    user:        Jan Vrany <jan.vrany@fit.cvut.cz>
            |    date:        Tue Nov 27 18:10:36 2012 +0000
            |    summary:     Commit 1 (created branch1)
            |
            o  changeset:   0:c81883a66d71
               user:        Jan Vrany <jan.vrany@fit.cvut.cz>
               date:        Tue Nov 27 18:09:47 2012 +0000
               summary:     Commit 0

    == mocks_hg_p1 ========================================

            @  changeset:   1:847b035d9aed
            |  tag:         tip
            |  user:        Jan Vrany <jan.vrany@fit.cvut.cz>
            |  date:        Wed Jan 29 13:56:10 2014 +0000
            |  summary:     Package name and version_HG fixed
            |
            o  changeset:   0:99acfa83a3bf
               user:        Jan Vrany <jan.vrany@fit.cvut.cz>
               date:        Fri Nov 16 11:29:05 2012 +0000
               summary:     Initial commit

    == mocks_hg_p2 ========================================

            @  changeset:   3:9e9134b80dfa
            |  tag:         tip
            |  user:        Jan Vrany <jan.vrany@fit.cvut.cz>
            |  date:        Sat Dec 01 15:42:22 2012 +0000
            |  summary:     - MocksHgP2N2N21Foo
            |
            o  changeset:   2:84a2ca31f8d9
            |  user:        Jan Vrany <jan.vrany@fit.cvut.cz>
            |  date:        Sat Dec 01 15:42:04 2012 +0000
            |  summary:     - mocks_hg_p2_n2
            |
            o  changeset:   1:efa1cc55f9f9
            |  user:        Jan Vrany <jan.vrany@fit.cvut.cz>
            |  date:        Sat Dec 01 15:41:47 2012 +0000
            |  summary:     - MocksHgP2N1Foo
            |
            o  changeset:   0:a662a0c5d8dd
               user:        Jan Vrany <jan.vrany@fit.cvut.cz>
               date:        Sat Dec 01 15:41:22 2012 +0000
               summary:     - mocks_hg_p2


    == mocks_hg_p3 ========================================

            o  changeset:   2:54cd319e4818
            |  branch:      branch1
            |  tag:         tip
            |  parent:      0:01f38ab5d98c
            |  user:        Jan Vrany <jan.vrany@fit.cvut.cz>
            |  date:        Mon Jan 14 14:47:02 2013 +0000
            |  summary:     Branch 1
            |
            | o  changeset:   1:54db7f7bc5b0
            |/   user:        Jan Vrany <jan.vrany@fit.cvut.cz>
            |    date:        Mon Jan 14 14:43:07 2013 +0000
            |    summary:     changed:
            |
            @  changeset:   0:01f38ab5d98c
               user:        Jan Vrany <jan.vrany@fit.cvut.cz>
               date:        Mon Jan 14 14:07:24 2013 +0000
               summary:     Initial package contents


    == mocks_hg_p4 ========================================

            @  changeset:   0:a0b5785fb55a
               tag:         tip
               user:        Jan Vrany <jan.vrany@fit.cvut.cz>
               date:        Wed Mar 27 11:31:36 2013 +0000
               summary:     Initial commit

    == mocks_hg_p5 ========================================

        @  changeset:   1:5abd9179e43d
        |  tag:         tip
        |  user:        Jan Vrany <jan.vrany@fit.cvut.cz>
        |  date:        Fri Nov 29 16:16:27 2013 +0000
        |  summary:     Added standard Java bundle
        |
        o  changeset:   0:07139f6f7907
           user:        Jan Vrany <jan.vrany@fit.cvut.cz>
           date:        Fri Nov 29 16:09:27 2013 +0000
           summary:     Initial commit

    == mocks_hg_p6 ========================================

        o  changeset:   6:7d0045fb7dba
        |  tag:         tip
        |  user:        Jan Vrany <jan.vrany@fit.cvut.cz>
        |  date:        Tue Feb 11 10:44:38 2014 +0000
        |  summary:     Removed extension method Object>>#greet
        |
        o  changeset:   5:ef448ae1bbbd
        |  user:        Jan Vrany <jan.vrany@fit.cvut.cz>
        |  date:        Tue Feb 11 10:43:51 2014 +0000
        |  summary:     Added extension method Object>>#greet.
        |
        o  changeset:   4:f71dfc6c6f9b
        |  user:        Jan Vrany <jan.vrany@fit.cvut.cz>
        |  date:        Tue Feb 11 10:39:47 2014 +0000
        |  summary:     MocksHGP6Bar>>#bar renamed to #greet
        |
        o  changeset:   3:c751cced3329
        |  user:        Jan Vrany <jan.vrany@fit.cvut.cz>
        |  date:        Tue Feb 11 10:37:44 2014 +0000
        |  summary:     Removed class MocksHGP6Foo.
        |
        o  changeset:   2:581b3cabbf8f
        |  user:        Jan Vrany <jan.vrany@fit.cvut.cz>
        |  date:        Tue Feb 11 10:36:53 2014 +0000
        |  summary:     Added new class MocksHGP6Qux
        |
        o  changeset:   1:506702fda231
        |  user:        Jan Vrany <jan.vrany@fit.cvut.cz>
        |  date:        Tue Feb 11 10:34:13 2014 +0000
        |  summary:     MocksHGP6Bar refactored
        |
        o  changeset:   0:c76faa501252
           user:        Jan Vrany <jan.vrany@fit.cvut.cz>
           date:        Tue Feb 11 12:53:12 2014 +0000
           summary:     Initial commit



    [author:]
        Jan Vrany <jan.vrany@fit.cvut.cz>

    [instance variables:]

    [class variables:]

    [see also:]

"
! !

!HGRepositoriesResource class methodsFor:'class initialization'!

initialize

    HGRepositoriesArchiveDir := (Smalltalk packageDirectoryForPackageId:self package)
                    / 'tests' / 'repositories'

    "Created: / 09-12-2010 / 23:07:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified (format): / 27-12-2011 / 18:07:34 / dundee"
    "Modified: / 17-10-2012 / 13:02:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!HGRepositoriesResource methodsFor:'accessing'!

directoryForRepositories
    ^repositoryDirectory

    "Created: / 22-11-2012 / 11:34:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

directoryForRepositoryNamed: nm
    ^self directoryForRepositoryNamed: nm unpack: true

    "Created: / 19-09-2012 / 18:57:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 14-01-2013 / 13:13:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

directoryForRepositoryNamed: nm init: init
    "Returns path to repository named nm.

     If `init` is true, then the repository is created and initialized
     (with no content at all). If 'init' is false, then only directory
     name is returned (without creating it)."

    ^self directoryForRepositoryNamed: nm unpack: false init: init

    "Created: / 01-02-2013 / 13:38:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

directoryForRepositoryNamed: nm revision: revision
    ^self directoryForRepositoryNamed: nm unpack: true revision: revision

    "Created: / 11-02-2014 / 11:16:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

directoryForRepositoryNamed: nm unpack: unpack
    "Returns path to repository named nm.

     If `unpack` is true, then the repository is frechly created and thus
     empty. If 'unpack' is true, then initial content of repository will 
     be loaded from zip archive located in
        <package path>/stx/libsvn/tests/repositories/<name>.git.zip
     If the files does not exists, an error is raised"

    ^self directoryForRepositoryNamed: nm unpack: unpack init: true

    "Created: / 14-01-2013 / 13:13:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 01-02-2013 / 13:39:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

directoryForRepositoryNamed: nm unpack: unpack init: init
    "Returns path to repository named nm.

     If `unpack` is true, then the repository is frechly created and thus
     empty, unless 'init' is false (in that case, only a name of directory
     that does not exists yet ir returned.

     If 'unpack' is true, then initial content of repository will 
     be loaded from zip archive located in
        <package path>/stx/libsvn/tests/repositories/<name>.git.zip
     If the files does not exists, an error is raised"

    ^ self directoryForRepositoryNamed: nm unpack: unpack init: init revision: nil

    "Created: / 01-02-2013 / 13:35:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 11-02-2014 / 11:12:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

directoryForRepositoryNamed: nm unpack: unpack init: init revision: revision     
    "Returns path to repository named nm.

     If `unpack` is true, then the repository is frechly created and thus
     empty, unless 'init' is false (in that case, only a name of directory
     that does not exists yet ir returned.

     If 'unpack' is true, then initial content of repository will 
     be loaded from zip archive located in
        <package path>/stx/libsvn/tests/repositories/<name>.git.zip
     If the files does not exists, an error is raised.

     If `revision` is not nil, then update working copy to specified revision,
     otherwise keep it as it is. Note, that `revision` is only valid if
     `unpack` is true. If not and `revision` is not nil, error is raised.       
     "

    | archiveNm archive repo dir  ok |

    unpack ifTrue:[
        self assert: init description: 'Cannot unpack non-initialized repo!!'
    ].

    archiveNm := nm copy 
                    replaceAll:$/ with:$_; 
                    yourself.
    archive := HGRepositoriesArchiveDir / (archiveNm , '.hg.zip').
    unpack ifTrue:[
        self assert:archive exists description:'dump file does not exist'.
    ].
    self assert:repositoryDirectory exists description:'repository directory does not exist'.

    dir := "/Filename newTemporaryDirectoryIn: 
                repositoryDirectory.

    init ifFalse:[
        ^ (dir asAbsoluteFilename / nm) pathName.
    ].

    unpack ifTrue:[
        ok := true.
        OperatingSystem 
            executeCommand:('unzip %1' bindWith: (archive asAbsoluteFilename pathName))
            inDirectory:dir 
            onError:[:status | ok := false].
        ok ifFalse:[
            OperatingSystem 
                executeCommand:('unzip %1' bindWith: (archive asAbsoluteFilename pathName))
                inDirectory:dir 
                onError:[:status | self assert:false description:'unzip failed'].
        ].
        revision notNil ifTrue:[ 
            OperatingSystem 
                executeCommand:('hg update -r %1' bindWith: revision)
                inDirectory:(dir asAbsoluteFilename / nm) 
                onError:[:status | self assert:false description:('hg uppdate -r %1 failed' bindWith: revision)].         
        ].
    ] ifFalse:[
        | repodir |

        self assert: revision isNil description:'unpack is false but revision given'.
        repodir := (dir asAbsoluteFilename / nm).
        repodir directory recursiveMakeDirectory.
        OperatingSystem 
                executeCommand:('hg init %1' bindWith: (repodir baseName))
                inDirectory:repodir directory pathName 
                onError:[:status | self assert:false description:'hg init failed'].
    ].

    repo := (dir asAbsoluteFilename / nm).
    self assert: repo exists.
    self assert: (repo / '.hg') exists.

    ^repo pathName

    "Created: / 11-02-2014 / 11:12:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

directoryForRepositoryNamed: nm unpack: unpack revision: revision
    "Returns path to repository named nm.

     If `unpack` is true, then the repository is frechly created and thus
     empty. If 'unpack' is true, then initial content of repository will 
     be loaded from zip archive located in
        <package path>/stx/libsvn/tests/repositories/<name>.git.zip
     If the files does not exists, an error is raised.

     If `revision` is not nil, then update working copy to specified revision,
     otherwise keep it as it is. Note, that `revision` is only valid if
     `unpack` is true. If not and `revision` is not nil, error is raised.
     "

    ^self directoryForRepositoryNamed: nm unpack: unpack init: true revision: revision

    "Created: / 11-02-2014 / 11:12:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!HGRepositoriesResource methodsFor:'running'!

setUp

    repositoryDirectory := Filename newTemporaryDirectory.
    Smalltalk packagePath: (Smalltalk packagePath asOrderedCollection
                                addFirst: repositoryDirectory pathName;
                                yourself)

    "Created: / 09-12-2010 / 23:53:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified (format): / 27-12-2011 / 18:07:04 / dundee"
    "Modified: / 16-11-2012 / 20:16:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

tearDown
    Smalltalk packagePath: (Smalltalk packagePath 
                                remove: repositoryDirectory pathName;
                                yourself).
    [
        repositoryDirectory recursiveRemove
    ] on: Error do:[
        "Stupid windows!!"
    ]

    "Created: / 09-12-2010 / 23:54:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 30-09-2012 / 05:26:04 / jv"
    "Modified: / 16-11-2012 / 20:16:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!HGRepositoriesResource methodsFor:'testing'!

isAvailable

    ^HGRepositoriesArchiveDir exists and:[OperatingSystem canExecuteCommand:'unzip']

    "Created: / 09-12-2010 / 23:06:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified (format): / 27-12-2011 / 18:05:57 / dundee"
    "Modified: / 17-10-2012 / 13:02:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!HGRepositoriesResource class methodsFor:'documentation'!

version_HG

    ^ '$Changeset: <not expanded> $'
!

version_SVN
    ^ 'Id::                                                                                                                        '
! !


HGRepositoriesResource initialize!