PackageId.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Wed, 02 Dec 2009 21:30:55 +0000
branchjv
changeset 17735 6a5bc05f696a
parent 17734 406b1590afe8
child 17761 b0e5971141bc
permissions -rw-r--r--
Merged with trunk

"
 COPYRIGHT (c) 2006 by eXept Software AG
              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:libbasic' }"

Object subclass:#PackageId
	instanceVariableNames:'packageIdString'
	classVariableNames:''
	poolDictionaries:''
	category:'System-Support-Projects'
!

!PackageId class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 2006 by eXept Software AG
              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
"
    Represents packageID's.
    Knows the relationship between modules and directories in the package-organization.
"
! !

!PackageId class methodsFor:'instance creation'!

from: aStringOrSymbol
    ^ self new packageIdString:aStringOrSymbol

    "
     (self from:'stx:libbasic') module      
     (self from:'stx:libbasic') directory      
    "

    "Created: / 18-08-2006 / 12:11:58 / cg"
    "Modified: / 12-09-2006 / 15:27:42 / cg"
!

module:moduleString directory:directoryString
    ^ self new module:moduleString directory:directoryString

    "
     (PackageId module:'stx' directory:'libbasic') module      
     (PackageId module:'stx' directory:'libbasic') directory      
    "

    "Created: / 12-09-2006 / 15:26:24 / cg"
    "Modified: / 18-11-2006 / 17:09:12 / cg"
! !

!PackageId class methodsFor:'defaults'!

noProjectID
    "return the symbol used to tag classes and methods which are loose.
     This means: not yet assigned to a particular project."

    ^ #'__NoProject__'.
! !

!PackageId methodsFor:'accessing'!

module:moduleString directory:directoryString
    packageIdString := moduleString,':',directoryString.

    "Created: / 12-09-2006 / 15:26:48 / cg"
!

packageIdString:something
    packageIdString := something.

    "Created: / 18-08-2006 / 12:14:45 / cg"
!

string
    ^ packageIdString

    "Created: / 18-08-2006 / 12:20:54 / cg"
! !

!PackageId methodsFor:'comparing'!

= aPackageId
    "compares equal to a corresponding string"

    ^ packageIdString = aPackageId asPackageId string

    "
     'stx:libbasic' asPackageId = 'stx:libbasic' 
     'stx:libbasic' asPackageId = 'stx:libbasic' asSymbol asPackageId  
     'stx:libbasic' asPackageId = 'stx:libbasic' asPackageId    
     'stx:libbasic2' asPackageId = 'stx:libbasic3' asPackageId  
    "

    "Created: / 18-08-2006 / 12:20:47 / cg"
    "Modified: / 12-09-2006 / 15:33:00 / cg"
!

hash
    ^ packageIdString hash

    "Created: / 18-08-2006 / 12:21:19 / cg"
! !

!PackageId methodsFor:'converting'!

asPackageId
    ^ self

    "Created: / 18-08-2006 / 12:22:10 / cg"
!

asString
    ^ packageIdString asString

    "Created: / 18-08-2006 / 12:12:22 / cg"
!

asSymbol
    ^ packageIdString asSymbol

    "Created: / 18-08-2006 / 12:12:29 / cg"
! !

!PackageId methodsFor:'printing'!

printOn:aStream
    aStream 
        nextPutAll:'PackageId('; nextPutAll:packageIdString; nextPutAll:')'

    "Created: / 12-10-2006 / 10:30:10 / cg"
! !

!PackageId methodsFor:'queries'!

directory
    "return the directory component. Thats the rest after the colon.
     The module is typically used to define the project-path or project-id within its
     sourcecode repository (which is selected via the module)."

    |idx|

    idx := packageIdString indexOf:$:.
    idx == 0 ifTrue:[
        ^ ''.
    ].
    ^ packageIdString copyFrom:idx+1

    "
     (PackageId from:'stx:libbasic') module  
     (PackageId from:'stx:libbasic') directory  
     (PackageId from:'stx') module  
     (PackageId from:'stx') directory  
     (PackageId from:'stx:goodies/xml/stx') module  
     (PackageId from:'stx:goodies/xml/stx') directory  
    "

    "Created: / 18-08-2006 / 12:15:33 / cg"
    "Modified: / 28-11-2006 / 11:39:14 / cg"
!

isModuleId
    "true if this is a module-id only (i.e. no directory component present).
     These are not allowed to be used as real projects, but only for organization.
     The reason is that this is used as selector to select the sourceCodeManager and
     also the managers repository"

    ^ self directory isEmptyOrNil
!

libraryName
    "return the name of the library, when compiled to a binary (i.e. dll/so).
     To avoid conflicts with the projectDefinition class 
     (which is named <module>_<directory_components>), we prefix the library name
     with 'lib'. This has the added advantage, that under unix, linking can be done with
     '-l'shortName."

    ^ 'lib' , (packageIdString copy asString replaceAny:':/' with:$_)

    "
     (PackageId from:'stx:libbasic') libraryName        
     (PackageId from:'stx:goodies/xml/stx') libraryName   
     (PackageId from:'bosch:dapasx') libraryName  
     (PackageId from:'exept:expecco') libraryName  
    "

    "Created: / 18-08-2006 / 12:35:04 / cg"
!

module
    "return the module component. Thats the first component up to the colon.
     The module is typically used to select a corresponding sourcecode repository."

    |idx|

    idx := packageIdString indexOf:$:.
    idx == 0 ifTrue:[
        ^ packageIdString.
    ].
    ^ packageIdString copyTo:idx-1

    "
     (PackageId from:'stx:libbasic') module  
     (PackageId from:'stx:libbasic') directory  
    "

    "Created: / 18-08-2006 / 12:13:53 / cg"
    "Modified: / 27-12-2006 / 11:51:25 / cg"
!

parentPackage
    |dir idx|

    dir := self directory.
    dir isNil ifTrue:[
        ^ nil.
    ].
    idx := dir lastIndexOf:$/.
    idx == 0 ifTrue:[
        ^ nil
    ].
    ^ self class from:(self module , ':' , (dir copyTo:idx-1))

    "
     (PackageId from:'stx:libbasic') parentPackage  
     (PackageId from:'stx:goodies/xml/stx') parentPackage  
     (PackageId from:'stx:goodies/xml/stx') parentPackage parentPackage  
    "

    "Created: / 23-08-2006 / 15:10:13 / cg"
!

pathRelativeToTopDirectory
    ^ (self module asFilename construct:(self directory)) pathName.

    "
     'stx:libbasic' asPackageId pathRelativeToTopDirectory  
     'stx:goodies/net/ssl' asPackageId pathRelativeToTopDirectory 
    "
!

pathRelativeToTopDirectory:aDirectory
    ^ aDirectory asFilename construct:(self pathRelativeToTopDirectory)

    "
     |top|

     top := Smalltalk packagePath first.
     'stx:goodies/net/ssl' asPackageId pathRelativeToTopDirectory:top    
    "
!

projectDefinitionClass
    ^ ProjectDefinition definitionClassForPackage:self

    "
     'stx:libbasic' asPackageId projectDefinitionClass
    "
! !

!PackageId class methodsFor:'documentation'!

version
    ^ '$Id: PackageId.st 10480 2009-12-02 21:30:55Z vranyj1 $'
!

version_CVS
    ^ '§Header: /cvs/stx/stx/libbasic/PackageId.st,v 1.16 2009/10/22 15:43:27 cg Exp §'
! !