Cédric,
On Jan 30, 2013, at 8:32 AM, Cédric Champeau wrote:
> mmm, reading your original instructions, it seems that your StringExtension file is not in a cz/ocs directory (corresponding to the package). May be the problem.
Hope not -- there seems to be absolutely no reason to sort the sources in folders by package. Eclipse does it (and it's darn annoying), but the compiler does not care, I believe. What's important is that the .class-es are at the proper folders in the jar, and that the compiler makes sure of due to the "package" declaration.
Anyway, I have just downloaded Groovy 2.1 to another computer where there were no groovy at all previously, and it _does_ work all right there.
Which is quadruple weird.
For sweet world I can't find why it does not work on the first machine. I've added a Groovy version log to be sure no old groovy-all.jar gets into the mess; it's all right, we are in 2.1. It must be somewhere in the runtime -- I've tried the JAR from the "ok" machine on the "bad" one, did not work. I've tried the JAR from the "bad" machine on the "ok" one, works all right.
The only difference I can see is the Mac OS X and Java version?!?
I've prepared a simple script (attached below). I'd be grateful, if anyone here happens to have a Mac OS X 10.8, if he could try and let me know the result; also, I'd be grateful if any of you Groovy Gurus might see the culprit why this might not work on my 10.8 machine -- details of the sources below in the script :-O
Here are the results on my two computers:
202 /tmp> ./tst /Users/ocs/groovy-2.1.0/embeddable/groovy-all-2.1.0.jar
ProductName: Mac OS X
ProductVersion: 10.7.3
BuildVersion: 11D50d
java version "1.6.0_31"
Java(TM) SE Runtime Environment (build 1.6.0_31-b04-415-11M3646)
Java HotSpot(TM) 64-Bit Server VM (build 20.6-b01-415, mixed mode)
- compiling StringExtension.groovy
- creating jar
- compiling test
- running
Groovy 2.1.0
direct IS OK
extension IS OK
- done
203 /tmp>
255 /tmp> ./tst /Users/ocs/Downloads/groovy-sdk-2.1.0/embeddable/groovy-all-2.1.0.jar
ProductName: Mac OS X
ProductVersion: 10.8
BuildVersion: 12A269
java version "1.6.0_33"
Java(TM) SE Runtime Environment (build 1.6.0_33-b03-424-11M3720)
Java HotSpot(TM) 64-Bit Server VM (build 20.8-b03-424, mixed mode)
- compiling StringExtension.groovy
- creating jar
- compiling test
- running
Groovy 2.1.0
direct IS OK
Exception in thread "main" groovy.lang.MissingMethodException: No signature of method: java.lang.String.reverseToUpperCase() is applicable for argument types: () values: []
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:55)
at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:46)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112)
at test.run(test.groovy:4)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1085)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:909)
at org.codehaus.groovy.runtime.InvokerHelper.invokePogoMethod(InvokerHelper.java:848)
at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:831)
at org.codehaus.groovy.runtime.InvokerHelper.runScript(InvokerHelper.java:407)
at org.codehaus.groovy.runtime.InvokerHelper$runScript.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
at test.main(test.groovy)
- done
256 /tmp>
Thanks a big lot for all the help!
OC
=== here's the script:
#!/bin/zsh
if [[ -z $1 ]] ; then
echo "Checks Groovy extensions. Usage:\n"
echo "$0 groovy-all-jar-path [testdirname]\n"
echo "The test dir, default 'test', will be created in /tmp"
echo "groovy/java bin must be at path, so that groovyc/java/jar can be run"
exit 0
fi
TD=${2-test}
if [[ -d /tmp/$TD ]] ; then
echo /tmp/$TD already exists, use another test dir name
exit 0
fi
sw_vers
java -version
mkdir -p /tmp/$TD/jardir/META-INF/services
pushd /tmp/$TD
echo "package cz.ocs\nclass StringExtension {\nstatic String reverseToUpperCase(String self) {\nStringBuilder sb = new StringBuilder(self)\nsb.reverse()\nsb.toString().toUpperCase()\n}\n}" > StringExtension.groovy
echo "- compiling StringExtension.groovy"
if groovyc -cp "$1" -d jardir StringExtension.groovy ; then
echo "moduleName=OCSExtensions\nmoduleVersion=1.0\nextensionClasses=cz.ocs.StringExtension\nstaticExtensionClasses=" > jardir/META-INF/services/org.codehaus.groovy.runtime.ExtensionModule
echo "- creating jar"
if jar -cf jar.jar -C jardir . ; then
echo "import cz.ocs.*\nprintln \"Groovy \${GroovySystem.getVersion()}\"\nprintln \"direct \${StringExtension.reverseToUpperCase('KO SI')}\"\nprintln \"extension \${'KO SI'.reverseToUpperCase()}\"" > test.groovy
echo "- compiling test"
if groovyc -cp "$1:jar.jar" test.groovy ; then
echo "- running"
java -cp "$1:jar.jar:." test
fi
fi
fi
popd
rm -rf /tmp/$TD
echo "- done"