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]
This commit is contained in:
Andy Wilkinson 2013-11-06 12:37:33 +00:00
parent c2488b1a9b
commit 5aba3272c2
2 changed files with 25 additions and 5 deletions

View File

@ -216,6 +216,14 @@ public class AetherGrapeEngine implements GrapeEngine {
return files;
}
@Override
public void addResolver(Map<String, Object> args) {
String name = (String) args.get("name");
String root = (String) args.get("root");
addRemoteRepository(this.repositories, name, root);
}
@Override
public Map<String, Map<String, List<String>>> 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<String, Object> args) {
throw new UnsupportedOperationException("Adding a resolver is not supported");
}
@Override
public Object grab(String endorsedModule) {
throw new UnsupportedOperationException(

View File

@ -85,6 +85,16 @@ public class AetherGrapeEngineTests {
}
}
@Test
public void resolutionWithCustomResolver() {
Map<String, Object> args = new HashMap<String, Object>();
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<String, Object> createDependency(String group, String module,
String version) {
Map<String, Object> dependency = new HashMap<String, Object>();
@ -100,4 +110,11 @@ public class AetherGrapeEngineTests {
dependency.put("transitive", transitive);
return dependency;
}
private Map<String, Object> createResolver(String name, String url) {
Map<String, Object> resolver = new HashMap<String, Object>();
resolver.put("name", name);
resolver.put("root", url);
return resolver;
}
}