Add support for custom (package-defined) project contents definition methods
Some packages may want to compile custom methods when project definition is updated
based on project contents - similarly to how #classNamesAndAttributes or #extensionMethodNames
are updated.
To support this, packages may add extension methods annotated by <method:category:overwrite:>
or <method:category:>.
This is currently used by STX:LIBJAVA to automatically generate #javaBundle method.
--- a/ProjectDefinition.st Wed Jun 10 08:43:00 2015 +0100
+++ b/ProjectDefinition.st Fri Jun 12 07:22:20 2015 +0100
@@ -103,6 +103,25 @@
extensionOverwriteInfo.
This is used to correctly reinstall an overwritten method, whenever a package is unloaded.
+ ## Custom project definition methods
+
+ Some packages may want to compile custom methods when project definition is updated
+ based on project contents - similarly to how #classNamesAndAttributes or #extensionMethodNames
+ are updated.
+
+ To support this, packages mey add extension methods annotated by <method:category:overwrite:>
+ or <method:category:>. The meaning og arguments is the following:
+
+ * method: <Symbol> - the selector of method which this method generates.
+ * category: <Symbol> - the category in which to place generated method
+ * overwrite: <Boolean> - specifies whether the method should obe overwritten
+ or not. Use `false` only for methods which should be
+ generated once and then left for user to manually tweak.
+ optional, defaults to `true` (i.e., do owerwrite methods)
+
+ The annotated method is invoked to get the code od the method to generate, i.e., it must
+ return the source code as String. If it returns nil - no method is generated.
+
## Build Support Files
To support pre-compilation of a package, ProjectDefinition can generate a set of makefiles and other
@@ -873,6 +892,7 @@
+
!ProjectDefinition class methodsFor:'accessing - packaging'!
classNames:aCollectionOfClassNames
@@ -1135,6 +1155,7 @@
].
! !
+
!ProjectDefinition class methodsFor:'accessing - tests'!
excludedFromTestSuite
@@ -1662,6 +1683,8 @@
If ignoreOldDefinition is true, new code is generated (class/method scan);
otherwise, new items are added to the existing lists"
+ | cls |
+
aTwoArgBlock
value:(self classNamesAndAttributes_code_ignoreOldEntries:ignoreOldDefinition ignoreOldDefinition:ignoreOldDefinition)
value:'description - contents'.
@@ -1699,7 +1722,32 @@
value: 'description - monticello'.
].
- "Modified: / 25-11-2013 / 13:56:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Add additional custom files"
+ cls := self.
+ [ cls ~~ Object ] whileTrue:[
+ cls class selectorsAndMethodsDo:[:selector :method |
+ | annotation overwrite |
+
+ annotation := method annotationAt: #method:category:overwrite:.
+ annotation notNil ifTrue:[
+ overwrite := annotation argumentAt: 3.
+ ] ifFalse:[
+ annotation := method annotationAt: #method:category:.
+ overwrite := true.
+ ].
+ (annotation notNil and:[ overwrite or:[ cls class methodDictionary includesKey: (annotation argumentAt:1) ] ]) ifTrue:[
+ | code |
+
+ code := self perform: selector.
+ code notNil ifTrue:[
+ aTwoArgBlock value: code value: (annotation argumentAt: 2)
+ ].
+ ].
+ ].
+ cls := cls superclass.
+ ].
+
+ "Modified: / 12-06-2015 / 07:02:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
forEachDescriptionMethodsCodeToCompileDo:aTwoArgBlock ignoreOldDefinition:ignoreOldDefinition
@@ -2687,6 +2735,7 @@
! !
+
!ProjectDefinition class methodsFor:'description - project information'!
applicationAdditionalIconFileNames
@@ -7933,6 +7982,11 @@
^ '$Header$'
!
+version_HG
+
+ ^ '$Changeset: <not expanded> $'
+!
+
version_SVN
^ '$ Id: ProjectDefinition.st 10645 2011-06-09 15:28:45Z vranyj1 $'
! !