ProjectDefinition.st
changeset 23866 75b931b9ed4e
parent 23865 6dacda4be899
child 24342 e1077b14f110
--- a/ProjectDefinition.st	Tue Mar 12 15:36:20 2019 +0100
+++ b/ProjectDefinition.st	Tue Mar 12 15:44:27 2019 +0100
@@ -1,5 +1,3 @@
-"{ Encoding: utf8 }"
-
 "
  COPYRIGHT (c) 2006 by eXept Software AG
 	      All Rights Reserved
@@ -215,6 +213,47 @@
 
 !ProjectDefinition class methodsFor:'instance creation'!
 
+definitionClassForMonticelloPackage:aMonicelloPackagename
+    ^ self definitionClassForMonticelloPackage:aMonicelloPackagename createIfAbsent:false
+
+    "
+     self definitionClassForMonticelloPackage:'foobar'
+    "
+!
+
+definitionClassForMonticelloPackage:aMonicelloPackagename createIfAbsent:createIfAbsent
+    ^ self allSubclasses
+        detect:[:eachProjectDefinition |
+            eachProjectDefinition monticelloPackageName = aMonicelloPackagename ]
+        ifNone:[
+            |dfn squeakPackageInfo|
+
+            createIfAbsent ifTrue:[
+                dfn := ApplicationDefinition
+                    definitionClassForPackage:'mc:',aMonicelloPackagename createIfAbsent:true projectType:GUIApplicationType.
+
+                "/ if the squeak-stuff is loaded, use it.
+                PackageInfo notNil ifTrue:[
+                    squeakPackageInfo := PackageInfo allSubclasses
+                                            detect:[:pi | pi new packageName = aMonicelloPackagename] ifNone:nil.
+                ].
+
+                squeakPackageInfo notNil ifTrue:[
+                    dfn classNames:(squeakPackageInfo new classes collect:[:each | each name]).
+                ].
+            ] ifFalse:[
+                nil
+            ]
+        ]
+
+    "
+     self definitionClassForMonticelloPackage:'foobar'
+     self definitionClassForMonticelloPackage:'foobar' createIfAbsent:true
+    "
+
+    "Modified: / 30-10-2010 / 00:26:07 / cg"
+!
+
 definitionClassForPackage:aPackageID
     "given a packageID (such as 'stx:libfoo/bar'), lookup the corresponding peoject definition class.
      Return it, or nil if not present"
@@ -939,7 +978,169 @@
     "Modified (comment): / 28-06-2013 / 11:25:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
-
+!ProjectDefinition class methodsFor:'accessing - hg'!
+
+hgBinaryRevision
+
+    "
+    Answers Mercurial revision from which the package was compiled.
+    If no binary revision is available, returns nil."
+
+
+    | revInfo |
+
+    self binaryRevisionString notNil ifTrue:[
+        revInfo := HGRevisionInfo readFrom: self binaryRevisionString onError:[nil].
+        revInfo notNil ifTrue:[
+            ^revInfo changesetId
+        ].
+    ].
+    ^nil
+
+
+    "
+        stx_libbasic hgBinaryRevision
+        stx_libsvn hgBinaryRevision
+        stx_libscm_mercurial hgBinaryRevision
+
+    "
+
+    "Created: / 20-11-2012 / 23:58:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+hgLogicalRevision
+
+    "
+    Answers Mercurial revision on which is this package based on logically.
+
+    Revision is computed as follows:
+        1) Look, if receiver's version_HG method has a (hidden) annotation HGRevision:, 
+           if so, return its value.
+        2) If receiver's binary revision is not nil, return it.
+        3) Look into a package directory and if there is a Mercurial repository,
+           return working copy's revision"
+
+    | versionMethod versionAnnotation revInfo pkgDir repoDir repo |
+
+    "1 --- "
+
+    versionMethod := self class compiledMethodAt: HGSourceCodeManager nameOfVersionMethodInClasses.
+    versionMethod notNil ifTrue:[
+        versionAnnotation := versionMethod annotationAt: #HGRevision:.
+        versionAnnotation notNil ifTrue:[
+            ^versionAnnotation revision
+        ].
+    ] ifFalse:[
+        HGSourceCodeManager compileVersionMethod:HGSourceCodeManager nameOfVersionMethodInClasses of:self for:'$Changeset: <not expanded> $'.
+        versionMethod := self class compiledMethodAt: HGSourceCodeManager nameOfVersionMethodInClasses.
+    ].
+    
+    "2 --- "
+    self binaryRevisionString notNil ifTrue:[
+        revInfo := HGRevisionInfo readFrom: self binaryRevisionString onError:[nil].
+        revInfo notNil ifTrue:[
+            ^revInfo changesetId
+        ].
+    ].
+
+    "3 --- "
+    pkgDir := Smalltalk getPackageDirectoryForPackage: self package.
+    pkgDir notNil ifTrue:[
+        repoDir := HGRepository discover: pkgDir.
+        repoDir notNil ifTrue:[
+            | id |
+
+            repo := HGRepository on: repoDir.
+            id := repo workingCopy changeset id.
+            versionMethod annotateWith: (HGRevisionAnnotation revision: id).
+            ^id
+        ]
+    ].
+
+    "4 --- "
+    self breakPoint: #jv.
+    ^nil
+
+
+    "
+        stx_libbasic hgLogicalRevision
+        stx_libsvn hgLogicalRevision
+        stx_libscm_mercurial hgLogicalRevision
+
+    "
+
+    "Created: / 20-11-2012 / 23:54:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 14-01-2013 / 13:42:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+hgLogicalRevision: anHGChangesetId
+    "
+    Set Mercurial revision on which is this package based on logically.
+    To be called only from Mercurial support upon commit from image.
+    "
+
+    | versionMethod |
+
+    versionMethod := self class compiledMethodAt: HGSourceCodeManager nameOfVersionMethodInClasses.
+    versionMethod isNil ifTrue:[ 
+        self class compile:(self class 
+                                    versionMethodTemplateForSourceCodeManager:HGSourceCodeManager)
+                                    classified:'documentation'.
+        versionMethod := self class compiledMethodAt:HGSourceCodeManager nameOfVersionMethodInClasses.
+        versionMethod setPackage:self package.
+    ].
+    versionMethod annotateWith: 
+        (HGRevisionAnnotation revision: anHGChangesetId)
+
+    "Created: / 20-02-2014 / 00:06:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 27-02-2014 / 22:16:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!ProjectDefinition class methodsFor:'accessing - hg - settings'!
+
+hgEnsureCopyrightMethod
+    "If true, then #copyright method is automatically compiled in each class
+     (but iff project definition defines it)
+
+     Default is true (compile such method) but if the repository is mirror of CVS and
+     you want to merge back to CVS at some point, you may want to not compile them
+     to keep changes against CVS minimal"
+
+    ^true "default"
+
+    "Created: / 09-10-2013 / 11:48:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+hgEnsureVersion_HGMethod
+    "If true, then #version_HG method is automatically compiled in each class.
+
+     Default is true (compile such method) but if the repository is mirror of CVS and
+     you want to merge back to CVS at some point, you may want to not compile them
+     to keep changes against CVS minimal. 
+
+     If false, version_HG is compiled only in classes that has been modified
+     and commited.
+
+     Note that Mercurial can live without them
+     just fine"
+
+    ^true "default"
+
+    "Created: / 09-10-2013 / 11:50:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+hgRemoveContainesForDeletedClasses
+    "If true, then containers for removed classes are __AUTOMATICALLY__ removed from the
+     repositoru. If false, obsolete containes are kept.
+
+     Default is true (remove obsolete containers) but if the repository is mirror of CVS and
+     you want to merge back to CVS at some point, you may want to return false to avoid deletions
+     of obsolete files. Usefull when branching off an old CVS repo with loads of mess."
+
+    ^true "default"
+
+    "Created: / 21-05-2013 / 16:44:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
 
 !ProjectDefinition class methodsFor:'accessing - packaging'!
 
@@ -2442,6 +2643,33 @@
     "Modified: / 17-08-2006 / 19:59:26 / cg"
 ! !
 
+!ProjectDefinition class methodsFor:'description - actions - hg'!
+
+hgPostLoad
+    "possibly update an version_HG"
+
+    <postLoad>
+
+    | dir repo versionMethod |
+
+    HGRepository notNil ifTrue:[
+        self binaryRevisionString isNil ifTrue:[
+            dir := Smalltalk getPackageDirectoryForPackage: self package.
+            dir notNil ifTrue:[  
+                dir := HGRepository discover: dir.
+                dir notNil ifTrue:[
+                    repo := HGRepository on: dir.
+                    versionMethod := HGSourceCodeManager ensureVersionMethodInClass: self package: self package.
+                    versionMethod annotateWith: 
+                        (HGRevisionAnnotation revision: repo workingCopy changesetId)
+                ].
+            ]
+        ].
+    ].
+
+    "Created: / 26-11-2012 / 13:06:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 07-02-2014 / 10:59:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
 
 !ProjectDefinition class methodsFor:'description - compilation'!
 
@@ -2963,6 +3191,37 @@
     "Created: / 23-01-2007 / 19:08:27 / cg"
 ! !
 
+!ProjectDefinition class methodsFor:'description - java'!
+
+javaBundle
+    "Defines a Java code bundle provided by this package.
+     Used by STX:LIBJAVA"
+
+    ^nil
+
+    "Created: / 15-01-2013 / 16:49:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+javaClassPath
+    | bundle |
+
+    bundle := self javaBundle.
+    ^ bundle notNil ifTrue:[ bundle classPath ] ifFalse: [ #() ]
+
+    "Created: / 13-12-2011 / 23:48:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 21-01-2015 / 11:11:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+javaSourcePath
+    | bundle |
+
+    bundle := self javaBundle.
+    ^ bundle notNil ifTrue:[ bundle sourcePath ] ifFalse: [ #() ]
+
+    "Created: / 13-12-2011 / 23:49:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 21-01-2015 / 11:11:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
 !ProjectDefinition class methodsFor:'description - project information'!
 
 applicationAdditionalIconFileNames
@@ -3832,6 +4091,42 @@
     "Created: / 24-02-2011 / 11:38:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
+generate_java_build_auto_dot_xml
+    <file: 'java/build.auto.xml' overwrite: true>
+
+    self javaBundle isNil ifTrue:[ ^ nil ].
+    ^self
+	replaceMappings: self java_build_auto_dot_xml_mappings
+	in:              self java_build_auto_dot_xml
+
+    "
+    stx_libjava_tools generate_java_build_auto_dot_xml
+    stx_libjava_experiments generate_java_build_auto_dot_xml
+
+    "
+
+    "Created: / 18-01-2015 / 07:32:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 19-01-2015 / 16:55:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+generate_java_build_dot_xml
+    <file: 'java/build.xml' overwrite: false>
+
+    self javaBundle isNil ifTrue:[ ^ nil ].
+    ^self
+	replaceMappings: self java_build_dot_xml_mappings
+	in:              self java_build_dot_xml
+
+    "
+    stx_libjava_tools generate_java_build_auto_dot_xml
+    stx_libjava_experiments generate_java_build_auto_dot_xml
+
+    "
+
+    "Created: / 19-01-2015 / 07:37:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 19-01-2015 / 16:32:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 generate_lccmake_dot_mak
 
     ^self replaceMappings: self bmake_dot_mak_mappings
@@ -4182,6 +4477,30 @@
     "Created: / 04-09-2012 / 13:04:26 / cg"
 !
 
+java_build_auto_dot_xml_mappings
+    ^ self common_mappings
+	at: 'TOP' put: (self pathToTopWithSeparator:'/');
+	at: 'PACKAGE_SLASHED' put:  (self package copyReplaceAll: $: with: $/);
+	at: 'PACKAGE_DOTTED' put: ((self package copyReplaceAll: $: with: $/) replaceAll: $/ with: $.);
+	at: 'BUILD_PREREQS_CLASSPATH_REFS'  put: (self generateJavaBuildPrereqsClasspathRefs);
+	at: 'BUILD_PREREQS_CLASSPATH_PATHS' put: (self generateJavaBuildPrereqsClasspathPaths);
+	at: 'BUILD_PREREQS'                 put: (self generateJavaBuildPrereqs);
+	yourself
+
+    "Created: / 18-01-2015 / 07:32:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 19-01-2015 / 07:21:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+java_build_dot_xml_mappings
+    ^ self common_mappings
+	at: 'TOP' put: (self pathToTopWithSeparator:'/');
+	at: 'PACKAGE_SLASHED' put:  (self package copyReplaceAll: $: with: $/);
+	at: 'PACKAGE_DOTTED' put: ((self package copyReplaceAll: $: with: $/) replaceAll: $/ with: $.);
+	yourself
+
+    "Created: / 19-01-2015 / 07:37:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 make_dot_proto_mappings
     ^ self common_mappings
 	at: 'MODULE' put: ( self module );
@@ -5081,6 +5400,69 @@
     ^ self subProjectMakeCallsUsing:'call vcmake %1 %2'.
 ! !
 
+!ProjectDefinition class methodsFor:'file mappings support-Java'!
+
+generateJavaBuildPrereqs
+    ^ self generateJavaBuildPrereqsUsingTemplate:
+
+'    <target name="prereqs.%(PREREQ_PACKAGE_DOTTED)" extensionOf="prereqs.main">
+	<ant antfile="${TOP}/../%(PREREQ_PACKAGE_SLASHED)/java/build.xml"
+	     target="${ant.project.invoked-targets}"
+	     inheritAll="false"
+	     useNativeBasedir="true"/>
+    </target>
+'
+
+    "Created: / 18-01-2015 / 07:40:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 19-01-2015 / 07:27:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+generateJavaBuildPrereqsClasspathPaths
+    ^ self generateJavaBuildPrereqsUsingTemplate:
+
+'    <path id="build.classpath.prereqs.%(PREREQ_PACKAGE_DOTTED)">
+	<pathelement path="${TOP}/../%(PREREQ_PACKAGE_SLASHED)/java/bin"/>
+	<fileset dir="${TOP}/../%(PREREQ_PACKAGE_SLASHED)/java/libs" includes="*.jar"/>
+    </path>
+'
+
+    "Created: / 18-01-2015 / 07:40:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 19-01-2015 / 07:27:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+generateJavaBuildPrereqsClasspathRefs
+    ^ self generateJavaBuildPrereqsUsingTemplate:
+
+'       <path refid="build.classpath.prereqs.%(PREREQ_PACKAGE_DOTTED)"/>
+'
+
+    "Created: / 18-01-2015 / 07:40:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+generateJavaBuildPrereqsUsingTemplate: template
+    | mappings |
+
+    mappings := Dictionary new.
+    mappings at: 'PACKAGE_SLASHED' put:  (self package copyReplaceAll: $: with: $/).
+    mappings at: 'PACKAGE_DOTTED' put: ((self package copyReplaceAll: $: with: $/) replaceAll: $/ with: $.).
+
+    ^ String streamContents:[ :s |
+	((self preRequisitesFor: self package) asArray sort) do:[:each |
+	    | def |
+
+	    def := ProjectDefinition definitionClassForPackage: each createIfAbsent: false.
+	    def javaBundle notNil ifTrue: [
+		mappings at: 'PREREQ_PACKAGE_SLASHED' put:  (each copyReplaceAll: $: with: $/).
+		mappings at: 'PREREQ_PACKAGE_DOTTED' put: ((each copyReplaceAll: $: with: $/) replaceAll: $/ with: $.).
+		s nextPutAll: (template expandPlaceholdersWith: mappings)
+	    ]
+	].
+    ]
+
+    "Created: / 18-01-2015 / 07:43:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 19-01-2015 / 07:29:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
 !ProjectDefinition class methodsFor:'file templates'!
 
 autopackage_default_dot_apspec
@@ -5269,6 +5651,41 @@
     "
 !
 
+java_build_auto_dot_xml
+    "Template for java/build.auto.xml"
+^ '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!!-- This file has been generated by STX:LIBJAVA. Do not edit!! Edit build.xml instead -->
+<project>
+    <property name="TOP" value="../%(TOP)" />
+    <import file="${TOP}/libjava/java/build.common.xml"/>
+
+    <path id="build.classpath.prereqs">
+%(BUILD_PREREQS_CLASSPATH_REFS)
+    </path>
+
+%(BUILD_PREREQS_CLASSPATH_PATHS)
+
+%(BUILD_PREREQS)
+
+</project>
+'
+
+    "Created: / 18-01-2015 / 07:32:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 19-01-2015 / 07:23:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+java_build_dot_xml
+    "Template for java/build.xml"
+^ '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<project name="%(PACKAGE_DITTED)" default="compile" basedir=".">
+    <import file="build.auto.xml"/>
+    <!!-- Put custom build code here, this file is never overwritten by Smalltalk/X -->
+</project>
+'
+
+    "Created: / 19-01-2015 / 07:35:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 lccmake_dot_mak
     "the template code for the lccmake.bat file"
 
@@ -5800,6 +6217,21 @@
     "Modified: / 20-11-2012 / 23:06:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
+!ProjectDefinition class methodsFor:'misc ui support'!
+
+iconInBrowserSymbol
+    "the browser will use this as index into the toolbariconlibrary"
+
+    <resource: #programImage>
+
+    self theNonMetaclass isApplicationDefinition ifTrue:[
+        self theNonMetaclass isGUIApplication ifTrue:[
+            ^ #guiApplicationDefinitionClassIcon
+        ].
+        ^ #applicationDefinitionClassIcon
+    ].
+    ^ super iconInBrowserSymbol
+! !
 
 !ProjectDefinition class methodsFor:'private'!
 
@@ -8139,26 +8571,12 @@
 !
 
 reasonForNotSupportedOnPlatform
-    "answer false, if this package is not suitable for
-     the current platform. The default here returns true.
-     Only to be redefined in packages which are definitely not valid
-     for the given platform. For example, the OLE package is only
-     usable under windows"
-
-    self preRequisites do:[:eachProjectDefinitionClassNameSymbol|
-        |cls|
-        cls := self definitionClassForPackage:eachProjectDefinitionClassNameSymbol.
-        cls isNil ifTrue:[
-            ^ 'Prerequisite package "', eachProjectDefinitionClassNameSymbol, '" is missing'.
-        ].
-        cls supportedOnPlatform ifFalse:[
-            ^ 'Prerequisite package "', eachProjectDefinitionClassNameSymbol, '" is not supported: ', cls reasonForNotSupportedOnPlatform.
-        ].
-    ].
-    ^ ''.
+    "answer a reason string, why the package is not supported on this platform
+     (if it is not, i.e. if supportedByPlatform returns false)"
+
+    ^ 'not supported by this OS-platform'
 
     "Created: / 07-02-2019 / 14:21:54 / Claus Gittinger"
-    "Modified: / 12-03-2019 / 15:26:07 / Stefan Vogel"
 !
 
 supportedOnPlatform
@@ -8168,19 +8586,7 @@
      for the given platform. For example, the OLE package is only
      usable under windows"
 
-    self preRequisites do:[:eachProjectDefinitionClassNameSymbol|
-        |cls|
-        cls := self definitionClassForPackage:eachProjectDefinitionClassNameSymbol.
-        cls isNil ifTrue:[
-            ^ false.    "prerequisite project is missing"
-        ].
-        cls supportedOnPlatform ifFalse:[
-            ^ false.
-        ].
-    ].
-    ^ true.
-
-    "Modified: / 12-03-2019 / 15:26:00 / Stefan Vogel"
+    ^ true
 !
 
 whoReferences:aPackageString
@@ -8475,6 +8881,10 @@
     "Modified: / 20-09-2006 / 15:00:00 / cg"
 !
 
+isPluginDefinition
+    ^ false
+!
+
 isProjectDefinition
     "concrete i.e. not abstract"