PackageId.st
author Claus Gittinger <cg@exept.de>
Wed, 22 Nov 2006 12:17:11 +0100
changeset 10190 806d4a4369d7
parent 10075 01633f527642
child 10208 8248266e5c0d
permissions -rw-r--r--
*** empty log message ***

"
 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:libbasic3' }"

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 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

    "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)."

    ^ packageIdString copyFrom:(packageIdString indexOf:$:)+1

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

    "Created: / 18-08-2006 / 12:15:33 / cg"
!

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."

    ^ packageIdString upTo:$:

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

    "Created: / 18-08-2006 / 12:13:53 / cg"
!

parentPackage
    |dir idx|

    dir := self directory.
    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"
! !

!PackageId class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libbasic/PackageId.st,v 1.7 2006-11-22 11:17:11 cg Exp $'
! !