Initial tests for commiting Java classes.
authorJan Vrany <jan.vrany@fit.cvut.cz>
Tue, 05 Aug 2014 23:02:02 +0100
changeset 455 50899df3e8c1
parent 454 d17370e0936e
child 456 53ccffa236ed
Initial tests for commiting Java classes.
mercurial/HGStXTests.st
--- a/mercurial/HGStXTests.st	Thu Jul 31 09:46:33 2014 +0100
+++ b/mercurial/HGStXTests.st	Tue Aug 05 23:02:02 2014 +0100
@@ -96,7 +96,13 @@
         ]
     ].
     Class withoutUpdatingChangesDo:[
-        classes do:[:cls|Smalltalk removeClass: cls].
+        classes do:[:cls|
+            Smalltalk removeClass: cls.
+            cls isJavaClass ifTrue:[ 
+                JavaVM registry unregisterClass: cls.
+            ].
+        ].
+
         methods do:[:m|m mclass removeSelector: m selector]
     ].
 "/    Delay waitForSeconds: 1.
@@ -112,7 +118,7 @@
     ]
 
     "Created: / 16-11-2012 / 19:00:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 18-03-2013 / 19:12:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 04-08-2014 / 01:32:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 test_infrastructure
@@ -1180,92 +1186,6 @@
     "Modified: / 05-03-2014 / 21:47:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
-test_commit_16a
-    "
-    Test correct fileout if Java extensions
-    "
-
-    | repo pmN111 ctN111 java_lang_String changeset |
-
-    "/ Hack for rel 6.2.2 - should use 'self skipIf: ... '
-    "/ but this is not supported by 6.2.2's SUnit..."
-    (Smalltalk versionString = '6.2.2') ifTrue:[ ^ self ].
-
-    repo := self repositoryNamed: 'mocks/hg/p5'.
-    self assert: (Smalltalk loadPackage:'mocks:hg/p5').
-
-    "/ Do skipIf after package is loaded!!!!!! otherwise the
-    "/ Java extension is not loaded!!
-
-    self skipIf: self stxlibjavaAvailable not description: 'STX:LIBJAVA not available'.
-
-    java_lang_String := Java classForName: 'java.lang.String'.
-    (Compiler compile:'test_commit_16a ^ #foo'  forClass: java_lang_String)
-        package:#'mocks:hg/p5'.
-    self assert: (java_lang_String methodDictionary includesKey:#test_commit_16a).
-
-    pmN111 := HGPackageWorkingCopy named: #'mocks:hg/p5'.
-    ctN111 := pmN111 commitTask.
-    ctN111 message:'test_commit_16a '.
-    ctN111 do.
-    "
-    repo workingCopy browse
-    "
-    changeset := repo @ 2.
-
-    self assert: (changeset changes contains:[:change | change isAdded ]).
-    self deny: (changeset changes contains:[:change | change isRemoved ]).
-
-    self assert: (changeset / 'java' / 'extensions' / 'java' / 'lang' / 'String.st' ) notNil.
-
-    "Created: / 29-11-2013 / 16:25:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 05-03-2014 / 21:47:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-test_commit_16b
-    "
-    Test covering issue #26: Java extension files are removed.
-
-    Check, that if the particular class is not loaded in the system,
-    extension file is kept intact.
-    "
-
-    | repo pmN111 ctN111 changeset |
-
-    "/ Hack for rel 6.2.2 - should use 'self skipIf: ... '
-    "/ but this is not supported by 6.2.2's SUnit..."
-    (Smalltalk versionString = '6.2.2') ifTrue:[ ^ self ].
-
-
-    repo := self repositoryNamed: 'mocks/hg/p5'.
-    self assert: (Smalltalk loadPackage:'mocks:hg/p5').
-
-    "/ Do skipIf after package is loaded!!!!!! otherwise the
-    "/ Java extension is not loaded!!
-    self skipIf: self stxlibjavaAvailable not description: 'STX:LIBJAVA not available'.
-
-    "/ Flush Java to make sure java.lang.Object is not loaded.
-    (Smalltalk at:#Java) flushAllJavaResources.
-
-
-    pmN111 := HGPackageWorkingCopy named: #'mocks:hg/p5'.
-    ctN111 := pmN111 commitTask.
-    ctN111 message:'test_commit_16a '.
-    ctN111 do.
-    "
-    repo workingCopy browse
-    "
-    changeset := repo @ 2.
-
-    self deny: (changeset changes contains:[:change | change isAdded ]).
-    self deny: (changeset changes contains:[:change | change isRemoved ]).
-
-    self assert: (changeset / 'java' / 'extensions' / 'java' / 'lang' / 'Object.st' ) notNil.
-
-    "Created: / 29-11-2013 / 17:34:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 05-03-2014 / 21:47:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
 test_commit_17a
     "
     Test class renames.
@@ -1708,6 +1628,189 @@
     "Created: / 01-05-2014 / 09:16:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
+!HGStXTests methodsFor:'tests - commit - java'!
+
+test_commit_16a
+    "
+    Test correct fileout if Java extensions
+    "
+
+    | repo pmN111 ctN111 java_lang_String changeset |
+
+    "/ Hack for rel 6.2.2 - should use 'self skipIf: ... '
+    "/ but this is not supported by 6.2.2's SUnit..."
+    (Smalltalk versionString = '6.2.2') ifTrue:[ ^ self ].
+
+    repo := self repositoryNamed: 'mocks/hg/p5'.
+    self assert: (Smalltalk loadPackage:'mocks:hg/p5').
+
+    "/ Do skipIf after package is loaded!!!!!! otherwise the
+    "/ Java extension is not loaded!!
+
+    self skipIf: self stxlibjavaAvailable not description: 'STX:LIBJAVA not available'.
+
+    java_lang_String := Java classForName: 'java.lang.String'.
+    (Compiler compile:'test_commit_16a ^ #foo'  forClass: java_lang_String)
+        package:#'mocks:hg/p5'.
+    self assert: (java_lang_String methodDictionary includesKey:#test_commit_16a).
+
+    pmN111 := HGPackageWorkingCopy named: #'mocks:hg/p5'.
+    ctN111 := pmN111 commitTask.
+    ctN111 message:'test_commit_16a '.
+    ctN111 do.
+    "
+    repo workingCopy browse
+    "
+    changeset := repo @ 2.
+
+    self assert: (changeset changes contains:[:change | change isAdded ]).
+    self deny: (changeset changes contains:[:change | change isRemoved ]).
+
+    self assert: (changeset / 'java' / 'extensions' / 'java' / 'lang' / 'String.st' ) notNil.
+
+    "Created: / 29-11-2013 / 16:25:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 05-03-2014 / 21:47:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+test_commit_16b
+    "
+    Test covering issue #26: Java extension files are removed.
+
+    Check, that if the particular class is not loaded in the system,
+    extension file is kept intact.
+    "
+
+    | repo pmN111 ctN111 changeset |
+
+    "/ Hack for rel 6.2.2 - should use 'self skipIf: ... '
+    "/ but this is not supported by 6.2.2's SUnit..."
+    (Smalltalk versionString = '6.2.2') ifTrue:[ ^ self ].
+
+
+    repo := self repositoryNamed: 'mocks/hg/p5'.
+    self assert: (Smalltalk loadPackage:'mocks:hg/p5').
+
+    "/ Do skipIf after package is loaded!!!!!! otherwise the
+    "/ Java extension is not loaded!!
+    self skipIf: self stxlibjavaAvailable not description: 'STX:LIBJAVA not available'.
+
+    "/ Flush Java to make sure java.lang.Object is not loaded.
+    (Smalltalk at:#Java) flushAllJavaResources.
+
+
+    pmN111 := HGPackageWorkingCopy named: #'mocks:hg/p5'.
+    ctN111 := pmN111 commitTask.
+    ctN111 message:'test_commit_16a '.
+    ctN111 do.
+    "
+    repo workingCopy browse
+    "
+    changeset := repo @ 2.
+
+    self deny: (changeset changes contains:[:change | change isAdded ]).
+    self deny: (changeset changes contains:[:change | change isRemoved ]).
+
+    self assert: (changeset / 'java' / 'extensions' / 'java' / 'lang' / 'Object.st' ) notNil.
+
+    "Created: / 29-11-2013 / 17:34:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 05-03-2014 / 21:47:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+test_commit_java_01a
+    "
+    Test commit of Java classes
+    "
+
+    | repo classes pm ct changeset |
+
+    "/ Hack for rel 6.2.2 - should use 'self skipIf: ... '
+    "/ but this is not supported by 6.2.2's SUnit..."
+    (Smalltalk versionString = '6.2.2') ifTrue:[ ^ self ].
+
+    repo := self repositoryNamed: 'mocks/hg/p5'.
+    self assert: (Smalltalk loadPackage:'mocks:hg/p5').
+
+    "/ Do skipIf after package is loaded!!!!!! otherwise the
+    "/ Java extension is not loaded!!
+
+    self skipIf: (self stxlibjavaAvailableRequireReboot: false) not description: 'STX:LIBJAVA not available'.
+
+    classes := JavaCompiler compile:'
+package mocks.hg.p5;
+
+@stx.libjava.annotation.Package("mocks:hg/p5")
+class Foo {
+}
+'.
+    JavaVM registry registerClasses: classes.
+    
+
+    pm := HGPackageWorkingCopy named: #'mocks:hg/p5'.
+    ct := pm commitTask.
+    ct message:'test_commit_java_01'.
+    ct do.
+    "
+    repo workingCopy browse
+    "
+    changeset := repo @ 2.
+
+    self assert: (changeset changes select:[:change | change isAdded ]) size == 1.
+
+    self assert: (changeset / 'java' / 'src' / 'mocks' / 'hg' / 'p5' / 'Foo.java' ) notNil.
+
+    "Created: / 04-08-2014 / 01:42:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 05-08-2014 / 22:48:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+test_commit_java_01b
+    "
+    Test commit of Java class with nested class
+    "
+
+    | repo classes pm ct changeset |
+
+    "/ Hack for rel 6.2.2 - should use 'self skipIf: ... '
+    "/ but this is not supported by 6.2.2's SUnit..."
+    (Smalltalk versionString = '6.2.2') ifTrue:[ ^ self ].
+
+    repo := self repositoryNamed: 'mocks/hg/p5'.
+    self assert: (Smalltalk loadPackage:'mocks:hg/p5').
+
+    "/ Do skipIf after package is loaded!!!!!! otherwise the
+    "/ Java extension is not loaded!!
+
+    self skipIf: (self stxlibjavaAvailableRequireReboot: false) not description: 'STX:LIBJAVA not available'.
+
+    classes := JavaCompiler compile:'
+package mocks.hg.p5;
+
+@stx.libjava.annotation.Package("mocks:hg/p5")
+public class Foo {
+    public class Bar {
+        public class Baz {
+        }
+    }
+}
+'.
+    JavaVM registry registerClasses: classes.
+    
+
+    pm := HGPackageWorkingCopy named: #'mocks:hg/p5'.
+    ct := pm commitTask.
+    ct message:'test_commit_java_01'.
+    ct do.
+    "
+    repo workingCopy browse
+    "
+    changeset := repo @ 2.
+
+    self assert: (changeset changes select:[:change | change isAdded ]) size == 1.
+
+    self assert: (changeset / 'java' / 'src' / 'mocks' / 'hg' / 'p5' / 'Foo.java' ) notNil.
+
+    "Created: / 04-08-2014 / 01:43:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
 !HGStXTests methodsFor:'tests - commit - nested'!
 
 test_commit_nested_01a
@@ -3584,34 +3687,41 @@
 !
 
 stxlibjavaAvailable
-    "raise an error: this method should be implemented (TODO)"
+    ^ self stxlibjavaAvailableRequireReboot: true.
+
+    "Created: / 29-11-2013 / 16:21:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 04-08-2014 / 01:39:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+stxlibjavaAvailableRequireReboot: reboot
 
     (Smalltalk at:#JavaVM) isNil ifTrue:[
-        Smalltalk loadPackage:'stx:libjava'.
+        [
+            Smalltalk loadPackage:'stx:libjava'.
+            Smalltalk loadPackage:'stx:libjava/tools'.
+        ] on: PackageLoadError do:[
+            ^ false.
+        ]
     ].
-    (Smalltalk at:#JavaVM) isNil ifTrue:[
-        ^ false
-    ].
-    (Smalltalk at:#Java) isNil ifTrue:[
+
+    ((Smalltalk at:#JavaVM) isNil or:[(Smalltalk at:#Java) isNil]) ifTrue:[
         ^ false
     ].
-    ^ [
-        (Smalltalk at:#JavaVM) booted ifTrue:[
-            "/ Sorry, flush it...
-            (Smalltalk at:#Java) flushAllJavaResources.
-        ].
-
-        "/ Opps, workaround - have to nil out Java:ExtensionsPathPackages
-        Smalltalk at: #'Java:ExtensionsPathPackages' put: nil.
-
-        "/ Now, initialize ot..."
-        (Smalltalk at:#Java) initialize.
-        (Smalltalk at:#JavaVM) initializeVM.
-        true.
-    ] on:Error do:[:ex | false ]
-
-    "Created: / 29-11-2013 / 16:21:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 29-11-2013 / 17:30:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+
+    ((Smalltalk at:#JavaVM) booted not or:[ reboot ]) ifTrue:[
+        ^ [
+            "/ Opps, workaround - have to nil out Java:ExtensionsPathPackages
+            Smalltalk at: #'Java:ExtensionsPathPackages' put: nil.
+            (Smalltalk at:#JavaVM) reboot.
+            true.
+        ] on:Error do:[:ex | 
+            false 
+        ]
+    ].
+
+    ^ true.
+
+    "Created: / 04-08-2014 / 01:36:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !HGStXTests class methodsFor:'documentation'!