From 5aba3272c20065b5c260b6ccbe4c065528df078e Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Wed, 6 Nov 2013 12:37:33 +0000 Subject: [PATCH] Add support for @GrabResolver to AetherGrapeEngine @GrabResolver can now be used to add a repository to the list that is used for dependency resolution. Any repository that is added via the annotation will then be available for the lifetime of the AetherGrapeEngine instance. In reality, this equates to the lifetime of the Boot application. This is in keeping with the documented default behaviour [1]: "By default, the grape subsystem is shared globally, so added resolvers will become available for any subsequent grab calls". [1] - http://groovy.codehaus.org/api/groovy/lang/GrabResolver.html [bs-345] [60145036] --- .../cli/compiler/grape/AetherGrapeEngine.java | 13 ++++++++----- .../compiler/grape/AetherGrapeEngineTests.java | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngine.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngine.java index 212b8b5d275..7fb1d56ecc9 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngine.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngine.java @@ -216,6 +216,14 @@ public class AetherGrapeEngine implements GrapeEngine { return files; } + @Override + public void addResolver(Map args) { + String name = (String) args.get("name"); + String root = (String) args.get("root"); + + addRemoteRepository(this.repositories, name, root); + } + @Override public Map>> enumerateGrapes() { throw new UnsupportedOperationException("Grape enumeration is not supported"); @@ -236,11 +244,6 @@ public class AetherGrapeEngine implements GrapeEngine { throw new UnsupportedOperationException("Listing dependencies is not supported"); } - @Override - public void addResolver(Map args) { - throw new UnsupportedOperationException("Adding a resolver is not supported"); - } - @Override public Object grab(String endorsedModule) { throw new UnsupportedOperationException( diff --git a/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngineTests.java b/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngineTests.java index 0403afda200..76f47ac4dd7 100644 --- a/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngineTests.java +++ b/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngineTests.java @@ -85,6 +85,16 @@ public class AetherGrapeEngineTests { } } + @Test + public void resolutionWithCustomResolver() { + Map args = new HashMap(); + this.grapeEngine.addResolver(createResolver("restlet.org", + "http://maven.restlet.org")); + this.grapeEngine.grab(args, + createDependency("org.restlet", "org.restlet", "1.1.6")); + assertEquals(1, this.groovyClassLoader.getURLs().length); + } + private Map createDependency(String group, String module, String version) { Map dependency = new HashMap(); @@ -100,4 +110,11 @@ public class AetherGrapeEngineTests { dependency.put("transitive", transitive); return dependency; } + + private Map createResolver(String name, String url) { + Map resolver = new HashMap(); + resolver.put("name", name); + resolver.put("root", url); + return resolver; + } }