On Thu, 2009-12-31 at 00:55 +0100, Paolo Bonzini wrote:
> On 12/30/2009 11:15 PM, Gwenael Casaccio wrote:
> > + parseVersion: aString [
> > + <category: 'version parsing'>
> > +
> > + | tokens |
> > + (tokens := aString tokenize: '\.') size = 3 ifFalse: [ self error: 'Bad
> > version string : ', aString, ' should be xx.yy.zz' ].
> > + self version: (Version major: tokens first asInteger minor: tokens
> > second asInteger patch: tokens third asInteger)
> > + ]
>
> This should:
>
> 1) use #subStrings: or alternatively a single regex match
>
> ^(\d+)\.(\d+)(?:\.(\d+))$
>
> instead of tokenize.
>
> 2) be in Version class>>#fromString:
>
> 3) accept a version like 1.0 and change it to 1.0.0 (see regex above).
>
> Otherwise looks fine, filtering of prerequisites based on their version
> can be done later.
>
> Paolo
hmm sorry here is the full patch,
Happy new year !
Cheers,
Gwen
diff --git a/kernel/PkgLoader.st b/kernel/PkgLoader.st
index 260d8b8..475d544 100644
--- a/kernel/PkgLoader.st
+++ b/kernel/PkgLoader.st
@@ -431,7 +431,7 @@ PackageContainer subclass: PackageDirectory [
self file withReadStreamDo: [ :fileStream |
[self parse: fileStream]
on: SystemExceptions.PackageNotAvailable
- do: [:ex | ex resignalAs: PackageSkip new]].
+ do: [:ex | ex resignalAs: PackageSkip new]].
self packages: (self packages reject: [:each | each isDisabled])
]
@@ -1101,16 +1101,108 @@ PackageInfo subclass: StarPackage [
+Namespace current: Kernel [
+
+Object subclass: Version [
+ | major minor patch |
+
+ Version class >> fromString: aString [
+ <category: 'instance creation'>
+
+ | result |
+ [ result := aString searchRegex: '^(\d+)\.(\d+)(?:\.(\d+))?' ] on: Error do: [ :ex | self error: 'Bad version format ', aString, ' should be xx.yy(.zz)' ].
+ ^ self major: result first asInteger minor: result second asInteger patch: (result third ifNil: [ 0 ] ifNotNil: [ result third asInteger ])
+ ]
+
+ Version class >> major: major minor: minor patch: patch [
+ <category: 'instance creation'>
+
+ ^ self new
+ major: major minor: minor patch: patch
+ ]
+
+ major: major minor: minor patch: patch [
+ <category: 'initialization'>
+
+ self
+ major: major;
+ minor: minor;
+ patch: patch
+ ]
+
+ major [
+ <category: 'accessing'>
+
+ ^ major
+ ]
+
+ major: anInteger [
+ <category: 'accessing'>
+
+ major := anInteger
+ ]
+
+ minor [
+ <category: 'accessing'>
+
+ ^ minor
+ ]
+
+ minor: anInteger [
+ <category: 'accessing'>
+
+ minor := anInteger
+ ]
+
+ patch [
+ <category: 'accessing'>
+
+ ^ patch
+ ]
+
+ patch: anInteger [
+ <category: 'accessing'>
+
+ patch := anInteger
+ ]
+]
+]
+
+
Kernel.PackageInfo subclass: Package [
| features prerequisites builtFiles files fileIns relativeDirectory
baseDirectories libraries modules callouts url namespace sunitScripts
- startScript stopScript test |
+ startScript stopScript test version |
<category: 'Language-Packaging'>
<comment: 'I am not part of a standard Smalltalk system. I store internally the
information on a Smalltalk package, and can output my description in
XML.'>
+ Package class [ | Tags | ]
+
+ Package class >> tags [
+ <category: 'accessing'>
+
+ ^ Tags ifNil: [ Tags := Dictionary from: {
+ 'file' -> #addFile:.
+ 'filein' -> #addFileIn:.
+ 'prereq' -> #addPrerequisite:.
+ 'provides' -> #addFeature:.
+ 'module' -> #addModule:.
+ 'directory' -> #relativeDirectory:.
+ 'name' -> #name:.
+ 'url' -> #url:.
+ 'version' -> #parseVersion:.
+ 'namespace' -> #namespace:.
+ 'library' -> #addLibrary:.
+ 'built-file' -> #addBuiltFile:.
+ 'sunit' -> #addSunitScript:.
+ 'start' -> #startScript:.
+ 'stop' -> #stopScript:.
+ 'callout' -> #addCallout: } ]
+ ]
+
Package class >> parse: file [
"Answer a package from the XML description in file."
<category: 'instance creation'>
@@ -1209,6 +1301,12 @@ XML.'>
namespace := aString
]
+ addFeature: aString [
+ <category: 'accessing'>
+
+ self features add: aString
+ ]
+
features [
"Answer a (modifiable) Set of features provided by the package."
@@ -1217,6 +1315,12 @@ XML.'>
^features
]
+ addPrerequisite: aString [
+ <category: 'accessing'>
+
+ self prerequisites add: aString
+ ]
+
prerequisites [
"Answer a (modifiable) Set of prerequisites."
@@ -1225,6 +1329,12 @@ XML.'>
^prerequisites
]
+ addBuiltFile: aString [
+ <category: 'accessing'>
+
+ self builtFiles add: aString
+ ]
+
builtFiles [
"Answer a (modifiable) OrderedCollection of files that are part of
the package but are not distributed."
@@ -1234,6 +1344,12 @@ XML.'>
^builtFiles
]
+ addFile: aString [
+ <category: 'accessing'>
+
+ self files add: aString
+ ]
+
files [
"Answer a (modifiable) OrderedCollection of files that are part of
the package."
@@ -1243,6 +1359,12 @@ XML.'>
^files
]
+ addFileIn: aString [
+ <category: 'accessing'>
+
+ self fileIns add: aString
+ ]
+
fileIns [
"Answer a (modifiable) OrderedCollections of files that are to be
filed-in to load the package. This is usually a subset of
@@ -1253,6 +1375,12 @@ XML.'>
^fileIns
]
+ addLibrary: aString [
+ <category: 'accessing'>
+
+ self libraries add: aString
+ ]
+
libraries [
"Answer a (modifiable) Set of shared library names
that are required to load the package."
@@ -1262,6 +1390,12 @@ XML.'>
^libraries
]
+ addModule: aString [
+ <category: 'accessing'>
+
+ self modules add: aString
+ ]
+
modules [
"Answer a (modifiable) Set of modules that are
required to load the package."
@@ -1271,6 +1405,12 @@ XML.'>
^modules
]
+ addSunitScript: aString [
+ <category: 'accessing'>
+
+ self sunitScripts add: aString
+ ]
+
sunitScripts [
"Answer a (modifiable) OrderedCollection of SUnit scripts that
compose the package's test suite."
@@ -1280,6 +1420,12 @@ XML.'>
^sunitScripts
]
+ addCallout: aString [
+ <category: 'accessing'>
+
+ self callouts add: aString
+ ]
+
callouts [
"Answer a (modifiable) Set of call-outs that are required to load
the package. Their presence is checked after the libraries and
@@ -1366,6 +1512,24 @@ XML.'>
relativeDirectory := dir
]
+ version [
+ <category: 'accessing'>
+
+ ^ version
+ ]
+
+ version: aVersion [
+ <category: 'accessing'>
+
+ version := aVersion
+ ]
+
+ parseVersion: aString [
+ <category: 'version parsing'>
+
+ self version: (Version fromString: aString)
+ ]
+
primFileIn [
"Private - File in the given package without paying attention at
dependencies and C callout availability"
@@ -1417,24 +1581,8 @@ XML.'>
(file upTo: $>) = tag
ifFalse: [^self error: 'error in packages file: unmatched end tag ' , tag].
- "I tried to put these from the most common to the least common"
- tag = 'file' ifTrue: [self files add: cdata] ifFalse: [
- tag = 'filein' ifTrue: [self fileIns add: cdata] ifFalse: [
- tag = 'prereq' ifTrue: [self prerequisites add: cdata] ifFalse: [
- tag = 'provides' ifTrue: [self features add: cdata] ifFalse: [
- tag = 'module' ifTrue: [self modules add: cdata] ifFalse: [
- tag = 'directory' ifTrue: [self relativeDirectory: cdata] ifFalse: [
- tag = 'name' ifTrue: [self name: cdata] ifFalse: [
- tag = 'url' ifTrue: [self url: cdata] ifFalse: [
- tag = 'namespace' ifTrue: [self namespace: cdata] ifFalse: [
- tag = 'library' ifTrue: [self libraries add: cdata] ifFalse: [
- tag = 'built-file' ifTrue: [self builtFiles add: cdata] ifFalse: [
- tag = 'sunit' ifTrue: [self sunitScripts add: cdata] ifFalse: [
- tag = 'start' ifTrue: [self startScript: cdata] ifFalse: [
- tag = 'stop' ifTrue: [self stopScript: cdata] ifFalse: [
- tag = 'callout' ifTrue: [self callouts add: cdata] ifFalse: [
- tag = openingTag ifTrue: [^self] ifFalse: [
- self error: 'invalid tag ' , tag]]]]]]]]]]]]]]]].
+ tag = openingTag ifTrue: [ ^ self ].
+ self perform: (self class tags at: tag ifAbsent: [ self error: 'invalid tag ', tag ]) with: cdata.
cdata := nil].
ch isAlphaNumeric
ifTrue:
_______________________________________________
help-smalltalk mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-smalltalk