Skip to content

Commit 5aba327

Browse files
committed
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]
1 parent c2488b1 commit 5aba327

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngine.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,14 @@ private List<File> getFiles(DependencyResult dependencyResult) {
216216
return files;
217217
}
218218

219+
@Override
220+
public void addResolver(Map<String, Object> args) {
221+
String name = (String) args.get("name");
222+
String root = (String) args.get("root");
223+
224+
addRemoteRepository(this.repositories, name, root);
225+
}
226+
219227
@Override
220228
public Map<String, Map<String, List<String>>> enumerateGrapes() {
221229
throw new UnsupportedOperationException("Grape enumeration is not supported");
@@ -236,11 +244,6 @@ public Map[] listDependencies(ClassLoader classLoader) {
236244
throw new UnsupportedOperationException("Listing dependencies is not supported");
237245
}
238246

239-
@Override
240-
public void addResolver(Map<String, Object> args) {
241-
throw new UnsupportedOperationException("Adding a resolver is not supported");
242-
}
243-
244247
@Override
245248
public Object grab(String endorsedModule) {
246249
throw new UnsupportedOperationException(

spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngineTests.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@ public void resolutionWithSnapshotRepositoriesDisabled() {
8585
}
8686
}
8787

88+
@Test
89+
public void resolutionWithCustomResolver() {
90+
Map<String, Object> args = new HashMap<String, Object>();
91+
this.grapeEngine.addResolver(createResolver("restlet.org",
92+
"http://maven.restlet.org"));
93+
this.grapeEngine.grab(args,
94+
createDependency("org.restlet", "org.restlet", "1.1.6"));
95+
assertEquals(1, this.groovyClassLoader.getURLs().length);
96+
}
97+
8898
private Map<String, Object> createDependency(String group, String module,
8999
String version) {
90100
Map<String, Object> dependency = new HashMap<String, Object>();
@@ -100,4 +110,11 @@ private Map<String, Object> createDependency(String group, String module,
100110
dependency.put("transitive", transitive);
101111
return dependency;
102112
}
113+
114+
private Map<String, Object> createResolver(String name, String url) {
115+
Map<String, Object> resolver = new HashMap<String, Object>();
116+
resolver.put("name", name);
117+
resolver.put("root", url);
118+
return resolver;
119+
}
103120
}

0 commit comments

Comments
 (0)