You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2026/03/19 20:41:18 UTC
(groovy) 01/02: minor refactor: remove hard compile-time dependency for ConsoleIvyPlugin
This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 64f581612dc61c9f6554104317ea9837f8337e1b
Author: Paul King <pa...@asert.com.au>
AuthorDate: Fri Mar 20 06:33:29 2026 +1000
minor refactor: remove hard compile-time dependency for ConsoleIvyPlugin
---
src/main/groovy/groovy/grape/GrapeIvy.groovy | 5 +++
.../groovy/console/ui/ConsoleIvyPlugin.groovy | 50 +++++++++++-----------
2 files changed, 29 insertions(+), 26 deletions(-)
diff --git a/src/main/groovy/groovy/grape/GrapeIvy.groovy b/src/main/groovy/groovy/grape/GrapeIvy.groovy
index b2d6a61217..1ecc9141ee 100644
--- a/src/main/groovy/groovy/grape/GrapeIvy.groovy
+++ b/src/main/groovy/groovy/grape/GrapeIvy.groovy
@@ -28,6 +28,7 @@ import org.apache.groovy.plugin.GroovyRunner
import org.apache.groovy.plugin.GroovyRunnerRegistry
import org.apache.ivy.Ivy
import org.apache.ivy.core.IvyContext
+import org.apache.ivy.core.event.IvyListener
import org.apache.ivy.core.event.download.PrepareDownloadEvent
import org.apache.ivy.core.event.resolve.StartResolveEvent
import org.apache.ivy.core.module.descriptor.Configuration
@@ -730,6 +731,10 @@ class GrapeIvy implements GrapeEngine {
resolvedDependencies = []
downloadedArtifacts = []
}
+
+ IvyListener makeIvyListener(Closure c) {
+ [progress: c] as IvyListener
+ }
}
@CompileStatic
diff --git a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/ConsoleIvyPlugin.groovy b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/ConsoleIvyPlugin.groovy
index 9af8fce759..286620bcad 100644
--- a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/ConsoleIvyPlugin.groovy
+++ b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/ConsoleIvyPlugin.groovy
@@ -19,10 +19,7 @@
package groovy.console.ui
import groovy.grape.Grape
-import groovy.grape.GrapeIvy
-import org.apache.ivy.core.event.IvyListener
-import org.apache.ivy.core.event.download.PrepareDownloadEvent
-import org.apache.ivy.core.event.resolve.StartResolveEvent
+import groovy.grape.GrapeEngine
/**
* Groovy Swing console.
@@ -36,29 +33,30 @@ class ConsoleIvyPlugin {
def addListener(Console console) {
savedConsole = console
-
- ((GrapeIvy) Grape.instance).ivyInstance.eventManager.addIvyListener([progress: { ivyEvent ->
- switch (ivyEvent) {
- case StartResolveEvent:
- ivyEvent.moduleDescriptor.dependencies.each { it ->
- def name = it.toString()
- if (!resolvedDependencies.contains(name)) {
- resolvedDependencies << name
- savedConsole.showMessage "Resolving ${name} ..."
+ GrapeEngine engine = Grape.instance
+ if (engine?.class?.name == 'groovy.grape.ivy.GrapeIvy' && engine.metaClass.respondsTo(engine, 'getIvyInstance', Closure)) {
+ engine.ivyInstance.eventManager.addIvyListener(engine.makeIvyListener{ ivyEvent ->
+ switch (ivyEvent.class.simpleName) {
+ case 'StartResolveEvent':
+ ivyEvent.moduleDescriptor.dependencies.each { it ->
+ def name = it.toString()
+ if (!resolvedDependencies.contains(name)) {
+ resolvedDependencies << name
+ savedConsole.showMessage "Resolving ${name} ..."
+ }
}
- }
- break
- case PrepareDownloadEvent:
- ivyEvent.artifacts.each { it ->
- def name = it.toString()
- if (!downloadedArtifacts.contains(name)) {
- downloadedArtifacts << name
- savedConsole.showMessage "Downloading artifact ${name} ..."
+ break
+ case 'PrepareDownloadEvent':
+ ivyEvent.artifacts.each { it ->
+ def name = it.toString()
+ if (!downloadedArtifacts.contains(name)) {
+ downloadedArtifacts << name
+ savedConsole.showMessage "Downloading artifact ${name} ..."
+ }
}
- }
- break
- }
- }] as IvyListener)
-
+ break
+ }
+ })
+ }
}
}