Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.0-rc-4
-
None
-
Snow Leopard OS X with Java 1.6
Description
There seems to be an issue with Modular Extensions not selecting the correct classes to decorate when @Grabbed
In my groovy-stream project, I define my extension class as:
package groovy.stream ; import groovy.lang.Closure ; import java.util.* ; public class StreamExtension { public static Stream toStream( Closure delegate ) { return Stream.from( delegate ) ; } public static Stream toStream( Iterator delegate ) { return Stream.from( delegate ) ; } public static Stream toStream( Iterable delegate ) { return Stream.from( delegate ) ; } public static Stream toStream( Map delegate ) { return Stream.from( delegate ) ; } }
If you then run a test class:
def m = [ x:1..3, y:5..7 ].toStream().where { x + 4 == y }
assert [[x:1,y:5],[x:2,y:6],[x:3,y:7]] == m.collect()
With groovy -cp groovy-stream-0.3-map.jar testscript.groovy, it all works fine, however if you push the jar to a maven repo, and change the test script to:
@GrabResolver( name='bloidonia', root='https://raw.github.com/timyates/bloidonia-repo/master' ) @Grab('com.bloidonia:groovy-stream:0.3-map') import groovy.stream.Stream def m = [ x:1..3, y:5..7 ].toStream().where { x + 4 == y } assert [[x:1,y:5],[x:2,y:6],[x:3,y:7]] == m.collect()
Then running groovy testscript.groovy, you get the exception:
Caught: groovy.lang.MissingMethodException: No signature of method: java.util.LinkedHashMap.toStream() is applicable for argument types: () values: []
Possible solutions: toString(), toString(), toString(), toString(), toSpreadMap(), spread()
If I change the extension class so that the Map function is replaced with:
public static Stream toStream( LinkedHashMap delegate ) { return Stream.from( delegate ) ; }
Then running:
@GrabResolver( name='bloidonia', root='https://raw.github.com/timyates/bloidonia-repo/master' ) @Grab('com.bloidonia:groovy-stream:0.3') import groovy.stream.Stream def m = [ x:1..3, y:5..7 ].toStream().where { x + 4 == y } assert [[x:1,y:5],[x:2,y:6],[x:3,y:7]] == m.collect()
Works.