1919package groovy.console.ui
2020
2121import groovy.grape.Grape
22- import groovy.grape.GrapeIvy
23- import org.apache.ivy.core.event.IvyListener
24- import org.apache.ivy.core.event.download.PrepareDownloadEvent
25- import org.apache.ivy.core.event.resolve.StartResolveEvent
22+ import groovy.grape.GrapeEngine
2623
2724/**
2825 * Groovy Swing console.
@@ -36,29 +33,30 @@ class ConsoleIvyPlugin {
3633
3734 def addListener (Console console ) {
3835 savedConsole = console
39-
40- ((GrapeIvy ) Grape . instance). ivyInstance. eventManager. addIvyListener([progress : { ivyEvent ->
41- switch (ivyEvent) {
42- case StartResolveEvent :
43- ivyEvent. moduleDescriptor. dependencies. each { it ->
44- def name = it. toString()
45- if (! resolvedDependencies. contains(name)) {
46- resolvedDependencies << name
47- savedConsole. showMessage " Resolving ${ name} ..."
36+ GrapeEngine engine = Grape . instance
37+ if (engine?. class?. name == ' groovy.grape.ivy.GrapeIvy' && engine. metaClass. respondsTo(engine, ' getIvyInstance' , Closure )) {
38+ engine. ivyInstance. eventManager. addIvyListener(engine. makeIvyListener{ ivyEvent ->
39+ switch (ivyEvent. class. simpleName) {
40+ case ' StartResolveEvent' :
41+ ivyEvent. moduleDescriptor. dependencies. each { it ->
42+ def name = it. toString()
43+ if (! resolvedDependencies. contains(name)) {
44+ resolvedDependencies << name
45+ savedConsole. showMessage " Resolving ${ name} ..."
46+ }
4847 }
49- }
50- break
51- case PrepareDownloadEvent :
52- ivyEvent . artifacts . each { it ->
53- def name = it . toString()
54- if ( ! downloadedArtifacts. contains(name)) {
55- downloadedArtifacts << name
56- savedConsole . showMessage " Downloading artifact ${ name } ... "
48+ break
49+ case ' PrepareDownloadEvent ' :
50+ ivyEvent . artifacts . each { it ->
51+ def name = it . toString()
52+ if ( ! downloadedArtifacts . contains(name)) {
53+ downloadedArtifacts << name
54+ savedConsole . showMessage " Downloading artifact ${ name} ... "
55+ }
5756 }
58- }
59- break
60- }
61- }] as IvyListener )
62-
57+ break
58+ }
59+ })
60+ }
6361 }
6462}
0 commit comments