From 0f52bbc5607ad91fcd3fa2791b2130c5c0d4ee96 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Wed, 16 Jun 2021 12:24:38 +0100 Subject: [PATCH] Stop using ConfigureUtil in BomExtension While we're building with Gradle 6.9 at the moment and ConfigureUtil has only been deprecated in Gradle 7.1, it doesn't do any harm to stop using it now. Closes gh-26928 --- .../boot/build/bom/BomExtension.java | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/buildSrc/src/main/java/org/springframework/boot/build/bom/BomExtension.java b/buildSrc/src/main/java/org/springframework/boot/build/bom/BomExtension.java index 95f87bd498..22eb275795 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/bom/BomExtension.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/bom/BomExtension.java @@ -47,11 +47,11 @@ import org.gradle.api.Project; import org.gradle.api.Task; import org.gradle.api.artifacts.Configuration; import org.gradle.api.artifacts.dsl.DependencyHandler; +import org.gradle.api.model.ObjectFactory; import org.gradle.api.plugins.JavaPlatformPlugin; import org.gradle.api.publish.maven.tasks.GenerateMavenPom; import org.gradle.api.tasks.Sync; import org.gradle.api.tasks.TaskExecutionException; -import org.gradle.util.ConfigureUtil; import org.w3c.dom.Document; import org.w3c.dom.NodeList; @@ -77,7 +77,7 @@ public class BomExtension { private final List libraries = new ArrayList<>(); - private final UpgradeHandler upgradeHandler = new UpgradeHandler(); + private final UpgradeHandler upgradeHandler; private final DependencyHandler dependencyHandler; @@ -85,6 +85,7 @@ public class BomExtension { public BomExtension(DependencyHandler dependencyHandler, Project project) { this.dependencyHandler = dependencyHandler; + this.upgradeHandler = project.getObjects().newInstance(UpgradeHandler.class); this.project = project; } @@ -92,8 +93,8 @@ public class BomExtension { return this.libraries; } - public void upgrade(Closure closure) { - ConfigureUtil.configure(closure, this.upgradeHandler); + public void upgrade(Action action) { + action.execute(this.upgradeHandler); } public Upgrade getUpgrade() { @@ -101,9 +102,10 @@ public class BomExtension { this.upgradeHandler.gitHub.repository, this.upgradeHandler.gitHub.issueLabels)); } - public void library(String name, String version, Closure closure) { - LibraryHandler libraryHandler = new LibraryHandler(); - ConfigureUtil.configure(closure, libraryHandler); + public void library(String name, String version, Action action) { + ObjectFactory objects = this.project.getObjects(); + LibraryHandler libraryHandler = objects.newInstance(LibraryHandler.class); + action.execute(libraryHandler); addLibrary(new Library(name, DependencyVersion.parse(version), libraryHandler.groups, libraryHandler.prohibitedVersions)); } @@ -196,16 +198,16 @@ public class BomExtension { private final List prohibitedVersions = new ArrayList<>(); - public void group(String id, Closure closure) { + public void group(String id, Action action) { GroupHandler groupHandler = new GroupHandler(id); - ConfigureUtil.configure(closure, groupHandler); + action.execute(groupHandler); this.groups .add(new Group(groupHandler.id, groupHandler.modules, groupHandler.plugins, groupHandler.imports)); } - public void prohibit(String range, Closure closure) { + public void prohibit(String range, Action action) { ProhibitedVersionHandler prohibitedVersionHandler = new ProhibitedVersionHandler(); - ConfigureUtil.configure(closure, prohibitedVersionHandler); + action.execute(prohibitedVersionHandler); try { this.prohibitedVersions.add(new ProhibitedVersion(VersionRange.createFromVersionSpec(range), prohibitedVersionHandler.reason)); @@ -258,7 +260,10 @@ public class BomExtension { Object arg = ((Object[]) args)[0]; if (arg instanceof Closure) { ExclusionHandler exclusionHandler = new ExclusionHandler(); - ConfigureUtil.configure((Closure) arg, exclusionHandler); + Closure closure = (Closure) arg; + closure.setResolveStrategy(Closure.DELEGATE_FIRST); + closure.setDelegate(exclusionHandler); + closure.call(exclusionHandler); return new Module(name, exclusionHandler.exclusions); } } @@ -289,8 +294,8 @@ public class BomExtension { this.upgradePolicy = upgradePolicy; } - public void gitHub(Closure closure) { - ConfigureUtil.configure(closure, this.gitHub); + public void gitHub(Action action) { + action.execute(this.gitHub); } }